Hardware accelerator and acceleration method supporting the national secret SM2 algorithm

Through the design of hardware accelerator, the conversion of affine coordinates to Jacobian coordinates and pipelines and finite state machine methods are used to perform the SM2 algorithm operations, which solves the problem of complexity and low efficiency of point operations on the elliptic curve, and achieves high efficiency The algorithm performance is improved.

CN118353636BActive Publication Date: 2024-11-26BEIHANG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410501941.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-04-24
Publication Date
2024-11-26
Estimated Expiration
2044-04-24

AI Technical Summary

Technical Problem

The SM2 algorithm has complex and time-consuming calculations of points on the elliptic curve, resulting in low implementation efficiency and is not suitable for high throughput and high performance application scenarios.

Method used

Design a hardware accelerator, including a control module, an ECC engine, a hash module and a coordinate conversion module, through the conversion of affine coordinates to Jacobian coordinates, and performs modular operations and elliptic curve point operations in combination with pipelines and finite state machines, eliminating the loss of Modal inverse operation to improve processing efficiency.

Benefits of technology

It greatly improves the processing efficiency and performance of Guomi SM2 algorithm and can be suitable for high throughput and high performance application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118353636B_ABST
    Figure CN118353636B_ABST
Patent Text Reader

Abstract

The embodiment of the present application discloses a hardware accelerator and acceleration method supporting the national secret SM2 algorithm, wherein the accelerator includes: a control module, which is used to receive input data through an interface, perform conversion from affine coordinates to Jacobian coordinates on the input data and point value data in the elliptic curve parameters, and send the scalar data in the input data and the elliptic curve parameters and the point value data of the Jacobian coordinates to an ECC engine; the ECC engine, which is used to perform modular operations in a pipeline manner and point operations of the elliptic curve in a finite state machine manner according to the scalar data and the point value data of the Jacobian coordinates; a hash module, which is used to perform hash function operations in the encryption and decryption process according to the point operation results; a coordinate conversion module, which is used to perform conversion from Jacobian coordinates to affine coordinates on the point operation results; and the control module is also used to control the sending of at least one operation result of the modular operation, the point operation and the hash function operation as output data through the interface.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of cryptography, and in particular to a hardware accelerator and an acceleration method supporting a national cryptographic SM2 algorithm. Background Art

[0002] At present, with the rapid development of network technology, cross-domain information exchange is becoming more and more frequent. In this process, malicious attacks such as information interception, destruction or forgery may occur, which inevitably leads to information security problems. ECC (Elliptic Curve Cryptography) is an important cryptographic algorithm in the field of modern information security. It is mainly used in encrypted communication, digital signatures, identity authentication, digital currency and blockchain technology, and provides effective solutions for scenarios such as secure communication and data protection. The SM2 algorithm is an asymmetric public key cryptographic algorithm based on ECC, which provides higher security than traditional symmetric encryption and is widely used in commercial cryptographic systems.

[0003] However, since the SM2 algorithm involves operations on points on elliptic curves, it is complex and time-consuming, has low implementation efficiency and slow performance, and is not suitable for high-throughput and high-performance application scenarios. Summary of the invention

[0004] The purpose of the embodiments of the present application is to provide a hardware accelerator, acceleration method and electronic device that supports the national secret SM2 algorithm to solve the problems in the prior art.

[0005] To solve the above technical problems, the embodiments of the present application are implemented as follows:

[0006] In a first aspect, an embodiment of the present application provides a hardware accelerator supporting the national secret SM2 algorithm, including: a control module, an ECC engine, a hash module and a coordinate conversion module;

[0007] The control module is used to receive input data through the interface, perform conversion from affine coordinates to Jacobian coordinates on the input data and point value data in the elliptic curve parameters, and send the input data and scalar data in the elliptic curve parameters and the converted point value data of the Jacobian coordinates to the ECC engine;

[0008] The ECC engine is used to receive the scalar data and the point value data of the Jacobian coordinates sent by the control module, and perform modular operations in a pipeline manner and point operations of elliptic curves in a finite state machine manner according to the scalar data and the point value data of the Jacobian coordinates;

[0009] The hash module is used to perform hash function operations in the encryption and decryption process of the national secret SM2 algorithm according to the point operation results of the ECC engine;

[0010] The coordinate conversion module is used to perform conversion from Jacobian coordinates to affine coordinates on the point operation result of the ECC engine;

[0011] The control module is further used to control sending at least one operation result of the modular operation, the point operation and the hash function operation as output data through the interface.

[0012] In a second aspect, an embodiment of the present application provides an acceleration method, which is applied to the hardware accelerator supporting the national secret SM2 algorithm as described above, including:

[0013] Receive input data;

[0014] Perform affine coordinate to Jacobian coordinate conversion on the point value data in the input data and elliptic curve parameters;

[0015] According to the scalar data in the input data and the elliptic curve parameters and the point value data of the Jacobian coordinates, the modular operation is performed in a pipeline manner and the point operation of the elliptic curve is performed in a finite state machine manner;

[0016] According to the point operation results, the hash function operation is performed during the encryption and decryption process of the national secret SM2 algorithm;

[0017] Control to send at least one operation result of the modular operation, the point operation and the hash function operation as output data through the interface.

[0018] In a third aspect, an embodiment of the present application provides an electronic device, comprising the above-mentioned hardware accelerator supporting the national encryption SM2 algorithm.

[0019] It can be seen from the technical solution provided by the above embodiments of the present application that input data is received through an interface, and the affine coordinate to Jacobian coordinate conversion is performed on the input data and the point value data in the elliptic curve parameters, and the scalar data in the input data and the elliptic curve parameters and the converted Jacobian coordinate point value data are sent to the ECC engine. The ECC engine performs modular operations in a pipeline manner and point operations of the elliptic curve in a finite state machine manner according to the scalar data and the Jacobian coordinate point value data. The hash module performs hash function operations in the encryption and decryption process of the national secret SM2 algorithm according to the point operation results, and the coordinate conversion module performs Jacobian coordinate to affine coordinate conversion on the point operation results. Finally, the control module controls the results of the hash module and / or the coordinate conversion module to be sent as output data through the interface. This combination of pipeline and finite state machine realizes multi-level scheduling. Point value data can save a large number of modular inverse operations by performing operations under Jacobian coordinates, greatly improves processing efficiency, realizes acceleration of the national secret SM2 algorithm, greatly improves algorithm performance, and can be suitable for high-throughput and high-performance application scenarios. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0021] Figure 1 A schematic diagram of the structure of a hardware accelerator supporting the national secret SM2 algorithm provided in an embodiment of the present application;

