SM2 encryption and decryption method and system based on pre-computation and base point caching

By introducing pre-computation and base point caching in the SM2 encryption and decryption process, combined with multi-layer hash verification and hardware root of trust, and utilizing a true random number generator and SM4 encryption algorithm, the problems of excessive computing resource consumption and insufficient security in resource-constrained devices are solved, and efficient and secure encryption and decryption operations are achieved.

CN121193432BActive Publication Date: 2026-02-27SICHUAN ZHONGDIAN AOSTAR INFORMATION TECHNOLOGIES CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202511750388.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-11-26
Publication Date
2026-02-27
Estimated Expiration
2045-11-26

Smart Images

  • Figure CN121193432B_ABST
    Figure CN121193432B_ABST
Patent Text Reader

Abstract

The application relates to an SM2 encryption and decryption method and system based on precalculation and base point caching, and belongs to the technical field of information security. The method comprises the following steps: extracting reference point parameters from an SM2 standard document, generating reference hash values through CRC32; checking the consistency of external storage point parameters and check values, storing the consistent parameters into a cache and performing secondary hash comparison to complete cache initialization; generating a numerical value through a true random number generator, combining cache point parameters after SM4 encryption, generating corresponding points through a sliding window algorithm, and storing the points in a value pool in association with a timestamp; when an encryption request is received, reading valid data of the value pool into a byte stream, decrypting the byte stream through TPM and SM4 to obtain plaintext, performing SM2 lightweight encryption, and splicing the SM2 lightweight encryption into standard SM2 ciphertext according to a format; when decryption is performed, the ciphertext is split, the effectiveness of components is checked, an intermediate point in key negotiation is calculated, a shared key is obtained through a key derivation function, and finally, plaintext is recovered. The application can reduce the real-time operation amount in the encryption and decryption process, and significantly improve the encryption and decryption response speed.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application relates to an SM2 encryption and decryption method and system based on pre-computation and base point caching, and belongs to the technical field of information security. BACKGROUND

[0002] The SM2 algorithm is an elliptic curve public key cryptographic algorithm independently designed by China, and its security is based on the mathematical complexity of the elliptic curve discrete logarithm problem. The SM2 algorithm has been widely applied to the field of information security, covering financial transactions, Internet of Things data transmission, government information interaction and the like. In the encryption and decryption process of the algorithm, the core operations include signature generation based on a private key, signature verification based on a public key, and point multiplication operation on an elliptic curve, which collectively guarantee the security of data transmission and storage.

[0003] For example, the Chinese patent application with the publication number CN107483204A discloses an optimization processing method and device for the SM2 encryption algorithm of the State Secret, which includes the following steps: the method includes twice encryption, and the value association relationship between the previous encryption and the next encryption is pre-set. In the previous encryption, the first and second elliptic curve point coordinates calculated in the encryption process are saved. In the next encryption, the first and second elliptic curve point coordinates of the previous encryption saved are used, and the value association relationship between the previous encryption and the next encryption pre-set is used to calculate the first and second elliptic curve point coordinates of the current encryption, and then the current encryption is completed. However, the above technical solution pre-calculates the value in advance to reduce the time consumption, which is easy to cause security risks (such as value leakage will lead to private key cracking) due to the long storage period of the value and the excessive reuse times, and it is difficult to balance between value large-scale pre-computation and safe application.

[0004] For another example, the Chinese patent application with the publication number CN114895870A discloses an efficient and reconfigurable SM2 point multiplication method and system based on FPGA implementation, which includes the following steps: the random number and the elliptic curve parameter point are preprocessed, including random number bit scanning and conversion of the parameter point to the Montgomery domain and initialization; based on the random number bit information, the doubling and point addition operations are performed in the Montgomery domain through a modulo operation; finally, the calculation result is converted back to the affine coordinate normal domain through coordinate transformation and modulo inverse operation and is output. However, the above technical solution relies on special hardware devices to realize point multiplication operation acceleration, and the research and development, production and procurement of special hardware devices require additional costs, and the interface protocols of hardware devices of different types and brands are different, which leads to the fact that when the scheme is connected with existing devices supporting the SM2 algorithm, a large amount of adaptive development work is required, and the compatibility is poor.

[0005] In summary, there is an urgent need for a random number And perform Dot multiplication operation, in the resource limited scene such as embedded device, Internet of Things terminal, frequent reading Dot data will not occupy additional computing resources, reduce the operation efficiency of a pre-computation and base point cache based on SM2 encryption and decryption method and system. SUMMARY

[0006] In order to solve the problems existing in the prior art, the present application provides a pre-computation and base point cache based SM2 encryption and decryption method and system.

[0007] The technical scheme of the present application is as follows:

[0008] On the one hand, the present application provides a pre-computation and base point cache based SM2 encryption and decryption method, comprising the following steps:

[0009] S100, extracting the reference Point parameters from the preset SM2 elliptic curve public key cryptography standard document, inputting into the CRC32 hash algorithm, outputting the reference hash value, and writing into the non-modifiable storage area of the hardware trust root;

[0010] S200, reading the preset Point parameters and preset Point parameter check value from the preset external storage, inputting the preset Point parameters into the CRC32 hash algorithm to obtain the initial hash value; comparing the initial hash value with the preset Point parameter check value, the preset Point parameter corresponding to the consistent initial hash value is written into the cache, and the key-value pair index is established; the preset Point parameters written into the cache are inputted into the CRC32 hash algorithm to obtain the real-time hash value, and compared with the reference hash value in the non-modifiable storage area of the hardware trust root, and after consistent comparison, the cache initialization of the reference Point parameters is completed;

[0011] S300, based on the true random number generator, a plurality of Values meeting the preset random number conditions are generated; the generated plurality of Values are inputted into the SM4 symmetric encryption algorithm to obtain the encrypted Value ; the encrypted Value And the preset Point parameters in the cache are inputted into the sliding window algorithm to output the corresponding Value Of each encrypted point, and point generation time; according to the encrypted value , combined with each encrypted value corresponding point , get the associated data with point generation time, and store in a preset value pool;

[0012] S400, when receiving a data encryption request, reading the associated data in the value pool that is not used and does not exceed the preset task cycle, obtaining the final standard SM2 ciphertext by decrypting the value in the associated data and performing a lightweight encryption operation;

[0013] S500, splitting the final standard SM2 ciphertext to obtain a ciphertext component, and performing validity verification; using the preset point parameters in the cache, calculating the intermediate point and the derived shared key for key agreement, and restoring the plaintext of the final standard SM2 ciphertext.

[0014] Preferably, the S100 step further comprises:

[0015] inputting the reference hash value to the non-modifiable storage area of the hardware trust root; performing consistency verification on the reference hash value and the reference point parameters using a preset security verification tool; recording the reference hash value generation time and the device serial number that pass the consistency verification, to obtain a hash value generation log.

[0016] Preferably, the hardware trust root comprises a trusted execution environment TEE, a trusted platform module TPM and a secure element SE.

[0017] Preferably, the consistency comparison between the real-time hash value and the reference hash value further comprises the steps of:

[0018] when the comparison result is inconsistent, emptying the preset point parameters in the current cache, and triggering a device alarm at the same time; and re-reading the preset point parameters from the preset external storage space, inputting them to the CRC32 hash algorithm, outputting the initial hash value, comparing the initial hash value with the preset point parameter verification value, writing the preset point parameters that are consistent into the cache, and establishing a key-value pair index; and writing the preset The point parameter is input into a CRC32 hash algorithm, and a real-time hash value is output; the reference hash value and the real-time hash value are compared for consistency, and a new consistency comparison result is obtained.

[0019] After the cache initialization is completed, the consistency comparison operation of the real-time hash value and the reference hash value is repeatedly performed within a preset time.

[0020] Preferably, the step S400 specifically comprises:

[0021] When receiving the data encryption request, the unused associated data that does not exceed a preset task period is read from a value pool, and the associated data is simultaneously encrypted. The point is converted into a byte stream in a non-compressed format; based on a trusted platform module (TPM), the SM4 symmetric encryption algorithm is used to decrypt the value, and a value plaintext is obtained; according to the point and the byte stream in the non-compressed format of the value and the decrypted value plaintext, an SM2 lightweight encryption operation is performed, and a ciphertext component , an encrypted ciphertext byte stream and a message authentication code are obtained; the byte streams are spliced according to a fixed format of the , and a standard SM2 ciphertext is formed.

[0022] Preferably, the step S500 specifically comprises:

[0023] The standard SM2 ciphertext is received, and the byte streams are split according to the fixed format of the ; the split ciphertext component is subjected to validity verification; after the validity verification passes, the intermediate point of the key agreement is calculated according to the ; the intermediate point and the encrypted ciphertext byte stream are input into a key derivation function , and a derived shared key is output; the plaintext of the standard SM2 ciphertext is recovered according to the intermediate point of the key agreement and the derived shared key .

[0024] On the other hand, the application further provides an SM2 algorithm optimization system based on pre-computation and cache base points, comprising the following modules:

[0025] A pre-module: reference ​​Point parameters are input into the CRC32 hash algorithm, the base hash value is output, and written to the immutable storage area of ​​the hardware root of trust.

