SM2 rapid implementation method based on improved Montgomery domain large number operation
By optimizing the addition, subtraction and point multiplication operations of the SM2 algorithm in the Montgomery domain, the problem of low efficiency of large-number operations of the original SM2 algorithm is solved, and more efficient encryption and decryption performance and resource utilization are achieved, which promotes the development of my country's cryptographic algorithm and application.
Patent Information
- Application Number
- CN202411051546.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-01
- Publication Date
- 2024-12-27
AI Technical Summary
The original SM2 algorithm is slow in large numbers and has high computational complexity, resulting in more resource consumption. It is necessary to develop more efficient implementation technologies to improve the encryption and decryption efficiency.
Using improved Montgomery domain large number operation, the addition, subtraction and point multiplication operations in the SM2 algorithm are performed on the Montgomery domain, and the repeated calculations and modulo N operations are avoided, the Montgomery domain conversion is optimized, the power calculation efficiency is improved, and combined with the SM3 algorithm is used. Hash operation and key generation.
It significantly improves the performance and efficiency of the SM2 algorithm, reduces resource consumption, enhances the flexibility and portability of the algorithm, and enhances the competitiveness in the field of information security.
Smart Images

Figure CN119210722A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of digital information transmission, in particular to a fast SM2 implementation method based on improved Montgomery field large number operation. Background Art
[0002] The SM2 cryptographic algorithm is an asymmetric encryption algorithm independently developed in my country. Its security has been widely recognized and applied in many fields.
[0003] However, the original SM2 algorithm uses a public key cryptography system based on elliptic curves and calculates message digests through the SM3 hash algorithm, but has the following problems when performing large number operations: 1. The efficiency of large number operations is slow. The large number operations used by SM2 are modular exponentiation calculations modulo n, which require multiple modulo n operations, increasing the computational complexity and time cost; 2. The scale of large numbers is too large, and the parameter scale in SM2 is large, resulting in more consumption of computing resources and memory space.
[0004] Since the original SM2 algorithm still has performance bottlenecks in large number operations, and large number operations require a lot of computing resources and time, it is necessary to develop faster and more efficient SM2 implementation technologies to improve its encryption and decryption efficiency. Summary of the invention
[0005] In view of the problems existing in the above-mentioned original SM2 algorithm, the present invention is proposed.
[0006] Therefore, the problem to be solved by the present invention is how to provide a more efficient SM2 implementation technology.
[0007] In order to solve the above technical problems, the present invention provides the following technical solutions:
[0008] In the first aspect, an embodiment of the present invention provides a fast implementation method of SM2 based on improved Montgomery field large number operations, which includes performing optimized Montgomery field conversion; performing addition and subtraction operations in the SM2 algorithm on the Montgomery field; and encrypting and decrypting SM2 to obtain plaintext.
[0009] As a preferred solution of the SM2 fast implementation method based on the improved Montgomery field large number operation of the present invention, wherein: the addition and subtraction operations in the SM2 algorithm are performed on the Montgomery field, including: the power calculation in the SM2 algorithm is performed on the Montgomery field, and the formula is as follows:
[0010] A^(d mod(p-1))=B×R mod p
[0011] Among them, A is the original large number, d is the exponent, B is the point on the Montgomery field, and R is a base element; the point multiplication operation in the SM2 algorithm is performed on the Montgomery field, that is, the point on the elliptic curve is converted to a point on the Montgomery field, the point multiplication calculation is performed, and the result is converted back to a point on the elliptic curve, that is:
[0012] B=A×R^(-1)mod p
[0013] Among them, B is a point on the Montgomery field, A is a point on the elliptic curve, R is a base element, and R^(-1) is the inverse element of R in the sense of modulo p.
[0014] As a preferred solution of the SM2 fast implementation method based on improved Montgomery field large number operation described in the present invention, the encryption and decryption of SM2 to obtain plaintext includes the following steps: selecting a set of elliptic curve parameters and random numbers to generate a public key and a private key; performing a hash operation on the plaintext according to the SM3 algorithm to obtain a message digest; determining a point S on the elliptic curve; calculating the SM3 hash value and the Montgomery coordinates of the point S to obtain a key; using the key K to perform an XOR operation on the plaintext to obtain a ciphertext C2, and at the same time using the SM3 algorithm to perform a hash operation on C2 to obtain a check value C3; the ciphertext C1, the check value C3 and the ciphertext C2 are combined into a ciphertext output; after the recipient obtains the ciphertext, the private key is used for calculation; C2 and C3 are verified, and if the verification fails, it indicates that the ciphertext has been tampered with; using the key K to perform an XOR operation on C2 to obtain the plaintext.
[0015] As a preferred solution of the SM2 fast implementation method based on improved Montgomery field large number operation described in the present invention, wherein: the hash operation is performed on the plaintext according to the SM3 algorithm to obtain the message digest, including: the plaintext M is divided into a number of plaintext data blocks of equal length; a padding operation is performed on each plaintext data block, and an iterative compression operation is performed on the padded plaintext data block; the iterative compression operation consists of a Boolean function, a constant and a bit cyclic shift to obtain a hash value of a fixed length as the message digest; a random number is selected to calculate the point on the elliptic curve:
[0016] C1=k×G
[0017] Among them, k is a random number and G is the base point.
[0018] As a preferred solution of the SM2 fast implementation method based on the improved Montgomery field large number operation of the present invention, the calculation process of determining the point S on the elliptic curve is:
[0019] S=h(dA)×C1
[0020] h(dA)=dA.G
[0021] Where dA is the private key, and h is a function that represents the product of the private key dA and the base point G;
[0022] The calculation process of calculating the SM3 hash value and the Montgomery coordinates of the S point is:
[0023] K = SM3 hash || Sx
[0024] Among them, Sx is the x-mark of point S on the SM2 curve, which serves as the encryption key.
[0025] As a preferred solution of the SM2 fast implementation method based on improved Montgomery field large number operation of the present invention, the process of composing the ciphertext C1, the check value C3 and the ciphertext C2 into a ciphertext output is:
[0026] Ciphertext = length field||C1||C3||C2||check field
[0027] Among them, the length field records the length of the subsequent fields for parsing; C1, C3, and C2 are the values calculated during encryption; the check field is the check value of the previous fields and is used to detect errors.
[0028] As a preferred solution of the SM2 fast implementation method based on improved Montgomery field large number operation described in the present invention, the process of verifying C2 and C3 is as follows: according to the format of the ciphertext, C1, C3, and C2 are parsed, and the plaintext C1' obtained by decryption is calculated using the private key of the receiver; the corresponding S' point is calculated based on the decrypted plaintext C1'; the key K' is calculated using the S' point; C2 is decrypted using K' to obtain the plaintext M'; the hash value H' is calculated for M' using the SM3 algorithm; H' is compared with C3, and if they are equal, the verification passes; if they are not equal, it means that the received ciphertext C2 has been tampered with during transmission or there is a problem with the ciphertext sent by the sender.
[0029] In the second aspect, in order to further solve the problems existing in the original SM2 algorithm, the embodiment of the present invention provides an SM2 fast implementation system based on improved Montgomery domain large number operations, which includes: a conversion module, used to optimize the Montgomery domain conversion process; an operation module, used to perform addition and subtraction operations in the SM2 algorithm on the Montgomery domain, avoiding repeated calculations and modulo N operations through R operations; an SM2 encryption and decryption module, used to perform encryption and decryption operations on SM2, including generating public keys and private keys, performing hash operations on plaintext, determining points on the elliptic curve, calculating SM3 hash values and S points, generating keys, encrypting plaintext and generating ciphertext, and verifying the integrity of the ciphertext to finally obtain the plaintext.
[0030] In a third aspect, an embodiment of the present invention provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, wherein: when the computer program is executed by the processor, any step of the SM2 fast implementation method based on improved Montgomery field large number operations as described in the first aspect of the present invention is implemented.
[0031] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein: when the computer program is executed by a processor, any step of the SM2 fast implementation method based on improved Montgomery field large number operations as described in the first aspect of the present invention is implemented.
[0032] The beneficial effect of the present invention is that the SM2 fast implementation technology based on improved Montgomery field large number operations proposed in the present invention can significantly improve the performance and efficiency of the SM2 algorithm, reduce resource consumption, and enhance the flexibility and portability of the algorithm, which is of great significance for promoting the development and application of cryptographic algorithms in my country, and helps to enhance my country's competitiveness in the field of global information security. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for describing the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. Among them:
[0034] Figure 1 This is a flow chart of the SM2 fast implementation method based on improved Montgomery field large number operations in Example 1. DETAILED DESCRIPTION
[0035] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are described in detail below in conjunction with the accompanying drawings.
[0036] In the following description, many specific details are set forth to facilitate a full understanding of the present invention, but the present invention may also be implemented in other ways different from those described herein, and those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.
[0037] Secondly, the term "one embodiment" or "embodiment" as used herein refers to a specific feature, structure, or characteristic that may be included in at least one implementation of the present invention. The term "in one embodiment" that appears in different places in this specification does not necessarily refer to the same embodiment, nor does it refer to a separate or selective embodiment that is mutually exclusive with other embodiments.
[0038] Example 1
[0039] Reference Figure 1 , which is the first embodiment of the present invention, provides a fast implementation method of SM2 based on improved Montgomery field large number operation, comprising the following steps:
[0040] S1: Perform optimized Montgomery domain transformation.
[0041] S1.1: Mathematical transformations.
[0042] The core of Montgomery field conversion is to convert an integer a into the form of aR mod N, where R is a preselected base and N is the modulus. In order to simplify this process, new mathematical methods and techniques can be explored: for example, in the conversion process, by expanding the variant of Euclidean algorithm, a more efficient algorithm can be used to calculate the modular inverse; Montgomery field conversion depends on the selection of N and R, and through in-depth research on number theory, N and R with special properties can be found to simplify the conversion process; choosing a suitable R can reduce the amount of calculation in the conversion process. For example, choosing R that is easy to calculate can reduce the number of square operations.
[0043] S1.2: Preprocessing is an effective means to improve algorithm performance, especially when the same calculation is performed frequently, including the following steps:
[0044] Pre-calculate multiple powers of R and store these values. In actual operations, you can directly look up these pre-stored values without having to calculate them each time.
[0045] If N is fixed, some constants related to N can be pre-computed and stored, such as the factorization of N-1, to speed up the modular exponentiation operation.
[0046] For large numbers that are used repeatedly, a caching mechanism can be used to avoid repeated calculations.
[0047] S1.3: The fast power algorithm is a technique to reduce the number of multiplications in modular power operations, which can be used to optimize power operations in the Montgomery domain:
[0048] Specifically, the basic idea of the fast power algorithm is to perform the power operation a k mod N is converted into a series of square and multiplication operations, which can significantly increase the operation speed by reducing the number of multiplications.
[0049] In the Montgomery field, multiplication operations can be implemented by Montgomery multiplication, which can maintain the characteristics of the field and reduce the number of modular inversion operations.
[0050] The complexity of the exponentiation k can be reduced by breaking it up into smaller parts (e.g., using a windowing method like "four squaring" or "one square one multiplication").
[0051] Through the above optimization measures, the efficiency of Montgomery domain transformation can be significantly improved, thereby improving the performance of the entire SM2 algorithm. These optimizations can not only reduce the calculation time, but also reduce the algorithm's demand for computing resources during execution.
[0052] S2: The addition and subtraction operations in the SM2 algorithm are performed on the Montgomery field, that is, R operations, to avoid repeated calculations and modulo n operations.
[0053] Specifically, the power calculation in the SM2 algorithm is performed on the Montgomery field as follows:
[0054] A^(d mod(p-1))=B×R mod p
[0055] Among them, A is the original large number, d is the exponent, B is the point on the Montgomery field, R is a base element, and is an identity element under the field.
[0056] The point multiplication operation in the SM2 algorithm is performed on the Montgomery field, that is, the points on the elliptic curve are converted to points on the Montgomery field, the point multiplication calculation is performed on the field, and the result is converted back to a point on the elliptic curve, that is:
[0057] B=A×R^(-1)mod p
[0058] Among them, B is a point on the Montgomery field, A is a point on the elliptic curve, R is a base element, and R^(-1) is the inverse element of R in the sense of modulo p.
[0059] It should be noted that the R operation converts an integer x into the Montgomery domain into the form of x*R (mod N). This conversion avoids the need to perform modulo N operations during the calculation process, thereby greatly reducing the computational overhead.
[0060] In the SM2 algorithm, addition and subtraction operations are performed on the Montgomery domain, taking advantage of the high efficiency of the R operation. The advantages of this approach are: it avoids the overhead of traditional modular operations, speeds up the calculation, keeps the intermediate results in the Montgomery domain, avoids unnecessary conversion overhead, and uses hardware instruction acceleration to further improve efficiency at the hardware level.
[0061] S3: Encrypt and decrypt SM2 to obtain plain text.
[0062] Specifically, S3.1: Select a set of elliptic curve parameters and random numbers to generate a public key and a private key.
[0063] Furthermore, the selection of elliptic curve parameters must meet the following requirements: satisfy the elliptic curve equation, have a large enough order to resist attacks, the order of the base point G is large enough to ensure the key space, and the parameters can be made public without the need for confidentiality.
[0064] The role of the random number k is to ensure that each operation is different during encryption and to enhance the security of the ciphertext. The random number k must be used temporarily and destroyed in a timely manner and cannot be reused, otherwise the key will be leaked.
[0065] S3.2: Perform hash operation on the plaintext according to the SM3 algorithm to obtain the message digest.
[0066] Pick a random number and calculate the point on the elliptic curve:
[0067] C1=k×G
[0068] Among them, k is a random number and G is the base point.
[0069] Furthermore, the process of performing hash operation on plaintext to obtain message digest according to SM3 algorithm is as follows: plaintext M is divided into several plaintext data blocks of equal length, a padding operation is performed on each plaintext data block, and an iterative compression operation is performed on the padded plaintext data block. The iterative compression operation consists of Boolean function, constant and bit rotation, and finally a fixed-length hash value is obtained as the message digest.
[0070] Specifically, pad the plaintext so that its bit length is equal to an integer multiple of 512, divide the padded plaintext into 16 32-bit groups, set registers A, B, C, D, and E with initial values as link variables, and perform 64 iterative compression operations; XOR ABCDE with the link variable to obtain a new link variable, and represent the new link variable as a 128-bit hexadecimal number, which is the message digest.
[0071] S3.3: Determine the point S on the elliptic curve:
[0072] S=h(dA)×C1
[0073] h(dA)=dA.G
[0074] Where dA is the private key, and h is a function that represents the product of the private key dA and the base point G;
[0075] S3.4: Calculate the SM3 hash value and the Montgomery coordinates of point S to get the key:
[0076] K = SM3 hash || Sx
[0077] Among them, Sx is the x-mark of point S on the SM2 curve, which serves as the encryption key.
[0078] It should be noted that the purpose of calculating the key K by concatenating the SM3 hash value and the x-coordinate of point S is to improve the entropy of the key, enhance the randomness of the key, make full use of the intermediate results of the SM2 operation, and the SM3 hash ensures that the source of the key is credible.
[0079] The advantage of this method is higher security, but the disadvantage is that the key length will increase, and the storage and transmission overhead will also increase.
[0080] S3.5: Use the key K to perform an XOR operation on the plaintext to obtain the ciphertext C2, and use the SM3 algorithm to perform a hash operation on C2 to obtain the check value C3.
[0081] Furthermore, the process of using the SM3 algorithm to perform a hash operation on C2 to obtain the check value C3 is as follows: C2 is divided into several data blocks of equal length, a padding operation is performed on each data block, and the padded data block is input into the SM3 algorithm; the iterative compression operation process of the SM3 algorithm is started, and finally a 128-bit hash value is output after multiple rounds of iterations. This hash value is the digital signature check value C3 of C2.
[0082] Specifically, pad C2 so that its bit length is equal to an integer multiple of 512, divide the padded C2 into 16 32-bit groups, set registers A, B, C, D, and E to preset values initially, perform 64 iterative compression operations, XOR ABCDE with the preset values to obtain C3, and output C3 as a 128-bit hexadecimal number.
[0083] It should be noted that C3 generated by the SM3 algorithm can ensure that C2 has not been tampered with during transmission, the sender's identity is legal and valid, and can provide digital signature services for C2.
[0084] The check value C3 is used to detect whether the ciphertext has been tampered with during transmission, and C3 is calculated by the hash value of C2. The receiver recalculates the hash value of C2 and compares it with C3.
[0085] S3.6: Combine C1, C3 and C2 to form the ciphertext output.
[0086] Preferably, the process of C1, C3 and C2 forming the ciphertext is as follows:
[0087] Ciphertext = length field||C1||C3||C2||check field
[0088] Among them, the length field records the length of the subsequent fields for parsing; C1, C3, and C2 are the values calculated during encryption; the check field is the check value of the previous fields, which can detect errors.
[0089] The length field helps in parsing and avoids length confusion, the check field can verify the integrity of the ciphertext, and this format is clear and convenient for hardware-accelerated parsing.
[0090] S3.7: After the receiver obtains the ciphertext, it uses the private key to calculate:
[0091] C1'=dB*C1
[0092] And calculate the SM3 hash value and S point based on C1, and calculate the key K.
[0093] S3.8: Verify C2 and C3. If the verification fails, it means that the ciphertext has been tampered with.
[0094] Preferably, the process of verifying C2 and C3 is as follows: according to the format of the ciphertext, C1, C3, and C2 are parsed, and the plaintext C1' obtained by decryption is calculated using the private key of the receiver, and the corresponding S' point is calculated based on the decrypted plaintext C1'; the key K' is calculated using the S' point; C2 is decrypted using K' to obtain the plaintext M'; the hash value H' is calculated for M' using the SM3 algorithm; H' is compared with C3, and if they are equal, the verification passes; if they are not equal, it means that the received ciphertext C2 has been tampered with during transmission or there is a problem with the ciphertext sent by the sender, which may have been maliciously modified or an error occurred in the key negotiation process and cannot be correctly decrypted, then the receiver will reject the ciphertext and may take the following measures, including requesting the sender to resend the ciphertext, terminating the current session, renegotiating the key, recording the exception, performing audit analysis, and prompting the user that the ciphertext has been tampered with; if it is a malicious attack, you can consider executing a defense strategy.
[0095] Furthermore, the criteria for determining whether the ciphertext has been tampered with include: if C3 is not equal to the recalculated hash value, the ciphertext has been tampered with; if C1 is an invalid point (not on the elliptic curve), the ciphertext has been tampered with; if the key K cannot be correctly decrypted, the ciphertext has been tampered with.
[0096] S3.9: Use the key K to perform an XOR operation on C2 to obtain the plain text.
[0097] This embodiment also provides an SM2 fast implementation system based on improved Montgomery field large number operations, including: a conversion module, used to optimize the Montgomery field conversion process; an operation module, used to perform addition and subtraction operations in the SM2 algorithm on the Montgomery field, avoiding repeated calculations and modulo N operations through R operations; an SM2 encryption and decryption module, used to perform encryption and decryption operations on SM2, including generating public keys and private keys, performing hash operations on plaintext, determining points on the elliptic curve, calculating SM3 hash values and S points, generating keys, encrypting plaintext and generating ciphertext, and verifying the integrity of the ciphertext, and finally obtaining the plaintext.
[0098] This embodiment also provides a computer device, which is suitable for the case of the SM2 fast implementation method based on improved Montgomery field large number operations, including: a memory and a processor; the memory is used to store computer executable instructions, and the processor is used to execute computer executable instructions to implement the SM2 fast implementation method based on improved Montgomery field large number operations as proposed in the above embodiment.
[0099] The computer device may be a terminal, and the computer device includes a processor, a memory, a communication interface, a display screen and an input device connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be achieved through WIFI, an operator network, NFC (near field communication) or other technologies. The display screen of the computer device may be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device may be a touch layer covering the display screen, or a key, trackball or touchpad provided on the housing of the computer device, or an external keyboard, touchpad or mouse, etc.
[0100] This embodiment also provides a storage medium on which a computer program is stored. When the program is executed by a processor, the SM2 fast implementation method based on improved Montgomery field large number operations as proposed in the above embodiment is implemented; the storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (Static Random Access Memory, referred to as SRAM), electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, referred to as EEPROM), erasable programmable read-only memory (Erasable Programmable Read Only Memory, referred to as EPROM), programmable read-only memory (Programmable Red-Only Memory, referred to as PROM), read-only memory (Read-Only Memory, referred to as ROM), magnetic storage, flash memory, magnetic disk or optical disk.
[0101] In summary, the SM2 fast implementation technology based on improved Montgomery field large number operations proposed in the present invention can significantly improve the performance and efficiency of the SM2 algorithm, reduce resource consumption, and enhance the flexibility and portability of the algorithm, which is of great significance for promoting the development and application of cryptographic algorithms in my country, and helps to enhance my country's competitiveness in the global information security field.
[0102] Example 2
[0103] Referring to Table 1, which is the second embodiment of the present invention, in order to further verify the advancement of the present invention, comparative data between the SM2 fast implementation method based on the improved Montgomery field large number operation and the original SM2 algorithm are provided.
[0104] In order to verify the effect of the SM2 fast implementation technology based on Montgomery domain large number operations, we conducted a series of experiments and compared the results with the original SM2 algorithm. The following is an overview of the experimental data and results:
[0105] The experimental environment is as follows:
[0106] Hardware environment: Intel Core i9 processor, 64GB RAM, SSD hard drive;
[0107] Software environment: 64-bit Linux operating system, GCC compiler;
[0108] Test tools: Use a custom test framework, including randomly generated large number test sets and standard encryption test vectors.
[0109] First, use the original SM2 algorithm to encrypt and decrypt randomly generated large numbers, and record the execution time. Then, use the SM2 fast implementation technology based on Montgomery field large number operations to encrypt and decrypt the same test data, and also record the execution time. Compare the execution time of the optimized implementation test with the execution time of the benchmark test, and calculate the performance improvement percentage. Monitor resource consumption such as CPU usage and memory usage during the experiment and compare them. Use standard encryption test vectors to verify the security of the new algorithm to ensure consistency with the original algorithm. The following are the experimental results:
[0110] Table 1 Comparison of experimental results between the present invention and the original SM2 algorithm
[0111] Test items Original SM2 algorithm Optimization algorithm based on Montgomery domain Performance Improvements Encryption speed (MB / S) 12.5 28.3 126% Decryption speed (MB / S) 11.8 26.7 125% CPU usage 70% 50% -28.6% Memory usage (MB) 250 230 -8%
[0112] As can be seen from the table above, the SM2 fast implementation technology based on Montgomery field large number operations has achieved significant improvements in encryption and decryption speeds, increasing by 126% and 125% respectively. This shows that the new algorithm significantly improves the performance and efficiency of the SM2 algorithm while maintaining the original security; and the new algorithm has reduced CPU usage and memory usage by 28.6% and 8% respectively. This helps to reduce the resource consumption of the algorithm in practical applications and improve the overall performance of the system; through standard encryption test vector verification, the new algorithm is consistent with the original SM2 algorithm in terms of security, and there are no security vulnerabilities.
[0113] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention, which should all be included in the scope of the claims of the present invention.
Claims
1. A fast implementation method of SM2 based on improved Montgomery field large number operation, characterized by: include: Perform optimized Montgomery domain conversion; Perform the addition and subtraction operations in the SM2 algorithm on the Montgomery field; Encrypt and decrypt SM2 to obtain plain text.
2. The SM2 fast implementation method based on improved Montgomery field large number operation as claimed in claim 1, characterized in that: The addition and subtraction operations in the SM2 algorithm are performed on the Montgomery domain including: The power calculation in the SM2 algorithm is performed on the Montgomery field, and the formula is as follows: A^(d mod(p-1))=B×R mod p Among them, A is the original large number, d is the exponent, B is the point on the Montgomery field, and R is a base element; The point multiplication operation in the SM2 algorithm is performed on the Montgomery field, that is, the point on the elliptic curve is converted to a point on the Montgomery field, the point multiplication is calculated, and the result is converted back to a point on the elliptic curve, that is: B=A×R^(-1)mod p Among them, B is a point on the Montgomery field, A is a point on the elliptic curve, R is a base element, and R^(-1) is the inverse element of R in the sense of modulo p.
3. The SM2 fast implementation method based on improved Montgomery field large number operation as claimed in claim 2, characterized in that: The encryption and decryption of SM2 to obtain the plaintext includes the following steps: Select a set of elliptic curve parameters and random numbers to generate public and private keys; Perform hash operation on the plaintext according to the SM3 algorithm to obtain the message digest; Determine the point S on the elliptic curve; Calculate the SM3 hash value and the Montgomery coordinates of point S to get the key; Use the key K to perform an XOR operation on the plaintext to obtain the ciphertext C2, and use the SM3 algorithm to perform a hash operation on C2 to obtain the check value C3; The ciphertext C1, check value C3 and ciphertext C2 are combined into a ciphertext output; After the receiver obtains the ciphertext, it uses the private key for calculation; Verify C2 and C3. If the verification fails, it means that the ciphertext has been tampered with. Use the key K to perform an XOR operation on C2 to obtain the plaintext.
4. The SM2 fast implementation method based on improved Montgomery field large number operation as claimed in claim 3, characterized in that: The hash operation of the plaintext according to the SM3 algorithm to obtain the message digest includes: The plaintext M is divided into several plaintext data blocks of equal length; Performing a padding operation on each plaintext data block, and performing an iterative compression operation on the padded plaintext data block; The iterative compression operation consists of Boolean functions, constants, and bit rotation to obtain a fixed-length hash value as the message digest; Pick a random number and calculate the point on the elliptic curve: C1=k×G Among them, k is a random number and G is the base point.
5. The SM2 fast implementation method based on improved Montgomery field large number operation as claimed in claim 4, characterized in that: The calculation process for determining the point S on the elliptic curve is: S=h(dA)×C1 h(dA)=dA.G Where dA is the private key, and h is a function that represents the product of the private key dA and the base point G; The calculation process of calculating the SM3 hash value and the Montgomery coordinates of the S point is: K = SM3 hash || Sx Among them, Sx is the x-mark of point S on the SM2 curve, which serves as the encryption key.
6. The SM2 fast implementation method based on improved Montgomery field large number operation as claimed in claim 5, characterized in that: The process of combining the ciphertext C1, the check value C3 and the ciphertext C2 into a ciphertext output is: Ciphertext = length field||C1||C3||C2||check field Among them, the length field records the length of the subsequent fields for parsing; C1, C3, and C2 are the values calculated during encryption; the check field is the check value of the previous fields and is used to detect errors.
7. The SM2 fast implementation method based on improved Montgomery field large number operation as claimed in claim 6, characterized in that: The process of verifying C2 and C3 is as follows: According to the format of the ciphertext, C1, C3, and C2 are parsed, and the plaintext C1' obtained by decryption is calculated using the recipient's private key; Calculate the corresponding S' point based on the decrypted plaintext C1'; Use point S' to calculate the key K'; Decrypt C2 using K' to obtain plaintext M'; Calculate the hash value H' for M' using the SM3 algorithm; Compare H' with C3. If they are equal, the verification passes. If they are not equal, it means that the received ciphertext C2 has been tampered with during transmission or there is a problem with the ciphertext sent by the sender.
8. A fast SM2 implementation system based on improved Montgomery domain large number operations, based on the fast SM2 implementation method based on improved Montgomery domain large number operations according to any one of claims 1 to 7, characterized in that: include: Conversion module, used to optimize the Montgomery domain conversion process; An operation module, used to perform addition and subtraction operations in the SM2 algorithm on the Montgomery domain, avoiding repeated calculations and modulo-N operations through R operations; The SM2 encryption and decryption module is used to perform encryption and decryption operations on SM2, including generating public keys and private keys, performing hash operations on plaintext, determining points on the elliptic curve, calculating SM3 hash values and S points, generating keys, encrypting plaintext and generating ciphertext, and verifying the integrity of ciphertext to finally obtain plaintext.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the SM2 fast implementation method based on improved Montgomery field large number operations as described in any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the SM2 fast implementation method based on improved Montgomery field large number operations as described in any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Data parallel encryption and decryption method and system based on register
CN121036949A
