mirror of
https://github.com/Neo-Desktop/WindowsXPKg
synced 2024-12-22 20:40:16 +02:00
Add pack/extract consistency
This commit is contained in:
parent
06920ede2a
commit
63bc103384
28
src/xp.cpp
28
src/xp.cpp
@ -18,32 +18,32 @@
|
|||||||
#include "header.h"
|
#include "header.h"
|
||||||
|
|
||||||
/* Unpacks the Windows XP Product Key. */
|
/* Unpacks the Windows XP Product Key. */
|
||||||
void unpackXP(DWORD *serial, DWORD *hash, DWORD *sig, DWORD *raw) {
|
void unpackXP(DWORD *pRaw, DWORD *pSerial, DWORD *pHash, DWORD *pSignature) {
|
||||||
|
|
||||||
// We're assuming that the quantity of information within the product key is at most 114 bits.
|
// We're assuming that the quantity of information within the product key is at most 114 bits.
|
||||||
// log2(24^25) = 114.
|
// log2(24^25) = 114.
|
||||||
|
|
||||||
// Serial = Bits [0..30] -> 31 bits
|
// Serial = Bits [0..30] -> 31 bits
|
||||||
if (serial)
|
if (pSerial)
|
||||||
serial[0] = raw[0] & 0x7fffffff;
|
pSerial[0] = pRaw[0] & 0x7fffffff;
|
||||||
|
|
||||||
// Hash (e) = Bits [31..58] -> 28 bits
|
// Hash (e) = Bits [31..58] -> 28 bits
|
||||||
if (hash)
|
if (pHash)
|
||||||
hash[0] = ((raw[0] >> 31) | (raw[1] << 1)) & 0xfffffff;
|
pHash[0] = ((pRaw[0] >> 31) | (pRaw[1] << 1)) & 0xfffffff;
|
||||||
|
|
||||||
// Signature (s) = Bits [59..113] -> 55 bits
|
// Signature (s) = Bits [59..113] -> 55 bits
|
||||||
if (sig) {
|
if (pSignature) {
|
||||||
sig[0] = (raw[1] >> 27) | (raw[2] << 5);
|
pSignature[0] = (pRaw[1] >> 27) | (pRaw[2] << 5);
|
||||||
sig[1] = (raw[2] >> 27) | (raw[3] << 5);
|
pSignature[1] = (pRaw[2] >> 27) | (pRaw[3] << 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Packs the Windows XP Product Key. */
|
/* Packs the Windows XP Product Key. */
|
||||||
void packXP(DWORD *raw, const DWORD *serial, const DWORD *hash, const DWORD *sig) {
|
void packXP(DWORD *pRaw, const DWORD *pSerial, const DWORD *pHash, const DWORD *pSignature) {
|
||||||
raw[0] = serial[0] | ((hash[0] & 1) << 31);
|
pRaw[0] = pSerial[0] | ((pHash[0] & 1) << 31);
|
||||||
raw[1] = (hash[0] >> 1) | ((sig[0] & 0x1f) << 27);
|
pRaw[1] = (pHash[0] >> 1) | ((pSignature[0] & 0x1f) << 27);
|
||||||
raw[2] = (sig[0] >> 5) | (sig[1] << 27);
|
pRaw[2] = (pSignature[0] >> 5) | (pSignature[1] << 27);
|
||||||
raw[3] = sig[1] >> 5;
|
pRaw[3] = pSignature[1] >> 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Verify Product Key */
|
/* Verify Product Key */
|
||||||
@ -57,7 +57,7 @@ bool verifyXPKey(EC_GROUP *eCurve, EC_POINT *generator, EC_POINT *publicKey, cha
|
|||||||
unbase24(bKey, cdKey);
|
unbase24(bKey, cdKey);
|
||||||
|
|
||||||
// Extract data, hash and signature from the bytecode.
|
// Extract data, hash and signature from the bytecode.
|
||||||
unpackXP(&pID, &checkHash, sig, bKey);
|
unpackXP(bKey, &pID, &checkHash, sig);
|
||||||
|
|
||||||
// e = Hash
|
// e = Hash
|
||||||
// s = Signature
|
// s = Signature
|
||||||
|
Loading…
Reference in New Issue
Block a user