[0026] Preset caching module: Reads presets from preset external storage. Point parameters and presets Point parameter verification value, preset The point parameters are input into the CRC32 hash algorithm to obtain the initial hash value; the initial hash value is then compared with the preset... Point parameter verification values ​​are compared, and the initial hash values ​​that match are the preset values. Point parameters are written to the cache, and a key-value pair index is created; the preset to be written to the cache is... Point parameters are input into the CRC32 hash algorithm to obtain a real-time hash value, which is then compared with the base hash value in the immutable storage area of ​​the hardware root of trust. If the comparison matches, the base hash value is completed. Initialize the point parameter cache;

[0027] Value pool management module: Based on a true random number generator, it generates multiple values ​​that meet preset random number conditions. Value; will generate multiple The value is input into the SM4 symmetric encryption algorithm to obtain the encrypted value. value ; encrypt value and presets in the cache Point parameters are input into the sliding window algorithm, and each encrypted value is output. value corresponding Points, and Point generation time; based on the encrypted value Combine each encrypted value corresponding point , obtain with point Generate time-related data and store it in a preset location. Value pool;

[0028] Encryption module: When a data encryption request is received, it reads... Unused associated data in the value pool that has not exceeded the preset task period can be decrypted. The value is then processed and a lightweight encryption operation is performed to obtain the final standard SM2 ciphertext;

[0029] The decryption module: split the final standard SM2 ciphertext, get the ciphertext components, and perform validity verification; use the pre-set point parameters in the cache to calculate the intermediate point of the key agreement and derive the shared key , restore the plaintext of the final standard SM2 ciphertext.

[0030] In another aspect, the present application also provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the SM2 encryption and decryption method based on pre-computation and base point caching according to any embodiment of the present application when executing the program.

[0031] In another aspect, the present application also provides a computer readable storage medium having a computer program stored thereon, wherein the program is executable on a processor to implement the SM2 encryption and decryption method based on pre-computation and base point caching according to any embodiment of the present application.

[0032] The present application has the following advantages:

[0033] (1) The present application is an SM2 encryption and decryption method and system based on pre-computation and base point caching, which significantly improves the security and integrity of the core parameters of the SM2 algorithm through the technical design of multi-layer hash verification combined with hardware trust root; first, the reference point parameters are extracted from the SM2 standard document to generate a reference hash value, and the point parameters stored externally are compared with the initial hash value and the check value generated by the CRC32 algorithm, and then stored in the cache after comparison, and then compared twice with the real-time hash and the reference hash; at the same time, the reference hash value is stored in the TEE, TPM or SE hardware trust root, and the check log is recorded; this multi-layer verification and hardware trusted storage combination can effectively intercept tampered point parameters, avoid errors in subsequent encryption operations due to abnormal parameters, and solve the problem of single verification dimension and easy tampering in traditional parameter management.

[0034] (2) The present application is an SM2 encryption and decryption method and system based on pre-computation and base point caching, which significantly improves the efficiency of SM2 encryption operation through the technical means of pre-computation point and value pool management; based on true random number generation, the qualified values are encrypted by SM4, combined with cache point parameters, pre-computed by sliding window algorithm, and then associated with the point and generation timestamp and stored in the value pool; when receiving the encryption request, the data in the value pool that is not used and within the task cycle can be directly read without real-time point parameter calculation and random number generation operation; SM4 encryption ensures the security of pre-computed points, and timestamp management avoids misuse of expired data, which reduces real-time operation amount and improves encryption response speed, while ensuring the security of pre-computed data, achieving the balance between efficiency and security.

[0035] ​​(3) The application is a SM2 encryption and decryption method and system based on pre-computation and base point caching, which takes into account the applicability and reliability of the algorithm through the technical design of SM2 lightweight encryption and full-process decryption verification; in the encryption stage, the TPM is used to ensure the credibility of SM4 decryption, the pre-computed point is used to simplify the elliptic curve point multiplication operation, and the ciphertext components, encrypted byte stream and message authentication code are generated; in the decryption stage, the ciphertext is split according to the fixed format, the component validity is verified first, then the exclusive or decryption is performed through the intermediate point and the derived shared key in the key negotiation, and the verification result is verified by comparing the check value; the lightweight encryption design reduces the device computing power consumption and can adapt to resource-constrained scenarios such as Internet of Things terminals; and the full-process verification mechanism such as component verification and MAC verification can effectively identify the problems of damaged ciphertext or incorrect key, avoid decryption failure or plaintext error, and improve the reliability and scene adaptability of the SM2 algorithm in practical application. BRIEF DESCRIPTION OF DRAWINGS

[0036] Figure 1 The method flowchart provided for the first embodiment of the application. DETAILED DESCRIPTION

[0037] The technical solutions in the embodiments of the application will be clearly and completely described below with reference to the drawings in the embodiments of the application. Obviously, the described embodiments are only part of the embodiments of the application, rather than all the embodiments of the application. Based on the embodiments in the application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the application.

[0038] It should be understood that the step numbers used herein are only for the convenience of description, and are not limited to the execution sequence of the steps.

[0039] It should be understood that the terms used in the specification of the application are only for the purpose of describing specific embodiments and are not intended to limit the application. As used in the specification and the appended claims of the application, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include the plural forms.

[0040] The terms "comprise" and "include" indicate the presence of the described features, integers, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.

[0041] The term "and / or" means any combination of one or more of the associated listed items and all possible combinations, and includes these combinations.

[0042] Embodiment one:

[0043] Reference Figure 1The embodiment provides an SM2 encryption and decryption method based on precalculation and base point caching, and comprises the following steps.

[0044] S100, extracting base point parameters of an SM2 elliptic curve from a preset SM2 elliptic curve public key cryptography algorithm standard document GB / T32918.1-2016 point parameters, the base point parameters comprise coordinates, coordinates and an order , wherein:

[0045] coordinates: 32C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7;

[0046] coordinates: BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0;

[0047] order : BD71344799D5C7FCDC45B59FA3B9AB8F6A948BC5.

[0048] S101, in the embodiment, by means of a secure environment such as a vendor encryption server, a TPM inside an administrator security terminal, a CRC32 hash algorithm is used to perform hash operation on the above base point parameters , and , and output a fixed-length base hash value.

[0049] S102, the fixed-length base hash value is input to a non-modifiable storage area of a hardware root of trust by means of a SPI interface of a TPM, a SWP interface of a SE and other hardware interfaces;

[0050] It should be noted that the hardware root of trust comprises a trusted execution environment TEE, a trusted platform module TPM and a secure element SE; the non-modifiable storage area only supports a reading operation, does not support a modifying or deleting operation, and can ensure uniqueness and non-tamperability of the base hash value;

[0051] It should be noted that the "non-modifiable storage area" of the trusted platform module TPM is the platform configuration register PCR (Platform Configuration Register); the "non-modifiable storage area" of the secure element SE is the secure storage area (Secure Storage), and in the embodiment, the hardware root of trust is the trusted platform module TPM.

[0052] S103, after the reference hash value is generated, the reference hash value and the reference point parameter are verified for consistency by a manufacturer, administrator, and SM3 digital signature verification method, the reference hash value generation time, the operator, and the equipment serial number that pass the consistency verification are recorded, a hash value generation local log is obtained, and is used for subsequent operation and maintenance auditing.

[0053] S200, according to the SM2 elliptic curve public key cryptography algorithm standard document GB / T32918.1-2016, it is determined whether the reference point parameter stored in the non-modifiable storage area of the hardware root of trust is still consistent with the reference point parameter extracted in step S100, both of which include the same , and three parameters.

[0054] S201, after confirming that the current reference point parameter is consistent with the reference point parameter extracted in step S100, the preset point parameter and the preset point parameter verification value of a preset external storage space (such as a hard disk, a flash memory, etc.) are obtained.

[0055] The preset point parameter is input into the CRC32 hash algorithm, and an initial hash value is output. The initial hash value is compared with the preset point parameter verification value to perform preliminary verification, and a preliminary verification result is obtained.

[0056] If the preliminary verification result shows that the initial hash value is inconsistent with the preset point parameter verification value, the preset point parameter is re-read, and an error log is recorded and generated.

[0057] If the preliminary verification result shows that the initial hash value is consistent with the preset point parameter verification value, the preset point parameter corresponding to the initial hash value is output, and step S202 is entered.

[0058] It should be noted that the preset The point parameter check value is also the result of CRC32 hash algorithm calculation, so it can be directly compared with the initial hash value; the preset The point parameter verification value is burned into the external storage space at the factory and cannot be tampered with; when preset... Point parameter verification values ​​are used to check the presets burned into external storage space. Are the point parameters corrupted?

[0059] S202, The preset that has passed the preliminary verification. Point parameters are written to a cache (such as CPU L3 cache, SRAM of embedded devices, etc.), and a key-value pair index is established, expressed by the formula:

[0060] ;

[0061] In the formula, Indicates key index, Indicates value index, Indicates preset The x-coordinate of the point parameter, Indicates preset The ordinate of the point parameter.

[0062] S203. Locate the preset cache location based on the key-value pair index. Point parameters are input into the CRC32 hash algorithm, and the real-time hash value is output. At the same time, the base hash value in the unmodifiable storage area of ​​the hardware root of trust is read, and the base hash value is compared with the real-time hash value to obtain the comparison result.

[0063] If the comparison results match, the preset cache can be confirmed. The point parameters have not been tampered with, and the preset has been completed. Initialize the cache for point parameters;

[0064] If the comparison results are inconsistent, immediately clear the preset values ​​in the current cache. The parameters are checked, and steps S201-S203 are re-executed; at the same time, the device alarm is triggered.

[0065] S204. After completing cache initialization, repeat the consistency comparison operation between the base hash value and the real-time hash value in step S203 within a preset one-hour period to continuously ensure the consistency of the preset hash value in the cache. Completeness of point parameters.

[0066] S300: Deploy a local scheduled task, setting the task period to 10 minutes (adjustable according to business concurrency: shorten to 5 minutes for high concurrency, extend to 30 minutes for low concurrency); each time the task is triggered, execute sequentially. Value generation, encryption, calculation Value pool update operation.

[0067] S301. Generate 10,000 random numbers based on a true random number generator. Value, each The value must conform to the conditions of the SM2 elliptic curve public-key cryptography algorithm, that is: ;in, For preset The order of the point parameter; if generated If the value does not meet the conditions of the SM2 elliptic curve public key cryptography algorithm, it is regenerated until a value that meets the conditions of the SM2 elliptic curve public key cryptography algorithm is obtained. value.

[0068] S302, the Trusted Platform Module (TPM) uses the SM4 symmetric encryption algorithm (the key is dynamically generated and stored by the TPM, accessible only to the security module) to perform encryption on each device that meets the conditions of the SM2 elliptic curve public-key cryptography algorithm. The value is encrypted to obtain the encrypted value. Value, denoted as ;

[0069] S303, Locate the preset in the cache based on the key-value index. Point parameters, using a sliding window algorithm with a window size of 4, to convert the original Values ​​and presets The point parameter performs an elliptic curve dot product operation, expressed by the formula:

[0070] ;

[0071] In the formula, express Sub-preset Point addition of elliptic curve with point parameters. This represents the original data generated by the true random number generator. value, Indicates the preset in the cache Point parameters;

[0072] Furthermore, to obtain each value corresponding coordinates of the point ,as well as Point generation time.

[0073] S304, According to the encrypted value Combine each corresponding point , obtain with The associated data for the point generation time is as follows:

[0074] It is an encrypted temporary private key This is core data and needs to be securely protected;

[0075] It is an encrypted temporary private key The corresponding public key, i.e., the elliptic curve point The coordinates are public values, used as an index or handle for finding data;

[0076] Store the associated data in a preset location. Value pool, and delete the preset value. Values ​​in the pool that have been used or stored for more than two task cycles Value data, avoid Storing values ​​for too long can lead to security risks.

[0077] S400, When an encryption request is received, from The value pool header reads unused associated data that has been stored for no more than two task cycles; at this point, pre-computed... The dot is the ciphertext component This reduces the amount of computation required for the ciphertext component in this step. Time;

[0078] Furthermore, ciphertext components Byte streams that need to be converted to an uncompressed format That is: 1-byte prefix 32 bytes 32 bytes After conversion, it becomes the first component of the ciphertext and will be subsequently transmitted to the decryptor. Simultaneously, the associated data is immediately marked as "occupied," employing a thread lock mechanism to prevent repeated use of the same data during concurrent multi-threaded calls. value.

[0079] S401, the Trusted Platform Module (TPM) uses the SM4 symmetric encryption algorithm (the key is dynamically generated and stored by the TPM, and can only be accessed by the security module). Decrypt to obtain The value is in plaintext; the decryption process is performed internally within the security module. The value is not exposed in plaintext and is destroyed immediately after use with zero overwrite.

[0080] S402, Perform SM2 lightweight encryption operation, specifically:

[0081] S4021, Directly use pre-computed ciphertext components ( The point), combined with the pre-generated SM2 public key of the receiving party , an elliptic curve point multiplication operation is performed, which is expressed in a formula as:

[0082] ;

[0083] In the formula, denotes an intermediate point for key agreement, denotes the pre-generated SM2 public key of the receiving party .

[0084] S4022, using function, the intermediate point for key agreement is converted into a key suitable for symmetric encryption , which is expressed in a formula as:

[0085] ;

[0086] In the formula, denotes the key suitable for symmetric encryption of the transmitting party, denotes the key derivation function, denotes the horizontal coordinate of the intermediate point for key agreement, denotes the vertical coordinate of the intermediate point for key agreement, denotes the expected bit length of the symmetric encryption key to be generated.

[0087] S4023, the byte stream of the ciphertext component is encrypted by byte-by-byte XOR operation, which is expressed in a formula as:

[0088] ; In the formula,

[0089] denotes the encrypted ciphertext byte stream, denotes the plaintext byte stream of the ciphertext component , denotes the XOR operation.

[0090] S4024, the message authentication code is calculated according to the SM2 standard, which is expressed in a formula as:

[0091] ;

[0092] In the formula, denotes the message authentication code, denotes the national secret hash algorithm, denotes the byte stream of , denotes the byte stream of ;

[0093] ​It needs to be explained that this link is the core simplified step of standard SM2 encryption, since the ciphertext components have been pre-calculated, there is no need to generate them in real time Point, simplifying the core step of standard SM2 encryption.

[0094] S403, splice the byte stream according to the fixed order , form the final standard SM2 ciphertext, specifically:

[0095] 65 bytes: 0x04 prefix + 32 bytes + 32 bytes ;

[0096] Length = length of plaintext byte stream of ciphertext components ;

[0097] 32 bytes;

[0098] The above standard can ensure compatibility with existing SM2 decryption equipment.

[0099] S404, after encryption, delete (or mark as invalid) the associated data used from Value pool, release Value pool space; At the same time, zero cover destroys the shared key and Point data, avoid sensitive information residue.

[0100] S500, the decryption module receives the standard SM2 ciphertext sent by the encryption side, and splits the components according to the format, specifically:

[0101] Intercept the first 65 bytes: (non-compressed format Point, containing Prefix, , );

[0102] Middle part: (length Len )=standard SM2 ciphertext total length-65-32=length of plaintext byte stream of ciphertext components );

[0103] Intercept the last 32 bytes: (SM3 hash check value).

[0104] S501, further, verify the validity of , specifically:

[0105] Analysis :extract , To verify whether the equation of the SM2 elliptic curve is satisfied, it can be expressed as the formula:

[0106] ;

[0107] In the formula, express The ordinate of the point, express The x-coordinate of the point Indicates the parameters of the SM2 standard curve;

[0108] verify Order: calculation ;

[0109] like , It satisfies the SM2 elliptic curve equation, and The calculation result is the point O at infinity, then efficient;

[0110] like , It does not satisfy the equation of the SM2 elliptic curve, and If the calculation result is not the point O at infinity, then... If invalid, discard the ciphertext directly to prevent invalidity point attacks.

[0111] S502, due to Therefore, the intermediate point in the key negotiation between the receiver (decryptor) and the sender (encryptor) is... The points are the same, so I will not repeat them here;

[0112] At the same time, it should be completely consistent with the sender (encryptor). Derived shared key ,make sure The same as the encryption side, expressed by the formula:

[0113] ;

[0114] In the formula, This indicates the key that the recipient is using for symmetric encryption. This represents the key derivation function. Indicates the midpoint of key negotiation x-axis, Indicates the midpoint of key negotiation ordinate, express length.

[0115] S503, further, restore plaintext and integrity check, specifically:

[0116] XOR decryption ciphertext, expressed as a formula:

[0117] ;

[0118] In the formula, The output plaintext is represented as:

[0119] Calculate the check value , expressed as a formula:

[0120] ;

[0121] In the formula, The check value is represented as:

[0122] Further, compare With , if consistent, output plaintext (i.e. the original plaintext ); if not consistent, discard , indicating decryption failure.

[0123] S504, after decryption, zero cover destroy shared key And Point data, no need to store Value, release memory resources.

[0124] Example two:

[0125] This embodiment proposes a SM2 encryption and decryption system based on pre-computation and base point caching, including the following modules:

[0126] Pre-module: extract the reference Point parameters from the preset SM2 elliptic curve public key cryptography standard document, input to the CRC32 hash algorithm, output the reference hash value, and write it to the non-modifiable storage area of the hardware trust root;

[0127] Preset caching module: read the preset Point parameters and preset Point parameter check value from the preset external storage, input the preset Point parameters to the CRC32 hash algorithm to get the initial hash value; compare the initial hash value with the preset Point parameter check value, the preset Point parameters corresponding to the consistent initial hash value are written into the cache, and a key-value pair index is established; the preset Point parameters are input into the CRC32 hash algorithm to obtain a real-time hash value, which is then compared with the base hash value in the immutable storage area of ​​the hardware root of trust. If the comparison matches, the base hash value is completed. Initialize the point parameter cache;

[0128] Value pool management module: Based on a true random number generator, it generates multiple values ​​that meet preset random number conditions. Value; will generate multiple The value is input into the SM4 symmetric encryption algorithm to obtain the encrypted value. value ; encrypt value and presets in the cache Point parameters are input into the sliding window algorithm, and each encrypted value is output. value corresponding Points, and Point generation time; based on the encrypted value Combine each encrypted value corresponding point , obtain with point Generate time-related data and store it in a preset location. Value pool;

[0129] Encryption module: When a data encryption request is received, it reads... Unused associated data in the value pool that has not exceeded the preset task period can be decrypted. The value is then processed and a lightweight encryption operation is performed to obtain the final standard SM2 ciphertext;

