A SM2 signature optimization method and system based on table lookup method

By adopting the optimization method of table lookup method in the SM2 algorithm, dynamic segmentation adjustment and hybrid table lookup strategy, combined with randomized index and mask technology, the problems of large calculation amount and insufficient security of the traditional SM2 algorithm are solved, and an efficient, Secure SM2 signature algorithm.

CN118972063BActive Publication Date: 2025-01-21数盾信息科技股份有限公司
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202411441027.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-16
Publication Date
2025-01-21
Estimated Expiration
2044-10-16

AI Technical Summary

Technical Problem

The traditional SM2 algorithm uses a site-by-site multiplication accumulation method, resulting in a significant increase in the calculation amount, and the signature and verification processes are long, making it difficult to meet high performance and security requirements.

Method used

The SM2 signature optimization method based on the table lookup method is used to optimize the table lookup index calculation and accumulation process through dynamic segmentation adjustment and hybrid table lookup strategies, and combines randomized indexing and masking technology to enhance security.

Benefits of technology

It significantly improves the performance and resource utilization of the SM2 signature algorithm, reduces the amount of real-time calculations, accelerates the signature process, improves processing efficiency, enhances security, and effectively defends against side-channel attacks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118972063B_ABST
    Figure CN118972063B_ABST
Patent Text Reader

Abstract

The present invention discloses an SM2 signature optimization method and system based on table lookup method, and relates to the technical field of SM2 signature. The SM2 signature optimization method and system based on table lookup method include: S1, preparation; S2, building a table lookup; S3, security enhancement; S4, error handling and recovery; S5, algorithm optimization and adjustment; S6, testing and verification; significant performance improvement and resource optimization are achieved through table lookup method. By segmenting the data according to the number of bits, and pre-calculating the point multiplication result of each segment of data as prefabricated data, the amount of real-time calculation is greatly reduced. At runtime, the results are quickly obtained and accumulated through table lookup, which significantly accelerates the signature process and improves processing efficiency; in addition, the table lookup size and strategy are dynamically adjusted, combined with randomized index and mask technology, which not only balances memory usage and computing efficiency, but also enhances security and effectively defends against side channel attacks.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of SM2 signatures, and in particular to an SM2 signature optimization method and system based on a table lookup method. Background Art

[0002] The SM2 algorithm uses Elliptic Curve Cryptography (ECC) for key exchange, digital signatures, and public key encryption. Its security is based on the Elliptic Curve Discrete Logarithm Problem (ECDLP), which provides high security with a relatively short key length. At the same time, the SM2 algorithm has high computational efficiency and can meet the needs of large amounts of data encryption, decryption, and digital signatures.

[0003] Publication No. CN110048844A discloses a multiple point calculation method and device for implementing the SM2 algorithm, the method comprising: S10. Obtain a binary number k, and divide k into windows to obtain w bit strings K, and the length of each bit string K is d, wherein w is greater than 1; S20. Set the initial i to d-1; S30. Scan each window one by one to obtain Kiw-1, ..., Ki1, Ki0, and update the Q value according to formula 1; S40. Determine Check whether Kiw-1, ..., Ki1, Ki0 are all 0, if not, execute S50; if yes, execute S60; S50. Get the corresponding dot product value M from the pre-stored multiple dot product values, and update the Q value according to formula 2, wherein the pre-stored multiple dot product values ​​are the dot product values ​​of P and 2w different bit strings of length w; S60. Subtract 1 from the current i, and determine whether the current i is less than 0, if not, execute S30, if yes, output the current Q value.

[0004] As shown in the above technology, the traditional SM2 algorithm uses a point-by-point multiplication and accumulation method. The point-by-point multiplication method means that for each bit of each scalar (private key or random number), a point multiplication operation on the elliptic curve is required. As the length of the scalar increases, the amount of calculation of this method will increase significantly, resulting in a more time-consuming signing and verification process. Although the accumulation method can optimize the calculation process to a certain extent, it is still limited by the nature of bit-by-bit processing as a whole, and it is difficult to significantly improve the calculation efficiency; in an environment with limited computing resources (such as mobile devices, IoT devices, etc.), the point-by-point multiplication method will consume more processor time and memory resources, affecting the overall performance and battery life of the device. With the expansion of application scenarios and the improvement of security requirements, this kind of traditional point-by-point multiplication method is difficult to meet the requirements of higher performance and security. Summary of the invention

[0005] In view of the deficiencies in the prior art, the present invention provides an SM2 signature optimization method and system based on a table lookup method, which solves the problem of low efficiency of the traditional SM2 algorithm, which adopts a point-by-point multiplication and accumulation method.

[0006] To achieve the above objectives, the present invention is implemented by the following technical solutions: an SM2 signature optimization method based on a table lookup method, specifically comprising the following steps:

[0007] S1. Preparation: Determine the parameters of the SM2 elliptic curve; prepare dynamic table lookup, analyze the distribution of scalar k, design segmentation strategy, and consider the balance between memory and performance;

[0008] S2. Build a lookup table: Implement adaptive segmentation and dynamically adjust the lookup table size; use a fixed lookup table for high-frequency segments and dynamically calculate and cache the results for low-frequency segments to balance memory and computing efficiency;