[0022] Figure 2 A schematic diagram of the structure of the ECC engine provided in the embodiment of the present application;

[0023] Figure 3 A schematic diagram of the control principle of the FSM top-level control unit provided in an embodiment of the present application;

[0024] Figure 4 A schematic diagram of the principle of multiplication optimization in a modular multiplication unit provided in an embodiment of the present application;

[0025] Figure 5 A schematic diagram of the structure of a 256-bit wide multiplier provided in an embodiment of the present application;

[0026] Figure 6 A schematic diagram of the processing process of a hardware accelerator supporting the national secret SM2 algorithm provided in an embodiment of the present application;

[0027] Figure 7 A schematic diagram of a flow chart of an acceleration method provided in an embodiment of the present application;

[0028] Figure 8 A schematic diagram of the process of the dot product operation provided in the embodiment of the present application;

[0029] Fig. 9 A schematic diagram of a flow chart of a state machine control provided in an embodiment of the present application;

[0030] Fig.10 A flowchart of the signing process provided in the embodiment of the present application;

[0031] Fig.11 A flowchart of a signature verification process provided in an embodiment of the present application;

[0032] Fig.12 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0033] The embodiments of the present application provide a hardware accelerator, an acceleration method, and an electronic device that support the national secret SM2 algorithm.

[0034] In order to enable those skilled in the art to better understand the technical solutions in the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings 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 should fall within the scope of protection of the present invention.

[0035] First, the terms involved in the present invention are explained.

[0036] Elliptic curve: In cryptography, an elliptic curve E defined by a and b over a finite field. The points on these curves form a group that supports addition operations. This structure makes the elliptic curve suitable for various encryption algorithms.

[0037] Finite field: A field with a finite number of elements, which can be represented by F q , q is the number of elements in the finite field. A field is a set on which addition, subtraction, multiplication and division operations can be performed without exceeding the field. For example, the set of rational numbers, the set of real numbers and the set of complex numbers are all fields. If the number of elements in a finite field is a prime number, it is called a Galois field.

[0038] Point multiplication: also known as elliptic curve scalar multiplication or multiple point multiplication, is multiple addition operations on the same point on the elliptic curve. The k-times point operation of a point P on an elliptic curve is k addition operations on point P, which can be written as Q = [k] P = P + P + ... + P (a total of k), where k is a positive integer.

[0039] Modular operation: mod n is a modular operation, which means the remainder after division by n. Modular operations include modular addition, modular subtraction, modular multiplication, modular exponentiation and modular inverse. Among them, modular inverse is more complex and time-consuming, and is the key factor affecting the SM2 algorithm.

[0040] Affine coordinate system: A coordinate system in a multidimensional space that contains an origin and a set of basis vectors. For example, the plane rectangular coordinate system is an affine coordinate system, which is a very common coordinate representation method.

[0041] Jacobi coordinate system: It is a special coordinate system that is often used to study the solution of multivariate function calculus related problems. In elliptic curve cryptography, operations in the Jacobi coordinate system can avoid modular inverse operations, thereby greatly saving computing time.

[0042] FSM (Finite State Machine): is a tool for modeling object behavior. It represents a mathematical model of a finite number of states and the transitions and actions between these states. The core of the finite state machine is to process various input events and state switching and generate output control signals. At any time, the finite state machine is in a state in the finite state set. When an input character is obtained, the finite state machine will switch from the current state to another state or remain in the current state.

[0043] CSA (Carry Save Adder) is a digital adder mainly used to calculate the sum of three or more binary numbers. The input is three source operands, and the output includes two operation results: sum and carry.

[0044] FIFO (First Input First Output) is a first-in, first-out data storage device that can cache continuous data streams. The data address is automatically incremented by 1 by the internal read-write pointer, and data must be written and read sequentially.

[0045] The hardware accelerator and acceleration method supporting the national secret SM2 algorithm provided in the embodiment of the present application can be applied to an electronic device, which can be a terminal device or a server. The server can be an independent server or a server cluster composed of multiple servers, which is not specifically limited. The terminal device can be a device such as a personal computer, or a mobile terminal device such as a mobile phone or a tablet computer, which is not specifically limited. The application scenarios of the above-mentioned accelerator and acceleration method include but are not limited to: using the SM2 algorithm on a terminal device or server to perform modular operations, point operations, encryption, decryption, signing or verifying signatures, etc. The elliptic curve used can be an elliptic curve of a 256-bit prime field, etc., which is not specifically limited in the embodiment of the present application.

[0046] like Figure 1 As shown, an embodiment of the present application provides a hardware accelerator that supports the national encryption SM2 algorithm, which may include: a control module 10, an ECC engine 20, a hash module 30 and a coordinate conversion module 40.

[0047] The control module 10 is used to receive input data through an interface, perform conversion from affine coordinates to Jacobian coordinates on the input data and point value data in the elliptic curve parameters, and send the scalar data in the input data and elliptic curve parameters and the point value data of the converted Jacobian coordinates to the ECC engine 20.

[0048] The ECC engine 20 is used to receive the scalar data and the point value data of the Jacobian coordinates sent by the control module 10, and perform modular operations in a pipeline manner and point operations of elliptic curves in a finite state machine manner according to the scalar data and the point value data of the Jacobian coordinates.

[0049] The hash module 30 is used to perform hash function operations during the encryption and decryption process of the national secret SM2 algorithm according to the point operation results of the ECC engine 20.

[0050] The coordinate conversion module 40 is used to perform conversion from Jacobian coordinates to affine coordinates on the point operation result of the ECC engine 20 .

[0051] The control module 10 is further used to control at least one operation result of a modulus operation, a point operation and a hash function operation to be sent as output data through an interface.

[0052] In an embodiment of the present application, the input data may be data in a variety of scenarios, such as encryption and decryption scenarios, signature scenarios, signature verification scenarios, modular operation scenarios, or point operation scenarios. Among them, the types of input data include point value data and scalar data. Point value data refers to two-dimensional data, which can be represented in the form of (x, y) coordinates. Scalar data refers to one-dimensional data, which can be represented by binary numbers. In an execution task, the received input data may include point value data, or scalar data, or both point value data and scalar data, which is determined by the operation involved in the task.

[0053] For example, the plaintext data to be encrypted received in the encryption task is scalar data, which can be a string of characters or an encoded image, etc.; or, the ciphertext data to be decrypted received in the decryption task includes three parts C1, C2 and C3, where C1 is the elliptic curve point, which is the point value data, and C2 and C3 are scalar data; or, the 256-bit binary data to be signed / verified received in the signing / verification task is scalar data, etc.

[0054] In the embodiment of the present application, the elliptic curve parameters are preset parameters, which have been set during initialization and can be directly used to participate in various operations when executing tasks. The elliptic curve parameters usually have multiple parameters, including scalar data and point value data.

[0055] For example, the base point G and the infinite point O in the elliptic curve parameters are both point value data, the order n of the base point G is scalar data, and the finite field F q The number of elements q in is scalar data, etc.

[0056] In the embodiment of the present application, the conversion of point value data from affine coordinates to Jacobian coordinates is to add a z coordinate with a value of 1, that is, from (x, y) to (x, y, 1), which is relatively simple, so it can be directly completed using the control module 10, and the coordinate conversion module 40 completes the conversion from Jacobian coordinates to affine coordinates.

[0057] In the embodiment of the present application, the above interface is used to receive input data from the outside and send it to the control module 10, and receive output data sent by the control module 10 and send it to the outside. Specifically, the above hardware accelerator can support multiple types of interfaces to expand applications in different scenarios, which is not specifically limited in the embodiment of the present application.

[0058] In the embodiment of the present application, the control module 10 controls to use at least one operation result of a modulus operation, a point operation and a hash function operation as output data, and the corresponding output data is different in different scenarios.

[0059] For example, in the encryption or decryption process of the national secret SM2 algorithm, the result of the hash function operation, that is, the encryption or decryption result, is used as the output data. In the signature or signature verification process of the national secret SM2 algorithm, after the signature or signature verification result is calculated and the legitimacy of the data is judged, the correct signature or signature verification result, that is, the modulo operation result, is obtained as the output data. In the point operation process, the point operation result is converted into affine coordinates as the output data.

[0060] The above-mentioned hardware accelerator provided in the embodiment of the present application receives input data through an interface, performs conversion from affine coordinates to Jacobian coordinates on the input data and the point value data in the elliptic curve parameters, and sends the scalar data in the input data and the elliptic curve parameters and the point value data of the converted Jacobian coordinates to the ECC engine. The ECC engine performs modular operations in a pipeline manner and point operations of the elliptic curve in a finite state machine manner according to the scalar data and the point value data of the Jacobian coordinates. The hash module performs hash function operations in the encryption and decryption process of the national secret SM2 algorithm according to the point operation results, and the coordinate conversion module performs Jacobian coordinates to affine coordinates conversion on the point operation results. Finally, the control module controls the results of the hash module and / or the coordinate conversion module to be sent as output data through the interface. This combination of pipeline and finite state machine realizes multi-level scheduling. The point value data performs operations under Jacobian coordinates, which can save a large number of modular inverse operations, greatly improves processing efficiency, realizes the acceleration of the national secret SM2 algorithm, greatly improves algorithm performance, and can be suitable for high-throughput and high-performance application scenarios.

[0061] See also Figure 2 , is a schematic diagram of the ECC engine structure provided in the embodiment of the present application. Figure 2As shown, the ECC engine 20 in the hardware accelerator provided in the embodiment of the present application may specifically include: an FSM top-level control unit 21, a sub-state machine 22, an addressing unit 23, an instruction memory 24, a decoding unit 25, a register stack 26, a finite field calculation unit 27 and a write back control unit 28.

[0062] The FSM top-level control unit 21 is used to receive the scalar data and Jacobian coordinate point value data sent by the control module 10, send a notification to the corresponding sub-state machine according to the current operation type, and receive the feedback signal sent by the sub-state machine and transmit it to the control module.

[0063] In one implementation, the FSM top-level control unit 21 can be specifically used to: determine whether the current operation type is an application layer operation, a point multiplication operation or a custom operation, send a notification to the corresponding sub-state machine according to the current operation type, and receive a feedback signal sent by the sub-state machine and transmit it to the control module. The application layer operation includes at least one of encryption, decryption, signature and signature verification, and the custom operation includes at least one of point addition, doubling, modular addition, modular subtraction, modular multiplication and modular inverse.

[0064] The above method of setting different operation types can support finer-grained operations and realize a multi-level scheduling mechanism. Moreover, users can customize multiple operations, making the application more convenient and flexible.

[0065] The sub-state machine 22 is used to receive the notification sent by the FSM top-level control unit and issue a redirection instruction, and send a feedback signal to the FSM top-level control unit after the current operation is completed.

[0066] In the embodiment of the present application, the sub-state machine 22 may be one or more, usually multiple, such as a sub-state machine corresponding to application layer operations, a sub-state machine corresponding to point multiplication operations, and a sub-state machine corresponding to custom operations.

[0067] The addressing unit 23 is used to read instructions in address order, and redirect to the corresponding address reading instruction when receiving a redirection instruction issued by the sub-state machine.

[0068] Among them, reading instructions in address order can be achieved through PC (Program Counter), the program accelerator automatically adds one, and the address unit 23 will automatically read the next address of the current address, which is a scenario where no jump occurs. When the address unit 23 receives a redirection instruction issued by the sub-state machine, it belongs to a scenario where a jump occurs. In this case, the instruction is read from the current multiple redirections to the address pointed to by the instruction to complete the jump.

[0069] The instruction memory 24 is used to store the instructions read by the addressing unit.

[0070] Exemplarily, the instruction memory 24 may be a ROM with a bit width of 16 bits and a depth of 256 bits, which internally stores instructions such as instructions for executing various tasks. Of course, memories with other configurations may also be used, and the embodiments of the present application do not specifically limit this.

[0071] The decoding unit 25 is used to parse the instructions in the instruction memory.

[0072] The decoding unit 25 can parse the instruction according to the custom instruction set to determine the content that needs to be executed currently. For example, the execution instruction is parsed to determine the current operation type, or the branch jump instruction is parsed to determine what kind of data check and branch jump are currently executed, or the status indication instruction is parsed to determine whether the current execution status is: normal end, execution failure, waiting state, or execution of an empty instruction, etc.

[0073] Register stack 26 is used to cache the elliptic curve parameters used by the national secret SM2 algorithm and the point value data of the Jacobian coordinates sent by the control module, as well as the intermediate data generated during the cache calculation process.

[0074] The intermediate data generated during the calculation process includes: the intermediate data generated during the main calculation process and the pre-calculated multiple point results in the dot multiplication operation. Pre-calculation means that in the dot multiplication process, the dot addition and dot multiplication operations need to be performed first, and then the dot multiplication operation can be performed based on the results of the dot addition and dot multiplication operations, that is, the multiple point results.

