Skip to content

Commit

Permalink
v2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Endermanch committed Apr 12, 2023
1 parent 70e2c6f commit 0e59a27
Show file tree
Hide file tree
Showing 13 changed files with 616 additions and 419 deletions.
2 changes: 2 additions & 0 deletions Keygen.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@
<Image Include="resources\ender.bmp" />
<Image Include="resources\icon.ico" />
<Image Include="resources\logo.bmp" />
<Image Include="resources\musicoff.bmp" />
<Image Include="resources\musicon.bmp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
2 changes: 2 additions & 0 deletions Keygen.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@
<Image Include="resources\icon.ico" />
<Image Include="resources\ender.bmp" />
<Image Include="resources\logo.bmp" />
<Image Include="resources\musicon.bmp" />
<Image Include="resources\musicoff.bmp" />
</ItemGroup>
</Project>
41 changes: 22 additions & 19 deletions header.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#define IDC_INPUT2 1021

#define IDC_IMAGE1 1050
#define IDC_IMAGE2 1051

#define IDC_LABEL1 1055
#define IDC_LABEL2 1056
Expand All @@ -58,76 +59,78 @@ extern const long aXP;
extern const long bXP;

// xp.cpp
int keyXP(
char *pKey,
ul32 *hash,
ul32 *sig,
ul32 nRaw
bool keyXP(
char *pKey,
ul32 nRaw
);

void unpackXP(
ul32 *serial,
ul32 *hash,
ul32 *sig,
ul32 *raw
);
);

void packXP(
ul32 *raw,
ul32 *serial,
ul32 *hash,
ul32 *sig
);
);

void verifyXPKey(
bool verifyXPKey(
EC_GROUP *eCurve,
EC_POINT *generator,
EC_POINT *publicKey,
char *cdKey
);
);

void generateXPKey(
byte *pKey,
char *pKey,
EC_GROUP *eCurve,
EC_POINT *generator,
BIGNUM *order,
BIGNUM *privateKey,
ul32 *pRaw
);
);

// server.cpp
bool keyServer(
char *pKey
);

void unpackServer(
ul32 *osFamily,
ul32 *hash,
ul32 *sig,
ul32 *prefix,
ul32 *raw
);
);

void packServer(
ul32 *raw,
ul32 *osFamily,
ul32 *hash,
ul32 *sig,
ul32 *prefix
);
);

void verifyServerKey(
bool verifyServerKey(
EC_GROUP *eCurve,
EC_POINT *generator,
EC_POINT *public_key,
char *cdKey
);
);

void generateServerKey(
byte *pKey,
char *pKey,
EC_GROUP *eCurve,
EC_POINT *generator,
BIGNUM *order,
BIGNUM *privateKey,
ul32 *osFamily,
ul32 *prefix
);
);

// utilities.cpp
void cprintf(const char *Format, int nColor, ...);
Expand All @@ -149,8 +152,8 @@ EC_GROUP *initializeEllipticCurve(
);

// key.cpp
void unbase24(ul32 *byteSeq, byte *cdKey);
void base24(byte *cdKey, ul32 *byteSeq);
void unbase24(ul32 *byteSeq, const char *cdKey);
void base24(char *cdKey, ul32 *byteSeq);
void printProductKey(const char *pKey);
void printProductID(const ul32 *pRaw);

Expand Down
34 changes: 23 additions & 11 deletions key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "header.h"

