Skip to content

Commit 0e59a27

Browse files
committed
v2.2
1 parent 70e2c6f commit 0e59a27

13 files changed

+616
-419
lines changed

Keygen.vcxproj

+2
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@
171171
<Image Include="resources\ender.bmp" />
172172
<Image Include="resources\icon.ico" />
173173
<Image Include="resources\logo.bmp" />
174+
<Image Include="resources\musicoff.bmp" />
175+
<Image Include="resources\musicon.bmp" />
174176
</ItemGroup>
175177
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
176178
<ImportGroup Label="ExtensionTargets">

Keygen.vcxproj.filters

+2
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,7 @@
4545
<Image Include="resources\icon.ico" />
4646
<Image Include="resources\ender.bmp" />
4747
<Image Include="resources\logo.bmp" />
48+
<Image Include="resources\musicon.bmp" />
49+
<Image Include="resources\musicoff.bmp" />
4850
</ItemGroup>
4951
</Project>

header.h

+22-19
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#define IDC_INPUT2 1021
4040

4141
#define IDC_IMAGE1 1050
42+
#define IDC_IMAGE2 1051
4243

4344
#define IDC_LABEL1 1055
4445
#define IDC_LABEL2 1056
@@ -58,76 +59,78 @@ extern const long aXP;
5859
extern const long bXP;
5960

6061
// xp.cpp
61-
int keyXP(
62-
char *pKey,
63-
ul32 *hash,
64-
ul32 *sig,
65-
ul32 nRaw
62+
bool keyXP(
63+
char *pKey,
64+
ul32 nRaw
6665
);
6766

6867
void unpackXP(
6968
ul32 *serial,
7069
ul32 *hash,
7170
ul32 *sig,
7271
ul32 *raw
73-
);
72+
);
7473

7574
void packXP(
7675
ul32 *raw,
7776
ul32 *serial,
7877
ul32 *hash,
7978
ul32 *sig
80-
);
79+
);
8180

82-
void verifyXPKey(
81+
bool verifyXPKey(
8382
EC_GROUP *eCurve,
8483
EC_POINT *generator,
8584
EC_POINT *publicKey,
8685
char *cdKey
87-
);
86+
);
8887

8988
void generateXPKey(
90-
byte *pKey,
89+
char *pKey,
9190
EC_GROUP *eCurve,
9291
EC_POINT *generator,
9392
BIGNUM *order,
9493
BIGNUM *privateKey,
9594
ul32 *pRaw
96-
);
95+
);
9796

9897
// server.cpp
98+
bool keyServer(
99+
char *pKey
100+
);
101+
99102
void unpackServer(
100103
ul32 *osFamily,
101104
ul32 *hash,
102105
ul32 *sig,
103106
ul32 *prefix,
104107
ul32 *raw
105-
);
108+
);
106109

107110
void packServer(
108111
ul32 *raw,
109112
ul32 *osFamily,
110113
ul32 *hash,
111114
ul32 *sig,
112115
ul32 *prefix
113-
);
116+
);
114117

115-
void verifyServerKey(
118+
bool verifyServerKey(
116119
EC_GROUP *eCurve,
117120
EC_POINT *generator,
118121
EC_POINT *public_key,
119122
char *cdKey
120-
);
123+
);
121124

122125
void generateServerKey(
123-
byte *pKey,
126+
char *pKey,
124127
EC_GROUP *eCurve,
125128
EC_POINT *generator,
126129
BIGNUM *order,
127130
BIGNUM *privateKey,
128131
ul32 *osFamily,
129132
ul32 *prefix
130-
);
133+
);
131134

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

151154
// key.cpp
152-
void unbase24(ul32 *byteSeq, byte *cdKey);
153-
void base24(byte *cdKey, ul32 *byteSeq);
155+
void unbase24(ul32 *byteSeq, const char *cdKey);
156+
void base24(char *cdKey, ul32 *byteSeq);
154157
void printProductKey(const char *pKey);
155158
void printProductID(const ul32 *pRaw);
156159

key.cpp

+23-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "header.h"
66

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

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

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

40+
// Remove dashes from the CD-key and put it into a Base24 byte array.
41+
for (int i = 0, k = 0; i < strlen(cdKey) && k < PK_LENGTH; i++) {
42+
for (int j = 0; j < 24; j++) {
43+
if (cdKey[i] != '-' && cdKey[i] == charset[j]) {
44+
pDecodedKey[k++] = j;
45+
break;
46+
}
47+
}
48+
}
49+
3850
// Empty byte sequence.
3951
memset(byteSeq, 0, 16);
4052

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

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

5062
// Place the generated code into the byte sequence.
51-
BN_bn2bin(y, (unsigned char *)byteSeq);
63+
BN_bn2bin(y, (byte *)byteSeq);
5264
BN_free(y);
5365

5466
// Reverse the byte sequence.
55-
endiannessConvert((unsigned char *) byteSeq, n);
67+
endiannessConvert((byte *) byteSeq, n);
5668
}
5769