[0075] In one embodiment, the register file 26 may include: a main calculation storage area and a pre-calculation storage area. The main calculation storage area is used to cache the elliptic curve parameters used by the national secret SM2 algorithm and the point value data of the Jacobian coordinates sent by the control module, as well as to cache the intermediate data generated during the main calculation process. The pre-calculation storage area is used to cache the pre-calculated multiple point results in the point multiplication operation.

[0076] The finite field calculation unit 27 is used to perform modular operations in a pipeline manner and point operations of elliptic curves in a finite state machine manner based on the scalar data and the point value data of the Jacobian coordinates according to the current operation analyzed and determined by the decoding unit.

[0077] The modular operation includes but is not limited to modular addition, modular subtraction or modular multiplication. Multiple iterations of modular addition, modular subtraction and modular multiplication can realize point addition and point doubling operations, and multiple point addition and point doubling operations can realize point multiplication operations.

[0078] The write-back control unit 28 is used to generate a write enable signal according to the execution cycle of the algorithm, and control whether to write the calculation result of the finite field calculation unit into the register file based on the write enable signal.

[0079] Among them, the execution cycle of the algorithm is fast or slow. The execution cycle of modular addition and modular subtraction is short, and the execution cycle of point multiplication is relatively long. Therefore, the write enable signal can be set to be generated after the algorithm with a short cycle is completed, rather than generating the write enable signal after the algorithm with a long cycle is completed, which can greatly shorten the processing time. The purpose of generating a write enable signal is to ensure that the operation result can be written into the register stack in time, and the operation result can be written in time when the register stack meets the write conditions.

[0080] In one implementation, the write-back control unit 28 may be specifically configured to generate a write enable signal according to an execution cycle of a unit operation, and control whether to write the calculation result of the finite field calculation unit into the register file based on the write enable signal, wherein the unit operation is a modular addition, modular subtraction or modular multiplication operation.

[0081] The above-mentioned unit operations belong to algorithms with shorter execution cycles. Other algorithms such as dot addition, dot multiplication, and dot multiplication can be implemented by iterating or combining these unit operations. Therefore, the method of generating a write enable signal based on the execution cycle of a unit operation can achieve the effect of out-of-order writing, that is, the timing of writing data to the register stack no longer depends on whether the current operation is dot addition, dot multiplication, or dot multiplication. As long as it is any of the operations of modular addition, modular subtraction, or modular multiplication, a write enable signal can be generated to control writing to the register stack. This mechanism not only improves the utilization rate of the register stack, but also avoids long waiting times for the results of operations such as dot multiplication, ensures timely writing of data, and improves the efficiency and performance of the algorithm.

[0082] In one embodiment, the ECC engine 20 may further include: a branch control unit 29, which is used to check the input data or the calculation result of the finite field calculation unit 27, and determine whether to issue a redirection instruction according to the check result and the branch jump type determined by the decoding unit 25. Accordingly, the addressing unit 23 is also used to redirect to the corresponding address read instruction according to the redirection instruction issued by the branch control unit 29.

[0083] Among them, the checks performed by the branch control unit 29 include but are not limited to: non-zero check on the input data, check on the infinity point of the elliptic curve, check on the validity of the input of the point addition operation or check on the validity of the result of the signature verification, etc., which will not be explained in detail here.

[0084] See also Figure 3 , is a schematic diagram of the control principle of the FSM top-level control unit provided in the embodiment of the present application. Figure 3As shown, the sub-state machine includes an application layer operation sub-state machine 22, a point multiplication operation sub-state machine 22 and a custom operation sub-state machine 22. The FSM top-level control unit 21 can determine whether the current operation type is an application layer operation, a point multiplication operation or a custom operation. If it is an application layer operation, a notification is sent to the application layer operation sub-state machine 22; if it is a point multiplication operation, a notification is sent to the point multiplication operation sub-state machine 22; if it is a custom operation, a notification is sent to the custom operation sub-state machine 22. Among them, the application layer operation includes at least one of encryption, decryption, signature and signature verification, and the custom operation includes at least one of point addition, doubling, modular addition, modular subtraction, modular multiplication and modular inversion. After receiving the notification sent by the FSM top-level control unit 21, any of the above sub-state machines 22 will send a redirection instruction to the addressing unit 23 through the FSM selector to instruct the addressing unit 23 to jump to the corresponding address reading instruction of the instruction memory 24 according to the redirection instruction. After the current operation is completed, each sub-state machine 22 will also send a feedback signal of FSM completion to the FSM top-level control unit 21 through the FSM selector.

[0085] In one implementation, the finite field computing unit may adopt a CSA addition tree architecture, such as using a CSA addition array, a CSA subtraction array, and a CSA overflow array to perform combinatorial operations to obtain modular multiplication results, thereby achieving fast simplicity, shortening calculation time, and improving algorithm processing efficiency.

[0086] In the embodiment of the present application, the hash module 30 may include:

[0087] The algorithm unit is used to perform the operations of the SM3 algorithm and the key derivation function algorithm in the encryption and decryption process of the national secret SM2 algorithm according to the point operation results of the ECC engine;

[0088] The first-in first-out FIFO is used to transmit data across clock domains and store encrypted and decrypted data based on the clock frequency difference between the ECC engine and the algorithm unit.

[0089] In an embodiment of the present application, the finite field computing unit 27 may include: a modular addition unit, a modular subtraction unit and a modular multiplication unit. The modular operation performed by the finite field computing unit 27 can be completed by the modular addition unit, the modular subtraction unit and the modular multiplication unit. The point operation performed by the finite field computing unit 27 can be completed by multiple iterations of the modular addition unit, the modular subtraction unit and the modular multiplication unit.

[0090] In one implementation, the modular multiplication unit may specifically include: a multiplier and a modular unit.

[0091] Among them, the multiplier can be specifically used for:

[0092] If the current operation is a modular multiplication operation of a specified bit width, the input data of the Jacobian coordinates of the two specified bit widths are split according to the principle that the number of high-order bits and low-order bits are equal, and one of the input data is split to obtain the first high-order data A1 and the first low-order data A0, and the other input data is split to obtain the second high-order data B1 and the second low-order data B0;

[0093] A first product T0 is obtained by performing a multiplication operation on the first low-order data A0 and the second low-order data B0, a second product T1 is obtained by performing a multiplication operation on the first low-order data A0 and the second high-order data B1, a third product T2 is obtained by performing a multiplication operation on the first high-order data A1 and the second low-order data B0, and a fourth product T3 is obtained by performing a multiplication operation on the first high-order data A1 and the second high-order data B1;

[0094] The first product T0 and the fourth product T3 are split according to the principle that the number of high and low bits is equal, and the low bits of the first product T0 after splitting are used as the low bits of the multiplication result of the two input data;

