Skip to content

Instantly share code, notes, and snippets.

@Davnit
Created April 4, 2016 00:43
Show Gist options
  • Save Davnit/a7177c874251a173f1c5f1c85076f515 to your computer and use it in GitHub Desktop.
Save Davnit/a7177c874251a173f1c5f1c85076f515 to your computer and use it in GitHub Desktop.
bncsutil key hashing
size_t CDKeyDecoder::calculateHash(uint32_t clientToken,
uint32_t serverToken)
{
struct CDKEYHASH kh;
SHA1Context sha;
if (!initialized || !keyOK) return 0;
hashLen = 0;
kh.clientToken = clientToken;
kh.serverToken = serverToken;
switch (keyType) {
case KEY_STARCRAFT:
case KEY_WARCRAFT2:
kh.product = (uint32_t) LSB4(product);
kh.value1 = (uint32_t) LSB4(value1);
kh.value2.s.zero = 0;
kh.value2.s.v = (uint32_t) LSB4(value2);
keyHash = new char[20];
calcHashBuf((char*) &kh, 24, keyHash);
hashLen = 20;
#if DEBUG
bncsutil_debug_message_a("%s: Hash calculated.", cdkey);
bncsutil_debug_dump(keyHash, 20);
#endif
return 20;
case KEY_WARCRAFT3:
kh.product = (uint32_t) MSB4(product);
kh.value1 = (uint32_t) MSB4(value1);
memcpy(kh.value2.l.v, w3value2, 10);
if (SHA1Reset(&sha))
return 0;
if (SHA1Input(&sha, (const unsigned char*) &kh, 26))
return 0;
keyHash = new char[20];
if (SHA1Result(&sha, (unsigned char*) keyHash)) {
SHA1Reset(&sha);
return 0;
}
SHA1Reset(&sha);
hashLen = 20;
#if DEBUG
bncsutil_debug_message_a("%s: Hash calculated.", cdkey);
bncsutil_debug_dump(keyHash, 20);
#endif
return 20;
default:
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment