Detailed Description
In order to better understand the technical solutions in the embodiments of the present application, the following description will clearly and completely describe the technical solutions in the embodiments of the present application with reference to the accompanying drawings in the embodiments of the present application, and it is obvious that the described embodiments are only some embodiments of the present application, not all embodiments. All other embodiments, which are derived by a person skilled in the art based on the embodiments of the present application, shall fall within the scope of protection of the embodiments of the present application.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in this specification and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used herein refers to and encompasses any or all possible combinations of one or more of the associated listed items.
It should be understood that although the terms first, second, third, etc. may be used herein to describe various information, these information should not be limited by these terms. These terms are only used to distinguish one type of information from another. For example, first information may also be referred to as second information, and similarly, second information may also be referred to as first information, without departing from the scope of the application. The term "if" as used herein may be interpreted as "at..once" or "when..once" or "in response to a determination", depending on the context.
Fig. 1 is a flowchart of a method for quickly generating a signature according to an embodiment of the present application, as shown in fig. 1, the method includes steps 101 to 105 as follows:
Step 101, a first random number is generated.
The first random number is generated, which may be generated according to the user's ID, or may be a randomly generated array, a randomly generated number, or the like.
Step 102, extracting m first matrix elements from a pre-generated private key matrix according to a first random number, wherein m is a positive integer greater than or equal to 2.
According to the first random number, m first matrix elements are randomly extracted from the private key matrix, m is a preset positive integer greater than or equal to 2, and in order to balance the calculation amount and the security requirement, the value range of m is generally 3-5, for example, m is 5, and then 5 first matrix elements are extracted from the private key matrix.
It should be understood that when the signing device is initialized, a private key matrix is automatically generated, after the private key matrix is generated, a public key matrix corresponding to the private key matrix is automatically generated according to a conversion relationship between the private key matrix and the public key matrix, for example, a 16×16 private key matrix and a corresponding 16×16 public key matrix are respectively generated, and the specific generating methods of the private key matrix and the public key matrix are not limited in the present application.
Step 103, extracting m second matrix elements with the same coordinates as the first matrix elements from a public key matrix which is generated in advance and corresponds to the private key matrix.
And randomly extracting m second matrix elements with the same coordinates as the first matrix elements from the public key matrix according to the first random number.
Step 104, adding m first matrix elements to obtain a first private key, and adding m second matrix elements to obtain a first public key.
The extracted m first matrix elements are added to obtain a first private key sk m, the extracted m second matrix elements are added to obtain a first public key PK m, and the public key corresponding to the first private key sk m is the first public key PK m according to the combined public key.
Since the matrix elements in the private key matrix and the public key matrix are different, the m first matrix elements extracted from the private key matrix are added to form a finite field addition operation, and the m second matrix elements extracted from the public key matrix are added to form a point addition operation of an elliptic curve.
Step 105, generating a digital signature according to the first private key, the first public key and a pre-generated hash value.
A digital signature is generated from the first private key sk m, the first public key PK m, and a pre-generated hash value.
In the embodiment of the application, the first matrix element and the second matrix element are extracted through the generated random number, the first private key is obtained by adding the extracted first matrix element, and the first public key is obtained by adding the second matrix element, so that the digital signature is generated according to the first private key, the first public key and the hash value, the first public key generated by adopting the first private key generated by finite field addition operation and the first public key generated by elliptic curve point addition operation replaces the result of the dot multiplication operation of the generated random number k, the calculation k and the base point G in the existing signature generation method, the dot multiplication operation is not needed in the generation process of the digital signature, and the operation amount of a small amount of finite field addition operation and a small amount of elliptic curve point addition operation is far smaller than that of one dot multiplication operation. The signature performance of the same cipher device in unit time can be improved by reducing the operation amount of the signature.
In one possible implementation manner, when M first matrix elements are extracted from a pre-generated private key matrix according to a first random number, M bytes may be determined from M bytes included in the first random number, where M is a positive integer greater than or equal to M, then M matrix coordinates are determined according to content corresponding to the M bytes in the first random number, and then M first matrix elements corresponding to the matrix coordinates are extracted from the private key matrix according to the M matrix coordinates.
The m bytes are randomly determined from all bytes included in the first random number, for example, m bytes before the first random number, m bytes after the first random number, m bytes in random order of random positions, and the like. And determining m matrix coordinates according to the determined m bytes, and extracting m first matrix elements corresponding to the coordinates from the private key matrix according to the m matrix coordinates.
It should be noted that, the positions of the elements in the private key matrix and the public key matrix may be represented by bytes, so that the matrix coordinates may be determined by the bytes, and thus, the matrix element located at the current position may be extracted according to the position corresponding to the matrix coordinates in the matrix.
In the embodiment of the application, m first matrix elements are randomly extracted according to a plurality of bytes included in the first random number, so that a random extraction function is realized, and the randomness of the first private key is ensured, thereby enabling the generated digital signature to have randomness. To ensure the security of the quick generation of the signature, the first private key sk m needs to be able to cover the entire range of [1, n-1 ].
In one possible implementation, m second matrix elements identical to the first matrix element coordinates are extracted from a public key matrix that is generated in advance and corresponds to the private key matrix, and m second matrix elements corresponding to the matrix coordinates may be extracted from the public key matrix according to the m matrix coordinates.
The extraction rule of the second matrix element is similar to that of the first matrix element, and is not described here again.
The public key corresponding to the first private key sk m generated by combining the m first matrix elements according to the combined public key is the first public key PK m generated by combining the m second matrix elements with the same coordinates as the first matrix elements.
In one possible implementation, when generating the hash information, the preprocessing information may be generated according to the relevant parameters of the elliptic curve and the identity of the signer, and the hash value may be generated according to the preprocessing information.
Initializing elliptic curve related parameters, calculating preprocessing information through a formula ZA=H256(ENTLA||IDA||a||b||xG||yG||xA||yA), wherein Z A is used for representing the preprocessing information, H 256 () is used for representing a hash function, ID A is used for representing a signer identity, ENTL A is two bytes converted by the bit length of ID A, a and b are used for representing two elements in a prime field Fp and satisfy y 2=x3+ax+b,(xG,yG) is used for representing coordinates of a base point G on the elliptic curve, n is an order of the base point G, (x A,yA) is used for representing a signature public key held by the signer, and a corresponding signature private key is d A, namely (x A,yA)=dA) G.
After the preprocessing information Z A is calculated, a hash value is calculated according to the preprocessing information Z A by the following formula e=h v(ZA ||m), where H v () is used to characterize the hash function, M is used to characterize the encoding of the information to be transmitted, and e is used to characterize the hash value. So that generation of a hash value can be achieved.
It should be appreciated that H 256 () and H v () are used to characterize a hash function, typically the cryptographic SM3 hash algorithm, by which a hash value can be generated.
In the embodiment of the application, the preprocessing information is generated through the relevant parameters of the elliptic curve and the identity of the signer, so that the hash value can be generated according to the preprocessing information, the preprocessing process in the rapid signature generation process is completed, and the normal operation of the rapid signature generation process is ensured.
Fig. 2 is a flowchart of another signature quick generation method according to an embodiment of the present application, as shown in fig. 2, the method includes the following steps 201 to 208:
step 201, a first random number is generated.
Step 202, extracting m first matrix elements from a pre-generated private key matrix according to a first random number, wherein m is a positive integer greater than or equal to 2.
Step 203, extracting m second matrix elements with the same coordinates as the first matrix elements from a public key matrix which is generated in advance and corresponds to the private key matrix.
Step 204, adding m first matrix elements to obtain a first private key, and adding m second matrix elements to obtain a first public key.
The first private key corresponds to a combination of m first matrix elements and the first public key corresponds to a combination of m second matrix operations.
It should be noted that, the steps 201 to 204 are similar to the steps 101 to 104 in other embodiments of the present application, and detailed descriptions thereof are omitted herein, and detailed descriptions of the steps 101 to 104 in other embodiments of the present application are omitted.
Step 205, obtain the second private key and the second public key used for last generation of the digital signature.
The second private key and the second public key used last time the digital signature was generated are obtained.
It should be appreciated that different digital signature devices may generate digital signatures multiple times depending on the signer's difference or data, e.g., two data of signer a may run a two-time digital signature method to generate two digital signatures, and then signer B may generate one digital signature for a total of 3 digital signatures. Thus, the second private key and the second public key used when the digital signature device performs the second digital signature are obtained for the first digital signature, the second private key and the second public key used for the second signature are obtained for the third signature, and so on.
Step 206, adding the first private key and the second private key used for generating the digital signature last time to obtain the second private key used for generating the digital signature last time.
Adding the first private key generated this time and the second private key used for generating the digital signature last time to obtain a second private key used for generating the digital signature this time, that is, sk i=ski-1+skm,ski is used for representing the second private key used for generating the digital signature this time, sk i-1 is used for representing the second private key used for generating the digital signature last time, and sk m is used for representing the first private key. The second private key of the ith signature thus corresponds to a combination of i x m first matrix elements.
Step 207, adding the first public key to the second public key used for generating the digital signature last time, and obtaining the second public key used for generating the digital signature currently.
And adding the first public key generated at this time and the second public key used for generating the digital signature last time to obtain the second public key used for generating the digital signature at this time, namely PK i=PKi-1+PKm,PKi is used for representing the second public key used for generating the digital signature at this time, PK i-1 is used for representing the second public key used for generating the digital signature last time, and PK m is used for representing the first public key. The second public key of the ith signature thus corresponds to a combination of i x m second matrix elements.
It should be understood that, since the private key matrix and the public key matrix are usually not too large, and are generally 16×16 matrices, only 256 elements, or j×j matrices, and only j 2 elements, 3-5 elements are randomly selected and added, and the first private key cannot cover the whole range of the finite field [1, n-1], so that the combination of the private key and the public key can be infinitely many by always accumulating in the generation process of the private key and the public key, the second private key can cover the whole range of [1, n-1], the range [1, n-1] of generating the random number k in the original signature step is satisfied, and the second public key is the public key corresponding to the second private key, so that the result of generating the random number k and calculating the dot product of k and the base point G in the original signature step can be replaced. And the first/second private key and the first/second public key are intermediate values of signature operation and are not disclosed, and the first matrix and the second matrix are not disclosed, so that linear collusion attack of the combined public keys can be avoided.
Step 208, generating the digital signature of the current time according to the second private key for generating the digital signature of the current time, the second public key for generating the digital signature of the current time and the hash value.
The current digital signature is generated from the current second private key sk i that generated the digital signature, the current second public key PK i that generated the digital signature, and the hash value.
In the embodiment of the application, a plurality of first matrix elements and second matrix elements are randomly selected, and the second private key and the second public key are always respectively accumulated to generate the digital signature according to the second private key and the second public key, so that the generation of the digital signature is realized, the second private key and the second public key used by accumulating the last digital signature when the second private key and the second public key are generated are accumulated, the generation range of the second private key and the second public key is larger, the generation range of the random number k of the original signature is met, the related matrix and the result are not disclosed as the intermediate value of the signature, the situation that the digital signature is cracked due to collusion attack is avoided, and the safety of the rapid signature generation method is improved.
In one possible implementation, before generating the digital signature of the current time according to the second private key used for generating the digital signature of the current time, the second public key used for generating the digital signature of the current time and the hash value, whether the second private key is equal to 0 may be further determined, and if the second private key is equal to 0, the generation of the first random number is performed to regenerate the second private key.
Since the value range of the random number k in the original signature generation method is [1, n-1], and the range of the second private key finite field is [0, n-1], if the value of the second private key is 0, the process of generating the random number is re-executed, so that a new first private key can be generated according to the generated new random number, and a new second private key can be generated.
In the embodiment of the application, whether the second private key is equal to 0 is judged, if the second private key is equal to 0, the random number is regenerated, and then the second private key can be regenerated, so that the second private key generated according to the method meets the value of the random number in the original signature process, and the process of generating the random number in the original signature method can be replaced.
In one possible implementation, when the digital signature of the current time is generated according to the second private key used for generating the digital signature of the current time, the second public key used for generating the digital signature of the current time and the hash value, the first signature part can be generated according to the hash value and/or the second public key used for generating the digital signature of the current time, the second signature part is generated according to the hash value and/or the second private key used for generating the digital signature of the current time, the signature private key and the first signature part are generated, and then the first signature part and the second signature part are combined to generate the digital signature.
The first signature part r is calculated from the second public key and the hash value of the digital signature currently generated by the following formula r= (e+x 1) mod n, where e is the hash value of the signed message, x 1 is used to characterize the x-axis coordinates of the second public key PK i and n is used to characterize the order of the base point G.
Or the first signature part r in the ECDSA signature process may be calculated from the second public key that is currently generated into a digital signature by the following formula r=x 1 mod n.
It should be appreciated that since the generation process of the public key is a point-plus-operation of the elliptic curve, the final value of the second public key is a point (x 1,y1) on the elliptic curve.
The second signature part s is generated from the second private key and the first signature part for the current generation of the digital signature by the following formula s= ((1+d A)-1*(ski-r*dA)) mod n, where d A is used to characterize the signature private key held by the signing user, sk i is used to characterize the second private key. The above is a signing procedure of the alternative national cipher SM 2.
The ECDSA signing process can also be replaced by calculating r=x 1 mod n by the x-axis coordinate x 1 of the second public key PK i, and calculating s= (sk i -1*(e+r*dA)) mod n, where sk i is used to characterize the second private key, e is the hash value of the signed message, d A is used to characterize the private key of the signature held by the signing user, and n is used to characterize the order of the base point G.
Similarly, the dot product operation that needs to generate the random number k and calculate k×g in the signature process of Schnorr, etc. can be replaced, and the replacement principle is the same as that described above, and will not be repeated here. Therefore, the signature rapid generation method has certain universality, the method can be used for replacing a second private key sk i and a second public key PK i in any point multiplication operation of generating a random number k and calculating k G in the signature process, the generated second private key sk i can meet the value coverage range [1, n-1] of k and has randomness, the security can be met, and the generated second public key PK i is the public key corresponding to sk i. Therefore, the signature does not need to calculate point multiplication operation any more, and only needs a small amount of finite field addition operation and a small amount of elliptic curve point addition operation, so that the operation amount required by the signature process can be reduced.
It should be further understood that, according to the ECC composite characteristic, the second public key is equal to the second private key multiplied by the base point G, that is, pk= [ sk ] = [ k ]. G, so as to satisfy the relation of (x 1,y1) = [ k ]. G in the prior art, and because the second private key is a random value, the second public key is a point on the elliptic curve, so that the second private key can replace the random number k in the prior art, the second public key can replace the elliptic curve point (x 1,y1) in the prior art, so that dot multiplication operation is not required, and only elliptic curve point addition operation and finite field addition operation are required to satisfy the elements required in the signature rapid generation process, and the derivation result of the specific ECC composite characteristic is not repeated herein.
The first signature part r and the second signature part s are combined and a signature (r, s) is output.
The evaluation was performed based on the calculation amount in the state secret SM2 document, and the addition and subtraction calculation amount of the finite field < the square calculation (S) amount of the finite field < the multiplication calculation (M) amount of the finite field < the inversion calculation (I) amount of the finite field. The point addition of SM2 in Jacobian accentuation projection coordinate system on Fp domain requires (12m+4s) computation, and the 2-fold point requires (4m+6s) computation. The method provided by the application optimizes the calculation process to calculate M times of point addition operations, the operand of the rest steps can be converted into 1M, namely, let t= (1+d A)-1 mod n, s= (t (sk i +r) -r) mod n), so that the ratio of the actual signature operand of M value 3-5 is about (37-61M+12-20S)/(897M+448S), and the total operand required by signature is less than the previous 1/10, thereby improving the signature performance of the password equipment.
In the embodiment of the application, the digital signature is generated through the second private key, the second public key and the hash value, the second private key and the second public key can be used for replacing the dot multiplication result of the random numbers k and the base point G in the SM2 signature or ECDSA signature step, and the operation of the second private key only needs m finite field addition operations, and the operation of the second public key only needs m finite field dot addition operations (because m elements are added and m-1 addition operations are needed, and then one addition operation is carried out with the second private key result or the second public key result of the last signature), so that the operation amount is greatly reduced when the signature is rapidly generated, and the method is suitable for signature generating equipment with poor performance, and therefore, the signature rapid generation method has higher applicability. The signature performance of the same cipher device in unit time can be improved by reducing the operation amount of the signature.
In one possible implementation, before combining the first signature part and the second signature part to generate the digital signature, it is determined whether the first signature part and the second signature part are constantly equal to 0. If the first signature part and/or the second signature part is/are constant equal to 0, then the generation of the first random number is performed to regenerate the digital signature.
When the first signature part and/or the second signature part are/is equal to 0, the step of generating the first random number, that is, the step 101 and the step 201 in other embodiments of the present application, is re-executed, and after the first random number is re-generated, the first private key and the first public key are changed due to the change of the first random number, so that the result of the subsequent steps is changed, and thus the first signature part and the second signature part can be re-generated until the requirement is met.
In the embodiment of the application, when the first signature part and/or the second signature part do not meet the requirement, the first random number is regenerated, so that the validity of the digital signature is ensured, the occurrence of invalid digital signature generation is avoided, and the safety of the signature rapid generation method is improved.
Fig. 3 is a schematic diagram of a signature rapid generating apparatus according to an embodiment of the present application, as shown in fig. 3, the apparatus 300 includes:
a first generation module 301 is configured to generate a first random number.
The first extraction module 302 is configured to extract m first matrix elements from a private key matrix generated in advance according to a first random number, where m is a positive integer greater than or equal to 2.
The second extraction module 303 is configured to extract m second matrix elements with coordinates identical to those of the first matrix elements from a public key matrix that is generated in advance and corresponds to the private key matrix.
The calculation module 304 is configured to add m first matrix elements to obtain a first private key, and add m second matrix elements to obtain a first public key.
The second generation module 305 is configured to generate a digital signature according to the first private key, the first public key and a hash value generated in advance.
In an embodiment of the present application, the first generating module 301 may be used to perform step 101 in the above method embodiment, the first extracting module 302 may be used to perform step 102 in the above method embodiment, the second extracting module 303 may be used to perform step 103 in the above method embodiment, the calculating module 304 may be used to perform step 104 in the above method embodiment, and the second generating module 305 may be used to perform step 105 in the above method embodiment.
In one possible implementation, the first extraction module 302 may be configured to determine M bytes from M bytes included in the first random number, where M is a positive integer greater than or equal to M, determine M matrix coordinates according to content corresponding to the M bytes in the first random number, and extract M first matrix elements corresponding to the matrix coordinates from the private key matrix according to the M matrix coordinates.
In one possible implementation, the second extraction module 303 may be configured to extract m second matrix elements corresponding to the matrix coordinates from the public key matrix according to the m matrix coordinates.
In one possible implementation, the signature rapid generation apparatus 300 may further generate preprocessing information according to the relevant parameters of the elliptic curve and the identity of the signer, and generate a hash value according to the preprocessing information.
In one possible implementation, the second generation module 305 may be configured to obtain a second private key and a second public key for generating the digital signature last time, add the first private key to the second private key for generating the digital signature last time to obtain the second private key for generating the digital signature last time, add the first public key to the second public key for generating the digital signature last time to obtain the second public key for generating the digital signature last time, and generate the digital signature last time based on the second private key for generating the digital signature last time, the second public key for generating the digital signature last time, and the hash value.
In one possible implementation, the second generation module 305 may be configured to generate the first signature part based on the hash value and/or the second public key used to generate the digital signature currently, generate the second signature part based on the hash value and/or the second private key used to generate the digital signature currently, and the signature private key and the first signature part, and combine the first signature part and the second signature part to generate the digital signature.
In one possible implementation, the second generation module 305 may be configured to determine whether the first signature part and the second signature part are equal to 0, and if the first signature part and/or the second signature part are equal to 0, perform generation of the first random number to regenerate the digital signature.
It should be noted that, because the content such as information interaction and execution process between each module in the signature rapid generation device is based on the same concept as that of the signature rapid generation method embodiment, specific content can be referred to the description in the signature rapid generation method embodiment, and will not be repeated here.
Referring to fig. 4, a schematic structural diagram of an electronic device according to an embodiment of the present application is shown, and the specific embodiment of the present application is not limited to the specific implementation of the electronic device.
As shown in FIG. 4, the electronic device may include a processor 402, a communication interface (Communications Interface) 404, a memory 406, and a communication bus 408.
Wherein:
processor 402, communication interface 404, and memory 406 communicate with each other via communication bus 408.
A communication interface 404 for communicating with other electronic devices or servers.
The processor 402 is configured to execute the program 410, and may specifically perform relevant steps in the foregoing signature rapid generation method embodiment.
In particular, program 410 may include program code including computer-operating instructions.
Processor 402 may be a Central Processing Unit (CPU), or a graphics processor GPU (Graphics Processing Unit), or an Application SPECIFIC INTEGRATED Circuit (ASIC), or one or more integrated circuits configured to implement embodiments of the application. The one or more processors included in the smart device may be the same type of processor, such as one or more CPUs, one or more GPUs, or different types of processors, such as one or more CPUs and one or more GPUs and one or more ASICs.
Memory 406 for storing programs 410. Memory 406 may comprise high-speed RAM memory or may also include non-volatile memory (non-volatile memory), such as at least one disk memory.
Program 410 may be specifically configured to cause processor 402 to perform the signature rapid generation method of any of the foregoing embodiments.
The specific implementation of each step in the procedure 410 may refer to corresponding descriptions in the corresponding steps and units in any of the foregoing signature rapid generation method embodiments, which are not repeated herein. It will be clear to those skilled in the art that, for convenience and brevity of description, specific working procedures of the apparatus and modules described above may refer to corresponding procedure descriptions in the foregoing method embodiments, which are not repeated herein.
In the embodiment of the application, the first matrix element and the second matrix element are extracted through the generated random number, the first private key is obtained by adding the extracted first matrix element, and the first public key is obtained by adding the second matrix element, so that the digital signature is generated according to the first private key, the first public key and the hash value, the first public key generated by adopting the first private key generated by finite field addition operation and the first public key generated by elliptic curve point addition operation replaces the result of the dot multiplication operation of the generated random number k, the calculation k and the base point G in the existing signature generation method, the dot multiplication operation is not needed in the generation process of the digital signature, and the operation amount of a small amount of finite field addition operation and a small amount of elliptic curve point addition operation is far smaller than that of one dot multiplication operation. The signature performance of the same cipher device in unit time can be improved by reducing the operation amount of the signature.
Embodiments of the present application also provide a computer program product comprising computer instructions that instruct a computing device to perform operations corresponding to any one of the above-described method embodiments.
It should be noted that, according to implementation requirements, each component/step described in the embodiments of the present application may be split into more components/steps, or two or more components/steps or part of operations of the components/steps may be combined into new components/steps, so as to achieve the objects of the embodiments of the present application.
The above-described methods according to embodiments of the present application may be implemented in hardware, firmware, or as software or computer code storable in a recording medium such as a CD ROM, RAM, floppy disk, hard disk, or magneto-optical disk, or as computer code originally stored in a remote recording medium or a non-transitory machine-readable medium and to be stored in a local recording medium downloaded through a network, so that the methods described herein may be stored on such software processes on a recording medium using a general purpose computer, special purpose processor, or programmable or special purpose hardware such as an ASIC or FPGA. It is understood that a computer, processor, microprocessor controller, or programmable hardware includes a memory component (e.g., RAM, ROM, flash memory, etc.) that can store or receive software or computer code that, when accessed and executed by the computer, processor, or hardware, implements the signature rapid generation methods described herein. Further, when the general-purpose computer accesses code for implementing the signature rapid generation method shown herein, execution of the code converts the general-purpose computer into a special-purpose computer for executing the signature rapid generation method shown herein.
Those of ordinary skill in the art will appreciate that the elements and method steps of the examples described in connection with the embodiments disclosed herein can be implemented as electronic hardware, or as a combination of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the embodiments of the present application.
The above embodiments are only for illustrating the embodiments of the present application, but not for limiting the embodiments of the present application, and various changes and modifications may be made by one skilled in the relevant art without departing from the spirit and scope of the embodiments of the present application, so that all equivalent technical solutions also fall within the scope of the embodiments of the present application, and the scope of the embodiments of the present application should be defined by the claims.