[0095] After the high bit of the first product T0 is split, the low bit of the fourth product T3 is spliced, and then the CSA addition operation is performed on the second product T1 and the third product T2, and the sum result of the CSA addition operation and the carry result are added to obtain the result and overflow bit, and the result of the addition operation is used as the middle bit of the multiplication result of the two input data;

[0096] The highest bit of the carry result of the CSA addition operation is added to the high bit after the fourth product T3 is split to obtain the first candidate value R1, and the first candidate value R1 is added to 1 to obtain the second candidate value R2. The first candidate value R1 or the second candidate value R2 is selected as the high bit of the multiplication result of the two input data according to the overflow bit.

[0097] The modulo unit can be specifically used to: after splicing the high bit, middle bit and low bit of the multiplication result of two input data obtained by the multiplier, perform a modulo operation to obtain a modular multiplication result output, and the modulus of the modulo operation is the modulus of the elliptic curve.

[0098] In the embodiment of the present application, the modular operation involved in the modular multiplication process can use a fast reduction algorithm to improve the speed of modular multiplication.

[0099] The above modular multiplication optimization method can reduce the complexity of the operation logic, reduce the delay of the operation path, and can achieve the effect of reducing the longest addition carry chain, thereby improving the efficiency of the modular multiplication operation.

[0100] See also Figure 4 , is a schematic diagram of the principle of multiplication optimization in the modular multiplication unit provided in the embodiment of the present application. Figure 4, taking the current operation as a 256-bit modular multiplication operation as an example. The two 256-bit Jacobian coordinate input data A and B are split according to the principle that the number of high and low bits is equal, where A is split to obtain the first high-order data A1 and the first low-order data A0, expressed as A = {A1, A0}, that is, A = A1×2 128 +A0. After B is split, the second high-order data B1 and the second low-order data B0 are obtained, which is expressed as B = {B1, B0}, that is, B = B1×2 128 +B0. Four multiplication operations are performed on the split data to obtain four products: the first product T0 = A0 × B0; the second product T1 = A0 × B1, the third product T2 = A1 × B0, and the fourth product T3 = A1 × B1. Therefore, the modular multiplication operation of input data A and B can be evolved as: C mod p, where C = A × B = T3 × 2 256 +T2×2 128 +T1×2 128 +T0, p is the modulus of the elliptic curve.

[0101] See also Figure 5 , is a schematic diagram of the structure of a 256-bit wide multiplier provided in an embodiment of the present application. Figure 4 The calculation logic shown can be used Figure 5 The 256-bit wide multiplier shown in FIG. 1 is used to optimize the multiplication in the modular multiplication operation. Figure 5As shown, four 128-bit multipliers are used to calculate the first product T0, the second product T1, the third product T2 and the fourth product T3 respectively. The first product T0 and the fourth product T3 are split according to the principle that the number of high and low bits is equal, and the low bit T0[127:0] of the first product T0 after splitting is used as the low bit C[127:0] of the multiplication result C of A and B. The high bit T0[255:128] of the first product T0 after splitting is concatenated with the low bit T3[127:0] of the fourth product T3 after splitting, and then a 256-bit CSA addition operation is performed with the second product T1 and the third product T2. The sum result SUM1[255:0] of the CSA addition operation is added to the carry result CARRY1[255:0] to obtain the result SUM2[256:0] and the overflow bit, and the result SUM2[256:0] of the addition operation is used as the middle bit C[383:128] of the multiplication result C of A and B. The highest bit CARRY1

[256] of the CSA addition operation is added to the high bit T3[255:128] after the fourth product T3 is split to obtain the first candidate value R1, and the first candidate value R1 is added to 1 to obtain the second candidate value R2. According to the overflow bit obtained by the above addition operation, the first candidate value R1 or the second candidate value R2 is selected as the high bit C[511:384] of the multiplication result C of A and B. Specifically, if the overflow bit is 1, R2 is selected as the high bit of C, and if the overflow bit is 0, R1 is selected as the high bit of C. The above process realizes the optimization of multiplication by the multiplier in the modular multiplication unit. Based on the output result of the multiplier, the modulo unit can concatenate the high bit, middle bit and low bit of the multiplication result C of A and B, and perform a modular operation (C mod p) to obtain the modular multiplication result output.

[0102] See also Figure 6 , is a schematic diagram of the processing process of the hardware accelerator supporting the national encryption SM2 algorithm provided in the embodiment of the present application. Figure 6As shown, the hash module 30 includes an SM3 IP unit for performing SM3 hash algorithm and KDF (Key Derivation Function) operation, a cross-clock FIFO, a hash control unit and a hash control interface. Since the clock frequencies of the ECC engine and the SM3 IP are different, a true dual-port FIFO can be used to implement a cross-clock domain design to complete cross-clock domain data transmission. The hash control unit controls the SM3 IP unit to perform hash function operations during encryption and decryption according to the point operation results of the ECC engine 20, and outputs the encryption and decryption results through the FIFO. The coordinate conversion module 40 includes a FIFO, a modular inversion unit and a control unit, which mainly performs the conversion of Jacobian coordinates to affine coordinates when data is output. The Jacobian coordinates (X3, Y3, Z3) obtained by the ECC engine 20 are converted into affine coordinates (x, y) by the coordinate conversion module 40 and sent to the control module 10. The control module 10 thus controls the corresponding results to be output as output data through the interface.

[0103] The above is a hardware accelerator supporting the national secret SM2 algorithm provided in the embodiment of the present application. Based on the same idea, the embodiment of the present application also provides an acceleration method, which is applied to the hardware accelerator supporting the national secret SM2 algorithm in any embodiment provided in the present application, such as Figure 7 As shown, the method specifically includes:

[0104] S702: Receive input data.

[0105] S704: Perform a conversion from affine coordinates to Jacobi coordinates on the input data and the point value data in the elliptic curve parameters.

[0106] S706: According to the input data and the scalar data in the elliptic curve parameters and the point value data of the Jacobian coordinates, the modular operation is performed in a pipeline manner and the point operation of the elliptic curve is performed in a finite state machine manner.

[0107] S708: Based on the point operation result, perform hash function operation in the encryption and decryption process of the national secret SM2 algorithm.

[0108] S710: Control to send at least one operation result of the modular operation, the point operation and the hash function operation as output data through the interface.

