The advantage of using public key algorithm as a software registration algorithm is that cracker is difficult to get keygen by tracking verification algorithm. Below, the method for software registration using the SM2 algorithm is described.
Generate Authorization Code
- Select SM2 Elliptic curve parameter (p,a,b,n,gx,gy)
- Generate random numbers using random number generators r∈[1,n-1]
- Calculate Elliptic Curve point r=[r]g= (Xr,yr)
- Computes the hash value h=sm3 (user name ∥xr∥yr)
- Calculates the serial number S≡ (r-h * d) mod n, where D is the private key and N is the order of the G-point
- Use S and h together as the user's authorization code
Verify Authorization Code
- Determining SM2 Elliptic Curve parameters (P,a,b,n,gx,gy)
- Extract serial number S and hash value H
- Compute Point R≡ ([S]g + [h]q) mod p, where Q is the public key and P is the number of element elements
- Compute hash Value h ' =sm3 (user name ∥xr∥yr)
- If H ' =h is registered successfully; if H ' ≠h, then registration fails
The method of generation and verification of authorization codes has been integrated in the SM2 class of the open dynamic Library OpenSM.dll of the National Commercial cryptography algorithm. The corresponding member functions are:
<summary>///Generate Authorization Code///</summary>///<param name= "userId" > User registration information </param>///<param name = "Privatekey" > Private key </param>///<returns> Authorization Code </returns>//<remarks> Note: For the same registration information, Each generated authorization code is not the same </remarks>public Eclicensekey Licensekeymaker (byte[] userId, BigInteger privatekey);///< summary>///Generate Authorization Code//</summary>///<param name= "userId" > User registration Information </param>///<param name= " Privatekey "> Private key </param>///<param name=" R "> random number, whose value is at [1, N-1],n is the order of the G-point </param>///<returns> Authorization Code </returns>///<remarks> Note: For the same registration information and the same r, each generated authorization code is consistent </remarks>public Eclicensekey Licensekeymaker (byte[] userId, BigInteger Privatekey, BigInteger R);///<summary>///Check Authorization code///</summary>// /<param name= "userId" > User registration Information </param>///<param name= "Registercode" > Registration Code </param>///< param name= "PublicKey" > Public key </param>///<returns>///true: Validation passed//Fasle: Checksum failed//</returns>public bool Licensekeyverifier (byte[] userId, Eclicensekey registercode, Ecpoint publickey);
The Eclicensekey class is defined as follows:
<summary>///SM2 cipher algorithm keygen generate Authorization code format///</summary>public class eclicensekey{public readonly BigInteger Mkey; Public ReadOnly BigInteger Mhash; <summary>///constructors///</summary>//<param name= "key" > Authorization code </param>//<param name= "hash" > Hash Value </param> public eclicensekey (BigInteger key, BigInteger hash) { this.mkey = key; This.mhash = hash; }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
National Business Password (v) generation and verification of software authorization code based on SM2