[0130] Decryption module: Decomposes the final standard SM2 ciphertext into ciphertext components and performs validity verification; utilizes preset cached data. Point parameters, calculating the midpoint of key negotiation. and derived shared keys To restore the plaintext of the final standard SM2 ciphertext.

[0131] Example 3:

[0132] This embodiment proposes an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it implements the method described in any embodiment of the present invention.

[0133] Example 4:

[0134] The embodiment provides a computer readable storage medium, which stores a computer program. The computer program is executed by a processor to implement the method in any embodiment of the application.

[0135] In the embodiments of the present application, "at least one" refers to one or more, and "multiple" refers to two or more. The "and / or" describes the association relationship of the associated objects, which means that there can be three kinds of relationships, for example, A and / or B, which means that A exists alone, A and B exist together, and B exists alone. Wherein A and B can be singular or plural. The character " / " generally represents that the associated objects before and after it are in an "or" relationship. "At least one of the following" and the like means any combination of these items, including any combination of single or multiple items. For example, at least one of a, b and c can represent: a, b, c, a and b, a and c, b and c, or a and b and c, wherein a, b, and c can be single or multiple.

[0136] Those skilled in the art can appreciate that the units and algorithm steps described in the embodiments disclosed herein can be realized by electronic hardware, computer software and combination of electronic hardware and computer software. Whether the functions are realized in hardware or software mode depends on the specific application and design constraints of the technical solution. The skilled person can use different methods to realize the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.

[0137] Those skilled in the art can clearly understand that, for the convenience and brevity of the description, the specific working process of the system, device and unit described above can refer to the corresponding process in the foregoing method embodiments, which will not be described here.

[0138] In several embodiments provided in the present application, any function realized in the form of a software function unit and sold or used as an independent product can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application essentially or the parts that make contributions to the prior art or parts of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, including a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in the embodiments of the present application. The foregoing storage medium includes: a secure U disk, an encrypted mobile hard disk, a read-only memory (Read-Only Memory; hereinafter referred to as: ROM), a random access memory (Random Access Memory; hereinafter referred to as: RAM), a magnetic disk or an optical disk, and various media that can store program codes.

[0139] The above merely illustrates the embodiments of the present application, and does not limit the patent scope of the present application, and any equivalent structure or equivalent process transformation, or direct or indirect application in other related technical fields, which are made by using the content of the present application specification and drawings, are also included in the patent protection scope of the present application.

Claims

1. An SM2 encryption / decryption method based on pre-computation and basepoint caching, characterized in that, Includes the following steps: S100. Extract the baseline from the pre-defined SM2 elliptic curve public key cryptography algorithm standard document. Point parameters are input into the CRC32 hash algorithm, the base hash value is output, and written to the immutable storage area of ​​the hardware root of trust. S200, Read preset from preset external storage Point parameters and presets Point parameter verification value, preset The point parameters are input into the CRC32 hash algorithm to obtain the initial hash value; the initial hash value is then compared with the preset... Point parameter verification values ​​are compared, and the initial hash values ​​that match are the preset values. Point parameters are written to the cache, and a key-value pair index is created; the preset to be written to the cache is... Point parameters are input into the CRC32 hash algorithm to obtain a real-time hash value, which is then compared with the base hash value in the immutable storage area of ​​the hardware root of trust. If the comparison matches, the base hash value is completed. Initialize the cache for point parameters; S300, Based on a true random number generator, generates multiple random numbers that meet preset random number conditions. Value; will generate multiple The value is input into the SM4 symmetric encryption algorithm to obtain the encrypted value. value ; encrypt value and presets in the cache Point parameters are input into the sliding window algorithm, and each encrypted value is output. value corresponding Points, and Point generation time; based on the encrypted value Combine each encrypted value corresponding point , obtain with point Generate time-related data and store it in a preset location. Value pool; S400, When a data encryption request is received, read... Unused associated data in the value pool that has not exceeded the preset task period can be decrypted. The value is then processed and a lightweight encryption operation is performed to obtain the final standard SM2 ciphertext; S500: Decompose the final standard SM2 ciphertext to obtain ciphertext components and perform validity verification; Utilize the preset in the cache Point parameters, calculating the midpoint of key negotiation. Shared key with derivative To restore the plaintext of the final standard SM2 ciphertext.

2. The SM2 encryption / decryption method based on pre-computation and basepoint caching according to claim 1, characterized in that, Step S100 also includes: Input the base hash value into the immutable storage area of ​​the hardware trust root; use a preset security verification tool to verify the base hash value and the base... Perform consistency checks on the point parameters; record the generation time of the baseline hash value that passes the consistency check and the device serial number to obtain the hash value generation log.

