|
1 | 1 | # XPKeygen |
2 | | -Windows XP VLK Keygen |
| 2 | +A command line Windows XP VLK key generator. This tool allows you to generate _valid Windows XP keys_ based on a single |
| 3 | +_raw product key_, which can be random. You can also provide the amount of keys to be generated using that raw |
| 4 | +product key. |
3 | 5 |
|
4 | | -Known issues: |
5 | | -* Some of the keys aren't valid, but it's generally a less common occurrence. About 2 in 3 of the keys should work. |
| 6 | +The **Raw Product Key (RPK)** is supplied in a form of 9 digits `XXX-YYYYYY`. |
6 | 7 |
|
7 | | -Issues/Pull Requests welcome. |
| 8 | + |
| 9 | +### Download |
| 10 | +Check the **Releases** tab and download the latest version from there. |
| 11 | + |
| 12 | + |
| 13 | +### Principle of operation |
| 14 | +We need to use a random Raw Product Key as a base to generate a Product ID in a form of `AAAAA-BBB-CCCCCCS-DDEEE`. |
| 15 | + |
| 16 | +#### Product ID |
| 17 | + |
| 18 | +| Digits | Meaning | |
| 19 | +|-------:|:-------------------------------------------------------| |
| 20 | +| AAAAA | OS Family constant | |
| 21 | +| BBB | Most significant 3 digits of the RPK | |
| 22 | +| CCCCCC | Least significant 6 digits of the RPK | |
| 23 | +| S | Check digit | |
| 24 | +| DD | Index of the public key used to verify the Product Key | |
| 25 | +| EEE | Random 3-digit number | |
| 26 | + |
| 27 | +The OS Family constant `AAAAA` is different for each series of Windows XP. For example, it is 76487 for SP3. |
| 28 | + |
| 29 | +The `BBB` and `CCCCCC` sections essentially directly correspond to the Raw Product Key. If the RPK is `XXXYYYYYY`, these two sections |
| 30 | +will transform to `XXX` and `YYYYYY` respectively. |
| 31 | + |
| 32 | +The check digit `S` is picked so that the sum of all `C` digits with it added makes a number divisible by 7. |
| 33 | + |
| 34 | +The public key index `DD` lets us know which public key was used to successfully verify the authenticity of our Product Key. |
| 35 | +For example, it's 22 for Professional keys and 23 for VLK keys. |
| 36 | + |
| 37 | +A random number `EEE` is used to generate a different Installation ID each time. |
| 38 | + |
| 39 | +#### Product Key |
| 40 | + |
| 41 | +The Product Key itself (not to confuse with the RPK) is of form `FFFFF-GGGGG-HHHHH-JJJJJ-KKKKK`, encoded in Base-24 with |
| 42 | +the alphabet `BCDFGHJKMPQRTVWXY2346789` to exclude any characters that can be easily confused, like `I` and `1` or `O` and `0`. |
| 43 | + |
| 44 | +As per the alphabet capacity formula, the key can at most contain 114 bits of information. |
| 45 | +$$N = log2(24^25) ~ 114$$ |
| 46 | + |
| 47 | +Based on that calculation, we unpack the 114-bit Product Key into 4 ordered segments: |
| 48 | + |
| 49 | +| Segment | Capacity | Data | |
| 50 | +|-----------|----------|-------------------------------------------| |
| 51 | +| Flag | 1 bit | Reserved, always set to `0x01`* | |
| 52 | +| Serial | 30 bits | Raw Product Key (RPK) | |
| 53 | +| Hash | 28 bits | RPK hash | |
| 54 | +| Signature | 55 bits | Elliptic Curve signature for the RPK hash | |
| 55 | + |
| 56 | +For simplicity' sake, we'll combine `Flag` and `Serial` segments into a single segment called `Data`. By that logic we'll be able to extract the RPK by |
| 57 | +shifting `Data` right and pack it back by shifting bits left. |
| 58 | + |
| 59 | +*It's not fully known what that bit does, but all a priori valid product keys I've checked had it set to 1. |
| 60 | + |
| 61 | +#### Elliptic Curves |
| 62 | +Elliptic Curve Cryptography (ECC) is a type of public-key cryptographic system. |
| 63 | +This class of systems relies on challenging "one-way" math problems - easy to compute one way and intractable to solve the "other" way. |
| 64 | +Sometimes these are called "trapdoor" functions - easy to fall into, complicated to escape.<sup>[2]</sup> |
| 65 | + |
| 66 | +ECC relies on solving equations of the form |
| 67 | +$$y^2 = x^3 + ax + b$$ |
| 68 | + |
| 69 | +In general, there are 2 special cases for the Elliptic Curve leveraged in cryptography - **F<sub>2m</sub>** and **F<sub>p</sub>**. |
| 70 | +They differ only slightly. Both curves are defined over the finite field, F<sub>p</sub> uses a prime parameter that's larger than 3, |
| 71 | +F<sub>2m</sub> assumes $p = 2m$. Microsoft used the latter in their algorithm. |
| 72 | + |
| 73 | +An elliptic curve over the finite field F<sub>p</sub> consists of: |
| 74 | +* a set of integer coordinates ${x, y}$, such that $0 <= x, y < p$; |
| 75 | +* a set of points $y^2 = x^3 + ax + b \mod p$. |
| 76 | + |
| 77 | +**An elliptic curve over F<sub>17</sub> would look like this:** |
| 78 | + |
| 79 | +The curve consists of the blue points in above image. In practice the "elliptic curves" |
| 80 | +used in cryptography are "sets of points in square matrix". |
| 81 | + |
| 82 | +The above curve is "educational". It provides very small key length (4-5 bits). |
| 83 | +In real world situations developers typically use curves of 256-bits or more. |
| 84 | + |
| 85 | + |
| 86 | +Since it is a public-key cryptographic system, Microsoft had to share the public key with their Windows XP release to check entered product keys against. |
| 87 | +It is stored within `pidgen.dll` in a form of a BINK resource. The first set of BINK data is there to validate retail keys, the second is for the |
| 88 | +OEM keys respectively. |
| 89 | + |
| 90 | +In case you want to explore further, the source code of `pidgen.dll` and all its functions is available within this repository, in the "pidgen" folder. |
| 91 | + |
| 92 | +#### Generating valid keys |
| 93 | + |
| 94 | +To create the CD-key generation algorithm we must compute the corresponding private key using the public key supplied with `pidgen.dll`, |
| 95 | +which means we have to reverse-solve the one-way ECC task. |
| 96 | + |
| 97 | +Judging by the key exposed in BINK, p is a prime number with a length of **384 bits**. |
| 98 | +The computation difficulty using the most efficient Pollard's Rho algorithm ($O(\sqrtn)$) would be at least $O(2^168)$, but lucky for us, |
| 99 | +Microsoft limited the value of the signature to 55 bits in order to reduce the amount of matching product keys, reducing the difficulty |
| 100 | +to a far more manageable $O(2^28)$. |
| 101 | + |
| 102 | +The private key was, of course, conveniently computed before us in just 6 hours on a Celeron 800 machine. |
| 103 | + |
| 104 | +The rest of the job is done within the code of this keygen. |
| 105 | + |
| 106 | + |
| 107 | +### Known issues |
| 108 | +* ~~Some keys aren't valid, but it's generally a less common occurrence. About 2 in 3 of the keys should work.~~<br> |
| 109 | +**Fixed in v1.2**. Prior versions generated a valid key with an exact chance of `0x40000/0x62A32`, which resulted in exactly |
| 110 | +`0.64884`, or about 65%. My "2 in 3" estimate was inconceivably accurate. |
| 111 | +* Tested **only** on Windows XP Professional SP3, but should work everywhere else as well. |
| 112 | +* Server 2003 key generation not included yet. |
| 113 | + |
| 114 | + |
| 115 | +### Literature |
| 116 | +I will add more decent reads into the bibliography in a later release. |
| 117 | + |
| 118 | +**Understanding basics of Windows XP Activation**: |
| 119 | +* [[1] Inside Windows Product Activation - Fully Licensed](https://www.licenturion.com/xp/fully-licensed-wpa.txt) |
| 120 | +* [[2] Elliptic Curve Cryptography for Beginners - Matt Rickard](https://matt-rickard.com/elliptic-curve-cryptography) |
| 121 | +* [[3] Elliptic Curve Cryptography (ECC) - Practical Cryptography for Developers](https://cryptobook.nakov.com/asymmetric-key-ciphers/elliptic-curve-cryptography-ecc) |
| 122 | + |
| 123 | + |
| 124 | +**Tested on Windows XP Professional SP3**. |
| 125 | + |
| 126 | +Testing/Issues/Pull Requests welcome. |
0 commit comments