/* Convert from byte sequence to the CD-key. */
void base24(byte *cdKey, ul32 *byteSeq) {
void base24(char *cdKey, ul32 *byteSeq) {
byte rbs[16];
BIGNUM *z;

Expand All @@ -31,39 +31,51 @@ void base24(byte *cdKey, ul32 *byteSeq) {
}

/* Convert from CD-key to a byte sequence. */
void unbase24(ul32 *byteSeq, byte *cdKey) {
void unbase24(ul32 *byteSeq, const char *cdKey) {
byte pDecodedKey[PK_LENGTH + NULL_TERMINATOR]{};
BIGNUM *y = BN_new();

BN_zero(y);

// 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]) {
pDecodedKey[k++] = j;
break;
}
}
}

// Empty byte sequence.
memset(byteSeq, 0, 16);

// For each character in product key, place its ASCII-code.
for (int i = 0; i < 25; i++) {
BN_mul_word(y, 24);
BN_add_word(y, cdKey[i]);
// Calculate the weighed sum of byte array elements.
for (int i = 0; i < PK_LENGTH; i++) {
BN_mul_word(y, PK_LENGTH - 1);
BN_add_word(y, pDecodedKey[i]);
}

// Acquire length.
int n = BN_num_bytes(y);

// Place the generated code into the byte sequence.
BN_bn2bin(y, (unsigned char *)byteSeq);
BN_bn2bin(y, (byte *)byteSeq);
BN_free(y);

// Reverse the byte sequence.
endiannessConvert((unsigned char *) byteSeq, n);
endiannessConvert((byte *) byteSeq, n);
}

/* Print Product Key. */
void printProductKey(const char *pKey) {
assert(strlen((const char *)pKey) == 25);
assert(strlen(pKey) == 25);

SetConsoleTextAttribute(hConsole, 0x0A);

for (int i = 0; i < 25; i++) {
for (int i = 0; i < PK_LENGTH; i++) {
putchar(pKey[i]);
if (i != 24 && i % 5 == 4) putchar('-');
if (i != PK_LENGTH - 1 && i % 5 == 4) putchar('-');
}

SetConsoleTextAttribute(hConsole, 0x0F);
Expand Down
74 changes: 0 additions & 74 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,80 +9,6 @@ HANDLE hConsole;
ul32 dwSeed;
byte charset[] = "BCDFGHJKMPQRTVWXY2346789";

int mainServer() {
BIGNUM *a, *b, *p, *generatorX, *generatorY, *publicKeyX, *publicKeyY, *genOrder, *privateKey;
BN_CTX *context = BN_CTX_new();

a = BN_new();
b = BN_new();
p = BN_new();

generatorX = BN_new();
generatorY = BN_new();

publicKeyX = BN_new();
publicKeyY = BN_new();

genOrder = BN_new();

privateKey = BN_new();

/* Public data */
// Data taken from pidgen.dll BINK-resources
BN_hex2bn(&p, "C9AE7AED19F6A7E100AADE98134111AD8118E59B8264734327940064BC675A0C682E19C89695FBFA3A4653E47D47FD7592258C7E3C3C61BBEA07FE5A7E842379");

BN_set_word(a, 1);
BN_set_word(b, 0);

// Base point G (Generator)
BN_hex2bn(&generatorX, "85ACEC9F9F9B456A78E43C3637DC88D21F977A9EC15E5225BD5060CE5B892F24FEDEE574BF5801F06BC232EEF2161074496613698D88FAC4B397CE3B475406A7");
BN_hex2bn(&generatorY, "66B7D1983F5D4FE43E8B4F1E28685DE0E22BBE6576A1A6B86C67533BF72FD3D082DBA281A556A16E593DB522942C8DD7120BA50C9413DF944E7258BDDF30B3C4");

// Inverse of the public key
BN_hex2bn(&publicKeyX, "90BF6BD980C536A8DB93B52AA9AEBA640BABF1D31BEC7AA345BB7510194A9B07379F552DA7B4A3EF81A9B87E0B85B5118E1E20A098641EE4CCF2045558C98C0E");
BN_hex2bn(&publicKeyY, "6B87D1E658D03868362945CDD582E2CF33EE4BA06369E0EFE9E4851F6DCBEC7F15081E250D171EA0CC4CB06435BCFCFEA8F438C9766743A06CBD06E7EFB4C3AE");

/* Computed data */
// Order of G <- from MSKey 4-in-1
BN_hex2bn(&genOrder, "4CC5C56529F0237D");

// Computed private key
BN_hex2bn(&privateKey, "2606120F59C05118");

/* Elliptical Curve calculations. */
// The group is defined via Fp = all integers [0; p - 1], where p is prime.
// The function EC_POINT_set_affine_coordinates() sets the x and y coordinates for the point p defined over the curve given in group.
EC_GROUP *eCurve = EC_GROUP_new_curve_GFp(p, a, b, context);

// Create new point for the generator on the elliptic curve and set its coordinates to (genX; genY).
EC_POINT *genPoint = EC_POINT_new(eCurve);
EC_POINT_set_affine_coordinates(eCurve, genPoint, generatorX, generatorY, context);

// Create new point for the public key on the elliptic curve and set its coordinates to (pubX; pubY).
EC_POINT *pubPoint = EC_POINT_new(eCurve);
EC_POINT_set_affine_coordinates(eCurve, pubPoint, publicKeyX, publicKeyY, context);

// If generator and public key points are not on the elliptic curve, either the generator or the public key values are incorrect.
assert(EC_POINT_is_on_curve(eCurve, genPoint, context) == 1);
assert(EC_POINT_is_on_curve(eCurve, pubPoint, context) == 1);

char pkey[25]{};
ul32 osfamily[1], prefix[1];

osfamily[0] = 1280;
RAND_bytes((byte *)prefix, 4);

prefix[0] &= 0x3ff;
generateServerKey((byte *)pkey, eCurve, genPoint, genOrder, privateKey, osfamily, prefix);
printProductKey(pkey);
printf("\n\n");
verifyServerKey(eCurve, genPoint, pubPoint, (char *) pkey);

BN_CTX_free(context);

return 0;
}

/*
* PK: VX8CG-8KC6V-PVPMD-GKPPH-GC7W8
*
Expand Down
4 changes: 3 additions & 1 deletion resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
#define IDR_WAVE1 102
#define IDB_BITMAP1 103
#define IDB_BITMAP2 104
#define IDB_BITMAP3 105
#define IDB_BITMAP4 106

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 105
#define _APS_NEXT_RESOURCE_VALUE 107
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
Expand Down
Binary file modified resource.rc
Binary file not shown.
Binary file added resources/musicoff.bmp
Binary file not shown.
Binary file added resources/musicon.bmp
Binary file not shown.
Loading

0 comments on commit 0e59a27

Please sign in to comment.