mirror of
https://github.com/Neo-Desktop/WindowsXPKg
synced 2024-12-22 20:40:16 +02:00
Slight logic tweak for better understanding
This commit is contained in:
parent
4f7fb772a5
commit
aa8e5ff8e7
@ -191,12 +191,12 @@ void generateServerKey(
|
|||||||
QWORD pRaw[2]{},
|
QWORD pRaw[2]{},
|
||||||
pSignature = 0;
|
pSignature = 0;
|
||||||
|
|
||||||
BOOL wrong = false;
|
BOOL noSquare = false;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
EC_POINT *r = EC_POINT_new(eCurve);
|
EC_POINT *r = EC_POINT_new(eCurve);
|
||||||
|
|
||||||
wrong = false;
|
noSquare = false;
|
||||||
|
|
||||||
// Generate a random number c consisting of 512 bits without any constraints.
|
// 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);
|
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,
|
// 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.
|
// hence if BN_sqrt_mod returns NULL, we need to restart with a different seed.
|
||||||
// s = sqrt(s (mod n))
|
// 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
|
// s = s (mod n) - e
|
||||||
BN_mod_sub(s, s, e, genOrder, numContext);
|
BN_mod_sub(s, s, e, genOrder, numContext);
|
||||||
@ -324,7 +324,7 @@ void generateServerKey(
|
|||||||
}
|
}
|
||||||
|
|
||||||
EC_POINT_free(r);
|
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
|
// The signature can't be longer than 62 bits, else it will
|
||||||
// overlap with the AuthInfo segment next to it.
|
// overlap with the AuthInfo segment next to it.
|
||||||
|
14
src/xp.cpp
14
src/xp.cpp
@ -148,14 +148,12 @@ void generateXPKey(
|
|||||||
*x = BN_new(),
|
*x = BN_new(),
|
||||||
*y = BN_new();
|
*y = BN_new();
|
||||||
|
|
||||||
QWORD pRaw[2]{};
|
QWORD pRaw[2]{},
|
||||||
|
pSignature = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
EC_POINT *r = EC_POINT_new(eCurve);
|
EC_POINT *r = EC_POINT_new(eCurve);
|
||||||
|
|
||||||
QWORD pSignature = 0;
|
|
||||||
DWORD pHash;
|
|
||||||
|
|
||||||
// Generate a random number c consisting of 384 bits without any constraints.
|
// 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);
|
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.
|
// Translate the byte digest into a 32-bit integer - this is our computed pHash.
|
||||||
// Truncate the pHash to 28 bits.
|
// 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);
|
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
|
// The signature can't be longer than 55 bits, else it will
|
||||||
// will make the CD-key longer than 25 characters.
|
// make the CD-key longer than 25 characters.
|
||||||
|
|
||||||
// Convert bytecode to Base24 CD-key.
|
// Convert bytecode to Base24 CD-key.
|
||||||
base24(pKey, (BYTE *)pRaw);
|
base24(pKey, (BYTE *)pRaw);
|
||||||
|
Loading…
Reference in New Issue
Block a user