[0109] In the embodiment of the present application, the point value data in the elliptic curve parameters refers to the elliptic curve base point. The point value data in the input data includes the public key used for encryption, the ciphertext C1 in decryption, and the public key in signature verification. The point value data used in the encryption process includes the public key and the base point, the point value data used in the decryption process includes the ciphertext C1, the point value data used in the signature process includes the elliptic curve base point, and the point value data used in the signature verification process includes the elliptic curve base point and the public key. At least one operation result of the modular operation, point operation, and hash function operation involved in the above step S710 represents the operation results in different scenarios, including but not limited to: encryption result, decryption result, signature result, or signature verification result, etc.

[0110] See also Figure 8 , is a schematic diagram of the process of the point multiplication operation provided by the embodiment of the present application. The point operation in the above step S706 includes but is not limited to the point multiplication operation. The following specifically describes how to perform the point multiplication operation process of the elliptic curve in a finite state machine manner. Figure 8 As shown, in the scenario where the point operation is a point multiplication operation, the core steps of the point multiplication operation include pre-calculation and main calculation. Among them, pre-calculation refers to the point addition and doubling operations performed first in the point multiplication process, and the main calculation refers to the point multiplication operation performed based on the results of the point addition and doubling operations, that is, the multiple dot results. The point multiplication operation sub-state machine can set four states, namely, Kp idle, pre-calculation, main calculation, and Kp completed, and control the state transition of the hardware accelerator through the enable signal and completion signal of the pre-calculation and main calculation. When the hardware accelerator determines that a point multiplication operation is currently required, the point multiplication operation sub-state machine controls the state to transition from Kp idle to pre-calculation state. According to the national secret SM2 algorithm, 15 points of pre-calculation are performed in the pre-calculation state, including 15 iterations of point addition operations and storage of intermediate results. When the pre-calculation is completed, the point multiplication operation sub-state machine controls the state to enter the main calculation state from the pre-calculation state. 64 loop iterations of point multiplication are performed in the main calculation state, including point addition operations and continuous doubling operations. After the dot product operation is completed, a Kp completion signal is generated, and the dot product operator state machine control state returns from the main calculation state to the idle state, waiting for the next task to arrive.

[0111] See also Fig. 9 , is a flow chart of the state machine control provided in the embodiment of the present application. Fig. 9As shown, in the input check phase, if the input data is not standardized or the parameters are missing, an error message will be directly output and the operation will be terminated. On the contrary, after the input check, different control units in the sub-state machine will be started according to the specific function currently being executed, and the control of the ECC engine will be transferred to the sub-state machine. After the corresponding control unit in the sub-state machine completes the specific function, the result will be sent to the output check unit. If the output data is not standardized or the result is wrong (such as a signature verification error), the corresponding error code will be fed back and the operation will be terminated, otherwise the correct result of the operation will be output.

[0112] See also Fig.10 , is a flow chart of the signing process provided by the embodiment of the present application. Fig.10 As shown, first, after starting the signature operation, the calculation of point multiplication and modular inversion is started, and the elliptic curve point (x1, y1) = [k] G and (1 + d A ) -1 The two are calculated synchronously, respectively by the ECC engine and the coordinate conversion module. After the dot multiplication and modular inverse calculations are completed, the modular addition operation is performed to obtain the parameter r = (e + x1) mod n, and the parameter r is checked. After the parameter r is checked, the parameter s = ((1 + d A ) -1 ·(kr·d A )) mod n, and then transmit the signature result (r, s) to the output check unit for inspection, and output it after the inspection is correct. Where G is a base point of the elliptic curve, n is the order of the base point G, k is a random number generated by a random number generator, k∈[1, n-1], d A is the user's private key, and e is the output value of the cryptographic hash algorithm applied to the message to be signed.

[0113] See also Fig.11 , is a flow chart of the signature verification process provided by the embodiment of the present application. Fig.11 As shown, first the ECC engine calculates the input digital signature (r ′ ,s ′ )Calculation parameter t=(r ′ +s ′ ) and put it into the input check unit to determine whether it is legal. If it is illegal, that is, parameter t = 0, it will directly output that the signature verification fails. If the input is legal, the dot multiplication operation [s ′ ]G, after the calculation is completed, save the result and perform [t]P A Dot multiplication operation. Perform dot addition operation on the above two dot multiplication results (x1′, y1′) = [s′]G + [t]P A Then calculate the parameter R = (e' + x1) mod n, and send the result to the output check unit for checking to verify that R = r ′If it is true, the verification is successful, otherwise the verification fails. Where G is a base point of the elliptic curve, n is the order of the base point G, P A is the user's public key, e ′ It is the output value of the cryptographic hash algorithm applied to the message to be verified.

[0114] The above-mentioned acceleration method provided in the embodiment of the present application realizes multi-level scheduling by combining pipeline and finite state machine. The point value data can save a large number of modular inverse operations by performing operations under Jacobian coordinates, which greatly improves the processing efficiency, realizes the acceleration of the national secret SM2 algorithm, greatly improves the algorithm performance, and can be suitable for high-throughput and high-performance application scenarios.

[0115] The technical solution provided in the embodiment of the present application can well handle branch judgment, state transfer and other non-sequential execution operations in the algorithm implementation process in the form of a state machine implementation. With the processor design idea, the control logic can be simplified and the operator pipeline characteristics can be effectively utilized. The SM2 algorithm is accelerated from multiple aspects such as overall architecture, data scheduling, operation scheduling, and underlying operator optimization, which can be upgraded from the ms level to the us level, greatly improving the algorithm efficiency and algorithm performance, and improving the application capabilities in high-throughput and high-performance application scenarios such as blockchain. It also has a certain degree of flexibility and can customize operators for operation, which helps the rapid development and wide application of domestic cryptographic technology.

[0116] Fig.12 The hardware structure diagram of an electronic device for implementing various embodiments of the present invention is shown below. The electronic device 1200 includes but is not limited to: a radio frequency unit 1201, a network module 1202, an audio output unit 1203, an input unit 1204, a sensor 1205, a display unit 1206, a user input unit 1207, an interface unit 1208, a memory 1209, a processor 1210, and a power supply 1211. Those skilled in the art will appreciate that Fig.12 The electronic device structure shown in the figure does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. In the embodiment of the present application, the electronic device includes but is not limited to a mobile phone, a tablet computer, a laptop computer, a PDA, a vehicle-mounted terminal, a wearable device, and a pedometer. Among them, the above-mentioned electronic device also includes a hardware accelerator supporting the national secret SM2 algorithm as described above.

[0117] It should be understood that in the embodiment of the present application, the radio frequency unit 1201 can be used for receiving and sending signals during information transmission or calls. Specifically, after receiving downlink data from the base station, it is sent to the processor 1210 for processing; in addition, the uplink data is sent to the base station. Generally, the radio frequency unit 1201 includes but is not limited to an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier, a duplexer, etc. In addition, the radio frequency unit 1201 can also communicate with the network and other electronic devices through a wireless communication system.

[0118] The electronic device provides users with wireless broadband Internet access through the network module 1202, such as helping users to send and receive emails, browse web pages, and access streaming media.

[0119] The audio output unit 1203 can convert the audio data received by the RF unit 1201 or the network module 1202 or stored in the memory 1209 into an audio signal and output it as sound. Moreover, the audio output unit 1203 can also provide audio output related to a specific function performed by the electronic device 1200 (for example, a call signal reception sound, a message reception sound, etc.). The audio output unit 1203 includes a speaker, a buzzer, a receiver, etc.

[0120] The input unit 1204 is used to receive audio or video signals. The input unit 1204 may include a graphics processor (GPU) 12041 and a microphone 12042. The graphics processor 12041 processes the image data of a static picture or video obtained by an image capture device (such as a camera) in a video capture mode or an image capture mode. The processed image frame can be displayed on the display unit 1206. The image frame processed by the graphics processor 12041 can be stored in the memory 1209 (or other storage medium) or sent via the radio frequency unit 1201 or the network module 1202. The microphone 12042 can receive sound and can process such sound into audio data. The processed audio data can be converted into a format output that can be sent to a mobile communication base station via the radio frequency unit 1201 in the case of a telephone call mode.

[0121] The electronic device 1200 also includes at least one sensor 1205, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor includes an ambient light sensor and a proximity sensor, wherein the ambient light sensor can adjust the brightness of the display panel 12061 according to the brightness of the ambient light, and the proximity sensor can turn off the display panel 12061 and / or the backlight when the electronic device 1200 is moved to the ear. As a type of motion sensor, the accelerometer sensor can detect the magnitude of acceleration in each direction (generally three axes), and can detect the magnitude and direction of gravity when stationary, which can be used to identify the posture of the electronic device (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, tapping), etc.; the sensor 1205 can also include a fingerprint sensor, a pressure sensor, an iris sensor, a molecular sensor, a gyroscope, a barometer, a hygrometer, a thermometer, an infrared sensor, etc., which will not be repeated here.

[0122] The display unit 1206 is used to display information input by the user or information provided to the user. The display unit 1206 may include a display panel 12061, which may be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), or the like.

[0123] The user input unit 1207 can be used to receive input digital or character information, and to generate key signal input related to user settings and function control of the electronic device. Specifically, the user input unit 1207 includes a touch panel 12071 and other input devices 12072. The touch panel 12071, also known as a touch screen, can collect user touch operations on or near it (such as operations performed by users using fingers, styluses, or any other suitable objects or accessories on or near the touch panel 12071). The touch panel 12071 may include a touch detection device and a touch controller. Among them, the touch detection device detects the user's touch orientation, detects the signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts it into contact point coordinates, and then sends it to the processor 1210, receives the command sent by the processor 1210 and executes it. In addition, the touch panel 12071 can be implemented in various types such as resistive, capacitive, infrared, and surface acoustic waves. In addition to the touch panel 12071, the user input unit 1207 may also include other input devices 12072. Specifically, other input devices 12072 may include but are not limited to physical keyboards, function keys (such as volume control keys, switch keys, etc.), trackballs, mice, and joysticks, which will not be repeated here.

[0124] Furthermore, the touch panel 12071 may be overlaid on the display panel 12061. When the touch panel 12071 detects a touch operation on or near it, it is transmitted to the processor 1210 to determine the type of touch event. Then, the processor 1210 provides corresponding visual output on the display panel 12061 according to the type of touch event. Fig.12 In the figure, the touch panel 12071 and the display panel 12061 are two independent components to realize the input and output functions of the electronic device. However, in some embodiments, the touch panel 12071 and the display panel 12061 can be integrated to realize the input and output functions of the electronic device, which is not limited here.

[0125] The interface unit 1208 is an interface for connecting an external device to the electronic device 1200. For example, the external device may include a wired or wireless headset port, an external power supply (or battery charger) port, a wired or wireless data port, a memory card port, a port for connecting a device with an identification module, an audio input / output (I / O) port, a video I / O port, a headphone port, etc. The interface unit 1208 may be used to receive input (e.g., data information, power, etc.) from an external device and transmit the received input to one or more elements within the electronic device 1200 or may be used to transmit data between the electronic device 1200 and an external device.

[0126] The memory 1209 can be used to store software programs and various data. The memory 1209 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, etc.), etc. In addition, the memory 1209 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.

[0127] The processor 1210 is the control center of the electronic device. It uses various interfaces and lines to connect various parts of the entire electronic device. By running or executing software programs and / or modules stored in the memory 1209 and calling data stored in the memory 1209, it performs various functions of the electronic device and processes data, thereby monitoring the electronic device as a whole. The processor 1210 may include one or more processing units; preferably, the processor 1210 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 1210.

[0128] The electronic device 1200 may also include a power supply 1211 (such as a battery) for supplying power to each component. Preferably, the power supply 1211 may be logically connected to the processor 1210 via a power management system, thereby implementing functions such as managing charging, discharging, and power consumption management through the power management system.

[0129] Preferably, an embodiment of the present application also provides an electronic device, including a processor 1210, a memory 1209, and a computer program stored in the memory 1209 and executable on the processor 1210. When the computer program is executed by the processor 1210, the various processes of the above-mentioned method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be described here.

[0130] An embodiment of the present application also provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the various processes of the above-mentioned method embodiment are implemented and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0131] The embodiment of the present application also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, each process of the above method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it is not repeated here. The computer-readable storage medium is, for example, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0132] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0133] The present invention is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0134] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0135] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0136] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0137] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0138] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, modules of programs or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. According to the definition in this article, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.

[0139] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity 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, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0140] The above description is only an embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent substitution, improvement, etc. made within the spirit and principle of the present invention should be included in the scope of the claims of the present invention.

Claims