[0009] S3. Security enhancement: Introduce randomized table lookup index and mask technology to defend against side channel attacks; conduct code review and test verification to ensure the security of table lookup implementation;

[0010] S4, Error handling and recovery: Implement error detection and response mechanisms to ensure that the table lookup index is valid and the results are complete; formulate backup and automatic downgrade strategies to ensure stable system operation;

[0011] S5. Algorithm optimization and adjustment: optimize table lookup index calculation and accumulation strategy, and use parallel processing to improve performance; regularly evaluate performance, adjust parameters, and continuously optimize and update;

[0012] S6. Testing and verification: Through unit testing, integration testing, performance testing and security testing, the correctness, stability and security of the table lookup implementation are fully verified.

[0013] Preferably, the preparation work of step S1 specifically includes:

[0014] S1.1 Determine the parameters of the elliptic curve: Determine the parameters of the SM2 elliptic curve, including the prime modulus p, coefficients a, b, base point G(x G ,y G ), and the order n of the base point G;

[0015] S1.2 Analysis and preparation of dynamic table lookup:

[0016] S1.2.1 Scalar analysis: Understand the distribution characteristics of the scalar k in the signing process through statistical analysis or simulation testing;

[0017] S1.2.2 Segmentation strategy design:

[0018] Initial segmentation: Set an initial segment size based on hardware memory limitations and expected performance goals;

[0019] Dynamic adjustment: Design a dynamic segment adjustment algorithm to dynamically adjust the segment size based on the actual distribution of scalars and current performance.

[0020] Preferably, the parameter setting of the dynamic segmentation adjustment algorithm includes:

[0021] enter:

[0022] k: the scalar currently to be processed;

[0023] H: historical scalar set, used to count the distribution characteristics of scalars;

[0024] S: current segmentation strategy, including the starting position and size of each segment;

[0025] M: memory usage limit;

[0026] P: performance target, including but not limited to table lookup hit rate and calculation time;

[0027] Output:

[0028] S′: updated segmentation strategy;

[0029] The steps of the dynamic segment adjustment algorithm include:

[0030] S1.2.2.1 Statistics and analysis: Use the historical scalar set H to count the frequency of occurrence of each value segment; analyze the table lookup hit rate and memory usage under the current segmentation strategy S;

[0031] S1.2.2.2 Performance evaluation: Based on the performance target P, evaluate whether the current segmentation strategy meets the requirements, that is, whether the table lookup hit rate and memory usage are within the performance target P. If not, enter the adjustment process;

[0032] S1.2.2.3 Dynamic Adjustment:

[0033] Identify high-frequency and low-frequency segments: Based on the statistical results, identify high-frequency and low-frequency value segments;

[0034] Adjust the segment size: For high-frequency bands, reduce their segment size to increase table lookup efficiency and hit rate; calculate the new segment size to ensure that it does not exceed the memory limit M and reduce the number of segments as much as possible; for low-frequency bands, increase their segment size or keep it unchanged to reduce memory usage; if increasing the low-frequency band size will cause the memory to exceed the limit M, keep the original size or increase it only moderately;

[0035] Reassign segments:

[0036] According to the new segment size, recalculate the starting position and size of each segment and generate a new segmentation strategy S′;

[0037] Verification and feedback: Use a small portion of new scalar data to verify the new segmentation strategy S′; evaluate the performance indicators of the new strategy’s table lookup hit rate, memory usage, and computation time; if the new strategy meets or exceeds the performance target P, update the segmentation strategy to S′; otherwise, fine-tune and re-verify based on the verification results;

[0038] Update historical data: Add the newly processed scalar data to the historical scalar set H for subsequent analysis and adjustment.

[0039] Preferably, the step of adjusting the segment size specifically includes:

[0040] A1. Define parameters:

[0041] fi: the occurrence frequency or relative frequency of the i-th value segment;

[0042] si: the size of the current i-th segment expressed as a scalar value in range or number of bits;

[0043] M: Available memory limit, used to store table lookup data;

[0044] α: high frequency segment size adjustment factor, where 0<α<1, used to reduce the size of the high frequency segment;

[0045] β: upper limit factor for adjusting the size of the low-frequency segment, and β≥1, used to control the upper limit of the increase of the low-frequency band;

[0046] A2. Calculate the new segment size:

[0047] High frequency band:

[0048] Calculate the new segment size si′=si×α and round it up to ensure that the segment size is not less than 1;

[0049] If si′ is too small, i.e., less than the set minimum threshold δ, it will be merged with other high-frequency bands or kept at the original size;

[0050] Verify whether the new segment size will cause memory usage to exceed the limit M. If so, further adjustments need to be made by merging segments or adjusting other low-frequency segments;

[0051] Low frequency band:

[0052] Initialize the new segment size si′=si. If the low frequency band needs to be increased, then: si′=si×β;

[0053] If the increase of si′ does not cause the memory usage to exceed the limit M, then keep si′; otherwise, reduce the value of β or keep si′=si, that is, do not increase the size of the low frequency band.

[0054] Preferably, the step of constructing a lookup table in step S2 specifically includes:

