Verifies the Windows Server 2003-like Product Key. */
| 51 | |
| 52 | /* Verifies the Windows Server 2003-like Product Key. */ |
| 53 | BOOL verifyServerKey( |
| 54 | EC_GROUP *eCurve, |
| 55 | EC_POINT *basePoint, |
| 56 | EC_POINT *publicKey, |
| 57 | CHAR (&pKey)[PK_LENGTH + NULL_TERMINATOR] |
| 58 | ) { |
| 59 | BN_CTX *context = BN_CTX_new(); |
| 60 | |
| 61 | QWORD bKey[2]{}, |
| 62 | pSignature = 0; |
| 63 | |
| 64 | DWORD pData, |
| 65 | pChannelID, |
| 66 | pHash, |
| 67 | pAuthInfo; |
| 68 | |
| 69 | BOOL pUpgrade; |
| 70 | |
| 71 | // Convert Base24 CD-key to bytecode. |
| 72 | unbase24((BYTE *)bKey, pKey); |
| 73 | |
| 74 | // Extract product key segments from bytecode. |
| 75 | unpackServer(bKey, pUpgrade, pChannelID, pHash, pSignature, pAuthInfo); |
| 76 | |
| 77 | pData = pChannelID << 1 | pUpgrade; |
| 78 | |
| 79 | BYTE msgDigest[SHA_DIGEST_LENGTH]{}, |
| 80 | msgBuffer[SHA_MSG_LENGTH_2003]{}, |
| 81 | xBin[FIELD_BYTES_2003]{}, |
| 82 | yBin[FIELD_BYTES_2003]{}; |
| 83 | |
| 84 | // Assemble the first SHA message. |
| 85 | msgBuffer[0x00] = 0x5D; |
| 86 | msgBuffer[0x01] = (pData & 0x00FF); |
| 87 | msgBuffer[0x02] = (pData & 0xFF00) >> 8; |
| 88 | msgBuffer[0x03] = (pHash & 0x000000FF); |
| 89 | msgBuffer[0x04] = (pHash & 0x0000FF00) >> 8; |
| 90 | msgBuffer[0x05] = (pHash & 0x00FF0000) >> 16; |
| 91 | msgBuffer[0x06] = (pHash & 0xFF000000) >> 24; |
| 92 | msgBuffer[0x07] = (pAuthInfo & 0x00FF); |
| 93 | msgBuffer[0x08] = (pAuthInfo & 0xFF00) >> 8; |
| 94 | msgBuffer[0x09] = 0x00; |
| 95 | msgBuffer[0x0A] = 0x00; |
| 96 | |
| 97 | // newSignature = SHA1(5D || Channel ID || Hash || AuthInfo || 00 00) |
| 98 | SHA1(msgBuffer, 11, msgDigest); |
| 99 | |
| 100 | // Translate the byte digest into a 64-bit integer - this is our computed intermediate signature. |
| 101 | // As the signature is only 62 bits long at most, we have to truncate it by shifting the high DWORD right 2 bits (per spec). |
| 102 | QWORD iSignature = NEXTSNBITS(BYDWORD(&msgDigest[4]), 30, 2) << 32 | BYDWORD(msgDigest); |
| 103 | |
| 104 | /* |
| 105 | * |
| 106 | * Scalars: |
| 107 | * e = Hash |
| 108 | * s = Schnorr Signature |
| 109 | * |
| 110 | * Points: |
no test coverage detected