Generates the Windows Server 2003-like Product Key. */
| 199 | |
| 200 | /* Generates the Windows Server 2003-like Product Key. */ |
| 201 | VOID generateServerKey( |
| 202 | EC_GROUP *eCurve, |
| 203 | EC_POINT *basePoint, |
| 204 | BIGNUM *genOrder, |
| 205 | BIGNUM *privateKey, |
| 206 | DWORD pChannelID, |
| 207 | DWORD pAuthInfo, |
| 208 | BOOL pUpgrade, |
| 209 | CHAR (&pKey)[PK_LENGTH + NULL_TERMINATOR] |
| 210 | ) { |
| 211 | BN_CTX *numContext = BN_CTX_new(); |
| 212 | |
| 213 | BIGNUM *c = BN_new(), |
| 214 | *e = BN_new(), |
| 215 | *s = BN_new(), |
| 216 | *x = BN_new(), |
| 217 | *y = BN_new(); |
| 218 | |
| 219 | QWORD pRaw[2]{}, |
| 220 | pSignature = 0; |
| 221 | |
| 222 | // Data segment of the RPK. |
| 223 | DWORD pData = pChannelID << 1 | pUpgrade; |
| 224 | BOOL noSquare; |
| 225 | |
| 226 | do { |
| 227 | EC_POINT *r = EC_POINT_new(eCurve); |
| 228 | |
| 229 | // Generate a random number c consisting of 512 bits without any constraints. |
| 230 | BN_rand(c, FIELD_BITS_2003, BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY); |
| 231 | |
| 232 | // R = cG |
| 233 | EC_POINT_mul(eCurve, r, nullptr, basePoint, c, numContext); |
| 234 | |
| 235 | // Acquire its coordinates. |
| 236 | // x = R.x; y = R.y; |
| 237 | EC_POINT_get_affine_coordinates(eCurve, r, x, y, numContext); |
| 238 | |
| 239 | BYTE msgDigest[SHA_DIGEST_LENGTH]{}, |
| 240 | msgBuffer[SHA_MSG_LENGTH_2003]{}, |
| 241 | xBin[FIELD_BYTES_2003]{}, |
| 242 | yBin[FIELD_BYTES_2003]{}; |
| 243 | |
| 244 | // Convert resulting point coordinates to bytes. |
| 245 | BN_bn2lebin(x, xBin, FIELD_BYTES_2003); |
| 246 | BN_bn2lebin(y, yBin, FIELD_BYTES_2003); |
| 247 | |
| 248 | // Assemble the first SHA message. |
| 249 | msgBuffer[0x00] = 0x79; |
| 250 | msgBuffer[0x01] = (pData & 0x00FF); |
| 251 | msgBuffer[0x02] = (pData & 0xFF00) >> 8; |
| 252 | |
| 253 | memcpy((void *)&msgBuffer[3], (void *)xBin, FIELD_BYTES_2003); |
| 254 | memcpy((void *)&msgBuffer[3 + FIELD_BYTES_2003], (void *)yBin, FIELD_BYTES_2003); |
| 255 | |
| 256 | // pHash = SHA1(79 || Channel ID || R.x || R.y) |
| 257 | SHA1(msgBuffer, SHA_MSG_LENGTH_2003, msgDigest); |
| 258 |
no test coverage detected