[0055] S2.1 Adaptive segmentation: Maintain a dynamic segmentation table to record the size and starting position of each segment; when processing a new scalar, segment it according to the current segmentation table and update the segmentation table to reflect the new scalar distribution;

[0056] S2.2 Mixed table lookup:

[0057] High-frequency segment fixed lookup table: For high-frequency segments, pre-calculate and use a hash table or array data structure to store the result of multiplying the segment value by the base point G;

[0058] Dynamic calculation of low-frequency segments: For low-frequency segments, the traditional point-by-point multiplication method is used to calculate the point multiplication results; and a cache mechanism is used to store the most recently calculated results to reduce repeated calculations.

[0059] Preferably, the security enhancement step in step S3 specifically includes:

[0060] S3.1 Prevention of side channel attacks:

[0061] Randomize the lookup index: Before looking up the table, apply a random offset or random mask to the lookup index to ensure that the index used for each lookup is random;

[0062] Use masking technology: Apply masks to sensitive data during table lookup; remove the mask before using the data to ensure data correctness;

[0063] S3.2 Security Audit:

[0064] Code review: Thoroughly review all code for table lookup implementation to find potential security vulnerabilities;

[0065] Test verification: Use fuzz testing and penetration testing methods to verify the security of the table lookup implementation.

[0066] Preferably, the error handling and recovery steps in step S4 specifically include:

[0067] S4.1 Error handling mechanism:

[0068] Error detection: Before looking up a table, check whether the table index is out of bounds; and before using the table result, verify the integrity of the result;

[0069] Error response: When an error is detected, the error log is recorded and the error code and error information are returned;

[0070] S4.2 Fault recovery strategy:

[0071] Back up table lookup data: regularly back up table lookup data to a secure storage medium;

[0072] Automatic downgrade: When table lookup fails, it automatically switches to non-table lookup mode and notifies the system administrator or user.

[0073] Preferably, the algorithm optimization and adjustment step in step S5 specifically includes:

[0074] 5.1 Refinement and adjustment:

[0075] Lookup index calculation: Optimize the calculation method of lookup index to reduce calculation complexity and improve performance;

[0076] Accumulation strategy: Use elliptic curve addition algorithm to accumulate table lookup results; consider parallel processing or SIMD instructions to speed up the accumulation process;

[0077] 5.2 Regular evaluation and optimization:

[0078] Performance evaluation: Use benchmarking tools to evaluate the performance of algorithms; collect and analyze performance data;

[0079] Optimization iteration: Based on the performance evaluation results, adjust the segmentation strategy and table lookup size parameters, and perform optimization updates.

[0080] Preferably, the content of the test and verification in step S6 specifically includes:

[0081] Unit testing: Write unit tests to verify that the various parts of the table lookup implementation work as expected;

[0082] Integration test: Integrate the table lookup implementation into the SM2 signature algorithm for overall testing;

[0083] Performance testing: Testing the performance of the algorithm on a variety of hardware and software platforms to ensure stability and efficiency in different environments;

[0084] Security testing: Use professional security testing tools and methods to verify the security of the algorithm, including side channel attack testing and fault injection testing.

[0085] The present invention also discloses an SM2 signature optimization system based on table lookup method, including a parameter configuration module, a dynamic table lookup construction module, a security enhancement module, an error handling and recovery module, an algorithm optimization and adjustment module, and a testing and verification module, which are respectively used to implement steps S1 to S6.

[0086] The present invention provides a method and system for optimizing SM2 signature based on table lookup method. Compared with the prior art, it has the following beneficial effects:

[0087] 1. Compared with the traditional SM2 algorithm which adopts the point-by-point multiplication and accumulation method, this SM2 signature optimization method and system based on the table lookup method achieves significant performance improvement and resource optimization through the table lookup method. By segmenting the data by bit number and pre-calculating the point multiplication result of each segment of data as prefabricated data, the amount of real-time calculation is greatly reduced. At runtime, the results are quickly obtained and accumulated through table lookup, which significantly accelerates the signature process and improves processing efficiency. In addition, the dynamic adjustment of the table lookup size and strategy, combined with randomized indexing and masking technology, not only balances memory usage and computing efficiency, but also enhances security and effectively defends against side channel attacks. The overall design embodies the advantages of high efficiency, flexibility and security, and is a substantial optimization of the traditional SM2 algorithm.

[0088] 2. The SM2 signature optimization method and system based on the table lookup method optimizes the table lookup strategy by deeply analyzing the distribution characteristics of the scalar k and designing a dynamic segmentation adjustment algorithm. This optimization not only improves the table lookup hit rate and reduces the amount of real-time calculations, but also balances memory usage and computing efficiency by dynamically adjusting the segment size. In addition, by continuously updating historical data and verifying new strategies, it ensures that the segmentation strategy always adapts to actual application scenarios, further enhancing the flexibility and stability of the system. These improvements together constitute a substantial optimization of the existing technology and provide strong support for the efficient implementation of the SM2 signature algorithm.

