From da7e88b9701deb194b51ab45e4d0ae8367f04eb9 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 5 Jun 2023 15:07:31 +0300 Subject: [PATCH] Fix BYDWORD (implementation mistake) --- src/header.h | 2 +- src/server.cpp | 7 ++----- src/xp.cpp | 3 +-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/header.h b/src/header.h index bc4b7ea..afe0a4c 100644 --- a/src/header.h +++ b/src/header.h @@ -49,7 +49,7 @@ #define HIBYTES(field, bytes) NEXTSNBITS((QWORD)(field), ((bytes) * 8), ((bytes) * 8)) #define LOBYTES(field, bytes) FIRSTNBITS((QWORD)(field), ((bytes) * 8)) -#define BYDWORD(n) (*((n) + 0) | *((n) + 1) << 8 | *((n) + 2) << 16 | *((n) + 3) << 24) +#define BYDWORD(n) (DWORD)(*((n) + 0) | *((n) + 1) << 8 | *((n) + 2) << 16 | *((n) + 3) << 24) #define BITMASK(n) ((1ULL << (n)) - 1) // Confirmation ID generator constants diff --git a/src/server.cpp b/src/server.cpp index d0b077d..e7edb90 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -86,15 +86,12 @@ bool verifyServerKey( SHA1(msgBuffer, 11, msgDigest); - DWORD newHash[2]{}; - - newHash[0] = BYDWORD(msgDigest); - newHash[1] = BYDWORD(&msgDigest[4]) >> 2 & BITMASK(30); + QWORD newHash2 = (QWORD)(BYDWORD(&msgDigest[4]) >> 2 & BITMASK(30)) << 32 | BYDWORD(msgDigest); BIGNUM *x = BN_new(); BIGNUM *y = BN_new(); BIGNUM *s = BN_lebin2bn((BYTE *)&pSignature, sizeof(pSignature), nullptr); - BIGNUM *e = BN_lebin2bn((BYTE *)&newHash, sizeof(newHash), nullptr); + BIGNUM *e = BN_lebin2bn((BYTE *)&newHash2, 8, nullptr); EC_POINT *u = EC_POINT_new(eCurve); EC_POINT *v = EC_POINT_new(eCurve); diff --git a/src/xp.cpp b/src/xp.cpp index 2f12a2a..b9b89d3 100644 --- a/src/xp.cpp +++ b/src/xp.cpp @@ -186,8 +186,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; - pHash &= BITMASK(28); + pHash = BYDWORD(msgDigest) >> 4 & BITMASK(28); /* *