SM2 elliptic curve signature verification algorithm
Technical Field
The invention relates to the technical field of information security, in particular to an SM2 elliptic curve signature verification algorithm.
Background
The identity authentication technology is the leading strength for ensuring information security, and the design and implementation of the authentication system become important. Only through the high-reliability identity authentication system, the information safety of both communication parties can be effectively guaranteed, and the information is prevented from being intercepted by lawbreakers in the transmission process. The SM2 is an elliptic curve public key cryptographic algorithm issued by the State crypto administration in 12, month and 17 of 2010, and the digital signature technology is an important application of the elliptic curve public key cryptographic algorithm, and plays an important role in modern electronic commerce and government affairs, so that the integrity of the message in the transmission process can be ensured, the identity of the sender can be authenticated, and the repudiation in the transaction can be prevented.
In the existing SM2 signature verification algorithm, in the process of signature generation (signature verification), the head-to-tail splicing operation is mostly directly performed on a message to be signed (a message to be verified) and a hash value, and the head-to-tail splicing mode is too simple, is easily attacked by lawbreakers and has low safety.
In the SM2 elliptic curve public key cryptographic algorithm, the most time consuming is the point multiplication algorithm, in the point multiplication algorithm, the most time consuming is the modular inverse operation, the required time is more than ten times of the modular multiplication operation, because the times of the modular inverse operation required to be carried out by completing one point multiplication operation under different coordinates are different, in the Montgomery point multiplication algorithm under an affine coordinate system, the modular inverse operation is required to be carried out once for each point operation (point addition and point multiplication), the multiple modular inverse operations consume a large amount of time, in the Montgomery point multiplication algorithm under a standard projection coordinate, the point operation (point addition and point multiplication) does not need to be carried out with the modular inverse operation, but the times of the modular multiplication operation are greatly increased, and a large amount of time is also consumed. The traditional Montgomery point multiplication algorithm usually only carries out point multiplication operation under one coordinate system, only uses one modular multiplication unit and adopts a serial calculation method, so that the point multiplication operation speed is low, and further, the whole signature verification process is slow in operation speed and consumes a large amount of time.
Disclosure of Invention
The invention aims to overcome the defects in the prior art and provide the SM2 elliptic curve signature verification algorithm with higher operation speed and higher safety.
The purpose of the invention is realized by the following technical scheme:
an SM2 elliptic curve signature verification algorithm, comprising the following steps:
s1, digital signature generation algorithm:
s1.1, inputting original data of a signing party A, including system parameters (base points G and order n) of an elliptic curve, a hash value ZA and a private key d of the signing party AAMessage M to be signed;
s1.2, acquiring a random bit string W;
s1.3, carrying out XOR operation on the message M and the random bit string W to obtain Mw;
S1.4, hash values ZA and MwPerforming NAND operation to obtain Me;
S1.5, adopting SM3 algorithm to pair MeCarrying out cipher hash operation to obtain a hash value e;
s1.6, generating a random number k belonging to [1, n-1 ];
s1.7, calculating elliptic curve points (x) by using a point multiplication algorithm1,y1)=[k]G;
S1.8, calculate r ═ e + x1)mod n;
S1.9, checking whether r is 0 or r + k is n, if yes, returning to S1.6, and if not, executing S1.10;
s1.10, calculate S ═ ((1+ d)A)-1*(k-r*dA))mod n;
S1.11, checking whether S is equal to 0, if yes, returning to S1.6, and if not, executing S1.12;
s1.12, outputting a random bit string W, a message M and a digital signature (r, S) thereof;
s2, digital signature verification algorithm:
s2.1, inputting the original data of the verifier B, including elliptic curve system parameters (base point G, order n) and the public key P of the signature party AARandom bit string W, hash value ZA, message M ' needing signature verification and digital signature (r ', s ') thereof;
s2.2, checking whether r' belongs to [1, n-1] or not, if yes, executing S2.3, and if not, outputting verification failure;
s2.3, checking whether S' belongs to [1, n-1] or not, if yes, executing S2.4, and if not, outputting verification failure;
s2.4, carrying out XOR operation on the message M' and the random bit string W to obtain Mw';
S2.5, hashing values ZA and Mw' conducting NAND operation to obtain Me';
S2.6, adopting SM3 algorithm to pair MePerforming cryptographic hash operation to obtain a hash value e';
s2.7, calculate t ═ r '+ S') mod n;
s2.8, checking whether t is 0, if yes, outputting the verification failure, and if not, executing S2.9;
s2.9, calculating elliptic curve points (x) by using a point multiplication algorithm1',y1')=[s']G+[t]PA;
S2.10, calculate R ═ e' + x1')mod n;
And S2.11, checking whether R is satisfied or not, if so, outputting verification successfully, and if not, outputting verification failure.
Preferably, the point multiplication algorithm is a Montgomery point multiplication algorithm under standard projection coordinates, wherein C1、C2、C3Is three multiplication units, C1(XM,ZN) Is just a modular multiplication unit C1To XMAnd ZNPerforming modular multiplication operation; the dot multiplication algorithm comprises the following steps:
step one, input point G ═ xG,yG)∈E(F2m),k=(km-1,…k1,k0)2Wherein k isiIs belonged to {0,1}, and a positive integer i is belonged to [0, m-1 ]];
Converting the affine coordinates into standard projection coordinates, and performing the operation of the second step and the third step under the standard projection coordinates;
step two, let XM=1,ZM=0,XN=xG,ZN=1;
Calculating xG -1=1/xG;
Step three, for i from m-1 to 0, repeatedly executing the following dot addition operation and multiple dot operation:
3.1,W1=C1(XM,ZN),W2=C2(XN,ZM);
in 3.1, the modular multiplication unit C1And C2The parallel operation can accelerate the operation speed and reduce the operation time;
3.2 if kiWhen the value is 0, then ZN=(W1+W2)2,XM=(XM+ZM)4,
W1=C1(XM,ZM),W2=C2(W1,W2),W3=C3(xG,ZN),
XN=W2+W3,ZM=W1 2;
In 3.2, the modular multiplication unit C1、C2、C3In parallelThe operation can be accelerated, and the operation time is reduced;
3.3 if ki1, then ZM=(W1+W2)2,XN=(XN+ZN)4,
W1=C1(XN,ZN),W2=C2(W1,W2),W3=C3(xG,ZM),
XM=W2+W3,ZN=W1 2;
In 3.3, the modular multiplication unit C1、C2、C3The parallel operation can accelerate the operation speed and reduce the operation time;
step four, if ZNWhen the value is 0, then XM=xG,ZM=xG+yG(ii) a Converting points under the standard projective coordinates into points under affine coordinates;
step five, if ZNNot equal to 0, then XM=XM/ZM,XN=XN/ZN,
W2=C2(XM+xG,XN+xG),
W3=C3(XM+xG,xG -1),W4=W2+xG 2+yG,
W2=C2(W3,W4),ZM=W2+yG(ii) a Converting points under the standard projective coordinates into points under affine coordinates;
step six, x1=XM,y1=ZM;
Step seven, outputting [ k]G=(x1,y1)。
Compared with the prior art, the invention has the following beneficial effects:
(1) in the process of generating the digital signature, firstly, a section of random bit string is obtained, then, the message to be signed is subjected to XOR operation with the random bit string and then subjected to NAND operation with the hash value, if the signature information is intercepted by a lawbreaker in the transmission process, the lawbreaker cannot completely crack and forge under the condition that the XOR operation and the NAND operation in the signature process are unknown, so that the safety of the signature information is improved, and the lawbreaker is prevented from cracking and forging after intercepting the signature information;
(2) in the process of digital signature verification, the information to be verified is subjected to XOR operation with the random bit string and then subjected to NAND operation with the hash value, if the signature information to be verified is falsified by a lawbreaker in the transmission process, the falsified signature information cannot be verified successfully under the condition that the lawbreaker does not know the XOR operation and the NAND operation in the signature verification process, and therefore the safety of a verification system is improved;
(3) the point multiplication algorithm in the signature generation and signature verification processes adopts an improved Montgomery point multiplication algorithm to carry out point multiplication operation, converts affine coordinates into standard projection coordinates, eliminates the modular inverse operation in the point multiplication operation midpoint operation (point addition and point multiplication) process, carries out modular multiplication operation in a parallel calculation mode of three modular multiplication units, and simultaneously carries out the modular inverse operation required when converting the standard projection coordinates into the affine coordinates, greatly accelerates the speed of the point multiplication operation and reduces the operation time.
Drawings
FIG. 1 is a flow chart of a digital signature generation algorithm of the present invention;
FIG. 2 is a flow chart of a digital signature verification algorithm of the present invention;
FIG. 3 is a flowchart of the Montgomery dot product algorithm of the present invention.
Detailed Description
The present invention will be described in further detail with reference to examples and drawings, but the present invention is not limited thereto.
The invention aims to solve the technical problem of providing an SM2 elliptic curve signature verification algorithm, which improves an SM2 signature generation algorithm (signature verification algorithm), firstly, a section of random bit string is obtained, then, the message to be signed (the message to be verified) is subjected to XOR operation with the random bit string and then subjected to NAND operation with a hash value, the safety of a signature verification system is improved, a point multiplication algorithm in the processes of signature generation and signature verification adopts an improved Montgomery point multiplication algorithm to carry out point multiplication operation, affine coordinates are converted into standard projection coordinates, the modular inverse operation in the process of point multiplication operation (point addition and point multiplication) is eliminated, the modular multiplication operation is carried out in a mode of parallel calculation of three modular multiplication units, and the modular inverse operation required when the standard projection coordinates are converted into the affine coordinates is carried out simultaneously when the point operation (point addition and point multiplication) is carried out, the speed of dot product operation is greatly increased, and the operation time is reduced.
The SM2 elliptic curve and algorithm involved in the invention are defined in the binary field F2mThe equation of the elliptic curve is a non-super-singular curve y2+xy=x3+ax2+ b, where a, b ∈ F2mAnd b ≠ 0. Elliptic curve E (F)2m)={(x,y)|x,y∈F2mAnd satisfies the equation y2+xy=x3+ax2+ b } - [ O ], where O is an infinity point; will binary field F2mEquation y of non-super-singular elliptic curve2+xy=x3+ax2+ b conversion to equation Y in standard projection coordinates2Z+XYZ=X3+aX2Z+bZ3The projection point (X: Y: Z), Z ≠ 0 corresponds to the pseudo-spot (X/Z, Y/Z), and the infinity point ∞ corresponds to (0:1: 0).
As shown in fig. 1 to 3, an SM2 elliptic curve signature verification algorithm includes the following steps:
s1, as shown in fig. 1, the digital signature generation algorithm:
s1.1, inputting original data of a signing party A, including system parameters (base points G and order n) of an elliptic curve, a hash value ZA and a private key d of the signing party AAMessage M to be signed;
s1.2, acquiring a random bit string W;
s1.3, messagePerforming XOR operation on M and the random bit string W to obtain Mw;
S1.4, hash values ZA and MwPerforming NAND operation to obtain Me;
S1.5, adopting SM3 algorithm to pair MeCarrying out cipher hash operation to obtain a hash value e;
s1.6, generating a random number k belonging to [1, n-1 ];
s1.7, calculating elliptic curve points (x) by using a point multiplication algorithm1,y1)=[k]G;
S1.8, calculate r ═ e + x1)mod n;
S1.9, checking whether r is 0 or r + k is n, if yes, returning to S1.6, and if not, executing S1.10;
s1.10, calculate S ═ ((1+ d)A)-1*(k-r*dA))mod n;
S1.11, checking whether S is equal to 0, if yes, returning to S1.6, and if not, executing S1.12;
s1.12, outputting a random bit string W, a message M and a digital signature (r, S) thereof;
s2, as shown in fig. 2, the digital signature verification algorithm:
s2.1, inputting the original data of the verifier B, including elliptic curve system parameters (base point G, order n) and the public key P of the signature party AARandom bit string W, hash value ZA, message M ' needing signature verification and digital signature (r ', s ') thereof;
s2.2, checking whether r' belongs to [1, n-1] or not, if yes, executing S2.3, and if not, outputting verification failure;
s2.3, checking whether S' belongs to [1, n-1] or not, if yes, executing S2.4, and if not, outputting verification failure;
s2.4, carrying out XOR operation on the message M' and the random bit string W to obtain Mw';
S2.5, hashing values ZA and Mw' conducting NAND operation to obtain Me';
S2.6, adopting SM3 algorithm to pair MePerforming cryptographic hash operation to obtain a hash value e';
s2.7, calculate t ═ r '+ S') mod n;
s2.8, checking whether t is 0, if yes, outputting the verification failure, and if not, executing S2.9;
s2.9, calculating elliptic curve points (x) by using a point multiplication algorithm1',y1')=[s']G+[t]PA;
S2.10, calculate R ═ e' + x1')mod n;
And S2.11, checking whether R is satisfied or not, if so, outputting verification successfully, and if not, outputting verification failure.
As shown in FIG. 3, the point multiplication algorithm is a Montgomery point multiplication algorithm under standard projection coordinates, wherein C1、C2、C3Is three multiplication units, C1(XM,ZN) Is just a modular multiplication unit C1To XMAnd ZNPerforming modular multiplication operation; the dot multiplication algorithm comprises the following steps:
step one, input point G ═ xG,yG)∈E(F2m),k=(km-1,…k1,k0)2Where ki is in the range of {0,1}, and the positive integer i is in the range of [0, m-1 }];
Converting the affine coordinates into standard projection coordinates, and performing the operation of the second step and the third step under the standard projection coordinates;
step two, let XM=1,ZM=0,XN=xG,ZN=1;
Calculating xG -1=1/xG;
Step three, for i from m-1 to 0, repeatedly executing the following dot addition operation and multiple dot operation:
3.1,W1=C1(XM,ZN),W2=C2(XN,ZM);
in 3.1, the modular multiplication unit C1And C2The parallel operation can accelerate the operation speed and reduce the operation time;
3.2 if kiWhen the value is 0, then ZN=(W1+W2)2,XM=(XM+ZM)4,
W1=C1(XM,ZM),W2=C2(W1,W2),W3=C3(xG,ZN),
XN=W2+W3,ZM=W1 2;
In 3.2, the modular multiplication unit C1、C2、C3The parallel operation can accelerate the operation speed and reduce the operation time;
3.3 if k i1, then ZM=(W1+W2)2,XN=(XN+ZN)4,
W1=C1(XN,ZN),W2=C2(W1,W2),W3=C3(xG,ZM),
XM=W2+W3,ZN=W1 2;
In 3.3, the modular multiplication unit C1、C2、C3The parallel operation can accelerate the operation speed and reduce the operation time;
step four, if ZNWhen the value is 0, then XM=xG,ZM=xG+yG(ii) a Converting points under the standard projective coordinates into points under affine coordinates;
step five, if ZNNot equal to 0, then XM=XM/ZM,XN=XN/ZN,
W2=C2(XM+xG,XN+xG),
W3=C3(XM+xG,xG -1),W4=W2+xG 2+yG,
W2=C2(W3,W4),ZM=W2+yG(ii) a Converting points under the standard projective coordinates into points under affine coordinates;
step six, x1=XM,y1=ZM;
Step seven, outputting [ k]G=(x1,y1)。
In the process of generating the digital signature, firstly, a section of random bit string is obtained, then, the message to be signed is subjected to XOR operation with the random bit string and then subjected to NAND operation with the hash value, if the signature information is intercepted by a lawbreaker in the transmission process, the lawbreaker cannot completely crack and forge under the condition that the XOR operation and the NAND operation in the signature process are unknown, so that the safety of the signature information is improved, and the lawbreaker is prevented from cracking and forging after intercepting the signature information; in the process of digital signature verification, the information to be verified is subjected to XOR operation with the random bit string and then subjected to NAND operation with the hash value, if the signature information to be verified is tampered by a lawbreaker in the transmission process, the tampered signature information cannot be verified successfully under the condition that the lawbreaker does not know the XOR operation and the NAND operation in the signature verification process, and therefore the safety of a verification system is improved; the point multiplication algorithm in the signature generation and signature verification processes adopts an improved Montgomery point multiplication algorithm to carry out point multiplication operation, affine coordinates are converted into standard projection coordinates, the modular inverse operation in the point multiplication operation midpoint operation (point addition and point multiplication) process is eliminated, the modular multiplication operation is carried out in a parallel calculation mode of three modular multiplication units, and the modular inverse operation required when the standard projection coordinates are converted into the affine coordinates is carried out simultaneously when the point operation (point addition and point multiplication) is carried out, so that the speed of the point multiplication operation is greatly accelerated, and the operation time is reduced; the integrity of the message in the transmission process can be ensured, the identity of the sender is authenticated, and the repudiation in the transaction is prevented.
The present invention is not limited to the above embodiments, and any other changes, modifications, substitutions, combinations, and simplifications which do not depart from the spirit and principle of the present invention should be construed as equivalents and are included in the scope of the present invention.