3. The SM2 encryption / decryption method based on pre-computation and basepoint caching according to claim 2, characterized in that, The hardware root of trust includes the Trusted Execution Environment (TEE), the Trusted Platform Module (TPM), and the Security Element (SE).

4. The SM2 encryption / decryption method based on pre-computation and basepoint caching according to claim 1, characterized in that, The process of comparing the real-time hash value with the baseline hash value also includes the following steps: If the comparison results are inconsistent, clear the preset values ​​in the current cache. Pointing parameters triggers a device alarm and also re-reads the preset data from external storage. Point parameters are input into the CRC32 hash algorithm, which outputs an initial hash value. This initial hash value is then compared with a preset value. Point parameter verification value comparison, matching preset values Point parameters are written to the cache and a key-value pair index is created; presets in the cache are then retrieved. Point parameters are input into the CRC32 hash algorithm, and the real-time hash value is output. The baseline hash value and the real-time hash value are compared for consistency to obtain a new consistency comparison result. After the cache initialization is completed, the consistency comparison operation between the real-time hash value and the base hash value is repeatedly performed within a preset time.

5. The SM2 encryption / decryption method based on pre-computation and basepoint caching according to claim 1, characterized in that, Step S400 specifically includes: When a data encryption request is received, from The value pool reads unused associated data that has not exceeded the preset task period, and simultaneously... point Convert to an uncompressed byte stream; Based on the Trusted Platform Module (TPM), the SM4 symmetric encryption algorithm is used to... Decrypt to obtain Value plaintext; according to point and its uncompressed byte stream, Value and its decrypted form The plaintext is processed by performing SM2 lightweight encryption to obtain the ciphertext component. Encrypted ciphertext byte stream and message verification code ;according to The fixed format of byte streams is used to form standard SM2 ciphertext.

6. The SM2 encryption / decryption method based on pre-computation and basepoint caching according to claim 1, characterized in that, Step S500 specifically includes: Receive standard SM2 ciphertext, according to The fixed format of the byte stream is split; the resulting ciphertext components are processed. Perform validity verification; After the validity check passes, according to Calculate the midpoint of key negotiation ; the midpoint and the encrypted ciphertext byte stream Input to the key derivation function Output derived shared key ; Based on the midpoint of key negotiation Shared key with derivative Recover the plaintext from the standard SM2 ciphertext.

7. An SM2 algorithm optimization system based on pre-computation and cache base points, characterized in that, Includes the following modules: Pre-module: Extracts benchmarks from the pre-defined SM2 elliptic curve public key cryptography algorithm standard document. Point parameters are input into the CRC32 hash algorithm, the base hash value is output, and written to the immutable storage area of ​​the hardware root of trust. Preset caching module: Reads presets from preset external storage. Point parameters and presets Point parameter verification value, preset The point parameters are input into the CRC32 hash algorithm to obtain the initial hash value; the initial hash value is then compared with the preset... Point parameter verification values ​​are compared, and the initial hash values ​​that match are the preset values. Point parameters are written to the cache, and a key-value pair index is created; the preset to be written to the cache is... Point parameters are input into the CRC32 hash algorithm to obtain a real-time hash value, which is then compared with the base hash value in the immutable storage area of ​​the hardware root of trust. If the comparison matches, the base hash value is completed. Initialize the cache for point parameters; Value pool management module: Based on a true random number generator, it generates multiple values ​​that meet preset random number conditions. Value; will generate multiple The value is input into the SM4 symmetric encryption algorithm to obtain the encrypted value. value ; encrypt value and presets in the cache Point parameters are input into the sliding window algorithm, and each encrypted value is output. value corresponding Points, and Point generation time; based on the encrypted value Combine each encrypted value corresponding point , obtain with point Generate time-related data and store it in a preset location. Value pool; Encryption module: When a data encryption request is received, it reads... Unused associated data in the value pool that has not exceeded the preset task period can be decrypted. The value is then processed and a lightweight encryption operation is performed to obtain the final standard SM2 ciphertext; Decryption module: Decomposes the final standard SM2 ciphertext into ciphertext components and performs validity verification; Utilize the preset in the cache Point parameters, calculating the midpoint of key negotiation. Shared key with derivative To restore the plaintext of the final standard SM2 ciphertext.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements an SM2 encryption / decryption method based on pre-computation and basepoint caching as described in any one of claims 1 to 6.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by the processor, the program implements an SM2 encryption / decryption method based on pre-computation and basepoint caching as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Optimal processing method and device for national password SM2 encryption algorithm

    CN107483204A

  • Efficient reconfigurable SM2 point multiplication method and system based on FPGA

    CN114895870A

  • System safety starting method, device and system based on national cryptographic algorithm

    CN109598126A

  • Processor with a hash cryptographic algorithm and data processing thereof

    US20230066718A1