Slight logic tweak for better understanding

This commit is contained in:
Andrew 2023-06-07 02:34:01 +03:00
parent 4f7fb772a5
commit aa8e5ff8e7
2 changed files with 10 additions and 12 deletions

View File

@ -191,12 +191,12 @@ void generateServerKey(
QWORD pRaw[2]{},
pSignature = 0;
BOOL wrong = false;
BOOL noSquare = false;
do {
EC_POINT *r = EC_POINT_new(eCurve);
wrong = false;
noSquare = false;
// Generate a random number c consisting of 512 bits without any constraints.
BN_rand(c, FIELD_BITS_2003, BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY);
@ -295,7 +295,7 @@ void generateServerKey(
// Around half of numbers modulo a prime are not squares -> BN_sqrt_mod fails about half of the times,
// hence if BN_sqrt_mod returns NULL, we need to restart with a different seed.
// s = sqrt(s (mod n))
if (BN_mod_sqrt(s, s, genOrder, numContext) == nullptr) wrong = true;
noSquare = BN_mod_sqrt(s, s, genOrder, numContext) == nullptr;
// s = s (mod n) - e
BN_mod_sub(s, s, e, genOrder, numContext);
@ -324,7 +324,7 @@ void generateServerKey(
}
EC_POINT_free(r);
} while (pSignature > BITMASK(62) || wrong);
} while (pSignature > BITMASK(62) || noSquare);
// ↑ ↑ ↑
// The signature can't be longer than 62 bits, else it will
// overlap with the AuthInfo segment next to it.

View File

@ -148,14 +148,12 @@ void generateXPKey(
*x = BN_new(),
*y = BN_new();
QWORD pRaw[2]{};
QWORD pRaw[2]{},
pSignature = 0;
do {
EC_POINT *r = EC_POINT_new(eCurve);
QWORD pSignature = 0;
DWORD pHash;
// Generate a random number c consisting of 384 bits without any constraints.
BN_rand(c, FIELD_BITS, BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY);
@ -186,7 +184,7 @@ void generateXPKey(
// Translate the byte digest into a 32-bit integer - this is our computed pHash.
// Truncate the pHash to 28 bits.
pHash = BYDWORD(msgDigest) >> 4 & BITMASK(28);
DWORD pHash = BYDWORD(msgDigest) >> 4 & BITMASK(28);
/*
*
@ -228,10 +226,10 @@ void generateXPKey(
}
EC_POINT_free(r);
} while (pRaw[1] > BITMASK(50));
} while (pSignature > BITMASK(55));
// ↑ ↑ ↑
// pRaw[1] can't be longer than 50 bits, else the signature part
// will make the CD-key longer than 25 characters.
// The signature can't be longer than 55 bits, else it will
// make the CD-key longer than 25 characters.
// Convert bytecode to Base24 CD-key.
base24(pKey, (BYTE *)pRaw);