1. A hardware accelerator supporting the national secret SM2 algorithm, characterized in that: include: Control module, ECC engine, hash module and coordinate conversion module; The control module is used to receive input data through the interface, perform conversion from affine coordinates to Jacobian coordinates on the input data and point value data in the elliptic curve parameters, and send the input data and scalar data in the elliptic curve parameters and the converted point value data of the Jacobian coordinates to the ECC engine; The ECC engine is used to receive the scalar data and the point value data of the Jacobian coordinates sent by the control module, and perform modular operations in a pipeline manner and point operations of elliptic curves in a finite state machine manner according to the scalar data and the point value data of the Jacobian coordinates; The hash module is used to perform hash function operations in the encryption and decryption process of the national secret SM2 algorithm according to the point operation results of the ECC engine; The coordinate conversion module is used to perform conversion from Jacobian coordinates to affine coordinates on the point operation result of the ECC engine; The control module is also used to control at least one operation result of the modulus operation, the point operation and the hash function operation to be sent as output data through the interface; Wherein, the ECC engine includes: The FSM top-level control unit is used to receive the scalar data and the point value data of the Jacobian coordinates sent by the control module, send a notification to the corresponding sub-state machine according to the current operation type, and receive the feedback signal sent by the sub-state machine and transmit it to the control module; A sub-state machine, configured to receive a notification sent by the FSM top-level control unit and issue a redirection instruction, and send a feedback signal to the FSM top-level control unit after the current operation is completed; The address fetching unit is used to read instructions in address order, and redirect to the corresponding address reading instruction when receiving the redirection instruction issued by the sub-state machine; An instruction memory, used for storing instructions read by the addressing unit; A decoding unit, used for parsing the instructions in the instruction memory; A register stack, used to cache the elliptic curve parameters used by the national secret SM2 algorithm and the point value data of the Jacobian coordinates sent by the control module, as well as the intermediate data generated during the cache calculation process; A finite field computing unit, configured to perform modular operations in a pipeline manner and point operations of elliptic curves in a finite state machine manner based on the scalar data and the point value data of Jacobian coordinates according to the current operation determined by the decoding unit; A write-back control unit is used to generate a write enable signal according to an execution cycle of the algorithm, and control whether to write the calculation result of the finite field calculation unit into the register file based on the write enable signal.

2. The hardware accelerator according to claim 1, characterized in that: The FSM top-level control unit is specifically used for: Determine whether the current operation type is an application layer operation, a dot multiplication operation, or a custom operation, send a notification to the corresponding sub-state machine according to the current operation type, and receive a feedback signal sent by the sub-state machine and transmit it to the control module; The application layer operation includes at least one of encryption, decryption, signing and signature verification, and the custom operation includes at least one of point addition, point doubling, modular addition, modular subtraction, modular multiplication and modular inverse.

3. The hardware accelerator according to claim 1, characterized in that: The ECC engine also includes: A branch control unit, used to check the input data or the calculation result of the finite field calculation unit, and determine whether to issue a redirection instruction according to the check result and the branch jump type determined by the decoding unit; The address fetching unit is further used to redirect to a corresponding address reading instruction according to a redirection indication issued by the branch control unit.

4. The hardware accelerator according to claim 1, characterized in that: The write-back control unit is specifically used to generate a write enable signal according to an execution cycle of a unit operation, and control whether to write a calculation result of the finite field calculation unit into the register stack based on the write enable signal, wherein the unit operation is a modular addition, modular subtraction or modular multiplication operation.

5. The hardware accelerator according to claim 1, characterized in that: The finite field computing unit comprises: a modular addition unit, a modular subtraction unit and a modular multiplication unit. The modular operation is performed by the modular addition unit, the modular subtraction unit and the modular multiplication unit. The point operation is performed by multiple iterations of the modular addition unit, the modular subtraction unit and the modular multiplication unit.

6. The hardware accelerator according to claim 5, characterized in that: The modular multiplication unit comprises: A multiplier is used for, if the current operation is a modular multiplication operation of a specified bit width, splitting the input data of the Jacobian coordinates of two specified bit widths according to the principle that the number of high-order bits and low-order bits are equal, one of the input data is split to obtain the first high-order data A1 and the first low-order data A0, and the other input data is split to obtain the second high-order data B1 and the second low-order data B0; performing a multiplication operation on the first low-order data A0 and the second low-order data B0 to obtain a first product T0, performing a multiplication operation on the first low-order data A0 and the second high-order data B1 to obtain a second product T1, performing a multiplication operation on the first high-order data A1 and the second low-order data B0 to obtain a third product T2, and performing a multiplication operation on the first high-order data A1 and the second high-order data B1 to obtain a fourth product T3; performing a multiplication operation on the first product T0 and the fourth product T3 according to The high and low bits are equal in number, and the low bits of the first product T0 are split as the low bits of the multiplication result of the two input data; the high bits of the first product T0 are spliced ​​with the low bits of the fourth product T3, and then the CSA addition operation is performed with the second product T1 and the third product T2, and the sum result of the CSA addition operation and the carry result are added to obtain the result and the overflow bit, and the result of the addition operation is used as the middle bit of the multiplication result of the two input data; the highest bit of the carry result of the CSA addition operation is added to the high bit of the fourth product T3 to obtain the first candidate value R1, the first candidate value R1 is added to 1 to obtain the second candidate value R2, and the first candidate value R1 or the second candidate value R2 is selected as the high bit of the multiplication result of the two input data according to the overflow bit; The modulus unit is used to concatenate the high bit, the middle bit and the low bit of the multiplication result of two input data, and then perform a modulus operation to obtain a modular multiplication result output, wherein the modulus of the modulus operation is the modulus of the elliptic curve.

7. The hardware accelerator according to claim 1, characterized in that: The register file comprises: The main calculation storage area is used to cache the elliptic curve parameters used by the national secret SM2 algorithm and the point value data of the Jacobian coordinates sent by the control module, as well as to cache the intermediate data generated during the main calculation process; The pre-calculated storage area is used to cache the pre-calculated multiple point results in the dot multiplication operation.

8. The hardware accelerator according to claim 1, characterized in that: The hash module includes: An algorithm unit, for performing operations of the SM3 algorithm and the key derivation function algorithm in the encryption and decryption process of the national secret SM2 algorithm according to the point operation result of the ECC engine; The first-in first-out FIFO is used to perform cross-clock domain data transmission and store encrypted data and decrypted data based on the clock frequency difference between the ECC engine and the algorithm unit.

9. An acceleration method, characterized in that: A hardware accelerator supporting the national secret SM2 algorithm as described in any one of claims 1 to 8, comprising: Receive input data; Perform affine coordinate to Jacobian coordinate conversion on the point value data in the input data and elliptic curve parameters; According to the scalar data in the input data and the elliptic curve parameters and the point value data of the Jacobian coordinates, the modular operation is performed in a pipeline manner and the point operation of the elliptic curve is performed in a finite state machine manner; According to the point operation results, the hash function operation is performed during the encryption and decryption process of the national secret SM2 algorithm; Control to send at least one operation result of the modular operation, the point operation and the hash function operation as output data through the interface.