Files
2026-11-23 03:28:32 +02:00

38 lines
1.4 KiB
C

#ifndef GW_REALM_PREFERENCE_KEY_H
#define GW_REALM_PREFERENCE_KEY_H
#include <windows.h>
#include <wincrypt.h>
#include <stdint.h>
#include <string.h>
/* Names follow the same printable-ASCII uppercase normalization as SRP.
* Include the deployment namespace to keep unrelated local realms distinct. */
static int gw_realm_preference_digest(const char *scope, size_t scope_bytes,
const char *name, size_t name_bytes,
unsigned char digest[32])
{
static const char domain[] = "WoW-Hybrid realm preference v1";
unsigned char input[sizeof(domain) + 64 + 1 + 32];
size_t i, pos = sizeof(domain);
DWORD size = 32;
int ok = 0;
if (!scope || !scope_bytes || scope_bytes > 64 || !name || !name_bytes || name_bytes > 32)
return 0;
memcpy(input, domain, sizeof(domain));
memcpy(input + pos, scope, scope_bytes);
pos += scope_bytes;
input[pos++] = 0;
for (i = 0; i < name_bytes; i++) {
unsigned char c = (unsigned char)name[i];
if (c < 32 || c > 126) goto done;
input[pos++] = (c >= 'a' && c <= 'z') ? (unsigned char)(c - 'a' + 'A') : c;
}
ok = CryptHashCertificate2(L"SHA256", 0, NULL, input, (DWORD)pos, digest, &size) && size == 32;
done:
SecureZeroMemory(input, sizeof(input));
if (!ok) SecureZeroMemory(digest, 32);
return ok;
}
#endif