5870
/* Print Product Key. */
5971
void printProductKey(const char *pKey) {
60-
assert(strlen((const char *)pKey) == 25);
72+
assert(strlen(pKey) == 25);
6173

6274
SetConsoleTextAttribute(hConsole, 0x0A);
6375

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

6981
SetConsoleTextAttribute(hConsole, 0x0F);

main.cpp

-74
Original file line numberDiff line numberDiff line change
@@ -9,80 +9,6 @@ HANDLE hConsole;
99
ul32 dwSeed;
1010
byte charset[] = "BCDFGHJKMPQRTVWXY2346789";
1111

12-
int mainServer() {
13-
BIGNUM *a, *b, *p, *generatorX, *generatorY, *publicKeyX, *publicKeyY, *genOrder, *privateKey;
14-
BN_CTX *context = BN_CTX_new();
15-
16-
a = BN_new();
17-
b = BN_new();
18-
p = BN_new();
19-
20-
generatorX = BN_new();
21-
generatorY = BN_new();
22-
23-
publicKeyX = BN_new();
24-
publicKeyY = BN_new();
25-
26-
genOrder = BN_new();
27-
28-
privateKey = BN_new();
29-
30-
/* Public data */
31-
// Data taken from pidgen.dll BINK-resources
32-
BN_hex2bn(&p, "C9AE7AED19F6A7E100AADE98134111AD8118E59B8264734327940064BC675A0C682E19C89695FBFA3A4653E47D47FD7592258C7E3C3C61BBEA07FE5A7E842379");
33-
34-
BN_set_word(a, 1);
35-
BN_set_word(b, 0);
36-
37-
// Base point G (Generator)
38-
BN_hex2bn(&generatorX, "85ACEC9F9F9B456A78E43C3637DC88D21F977A9EC15E5225BD5060CE5B892F24FEDEE574BF5801F06BC232EEF2161074496613698D88FAC4B397CE3B475406A7");
39-
BN_hex2bn(&generatorY, "66B7D1983F5D4FE43E8B4F1E28685DE0E22BBE6576A1A6B86C67533BF72FD3D082DBA281A556A16E593DB522942C8DD7120BA50C9413DF944E7258BDDF30B3C4");
40-
41-
// Inverse of the public key
42-
BN_hex2bn(&publicKeyX, "90BF6BD980C536A8DB93B52AA9AEBA640BABF1D31BEC7AA345BB7510194A9B07379F552DA7B4A3EF81A9B87E0B85B5118E1E20A098641EE4CCF2045558C98C0E");
43-
BN_hex2bn(&publicKeyY, "6B87D1E658D03868362945CDD582E2CF33EE4BA06369E0EFE9E4851F6DCBEC7F15081E250D171EA0CC4CB06435BCFCFEA8F438C9766743A06CBD06E7EFB4C3AE");
44-
45-
/* Computed data */
46-
// Order of G <- from MSKey 4-in-1
47-
BN_hex2bn(&genOrder, "4CC5C56529F0237D");
48-
49-
// Computed private key
50-
BN_hex2bn(&privateKey, "2606120F59C05118");
51-
52-
/* Elliptical Curve calculations. */
53-
// The group is defined via Fp = all integers [0; p - 1], where p is prime.
54-
// The function EC_POINT_set_affine_coordinates() sets the x and y coordinates for the point p defined over the curve given in group.
55-
EC_GROUP *eCurve = EC_GROUP_new_curve_GFp(p, a, b, context);
56-
57-
// Create new point for the generator on the elliptic curve and set its coordinates to (genX; genY).
58-
EC_POINT *genPoint = EC_POINT_new(eCurve);
59-
EC_POINT_set_affine_coordinates(eCurve, genPoint, generatorX, generatorY, context);
60-
61-
// Create new point for the public key on the elliptic curve and set its coordinates to (pubX; pubY).
62-
EC_POINT *pubPoint = EC_POINT_new(eCurve);
63-
EC_POINT_set_affine_coordinates(eCurve, pubPoint, publicKeyX, publicKeyY, context);
64-
65-
// If generator and public key points are not on the elliptic curve, either the generator or the public key values are incorrect.
66-
assert(EC_POINT_is_on_curve(eCurve, genPoint, context) == 1);
67-
assert(EC_POINT_is_on_curve(eCurve, pubPoint, context) == 1);
68-
69-
char pkey[25]{};
70-
ul32 osfamily[1], prefix[1];
71-
72-
osfamily[0] = 1280;
73-
RAND_bytes((byte *)prefix, 4);
74-
75-
prefix[0] &= 0x3ff;
76-
generateServerKey((byte *)pkey, eCurve, genPoint, genOrder, privateKey, osfamily, prefix);
77-
printProductKey(pkey);
78-
printf("\n\n");
79-
verifyServerKey(eCurve, genPoint, pubPoint, (char *) pkey);
80-
81-
BN_CTX_free(context);
82-
83-
return 0;
84-
}
85-
8612
/*
8713
* PK: VX8CG-8KC6V-PVPMD-GKPPH-GC7W8
8814
*

resource.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
#define IDR_WAVE1 102
77
#define IDB_BITMAP1 103
88
#define IDB_BITMAP2 104
9+
#define IDB_BITMAP3 105
10+
#define IDB_BITMAP4 106
911

1012
// Next default values for new objects
1113
//
1214
#ifdef APSTUDIO_INVOKED
1315
#ifndef APSTUDIO_READONLY_SYMBOLS
14-
#define _APS_NEXT_RESOURCE_VALUE 105
16+
#define _APS_NEXT_RESOURCE_VALUE 107
1517
#define _APS_NEXT_COMMAND_VALUE 40001
1618
#define _APS_NEXT_CONTROL_VALUE 1001
1719
#define _APS_NEXT_SYMED_VALUE 101

resource.rc

306 Bytes
Binary file not shown.

resources/musicoff.bmp

3.05 KB
Binary file not shown.

resources/musicon.bmp

3.05 KB
Binary file not shown.

0 commit comments

Comments
 (0)