Slight refactor, prepare for QWORD upgrade

This commit is contained in:
Andrew 2023-06-04 15:40:08 +03:00
parent 3922223b9f
commit 1c5f93b687
5 changed files with 13 additions and 13 deletions

View File

@ -57,7 +57,7 @@ typedef uint32_t DWORD;
typedef uint64_t QWORD;
// Global variables
extern char charset[];
extern char pCharset[];
// util.cpp
void endian(BYTE *data, int length);
@ -74,8 +74,8 @@ EC_GROUP *initializeEllipticCurve(
);
// key.cpp
void unbase24(DWORD *byteSeq, const char *cdKey);
void base24(char *cdKey, DWORD *byteSeq);
void unbase24(BYTE *byteSeq, const char *cdKey);
void base24(char *cdKey, BYTE *byteSeq);
// cli.cpp
void print_product_key(char *pk);

View File

@ -5,7 +5,7 @@
#include "header.h"
/* Converts from CD-key to a byte sequence. */
void unbase24(DWORD *byteSeq, const char *cdKey) {
void unbase24(BYTE *byteSeq, const char *cdKey) {
BYTE pDecodedKey[PK_LENGTH + NULL_TERMINATOR]{};
BIGNUM *y = BN_new();
@ -14,7 +14,7 @@ void unbase24(DWORD *byteSeq, const char *cdKey) {
// Remove dashes from the CD-key and put it into a Base24 byte array.
for (int i = 0, k = 0; i < strlen(cdKey) && k < PK_LENGTH; i++) {
for (int j = 0; j < 24; j++) {
if (cdKey[i] != '-' && cdKey[i] == charset[j]) {
if (cdKey[i] != '-' && cdKey[i] == pCharset[j]) {
pDecodedKey[k++] = j;
break;
}
@ -34,15 +34,15 @@ void unbase24(DWORD *byteSeq, const char *cdKey) {
int n = BN_num_bytes(y);
// Place the generated code into the byte sequence.
BN_bn2bin(y, (BYTE *)byteSeq);
BN_bn2bin(y, byteSeq);
BN_free(y);
// Reverse the byte sequence.
endian((BYTE *)byteSeq, n);
endian(byteSeq, n);
}
/* Converts from byte sequence to the CD-key. */
void base24(char *cdKey, DWORD *byteSeq) {
void base24(char *cdKey, BYTE *byteSeq) {
BYTE rbyteSeq[16];
BIGNUM *z;
@ -62,7 +62,7 @@ void base24(char *cdKey, DWORD *byteSeq) {
cdKey[25] = 0;
for (int i = 24; i >= 0; i--)
cdKey[i] = charset[BN_div_word(z, 24)];
cdKey[i] = pCharset[BN_div_word(z, 24)];
BN_free(z);
}

View File

@ -4,7 +4,7 @@
#include "header.h"
char charset[] = "BCDFGHJKMPQRTVWXY2346789";
char pCharset[] = "BCDFGHJKMPQRTVWXY2346789";
const std::string filename = "keys.json";
using json = nlohmann::json;

View File

@ -1,6 +1,6 @@
#include "header.h"
char charset[] = "BCDFGHJKMPQRTVWXY2346789";
char pCharset[] = "BCDFGHJKMPQRTVWXY2346789";
void unpackServer(DWORD *osFamily, DWORD *hash, DWORD *sig, DWORD *prefix, DWORD *raw) {

View File

@ -51,7 +51,7 @@ bool verifyXPKey(EC_GROUP *eCurve, EC_POINT *generator, EC_POINT *publicKey, cha
QWORD sig = 0;
unbase24(bKey, cdKey);
unbase24((BYTE *)bKey, cdKey);
// Extract data, hash and signature from the bytecode.
unpackXP(bKey, pID, checkHash, sig);
@ -241,7 +241,7 @@ void generateXPKey(EC_GROUP *eCurve, EC_POINT *generator, BIGNUM *order, BIGNUM
// the CD-key longer than 25 characters.
// Convert the key to Base24.
base24(pKey, bKey);
base24(pKey, (BYTE *)bKey);
BN_free(c);
BN_free(s);