[0089] 3. This SM2 signature optimization method and system based on the table lookup method significantly improves the security of the algorithm and effectively resists potential security threats by introducing anti-side channel attack measures and security audits. At the same time, the perfect error handling and recovery mechanism ensures the stability and reliability of the algorithm, and it can quickly recover and continue to work even in the face of abnormal situations. In addition, continuous algorithm optimization and adjustment as well as comprehensive testing and verification not only improve the performance of the algorithm, but also ensure its compatibility and efficiency in different environments. These measures together constitute a comprehensive upgrade of the SM2 signature algorithm table lookup method, providing a strong guarantee for the safe and efficient application of the algorithm. BRIEF DESCRIPTION OF THE DRAWINGS

[0090] Figure 1 It is a schematic diagram of the steps of the present invention;

[0091] Figure 2 A logical schematic diagram for adjusting the segment size for the present invention;

[0092] Figure 3 It is a system principle block diagram of the present invention. DETAILED DESCRIPTION

[0093] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0094] See also Figure 1-Figure 2 The present invention discloses an SM2 signature optimization method based on a table lookup method, and provides the following three technical solutions:

[0095] The first implementation method includes the following steps:

[0096] S1. Preparation: Determine the parameters of the SM2 elliptic curve; prepare dynamic table lookup, analyze the distribution of scalar k, design segmentation strategy, and consider the balance between memory and performance;

[0097] S2. Build a lookup table: Implement adaptive segmentation and dynamically adjust the lookup table size; use a fixed lookup table for high-frequency segments and dynamically calculate and cache the results for low-frequency segments to balance memory and computing efficiency;

[0098] S3. Security enhancement: Introduce randomized table lookup index and mask technology to defend against side channel attacks; conduct code review and test verification to ensure the security of table lookup implementation;

[0099] S4, Error handling and recovery: Implement error detection and response mechanisms to ensure that the table lookup index is valid and the results are complete; formulate backup and automatic downgrade strategies to ensure stable system operation;

[0100] S5. Algorithm optimization and adjustment: optimize table lookup index calculation and accumulation strategy, and use parallel processing to improve performance; regularly evaluate performance, adjust parameters, and continuously optimize and update;

[0101] S6. Testing and verification: Through unit testing, integration testing, performance testing and security testing, the correctness, stability and security of the table lookup implementation are fully verified.

[0102] Compared with the traditional SM2 algorithm that uses the point-by-point multiplication and accumulation method, this design achieves significant performance improvement and resource optimization through the table lookup method. By segmenting the data by bit number and pre-calculating the point multiplication results of each segment of data as prefabricated data, the amount of real-time calculations is greatly reduced. At runtime, the results are quickly obtained and accumulated through table lookup, which significantly accelerates the signing process and improves processing efficiency. In addition, the dynamic adjustment of the table lookup size and strategy, combined with randomized indexing and masking technology, not only balances memory usage and computing efficiency, but also enhances security and effectively defends against side channel attacks. The overall design embodies the advantages of high efficiency, flexibility and security, and is a substantial optimization of the traditional SM2 algorithm.

[0103] The second implementation mode is mainly different from the first implementation mode in that the preparation work of step S1 specifically includes:

[0104] S1.1 Determine the parameters of the elliptic curve: Determine the parameters of the SM2 elliptic curve, including the prime modulus p, coefficients a, b, base point G(x G ,y G ), and the order n of the base point G;

[0105] S1.2 Analysis and preparation of dynamic table lookup:

[0106] S1.2.1 Scalar analysis: Through statistical analysis or simulation tests, understand the distribution characteristics of the scalar k in the signing process, such as which values ​​or value ranges appear more frequently;

[0107] S1.2.2 Segmentation strategy design:

[0108] Initial segmentation: Set an initial segment size (e.g. 8 bits, 16 bits, or more per segment) based on hardware memory limitations and expected performance goals.

[0109] Dynamic adjustment: Design a dynamic segment adjustment algorithm to dynamically adjust the segment size based on the actual distribution of scalars and current performance.

[0110] The parameter setting of the dynamic segmentation adjustment algorithm includes:

[0111] enter:

[0112] k: the scalar currently to be processed;

[0113] H: historical scalar set, used to count the distribution characteristics of scalars;

[0114] S: current segmentation strategy, including the starting position and size of each segment;

[0115] M: memory usage limit;

[0116] P: performance target, including but not limited to table lookup hit rate and calculation time;

[0117] Output:

[0118] S′: updated segmentation strategy;

[0119] The steps of the dynamic segment adjustment algorithm include:

[0120] S1.2.2.1 Statistics and analysis: Use the historical scalar set H to count the frequency of occurrence of each value segment; analyze the table lookup hit rate and memory usage under the current segmentation strategy S;

[0121] S1.2.2.2 Performance evaluation: Based on the performance target P, evaluate whether the current segmentation strategy meets the requirements, that is, whether the table lookup hit rate and memory usage are within the performance target P. If not (such as the table lookup hit rate is too low or the memory usage is too high), enter the adjustment process;

[0122] S1.2.2.3 Dynamic Adjustment:

[0123] Identify high-frequency and low-frequency segments: Based on the statistical results, identify high-frequency and low-frequency value segments;

