mirror of
https://github.com/bitcookies/winrar-keygen.git
synced 2026-03-11 17:45:31 +00:00
350 lines
20 KiB
Markdown
350 lines
20 KiB
Markdown
# How is "rarreg.key" generated?
|
|
|
|
WinRAR uses an ECC-based signature algorithm to generate `rarreg.key`. The algorithm it used is a variant of Chinese SM2 digital signature algorithm. Different to many standard ECDSAs, the curve that WinRAR selected is a curve over composite field  .
|
|
|
|
## 1. Composite field  
|
|
|
|
Elements in ground field  are represented with standard basis, i.e. polynomial basis. The irreducible polynomial is
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/1-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/1-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
|
|
where each coefficients is in . If we use
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/2-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/2-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
|
|
as the standard basis of the ground field, an element  in  can be denoted as
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/3-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/3-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
|
|
---
|
|
|
|
The irreducible polynomial of composite field   is
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/4-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/4-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
|
|
where each coefficients is in . If we use
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/5-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/5-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
|
|
as the standard basis of the composite field, an element  in   can be denoted as
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/6-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/6-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
|
|
---
|
|
|
|
For clarity, we use  , which is a 255-bits-long integer to denote an element  in  . The map between them is
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/7-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/7-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
|
|
## 2. Elliptic curve over  
|
|
|
|
The equation of the elliptic curve that WinRAR uses is
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/8-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/8-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
|
|
The base point  is
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/9-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/9-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
|
|
whose order  is
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/10-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/10-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
|
|
## 3. Message hash algorithm
|
|
|
|
We use
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/11-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/11-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
|
|
to denote a message whose length is . So the SHA1 value of  should be
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/12-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/12-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
|
|
where  are 5 state values when SHA1 outputs. Generally speaking, the final SHA1 value should be the join of these 5 state values while each of state values is serialized in big-endian.
|
|
|
|
However, WinRAR doesn't serialize the 5 state values. Instead, it use a big integer  as the hash of the input message.
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/15-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/15-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
|
|
## 4. ECC digital signature algorithm
|
|
|
|
We use  to denote private key,  to denote public key. So there must be
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/16-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/16-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
|
|
If we use  to denote the hash of input data, WinRAR use the following algorithm to perform signing:
|
|
|
|
1. Generate a random big integer  which satisfies .
|
|
|
|
2. Calculate 
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/19-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/19-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
|
|
where  means we take X coordinate of  and convert it from   to a big integer.
|
|
|
|
If  or , go back to step 1.
|
|
|
|
3. Calculate 
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/24-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/24-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
|
|
If , go back to step 1.
|
|
|
|
4. Output .
|
|
|
|
## 5. WinRAR private key generation algorithm
|
|
|
|
We use
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/26-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/26-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
|
|
to denote input data whose length is . WinRAR use it to generate private key .
|
|
|
|
1. We use  to denote 6 32-bits-long integer. So there is
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/28-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/28-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
2. Let .
|
|
|
|
3. If , we calculate SHA1 value of . Then assign SHA1 state value  to :
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/33-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/33-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
|
|
Otherwise, when , we let
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/35-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/35-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
4. Regard  as counter, add itself by 1.
|
|
|
|
Calculate SHA1:
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/37-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/37-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
|
|
We takes the lowest 16 bits of  and donote it as .
|
|
|
|
5. Repeat step 4 again with 14 times.
|
|
|
|
6. After that, we will get . Then output private key
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/41-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/41-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
## 6. The private key and public key of WinRAR
|
|
|
|
Private key  is
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/42-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/42-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
|
|
This private key is generated by the algorithm describled in section 5 where the length of data  is zero.
|
|
|
|
Public key  is
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/43-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/43-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
|
|
## 7. Generation of "rarreg.key"
|
|
|
|
The generation of license file `rarreg.key` requires 2 arguments:
|
|
|
|
1. Username, an ANSI-encoded string, without null-terminator. Denoted as
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/44-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/44-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
2. License type, an ANSI-encoded string, without null-terminator. Denoted as
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/45-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/45-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
The following is the algorithm to generate `rarreg.key`.
|
|
|
|
1. Use the algorithm describled in section 5, with argument , to generate private key  and public key . Then output hexlified public key string with SM2 compressed public key format. The hexlified public key is denoted as .
|
|
|
|
The length of  should be 64. If less, pad with `'0'` until the length is 64.
|
|
|
|
2. Let  be
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/48-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/48-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
3. Use the algorithm describled in section 5, with argument , to generate private key  and public key . Then output hexlified public key string with SM2 compressed public key format. The hexlified public key is denoted as .
|
|
|
|
The length of  should be 64. If less, pad with `'0'` until the length is 64.
|
|
|
|
4. Let  be
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/51-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/51-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
5. Use the algorithm describled in section 4, with argument  and private key  describled section 6, to get signature .
|
|
|
|
The bit length of  and  shall not be more than 240. Otherwise, repeat this step.
|
|
|
|
6. Convert  and  to hex-integer string  and , without `"0x"` prefix.
|
|
|
|
If the length of  or  is less than 60, pad character `'0'` until the length is 60.
|
|
|
|
7. Let  be
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/57-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/57-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
8. Let  be
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/58-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/58-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
|
|
Use the algorithm describled in section 4, with argument  and private key  describled section 6, to get signature .
|
|
|
|
The bit length of  and  shall not be more than 240. Otherwise, repeat this step.
|
|
|
|
9. Convert  and  to hex-integer string  and , without `"0x"` prefix.
|
|
|
|
If the length of  or  is less than 60, pad character `'0'` until the length is 60.
|
|
|
|
10. Let  be
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/64-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/64-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
11. Calculate CRC32 value of
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/65-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/65-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
|
|
The final checksum the complement of CRC32 value.
|
|
|
|
Then convert the checksum to decimal string . If the length is less than 10, pad character `'0'` until the length is 10.
|
|
|
|
12. Let  be
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/67-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/67-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
13. Output with format
|
|
|
|
* A fixed header `"RAR registration data"`, taking one line.
|
|
|
|
* Username, taking one line.
|
|
|
|
* License type, taking one line
|
|
|
|
* UID, taking one line, with format:
|
|
|
|
<p align="center">
|
|
<img src="assets/formula/68-light.svg#gh-light-mode-only">
|
|
<img src="assets/formula/68-dark.svg#gh-dark-mode-only">
|
|
</p>
|
|
|
|
* Output , with 54 characters a line.
|