[0124] Adjust the segment size: For high-frequency bands, reduce their segment size to increase table lookup efficiency and hit rate; calculate the new segment size to ensure that it does not exceed the memory limit M and reduce the number of segments as much as possible; for low-frequency bands, increase their segment size or keep it unchanged to reduce memory usage; if increasing the low-frequency band size will cause the memory to exceed the limit M, keep the original size or increase it only moderately;

[0125] Reassign segments:

[0126] According to the new segment size, recalculate the starting position and size of each segment and generate a new segmentation strategy S′;

[0127] Verification and feedback: Use a small amount of new scalar data to verify the new segmentation strategy S′; evaluate the performance indicators of the new strategy such as table lookup hit rate, memory usage, and computation time; if the new strategy meets or exceeds the performance target P, update the segmentation strategy to S′; otherwise, fine-tune and re-verify based on the verification results;

[0128] Update historical data: Add the newly processed scalar data to the historical scalar set H for subsequent analysis and adjustment.

[0129] The steps to adjust the segment size include:

[0130] A1. Define parameters:

[0131] fi: the occurrence frequency or relative frequency of the i-th value segment;

[0132] si: the size of the current i-th segment expressed as a scalar value in range or number of bits;

[0133] M: Available memory limit, used to store table lookup data;

[0134] α: high frequency segment size adjustment factor, where 0<α<1, used to reduce the size of the high frequency segment;

[0135] β: upper limit factor for adjusting the size of the low-frequency segment, and β≥1, used to control the upper limit of the increase of the low-frequency band;

[0136] A2. Calculate the new segment size:

[0137] High frequency band (higher fi):

[0138] Calculate the new segment size si′=si×α (round up), ensuring that the segment size is not less than 1;

[0139] If si′ is too small, i.e., less than the set minimum threshold δ, it will be merged with other high-frequency bands or kept at the original size;

[0140] Verify whether the new segment size will cause memory usage to exceed the limit M. If so, further adjustments need to be made by merging segments or adjusting other low-frequency segments;

[0141] Low frequency band (low fi):

[0142] Initialize the new segment size si′=si. If the low frequency band needs to be increased, then: si′=si×β;

[0143] If the increase of si′ does not cause the memory usage to exceed the limit M, then keep si′; otherwise, reduce the value of β or keep si′=si (i.e., do not increase the size of the low frequency band).

[0144] By deeply analyzing the distribution characteristics of the scalar k and designing a dynamic segmentation adjustment algorithm, the table lookup strategy is optimized. This optimization not only improves the table lookup hit rate and reduces the amount of real-time calculations, but also balances memory usage and computing efficiency by dynamically adjusting the segment size. In addition, by continuously updating historical data and verifying new strategies, it ensures that the segmentation strategy always adapts to actual application scenarios, further enhancing the flexibility and stability of the system. These improvements together constitute a substantial optimization of the existing technology and provide strong support for the efficient implementation of the SM2 signature algorithm.

[0145] The third implementation mode is mainly different from the first implementation mode in that: the step of constructing a lookup table in step S2 specifically includes:

[0146] S2.1 Adaptive segmentation: Maintain a dynamic segmentation table to record the size and starting position of each segment; when processing a new scalar, segment it according to the current segmentation table and update the segmentation table to reflect the new scalar distribution;

[0147] S2.2 Mixed table lookup:

[0148] High-frequency segment fixed lookup table: For high-frequency segments, pre-calculate and use a hash table or array data structure to store the result of multiplying the segment value by the base point G;

[0149] Dynamic calculation of low-frequency segments: For low-frequency segments, the traditional point-by-point multiplication method is used to calculate the point multiplication results; and a cache mechanism is used to store the most recently calculated results to reduce repeated calculations.

[0150] Adaptive segmentation can dynamically adjust the segmentation strategy to match the actual distribution of scalars, thereby optimizing table lookup efficiency and memory usage. Hybrid table lookup combines the efficiency of fixed table lookup with the flexibility of dynamic calculation. For high-frequency segments, fixed table lookup is used to reduce the amount of calculation, and for low-frequency segments, dynamic calculation and caching mechanism are used to balance performance and resource consumption. These strategies together improve the overall performance and resource utilization of the algorithm.

[0151] Step S3: The security enhancement steps specifically include:

[0152] S3.1 Prevention of side channel attacks:

[0153] Randomize table lookup index: Before looking up the table, apply a random offset or random mask to the table lookup index to ensure that the index used for each table lookup is random to defend against timing or power consumption-based side channel attacks;

[0154] Use masking technology: Apply masks to sensitive data (such as table lookup results) during the table lookup process; remove the mask before using the data to ensure the correctness of the data;

[0155] S3.2 Security Audit:

[0156] Code review: Thoroughly review all code for table lookup implementation to find potential security vulnerabilities;

[0157] Test verification: Use fuzz testing and penetration testing methods to verify the security of the table lookup implementation.

[0158] By introducing randomized table lookup index and mask technology, the SM2 signature algorithm's ability to resist side channel attacks is effectively enhanced, ensuring the security of the table lookup process. At the same time, through strict code review and test verification, the security of the algorithm implementation is further improved, reducing the risk of security vulnerabilities. These measures together constitute a significant improvement in the security of existing technologies, providing a more solid security guarantee for the SM2 signature algorithm.

[0159] Step S4: Error handling and recovery steps specifically include:

[0160] S4.1 Error handling mechanism:

[0161] Error detection: Before looking up the table, check whether the table index is out of bounds; and before using the table lookup result, verify the integrity of the result, such as whether the check point is on the curve;

[0162] Error response: When an error is detected, the error log is recorded and the error code and error information are returned; depending on the error type, it may be necessary to clear the cache, reset the table lookup status, or switch to non-table lookup mode;

[0163] S4.2 Fault recovery strategy:

[0164] Back up table lookup data: regularly back up table lookup data to a secure storage medium;

[0165] Automatic degradation: When table lookup fails (such as table lookup data corruption), it automatically switches to non-table lookup mode (such as bitwise multiplication) and notifies the system administrator or user so that they can take further recovery measures.

[0166] By introducing detailed error handling and recovery strategies, the stability and reliability of the SM2 signature algorithm have been significantly improved. The error detection and response mechanism ensures that the system can quickly and accurately identify and respond appropriately to anomalies, reducing potential risks. At the same time, the backup table data and automatic degradation strategy provide the system with strong fault tolerance. Even if the table data is damaged, the algorithm can be switched to non-table lookup mode to ensure continuous operation, which is of great significance for maintaining the high availability of the system and data security.

[0167] The steps of algorithm optimization and adjustment in step S5 specifically include:

[0168] 5.1 Refinement and adjustment:

[0169] Lookup index calculation: Optimize the calculation method of the lookup index (for example, using hash functions, bit operations, modular operation optimization, segmented mapping, pre-calculated indexes, hardware features, index compression, or a combination of the above strategies) to reduce calculation complexity and improve performance; for example:

[0170] 1. Hash function: Use a hash function to map a scalar (or part of a scalar) to a table lookup index. The hash function should be designed to be fast enough and minimize hash collisions to ensure the validity and performance of the index. For example, a truncated version of SHA-256 or a lighter hash function (such as SipHash) can be used to generate the index.

[0171] 2. Bit operations: If certain characteristics of the scalar or table index allow, bit operations (such as shift, bitwise AND, bitwise OR, etc.) can be used to quickly calculate the index. This method is usually suitable for situations where the scalar has a fixed length or can be decomposed into fixed-size blocks.

[0172] 3. Modular operation optimization: If the table lookup index is obtained based on modular operation (such as index = k % table_size), you can consider using more efficient modular operation algorithms, such as Montgomery reduction or Barrett reduction. These algorithms can be faster than direct modular operation in certain cases.

[0173] 4. Segmented mapping: In dynamic table lookup design, the scalar space can be divided into multiple segments, and a fixed table lookup index range is assigned to each segment. In this way, when calculating the index, you only need to determine which segment the scalar belongs to, and then calculate the final index based on the starting index of the segment and the offset of the scalar within the segment. This method reduces computational complexity because there is no need to perform complex hashing or modulo operations on the entire scalar.

[0174] 5. Precomputed indexes: If possible, the lookup indexes for some or all scalars can be precomputed and stored in memory before the signing or verification process. In this way, the indexes can be retrieved directly from memory when needed without recalculation. This approach is particularly suitable for scalar values ​​that can be predicted or known in advance.

[0175] 6. Utilize hardware features: Utilize the hardware features of modern processors, such as the SIMD (Single Instruction Multiple Data) instruction set, which can calculate multiple indexes in parallel, thereby significantly improving performance. In addition, the processor's cache hierarchy can be used to optimize memory access patterns and reduce cache miss rates.

[0176] 7. Index compression: If the table index takes up a lot of space, you can consider using a compression algorithm to reduce the storage size of the index. When needed, the index can be decompressed in real time to obtain the original value. This method can reduce memory usage, but may increase some computing overhead.

[0177] 8. Hybrid strategy: Combining the above strategies, design a hybrid index calculation method according to the specific application scenario and performance requirements. For example, you can use a combination of hash functions and bit operations to generate indexes, or use different index calculation strategies according to different parts of the scalar.

[0178] Accumulation strategy: Use elliptic curve addition algorithm to accumulate table lookup results; consider parallel processing or SIMD instructions to speed up the accumulation process;

[0179] 5.2 Regular evaluation and optimization:

[0180] Performance evaluation: Use benchmarking tools to evaluate the performance of the algorithm; collect and analyze performance data, such as table lookup hit rate, cumulative time, etc.;

[0181] Optimization iteration: According to the performance evaluation results, adjust the segmentation strategy, table lookup size and other parameters, and perform optimization updates, such as using more efficient memory access mode and more accurate table lookup index calculation.

[0182] By refining the table lookup index calculation and optimizing the accumulation strategy, combined with parallel processing and hardware characteristics, the algorithm performance has been significantly improved. Regular performance evaluation and optimization iterations ensure that the algorithm can continue to adapt to different application scenarios and maximize performance advantages. These optimization measures not only reduce the computational complexity, but also further improve the execution efficiency of the algorithm through efficient memory access and index calculation, providing strong support for the efficient implementation of the SM2 signature algorithm, and showing higher flexibility and performance advantages compared to existing technologies.

[0183] The content of the test and verification in step S6 specifically includes:

[0184] Unit testing: Write unit tests to verify that the various parts of the table lookup implementation work as expected;

[0185] Integration test: Integrate the table lookup implementation into the SM2 signature algorithm for overall testing;

[0186] Performance testing: Testing the performance of the algorithm on a variety of hardware and software platforms to ensure stability and efficiency in different environments;

[0187] Security testing: Use professional security testing tools and methods to verify the security of the algorithm, including side channel attack testing, fault injection testing, etc.

[0188] Through comprehensive testing and verification, the correctness, stability and security of the table lookup implementation in the SM2 signature algorithm are ensured. The comprehensive application of unit testing, integration testing, performance testing and security testing not only covers all levels of algorithm implementation, but also ensures the reliable operation of the algorithm in different environments. This comprehensive testing and verification method greatly improves the quality and credibility of the algorithm compared to existing technologies, and provides a solid guarantee for the secure application of the algorithm.

[0189] See also Figure 3 The present invention also discloses an SM2 signature optimization system based on table lookup method, including a parameter configuration module, a dynamic table lookup construction module, a security enhancement module, an error handling and recovery module, an algorithm optimization and adjustment module, and a testing and verification module, which are respectively used to implement steps S1 to S6.

[0190] Meanwhile, the contents not described in detail in this specification belong to the prior art known to those skilled in the art.

[0191] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.

[0192] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.

Claims

1. A SM2 signature optimization method based on table lookup method, characterized in that: The specific steps include: S1. Preparation: Determine the SM2 elliptic curve parameters; Prepare dynamic table lookup, analyze the distribution of scalar k, design segmentation strategy, and consider the balance between memory and performance. The preparation work of step S1 specifically includes: S1.1 Determine the parameters of the elliptic curve: Determine the parameters of the SM2 elliptic curve, including the prime modulus p, coefficients a, b, base point G(x G ,y G ), and the order n of the base point G; S1.2 Analysis and preparation of dynamic table lookup: S1.2.1 Scalar analysis: Understand the distribution characteristics of the scalar k in the signing process through statistical analysis or simulation testing; S1.2.2 Segmentation strategy design: Initial segmentation: Set an initial segment size based on hardware memory limitations and expected performance goals; Dynamic adjustment: Design a dynamic segment adjustment algorithm to dynamically adjust the segment size based on the actual distribution of scalars and current performance; The parameter setting of the dynamic segmentation adjustment algorithm includes: enter: k: the scalar currently to be processed; H: historical scalar set, used to count the distribution characteristics of scalars; S: current segmentation strategy, including the starting position and size of each segment; M: memory usage limit; P: performance target, including table lookup hit rate and calculation time; Output: S′: updated segmentation strategy; The steps of the dynamic segment adjustment algorithm include: S1.2.2.1 Statistics and analysis: Use the historical scalar set H to count the frequency of occurrence of each value segment; analyze the table lookup hit rate and memory usage under the current segmentation strategy S; S1.2.2.2 Performance evaluation: Based on the performance target P, evaluate whether the current segmentation strategy meets the requirements, that is, whether the table lookup hit rate and memory usage are within the performance target P. If not, enter the adjustment process; S1.2.2.3 Dynamic Adjustment: Identify high-frequency and low-frequency segments: Based on the statistical results, identify high-frequency and low-frequency value segments; Adjust the segment size: For high-frequency bands, reduce their segment size to increase table lookup efficiency and hit rate; calculate the new segment size to ensure that it does not exceed the memory limit M and reduce the number of segments as much as possible; for low-frequency bands, increase their segment size or keep it unchanged to reduce memory usage; if increasing the low-frequency band size will cause the memory to exceed the limit M, keep the original size or increase it only moderately; Reassign segments: According to the new segment size, recalculate the starting position and size of each segment and generate a new segmentation strategy S′; Verification and feedback: Use a small portion of new scalar data to verify the new segmentation strategy S′; evaluate the performance indicators of the new strategy’s table lookup hit rate, memory usage, and computation time; if the new strategy meets or exceeds the performance target P, update the segmentation strategy to S′; otherwise, fine-tune and re-verify based on the verification results; Update historical data: add the newly processed scalar data to the historical scalar set H for subsequent analysis and adjustment; S2, build a lookup table: implement adaptive segmentation and dynamically adjust the lookup table size; use a fixed lookup table for high-frequency segments, and dynamically calculate and cache the results for low-frequency segments to balance memory and computing efficiency; the steps of building a lookup table in step S2 specifically include: S2.1 Adaptive segmentation: Maintain a dynamic segmentation table to record the size and starting position of each segment; when processing a new scalar, segment it according to the current segmentation table and update the segmentation table to reflect the new scalar distribution; S2.2 Mixed table lookup: High-frequency segment fixed lookup table: For high-frequency segments, pre-calculate and use a hash table or array data structure to store the result of multiplying the segment value by the base point G; Dynamic calculation of low-frequency segments: For low-frequency segments, the traditional point-by-point multiplication method is used to calculate the point multiplication results; and a cache mechanism is used to store the most recently calculated results to reduce repeated calculations; S3. Security enhancement: Introduce randomized table lookup index and mask technology to defend against side channel attacks; conduct code review and test verification to ensure the security of table lookup implementation; S4, Error handling and recovery: Implement error detection and response mechanisms to ensure that the table lookup index is valid and the results are complete; formulate backup and automatic downgrade strategies to ensure stable system operation; S5. Algorithm optimization and adjustment: optimize table lookup index calculation and accumulation strategy, and use parallel processing to improve performance; regularly evaluate performance, adjust parameters, and continuously optimize and update; S6. Testing and verification: Through unit testing, integration testing, performance testing and security testing, the correctness, stability and security of the table lookup implementation are fully verified.

2. The SM2 signature optimization method based on table lookup method according to claim 1, characterized in that: The step of adjusting the segment size specifically includes: A1. Define parameters: fi: the occurrence frequency or relative frequency of the i-th value segment; si: the size of the current i-th segment expressed as a scalar value in range or number of bits; M: Available memory limit, used to store table lookup data; α: high frequency segment size adjustment factor, where 0<α<1, used to reduce the size of the high frequency segment; β: upper limit factor for adjusting the size of the low-frequency segment, and β≥1, used to control the upper limit of the increase of the low-frequency band; A2. Calculate the new segment size: High frequency band: Calculate the new segment size si′=si×α and round it up to ensure that the segment size is not less than 1; If si′ is too small, i.e., less than the set minimum threshold δ, it will be merged with other high-frequency bands or kept at the original size; Verify whether the new segment size will cause memory usage to exceed the limit M. If so, further adjustments need to be made by merging segments or adjusting other low-frequency segments; Low frequency band: Initialize the new segment size si′=si. If the low frequency band needs to be increased, then: si′=si×β; If the increase of si′ does not cause the memory usage to exceed the limit M, then keep si′; otherwise, reduce the value of β or keep si′=si, that is, do not increase the size of the low frequency band.

3. The SM2 signature optimization method based on table lookup method according to claim 1, characterized in that: The security enhancement steps in step S3 specifically include: S3.1 Prevention of side channel attacks: Randomize the lookup index: Before looking up the table, apply a random offset or random mask to the lookup index to ensure that the index used for each lookup is random; Use masking technology: Apply masks to sensitive data during table lookup; remove the mask before using the data to ensure data correctness; S3.2 Security Audit: Code review: Thoroughly review all code for table lookup implementation to find potential security vulnerabilities; Test verification: Use fuzz testing and penetration testing methods to verify the security of the table lookup implementation.

4. The SM2 signature optimization method based on table lookup method according to claim 1, characterized in that: Step S4: Error handling and recovery steps specifically include: S4.1 Error handling mechanism: Error detection: Before looking up a table, check whether the table index is out of bounds; and before using the table result, verify the integrity of the result; Error response: When an error is detected, the error log is recorded and the error code and error information are returned; S4.2 Fault recovery strategy: Back up table lookup data: regularly back up table lookup data to a secure storage medium; Automatic downgrade: When table lookup fails, it automatically switches to non-table lookup mode and notifies the system administrator or user.

5. The SM2 signature optimization method based on table lookup method according to claim 1, characterized in that: The steps of algorithm optimization and adjustment in step S5 specifically include: 5.1 Refinement and adjustment: Lookup index calculation: Optimize the calculation method of lookup index to reduce calculation complexity and improve performance; Accumulation strategy: Use elliptic curve addition algorithm to accumulate table lookup results; consider parallel processing or SIMD instructions to speed up the accumulation process; 5.2 Regular evaluation and optimization: Performance evaluation: Use benchmarking tools to evaluate the performance of algorithms; collect and analyze performance data; Optimization iteration: Based on the performance evaluation results, adjust the segmentation strategy and table lookup size parameters, and perform optimization updates.

6. The SM2 signature optimization method based on table lookup method according to claim 1, characterized in that: The content of the test and verification in step S6 specifically includes: Unit testing: Write unit tests to verify that the various parts of the table lookup implementation work as expected; Integration test: Integrate the table lookup implementation into the SM2 signature algorithm for overall testing; Performance testing: Testing the performance of the algorithm on a variety of hardware and software platforms to ensure stability and efficiency in different environments; Security testing: Use professional security testing tools and methods to verify the security of the algorithm, including side channel attack testing and fault injection testing.

7. A SM2 signature optimization system based on table lookup method, used to implement the SM2 signature optimization method based on table lookup method according to any one of claims 1 to 6, characterized in that: It includes a parameter configuration module, a dynamic table lookup construction module, a security enhancement module, an error handling and recovery module, an algorithm optimization and adjustment module, and a testing and verification module, which are respectively used to implement steps S1 to S6.

Citation Information

Patent Citations

  • Multiple-point calculation method and device for realizing SM2 algorithm

    CN110048844A

  • Resource dynamic scheduling technology of distributed cloud computing system

    CN117762644A

  • High-speed Switch chip network card function implementation system based on VLAN division

    CN118138402A