Configurable HMAC message authentication code circuit and method
By designing a configurable HMAC message authentication code circuit, flexible configuration and resource reuse of various hash functions are realized, solving the problems of system complexity and high cost in existing technologies, and improving the security and flexibility of the system.
Patent Information
- Application Number
- CN202411250825.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-06
- Publication Date
- 2024-11-05
- Estimated Expiration
- 2044-09-06
AI Technical Summary
In existing HMAC hardware designs, the independent modules of multiple hash functions increase system complexity and cost, making it difficult to flexibly respond to different security threats and attack scenarios.
A configurable HMAC message authentication code circuit was designed, which includes a data flow control unit, an SM3-SHA256 hash function unit, and a SHA3-512 hash function unit. Through mode selection circuit and state machine control, flexible configuration and resource reuse of multiple hash functions can be realized.
It simplifies the design of control and computing units, supports the characteristics of multiple hash functions, improves the security and flexibility of the system, adapts to different encryption needs, and reduces system resource consumption.
Smart Images

Figure CN118900171A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of encryption chips, and in particular to a configurable HMAC message authentication code circuit and method. Background Art
[0002] In order to ensure network security, cryptography is widely used and has become an important support and tool for building a secure and reliable network environment. Cryptography is a discipline that studies encryption and decryption algorithms, involving encryption technology, identity authentication, digital signatures, message authentication and other technologies. It is committed to protecting information security during communication and preventing information from being accessed, tampered with or stolen by unauthorized individuals or entities. In the digital information age, the impact of cryptography cannot be ignored. It provides key security for emerging technologies such as the Internet, the Internet of Things and big data.
[0003] The threats that messages may encounter during information transmission can be divided into active attacks and passive attacks. Active attacks include tampering, replay, forgery, etc., while passive attacks are in the form of eavesdropping and surveillance. In order to effectively deal with these attacks and ensure the security and integrity of communications, encryption and authentication technologies can be used. Encryption technology can convert sensitive information into unreadable ciphertext, and only authorized recipients can decrypt and obtain the original information. Authentication technology mainly includes digital signatures, identity authentication, and message authentication. Among them, message authentication is a technology that ensures the integrity and authenticity of messages by attaching authentication tags (such as message authentication codes MAC) to messages. Message authentication technology can confirm whether the message received is the original intention of the sender, which helps prevent unauthorized modification and forgery, and ensures the privacy and integrity of the message. Message authentication code is a technology that confirms integrity and performs authentication. It is a specific implementation method of message authentication and is widely used in communication protocols such as IPsec and SSL / TLS. In the field of information technology, message authentication codes can further improve the security and reliability of network communications. Message authentication codes are mainly implemented using one-way hash functions (also called hash functions, hash functions, hash functions), block ciphers, stream ciphers, public key ciphers, and other methods. In order to adapt to the high-speed transmission of network information, message authentication codes with fast calculation speed and resistance to common attacks are required. Message authentication algorithms composed of hash functions can meet the above requirements.
[0004] HMAC is a shared key encryption algorithm that uses the underlying hash function to verify data integrity and authenticity. It has been widely used in network security. HMAC uses the key and plaintext to generate a message authentication code through multiple rounds of hash functions. The hash function used by HMAC is not limited to a specific one. Any high-strength hash function can be used for it, and its strength is based on the strength of the underlying hash function. Commonly used hash functions for HMAC include MD5, SHA-1, SHA-2, SHA-3, etc. In response to the growing demand for hash functions, my country has independently developed the SM3 algorithm, which can be used in the construction of HMAC, random sequences, etc.
[0005] In practical applications, multiple different HMACs may be required. For example, in the SSL / TLS communication protocol, the client and server will use different HMACs, and other hash functions may be used to implement pseudo-random numbers. Although various HMACs can be used flexibly, equipping each algorithm with an independent module on the same core will increase the complexity and cost of the system. A feasible solution is to use a reconfigurable unit with multiple functions. The reconfigurable unit allows different hash functions and HMAC algorithms to be selected according to specific security requirements, thereby achieving flexible customization and configuration. By integrating multiple security functions into one unit, system resources are saved and the cost of hardware implementation is reduced. The flexibility and customization of the reconfigurable unit can also help the system select appropriate security strategies and algorithms for different security threats and attack scenarios, thereby improving the security of the system. In previous studies on HMAC hardware design, most of them only implemented the HMAC algorithm corresponding to one hash function. This paper studies the reconfigurable unit based on SM3, SHA-256, SHA3-512 and HAMC algorithms. Summary of the invention
[0006] The present invention provides a configurable HMAC message authentication code circuit and method, which can at least solve one of the technical problems in the background technology.
[0007] To achieve the above object, the present invention adopts the following technical solutions:
[0008] A configurable HMAC message authentication code circuit includes a data flow control unit, an SM3-SHA256 hash function unit, and a SHA3-512 hash function unit;
[0009] The internal modules of the HMAC message authentication code circuit are all controlled by the clock signal input and output terminal clk and the reset signal input terminal rst_n;
[0010] The mode signal selection circuit of the HMAC message authentication code circuit controls the enable signals of the SHA3-512 hash function unit and the SM3-SHA256 hash function unit through an XOR gate and an AND gate; the enable signal of the SM3-SHA256 hash function unit and mode[0] are used as the selection signal of the SM3-SHA256 module through an AND gate;
[0011] The data flow control unit includes five input terminals, namely, an HMAC enable signal terminal hmac_en, an input valid signal terminal date_en, a plaintext or key terminal data_in, a last byte input signal terminal msg_is_last_word, and a last byte byte number terminal byte_num, wherein the enable signal terminal hmac_en controls whether the remaining four ports are used as direct data input terminals of the SM3-SHA256 hash function unit and the SHA3-512 hash function unit;
[0012] The data flow control unit includes seven output terminals, wherein the output valid signal terminal hmac_vld and the data output signal terminal msg_hmac are both connected to the output terminals of the SHA3-512 hash function unit and the SM3-SHA256 hash function unit, and the output terminal need_data is used to output a data request signal;
[0013] The other four output terminals of the data flow control unit are the data state input terminal in_vld, the input data input terminal data, the byte number input terminal byte_numb and the last byte input terminal last_word, which are connected to the corresponding input terminals of the data flow control unit through a selector, and the control terminal of the selector is connected to the HMAC enable signal input terminal;
[0014] The data output end out and the out_ready signal output end of the SM3-SHA256 hash function unit and the SHA3-512 hash function unit are respectively connected to a selector at the same time, and the output is controlled by the input mode signal end. The output end of the selector is connected to the output end corresponding to the data flow control unit through the selector, and the final data of the HMAC circuit is output through the selector.
[0015] Furthermore, the SHA3-512 hash function unit in the HMAC message authentication code circuit of the present invention includes a padding module and a replacement module;
[0016] The filling module comprises three output terminals, namely a data output terminal, a last message block indication signal output terminal last_block and an output valid signal output terminal pout_r, wherein the last message block indication signal output terminal and the output valid signal output terminal are connected to the input terminal of the replacement module, and the data output terminal is connected to the little-end conversion module recode1;
[0017] The replacement module comprises six input terminals, three of which are respectively a data input terminal in, a last message block indication signal input terminal last_block and an input valid signal input terminal in_ready, the data input terminal is connected to the output terminal of the little end conversion module recode1, and the last message block indication signal input terminal and the input valid signal input terminal are connected to the corresponding output terminals of the filling module;
[0018] The replacement module comprises three output terminals, namely a data output terminal out, an output valid signal output terminal out_ready and an ack signal output terminal, wherein the data output terminal is connected to the input terminal of the little-end conversion module recode2, and the ack signal output terminal is connected to the input terminal of the filling module.
[0019] Furthermore, the permutation module in the SHA3-512 hash function unit in the HMAC message authentication code circuit of the present invention includes a round function module, the round function module selects an internal pipeline structure, and performs a two-level expansion processing round operation, the first-level round function processes the even-numbered rounds, and the second-level round function processes the odd-numbered rounds.
[0020] Furthermore, in the HMAC message authentication code circuit SHA3-512 hash function unit of the present invention, the even-numbered rounds of the pipeline structure insert the pipeline register between the θ2 logic circuit and the θ3 logic circuit, and the odd-numbered rounds insert the pipeline register between the θ logic circuit and the ρ logic circuit;
[0021] Among them, in the round function module, the even-numbered rounds use the initial data or the feedback of the previous round as input. The former passes through a selector, and the latter passes through two selectors before starting the replacement. The odd-numbered rounds only need to receive the data processed by the previous level without passing through the selector.
[0022] Furthermore, the SM3-SHA256 hash function unit in the HMAC message authentication code circuit of the present invention includes a message filling module, a message expansion module and an iterative compression module;
[0023] The message filling module comprises two output terminals, namely a data output terminal P_out and an output valid signal terminal Pout_ready, and is connected to the input terminal of the message expansion module;
[0024] The message expansion module comprises four output terminals, namely a wj0 data output terminal, a wj1 data output terminal, an out_vld signal output terminal and a ready signal output terminal, wherein the wj0 data output terminal, the wj1 data output terminal and the out_vld signal output terminal are connected to the input terminal of the iterative compression module, and the ready signal output terminal is connected to the output terminal of the message filling module;
[0025] The iterative compression module comprises two output terminals, namely a data output terminal out and an output valid signal terminal out_ready, which serve as output terminals of the SM3-SHA256 hash function unit.
[0026] Furthermore, the HMAC message authentication code circuit of the present invention is characterized in that the iterative compression module of the SM3-SHA256 hash function unit implements the A register and E register update circuits of the compression functions in the SM3 algorithm and the SHA-256 algorithm using a multiplexing structure, and further multiplexes the 8×32-bit registers A to H required by the SM3 algorithm and the SHA-256 algorithm.
[0027] In yet another aspect, a configurable HMAC message authentication method comprises the following steps;
[0028] S1. In the entire HMAC process, the key is padded to meet the length requirement before participating in encryption. There are two padding methods depending on the initial key length;
[0029] S2. The padded key is first XORed with an ipad sequence of equal length to obtain a bit sequence ipadkey related to the key; the length of the bit sequence ipadkey is the same as the message block length of the hash function used;
[0030] S3, after obtaining the bit sequence ipadkey, the bit sequence ipadkey is combined with the message, that is, the message is concatenated after the bit sequence ipadkey to obtain the bit sequence ipadkey||m;
[0031] S4, sending the spliced data to the SM3-SHA256 hash function unit or the SHA3-512 hash function unit for processing;
[0032] S5, firstly perform an XOR operation on the padded key and an opad sequence of equal length to obtain a bit sequence opadkey;
[0033] S6, after obtaining the bit sequence opadkey, concatenate the hash value obtained in the S4 process to the end of the bit sequence opadkey;
[0034] S7. Finally, the data obtained in S6 is sent to the SM3-SHA256 hash function unit or the SHA3-512 hash function unit for processing again. The resulting hash value is the final message authentication code value.
[0035] Furthermore, the HMAC message authentication method of the present invention has two filling modes:
[0036] One is that when the key length is greater than the length of the hash function message block, the data_en signal output is "2", and the key is first processed by the hash function, which delays the need_data signal frequency. The processed key length will be less than the message block length, so "0" is padded at the end to make it the same length as the hash function message block length;
[0037] Secondly, when the length of the key is less than the length of the hash function message block, the data_en signal output is "1" and "0" is directly filled at the end to make its length the same as the length of the hash function message block.
[0038] In summary, in the padding, message expansion and iterative compression modules, resource reuse is adopted and the multi-operand addition part is optimized, so that one block can realize two hash functions, SM3 and SHA-256; the round processing function module of the SHA3-512 hash function is designed by expansion and pipeline cutting, and the storage of round constants is optimized; the HMAC function module is designed using a state machine, and each part of the design adopts a hierarchical design, which is relatively independent of each other. It has a certain flexibility in realizing functions, and can realize the operation of SM3, SHA-256 and SHA3-512 hash functions, as well as the operation of HMAC-SM3, HMAC-SHA256, HMAC-SHA3-512 message authentication codes.
[0039] The present invention makes full use of the data path of the HMAC encryption algorithm hardware implementation, adopts the state machine control part to control the SHA3-512 hash function unit and the SM3-SHA256 hash function unit, and controls the input and output of the hash function in each state, encrypts the plain text information input externally at the rising edge of the clock signal, and then outputs the cipher text, and the encryption method of the plain text generates a control logic according to an enable signal and a mode signal, and performs round operations under a corresponding configuration mode, which greatly simplifies the design of the control and operation unit, has a simple structure, supports the characteristics of multiple hash functions, implements the encryption configuration parameters defined by the hash encryption algorithm in a single circuit, improves the flexibility of the hash encryption algorithm in the information security application of the Internet of Things, thereby realizing different encryption performances required in different encryption demand scenarios, and has multiple configuration modes, which is conducive to its wide use in Internet of Things scenarios.
[0040] Beneficial effects:
[0041] 1. Analyze the structures of two hash functions, SM3 and SHA-256. Resource reuse is adopted in the padding, message expansion and iterative compression modules, so that one module can implement two hash functions, SM3 and SHA-256, saving resource occupation. At the same time, the addition circuit is optimized in the message expansion module and iterative compression module to reduce the complexity of calculation.
[0042] 2. The round processing function module of the SHA3-512 hash function is expanded and pipelined to reduce the round cycle count, shorten the critical path, improve the frequency and throughput, optimize the storage of round constants, and reduce resource usage.
[0043] 3. The HMAC module uses a state machine design to complete the call of three hash functions. The various modules of the design adopt a hierarchical design and are relatively independent of each other. It has a certain flexibility in implementing functions and can realize the operation of SM3, SHA-256 and SHA3-512 hash functions, as well as the operation of HMACSM3, HMAC-SHA256, and HMAC-SHA3-512 message authentication codes. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 It is an overall structural block diagram of the HMAC message authentication circuit of the present invention;
[0045] Figure 2 This is a schematic diagram of the overall structure of the SM3-SHA256 module of the present invention;
[0046] Figure 3 Schematic diagram of a filling module in the SM3-SHA256 module of the present invention;
[0047] Figure 4 It is the filling rule of the prior art SM3;
[0048] Figure 5 This is a schematic diagram of a message expansion module in the SM3-SHA256 module of the present invention;
[0049] Figure 6 It is a schematic diagram of the CSA tree structure in the prior art;
[0050] Figure 7 It is a schematic diagram of a message word shift register of the present invention;
[0051] Figure 8 It is a schematic diagram of the iterative compression module in the SM3-SHA256 module of the present invention;
[0052] Fig. 9A and E register update logic circuit of the present invention;
[0053] Fig.10 This is a schematic diagram of the overall structure of the SHA3-512 module of the present invention;
[0054] Fig.11 This is a schematic diagram of the prior art SHA-3 filling rules;
[0055] Fig.12 Filling rules for the existing SHA-3 standard;
[0056] Fig.13 Schematic diagram of a padding module in the SHA3-512 module of the present invention;
[0057] Fig.14 It is a schematic diagram of the internal state of the permutation function Keccak-f;
[0058] Fig.15 It is a schematic diagram of the permutation function Keccak-f step θ;
[0059] Fig.16 Schematic diagram of the permutation function Keccak-f step ρ;
[0060] Fig.17 It is a schematic diagram of the permutation function Keccak-f step π;
[0061] Fig.18 Schematic diagram of step χ of permutation function Keccak-f;
[0062] Fig.19 Schematic diagram of the replacement module in the SHA3-512 module of the present invention;
[0063] Fig. 20 This is a diagram of the round function structure in the permutation module in the SHA3-512 module of the present invention;
[0064] Fig.21 Four internal pipeline schemes pre-selected for the present invention;
[0065] Fig. 22 This is the HMAC message authentication flow chart;
[0066] Fig.23 It is the simulation result of hash function;
[0067] Fig.24 The simulation result is that the key length is smaller than the message block length;
[0068] Fig.25 The simulation result is that the key length is greater than the message block length. DETAILED DESCRIPTION
[0069] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, 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.
[0070] The configurable HMAC message authentication code circuit of this embodiment includes a data flow control unit, an SM3-SHA256 hash function unit, and a SHA3-512 hash function unit; the data flow control unit is specifically a state machine FSM, the state machine FSM includes three output terminals, two of which output a valid signal msg_hmac_vld and a data output signal msg_hmac respectively, and are both connected to the output terminals of the SHA3-512 part and the SM3-SHA256 part through a selector, and another output terminal need_data of the data flow control unit is used to output a data request signal: the four input terminals are respectively a data state input terminal, an input data input terminal, a byte number input terminal, and a last byte input terminal, which are all connected to in_vld, data, byte_numb, and last_word corresponding to the state machine part through a selector, and the control terminal of the selector is connected to the HMAC enable signal input terminal;
[0071] The output end of the selector is connected to four input ends of the SHA3-512 hash function unit and the SM3-SHA256 hash function unit;
[0072] The data output end out and the valid signal output end out_ready of the SHA3-512 hash function unit and the SM3-SHA256 part are respectively connected to the same selector at the same time, and the output is controlled by the input signal mode. The output end of the selector is connected to the output end corresponding to the data flow control unit through the selector, and the final data of the HMAC circuit is output through the selector.
[0073] The mode signal selection circuit controls the enable signals of SHA3-512 and SM3-SHA256 through an XOR gate and an AND gate. The enable signal of SM3-SHA256 and mode[0] are used as the selection signal of SM3-SHA256 module through an AND gate;
[0074] The SM3-SHA256 hash function unit includes a message filling module, a message expansion module and an iterative compression module:
[0075] The message filling module comprises two output terminals, namely a data output terminal P_out and an output valid signal terminal Pout_ready, and is connected to the input terminal of the message expansion module;
[0076] The message expansion module comprises four output terminals, namely a wj0 data output terminal, a wj1 data output terminal, an out_vld signal output terminal and a ready signal output terminal, wherein the wj0 data output terminal, the wj1 data output terminal and the out_vld signal output terminal are connected to the input terminal of the iterative compression module, and the ready signal output terminal is connected to the output terminal of the message filling module;
[0077] The iterative compression module includes two output terminals, namely, a data output terminal out and an output valid signal terminal out_ready, which serve as the output terminals of the SM3-SHA256 hash function unit. The SHA3-512 hash function unit includes a padding module, a permutation module and a round function module;
[0078] The filling module comprises three output terminals, namely a data output terminal, a last message block indication signal output terminal last_block and an output valid signal output terminal pout_r, wherein the last message block indication signal output terminal and the output valid signal output terminal are connected to the input terminal of the replacement module, and the data output terminal is connected to the little-end conversion module recode1;
[0079] The replacement module comprises six input terminals, three of which are respectively a data input terminal in, a last message block indication signal input terminal last_block and an input valid signal input terminal in_ready, the data input terminal is connected to the output terminal of the little end conversion module recode1, and the last message block indication signal input terminal and the input valid signal input terminal are connected to the corresponding output terminals of the filling module;
[0080] The replacement module comprises three output terminals, namely a data output terminal out, an output valid signal output terminal out_ready and an ack signal output terminal, wherein the data output terminal is connected to the input terminal of the little-end conversion module recode2, and the ack signal output terminal is connected to the input terminal of the filling module.
[0081] The following are specific instructions:
[0082] In this embodiment, three hash functions SM3, SHA-256, SHA3-512 circuit implementation methods and three HMAC message authentication codes HMAC-SM3, HMAC-SHA256, HMAC-SHA3-512 circuit implementation methods are taken as examples, and six function parameter configuration modes are shown in Table 1.
[0083] Table 1 Six functional parameter configuration descriptions
[0084]
[0085] Figure 1The present invention is a schematic diagram of a configurable HMAC message authentication code circuit structure of an embodiment of the present invention. The configurable HMAC message authentication code circuit described in this embodiment includes a state machine control part (FSM), a SHA3-512 hash function unit and an SM3-SHA256 hash function unit. In this embodiment, three hash functions SM3, SHA-256, SHA3-512 circuit implementation methods and three HMAC message authentication code HMAC-SM3, HMAC-SHA256, HMAC-SHA3-512 circuit implementation methods are taken as examples.
[0086] Continue reading Figure 1 The configurable external ports of the HMAC message authentication code circuit are shown in Table 2, specifically receiving the external input clock signal clk, reset signal rst_n, HMAC enable signal hmac_en, input valid signal date_en[1:0], plain text or key data_in[31:0], last byte input signal msg_is_last_word, last byte number byte_num[1:0], mode selection signal mode[1:0], data request signal need_data, output valid signal msg_hmac_vld, output hash value or message authentication code msg_hmac[511:0].
[0087] Table 2 Description of HMAC input and output interfaces
[0088]
[0089] For details, please refer to Figure 1, the input hamc_en signal driven by the clock signal clk controls the enable of the data flow control unit state machine. The hamc_en signal is pulled high, and the two data bits of the input mode signal mode[1:0] pass through an XOR gate and an AND gate to control the enable signals of SHA3-512 and SM3-SHA256 respectively. The enable signal of SM3-SHA256 and mode[0] pass through an AND gate as the selection signal of the SM3-SHA256 module, which plays the role of selecting the hash function to be used currently; when performing the HMAC message authentication code function with a key less than 256 bits, when the input data_en[1:0] is 2'b01, data_in[31:0] inputs the key and stores the key in the key register. At the end of the key transmission, the 32-bit data in the key register is taken out in each cycle, XORed with 32'h36363636 and assigned to data[31:0], and the in_vld signal is pulled high at the same time. The key processing process is counted by the counter. When processing the data in the last 32 bits of the key register, the request data signal need_data is pulled high. When the input data_en[1:0] is 2'b11, in_vld is pulled high. The input plaintext data_in[31:0] is assigned to data[31:0], the input msg_is_last_word is assigned to last_word, and the input byte_num[1:0] is assigned to byte_numb[1:0]. The hash value output after the hash function is processed is stored in the hash value register hash_value[511:0]. The 32-bit data in the key register is taken out in sequence again, and the XOR with 32'h5c5c5c5c is assigned to data[31:0], and the in_vld signal is pulled high at the same time. The key processing process is counted by the counter. After the processing is completed, the data in the hash value register is shifted and transferred to data[31:0] and in_vld is pulled high. The counter is used again to count the data transmission process. When the last 32 bits of data are input, last_word is pulled high and byte_num[1:0] is assigned 2'b11. The hash value obtained after processing is stored in the hash value register hash_value[511:0], and hmac_vld is pulled high. The selector selects the output.
[0090] Specifically, the HMAC function module receives the external input clock signal clk, reset signal rst_n, HMAC enable signal hmac_en, data status signal data_en, input data data_in, byte number btye_num, last byte msg_is_last_word, mode selection signal mode, and uses the internal state machine control part FSM and selection signal mode to control the hash algorithm part. Under the triggering of the HMAC enable signal hmac_en, the control state machine is enabled at a high level, indicating that the HMAC function is executed at this time, and the mode signal is used to select whether to execute HMAC-SM3, HMAC-SHA256 or HMAC-SHA3-512. When hmac_en is at a low level, it means that the hash function function is executed by default at this time, and the mode signal is used to select whether to execute SM3, SHA-256 or SHA3-512.
[0091] The design of the SM3_SHA256 module also requires a mode selection signal mode, and the mode selection signal bit width is 1. When using the HMAC mode signal to select and enable, the two bits of the mode signal are XORed and ANDed to obtain the SM3_SHA256 and SHA3-512 module enable signals, and then ANDed with the low bit of mode to obtain the mode selection signal of the SM3_SHA256 module.
[0092] In the selection of data input to the hash algorithm module, the hmac_en signal is used to control four selectors to select. When executing the HMAC function, the hash algorithm module inputs the output from the state machine control module, and when executing the hash function function, the input comes from the input of the external port. In the HMAC module, the data input valid signal bit width is 2, but the hash module data input valid signal bit width is 1, and there are only two states that do not involve other situations. When the date_en signal is 2'b11, it is the data input, so the two bits of the date_en signal are ANDed to obtain the hash module data input valid signal. When the data is output, the hmac_en signal is used to select whether to output the value in the hash value register of the FSM module or the value of the hash algorithm module. The enable signal sm3_en of the SM3-SHA256 module is used to select which hash function to output. Since the output bit widths of SM3, SHA256 and SHA3-512 are different, the 256-bit data output by SM3 and SHA-256 are spliced with 256 bits of "0" when making the selection. The output valid signal also uses the hmac_en signal and the sm3_en signal, and the above method is used to select the output.
[0093] like Figure 2The SM3-SHA256 hash function unit shown includes a message filling module, a message expansion module and an iterative compression module;
[0094] Its external ports are specifically the clock signal clk, reset signal rst_n, enable signal sm3_en, data input signal in, data input status cycle signal in_ready, last byte number byte_num[1:0], last byte input signal is_last, mode selection signal mode, data output signal out, and data output status signal out_ready.
[0095] The message filling module is as follows Figure 3 As shown in the figure, the steps of message padding are to first pad a bit "1" at the end of the input data, then pad several bits "0", and finally add a 64-bit message length. The number of padding zeros must meet the message length (M L ), "1", "0", and the message length must be a minimum integer multiple of 512. There are two possible padding situations. The first one is Figure 4 As shown in (a), M L If the value of mod512 is less than 448, fill it normally as above. Figure 4 As shown in (b), M L When mod512 is greater than or equal to 448, the message block cannot continue to fill the 64-bit message length, and another message block needs to be added to fill the message length.
[0096] The specific message filling module enables the filling module when pad_en is pulled high, in_ready is pulled high to indicate that data starts to be input from the in port, and then pad_oready is pulled high to input the data into the data buffer through p_data. The r_ready signal indicates the status of the message expansion module. The high level represents that it is in an idle state. At this time, by pulling up r_vld, the data can be output through the r_data port. When the input is_last signal is high, it means that the current input is the last data. At this time, the input of byte_num is the number of valid data bytes of the current input. The last set of data needs to be filled according to the filling rules shown in Table 3 based on the value of byte_num. In addition, if the byte_num input is 2'b11, 32'h800000000000 will be filled in the next cycle. Two counters are also defined in the module to calculate the length of the data and the progress of the filling respectively. The data length counter is input according to the two hash algorithms with a maximum value of 2 64bits, the bit width is defined as 64. A count is added each time data is input. When the last set of data is input, byte_num is converted to the corresponding length value and added to the previous count value to obtain the final data length. Since the message block is 512 bits, 16 iterations are required for 32-bit data input. During the data input process, the progress counter is filled in a loop count. After the last set of data is input, the corresponding number of 32-bit "0" is filled according to the counter. Finally, the data length in the data length counter is filled in two cycles to obtain the filled data.
[0097] Table 3 SM3-SHA256 module filling rules
[0098]
[0099] like Figure 5 The figure shows the message extension module in the SM3-SHA256 hash function unit. The message extension part is to expand the message block after grouping. The message is obfuscated and rearranged in the extension stage, and a richer and more complex message sequence is generated using the information of the original message. In the SM3 algorithm, message extension generates a total of 132 message words, including 68 W message words and 64 W' message words.
[0100] (1) Divide the 512-bit message block into 16 words W0, W1, ...W15 according to 32 bits.
[0101] (2) Use the following formula to further expand the 16 words from W16 to W67, and finally obtain 68 W message words. In the formula, the <<< symbol represents a circular left shift, and the ⊕ symbol represents a 32-bit XOR.
[0102]
[0103] (3) Then use the obtained W message word to continue generating 64 W' message words through the following formula.
[0104]
[0105] The SHA-256 algorithm is different from the SM3 algorithm. Its message extension module only expands the 512-bit message block into 64 32-bit message words during the message extension phase. First, the message block is divided into 16 32-bit words W0, W1, ..., W16. Then, the remaining 48 message words are expanded according to the following formula. In the formula, POTR means circular right shift, SHR means right shift, the superscript n means the number of bits moved, and the ⊕ symbol means 32-bit XOR.
[0106]
[0107] Specifically, Figure 6The figure shows the carry-preserving adder CSA used by the hash algorithm SM3_SHA256 to optimize the addition operation used. The basic idea of CSA is to calculate and save the carry c and the sum bit s separately, and reduce the addition of three operands to the addition of two operands. For example, Result = x1 + x2 + x3, where the carry c = ((x1 & x2) | (x2 & x3) | (x1 & x3)) << 1, and the sum bit S = x1 ⊕ x2 ⊕ x3. When multiple operands are added, the CSA tree structure addition method is used, and the operands are passed through multiple CSAs and then the two operands output at the end are summed.
[0108] Specifically, Figure 7 The data received and updated by the message word shift register used by the hash algorithm SM3_SHA256 is shifted and stored starting from register Wt+15. The green line part in the figure represents the generation process of the SM3 message word, and the red line part represents the generation process of the SHA-256 message word. The mode selection signal mode is used to select whether to expand the SM3 or SHA-256 message word. In the output stage of the message word, SHA-256 only needs to expand W j The message word can be directly output from the Wt+15 register, while W'j only needs to output the calculated data when executing SM3, and outputs "0" when executing SHA-256. j By W j and W j+4 XOR is performed. If the Wt+15 register is still used as W j The output, W' j It will take four cycles to output, which will cause the output of the two groups of message words to be out of sync. To solve the above problem, the Wt+11 register is used as the W in SM3. j The output of the message word is therefore four cycles later than SHA-256 when performing SM3 message extension.
[0109] Specifically, the exp_en signal of the message expansion module in the SM3-SHA256 hash function unit is the enable signal of the message expansion module, and the mode signal is the mode selection signal used to select which hash algorithm to execute. When msg_vld is pulled high, it means that the input data is valid, and 32-bit data is passed into the module from msg_in. ready is connected to the padding module of the previous level. When it is pulled high, it means that the message expansion task is not being executed at this time and data can be received. On the contrary, when it is pulled low, it means that the message expansion task is being executed at this time. When out_vld is pulled high, data is output, and wj0 corresponds to W j , wj1 corresponds to W' j .
[0110] like Figure 8The schematic diagram of the iterative compression module in the SM3-SHA256 hash function unit is shown. Com_en is pulled high to enable the iterative compression module. The initial values of A to H of SM3 or SHA-256 are selected and sent to the A to H registers and the status register through the mode signal. The data valid signal msg_vld is pulled high to start accepting the extended message word. As the wj0 and wj1 inputs are updated, the A to H registers are updated accordingly to compress the message block. A counter is defined inside the iterative compression module to count 64 rounds of compression. When a message block is compressed, the mode signal is used to select whether to perform the XOR iteration of SM3 or the addition iteration of SHA-256. The data completed in this iteration is sent to the status register for storage and used as the initial value for the next iterative calculation. Last_block is pulled high to indicate that this is the last message block input at this time. After compression and iteration are completed, out_ready is pulled high to output the 256-bit hash value out.
[0111] Iterative compression is the key link of SM3 and SHA-256 algorithms. The iteration of the two algorithms is mainly through the update iteration of eight words A, B, C, D, E, F, G, H. The specific formulas of SM3 and SHA-256 compression functions are as follows.
[0112]
[0113]
[0114] From the formulas of SM3 and SHA-256 compression functions, we can see that the main difference between the two algorithms in B, D, F, and H lies in the update of A and E. Now the A and E update circuits of the two algorithms are implemented using a multiplexing structure, and the 8×32-bit registers A to H required by the two algorithms can be further reused. Specifically, Fig. 9 As shown in the figure: In SM3, whether calculating A or E, SS1 must be calculated first, and SS2 is calculated from SS1, and then TT1 and TT2 are calculated respectively. In the SS1 calculation process, the three operands need to be shifted after addition to participate in the subsequent calculation. Therefore, the CSA tree structure is not used in combination with the subsequent addition operation. Instead, a CSA and an adder are used to implement the addition of the three operands in SS1. FF in SM3 and SHA-256 calculation j , GG j , Ch, Maj and CSA pass through the same number of logic gates. When calculating these functions, a CSA is used to simultaneously calculate H, W j and K j The carry and sum bits. Since SM3 does not need to use K j, "0" is input through the selector when executing the SM3 hash algorithm. The remaining addition circuits continue to use the CSA tree structure for optimization, using selectors to select the operands used for SM3 and SHA-256 hash calculations. The critical path of the E register update circuit used passes through three CSAs, two adders, a P0 permutation function, and two selectors, which is significantly shorter than the addition path that passes through five operands. The critical path of the A register update circuit passes through four CSAs, two adders, and two selectors, which is significantly shorter than the addition path that passes through six operands in SHA-256.
[0115] SHA-3 uses a sponge structure. Table 4 shows that SHA3-512 has higher security among the SHA-3 series algorithms.
[0116] Table 4 Size specifications of SHA-3 hash functions
[0117]
[0118] like Fig.10 The SHA3-512 hash function unit includes a padding module and a permutation module;
[0119] Its external ports are specifically the clock signal clk, the reset signal rst_n, the enable signal en, the data input signal in, the data input status cycle signal in_ready, the last byte number byte_num[1:0], the last byte input signal is_last, the data output signal out, and the data output status signal out_ready.
[0120] Among them, the SHA-3 algorithm pads and blocks the message to be processed before the algorithm operation. SHA-3 uses a different padding rule from SM3 and SHA-2. There are two ways to fill the sponge structure, simple padding and multiple bit rate padding. Simple padding only requires filling a bit "1" and several bits "0" at the end of the message so that the length of the filled data is the minimum integer multiple of the packet length. The multiple bit rate filling method first adds a bit "1" to the end of the message, then adds a sufficient number of bits "0", and finally adds a bit "1" at the end again. After the filling is completed, the length of the data must still meet the minimum integer multiple of the packet length. When faced with different input message lengths, the following common padding situations may occur. Such as Fig.11 As shown in (a), when the length of the input message is not equal to an integer multiple of the packet length, it is necessary to fill the end with a bit sequence of "10...01" until the length after filling reaches the requirement of an integer multiple of the packet length. Fig.11As shown in (b), when the length of the input message is an integer multiple of the packet length, a new message block needs to be added and then a bit sequence of "10...01" equal to the packet length needs to be filled at the end. Fig.11 As shown in (c), when the input message length is equal to an integer multiple of the packet length minus one, it is necessary to first fill a bit "1" at the end of the message, and then add a message block to fill the "0...01" sequence until the length meets the requirement.
[0121] The SHA-3 standard FIPS202 released by NIST in 2015 is slightly different from the above padding rules. In order to distinguish different variants of Keccak, the domain specifier "01" is added before padding, such as Fig.12 shown.
[0122] The filling module is a key step before the data enters the replacement. In the implementation of the filling step, a filling method with multiple bit rates is selected to fill the 32-bit input data.
[0123] Specifically, fill the module ports as follows Fig.13 As shown in the figure, in a filling process, pad_en is first pulled high to enable the filling module. When the in_ready signal is pulled high, it indicates that the 32-bit input data is ready, and the filling module starts to receive data and sends the received data to the shift register. The counter is defined to count cyclically when inputting data. Since the message block length is 576, 32 bits of data are input each time, so the maximum count is 18. When the is_last signal is pulled high, it indicates that the data transmission is over. For each variable-length input, according to the given byte number byte_num, different numbers of padding bits are added according to the padding rules shown in Table 5. In addition, if byte_num is 2'b11, 32'h06000000 is filled in the next cycle. Then start filling several 32-bit 0s, and fill 1 at the end of the last 32-bit padding data to complete the filling. Pulling last_block high indicates that it is the last block of data of the message. When the count reaches 18, pout_r is pulled high to indicate that the data is ready and can be output through the p_data port. The replacement function module pulls up c_ack to indicate the removal of the filling data. After the data is taken away, it will pull pout_r low again and clear the counter and shift register.
[0124] Table 5 SHA3-512 module padding rules
[0125]
[0126] The permutation function is a key part of the hash function. The permutation function used in the SHA-3 algorithm can be recorded as Keccak-f or f. According to the corresponding relationship S[64(5y+x)+z]=A[x][y][z], the 1600-bit state is mapped to a 5×5×64 three-dimensional matrix for 24 rounds of operations. The internal state of Keccak is as follows Fig.14 shown.
[0127] Each square in the figure represents a bit. When the dimension is 1, the cylinder in the x-axis direction is called row, the cylinder in the y-axis direction is called column, and the cylinder in the z-axis direction is called lane. When the dimension is 2, the plane parallel to xz is called plane, the plane parallel to xy is called slice, and the plane parallel to yz is called sheet. The round function for 24 rounds of operations in Keccak-f includes five steps, namely θ, ρ, π, χ and ι, where θ can be divided into θ1, θ2 and θ3. Next, the operation of each step is explained. The mathematical formula for the five-step calculation is as follows:
[0128]
[0129] Step θ: Fig.15 As shown in the figure, in the θ step, each column in the state cube is linearly transformed. θ1 is an XOR operation on all data on each column. θ2 is an XOR operation on each column after the θ1 operation and its two adjacent columns. θ3 is an XOR operation on the result of θ2 and itself, and then covers it. The θ step increases the security of the algorithm by increasing the diffusion of the state.
[0130] Step ρ: If Fig.16 The figure shows a schematic diagram of step ρ when the lane length is 8. ρ is an operation on the lane. Different offsets r(x, y) are used to translate according to the difference between x and y to increase the confusion of the state. The corresponding relationship between the offset and x and y is shown in Table 6.
[0131] Table 6 Cyclic shift offset
[0132]
[0133] Step π: If Fig.17 The π shown here reorders the lanes in a fixed order, eliminating horizontal or vertical alignment and increasing the randomness of the state.
[0134] Step χ: Fig.18The χ shown in the figure is the processing of the data in row, which is the only nonlinear transformation in the five steps of the round function. The two adjacent data of each data in row are calculated and then XORed with themselves to obtain the final result, which increases the nonlinearity of the algorithm.
[0135] Step ι: ι uses a set of fixed round constants (Round Constant, RC) to perform XOR with lanes x=0, y=0, which increases the asymmetry of the algorithm. The round constants used in step ι are a set of constants related to the round number ir. The value of the round constant can be calculated by the following formula. Trunc represents the number of stage specified bits. The calculation results are shown in Table 7.
[0136]
[0137] Table 7 Round constant values
[0138]
[0139]
[0140] like Fig.19 The figure shows a schematic diagram of the permutation module in the SHA3-512 hash function unit. When the data is permuted, when the enable signal en is pulled high, it indicates that the permutation module starts working, and in_valid is pulled high to receive the 576-bit input signal in. The permutation module has received the data and the ack signal is pulled high to feed it back to the filling module. When the next cycle starts the round processing, ack is pulled low. The permutation module controls the round function module through the control module to select the data input by in or the data output by the previous round as input. The counter inside the control module provides a value for the round function module to select the round constant. A round counter is also defined in the control module. The counter executes two rounds for each count, and the permutation of the message block is completed when the count reaches 12. When last_block is high, it means that the current is the last message block. When the message block is processed, the permutation module outputs the signal out, and at the same time pulls the signal out_ready high to indicate that the permutation is completed.
[0141] Specifically, the round function part is as follows Fig. 20 As shown in the figure: The round function is the core part of SHA3-512, responsible for data replacement and the main operation of the algorithm. Therefore, optimizing this part can improve the overall performance. Pipeline and expansion technology are aimed at improving different directions such as frequency and throughput.
[0142] Specifically, in the implementation of the round function, the pipeline can be divided into a round operation pipeline and an internal pipeline. The round operation pipeline inserts registers after each round of operation, and the internal pipeline inserts intermediate registers during the round operation. The number of pipeline stages is the number of register stages inserted in the design, that is, the sum of the two pipeline register stages.
[0143] Using internal pipelines in the round operation module can shorten the critical path to increase the frequency. The round function of SHA-3 contains a total of five operations. The θ1 operation in the θ operation uses 4 XOR gates, the θ2 operation uses 1 XOR gate, and the θ3 operation uses 1 XOR gate. The ρ and π operations are just data rearrangements that do not consume logic gates, so the two steps are combined. The χ operation uses an XOR gate, a NOT gate, and an AND gate. The ι operation uses an XOR gate. Placing registers in different locations has different effects on the frequency, so we tried placing registers in four different locations, such as Fig.21 As shown in the figure. Since the ρ and π operations do not consume logic gates, they are not considered in this paper. More sub-pipeline levels can bring higher frequencies, but they will also consume more resources and reduce the overall efficiency. Therefore, only the case of using one internal pipeline is discussed.
[0144] The storage of RC values is also included in the implementation of the round function. The RC value consists of 24 groups of 64-bit data. By observing Table 7, it can be found that among the 24 RC values, only 0, 1, 3, 7, 15, 31, and 63 bits may be "1", and the remaining bits are zero. In order to reduce resource consumption and the amount of calculation required for the "ι" operation in the round function, the RC value is compressed into 7 bits for storage, as shown in Table 8.
[0145] Table 8 Simplified wheel constant values
[0146]
[0147] This article is aimed at Fig.21 The four internal pipeline solutions mentioned are implemented in Verilog language and simulated in Modelsim. ISE tool is used to synthesize on Xlinx Virtex5 (xc5vlx110-3ff1760) chip. Table 9 shows the comparison of the four solutions in terms of frequency, throughput, resource usage and efficiency. The formulas for throughput and efficiency are as follows and Where r is the size of the message block. In SM3 and SHA-256, r is 512, f is the maximum frequency, N is the number of message blocks processed simultaneously, cycles is the number of cycles, and the message block size r is 576 in SHA3-512.
[0148] Table 9 Experimental results of four internal pipelines
[0149]
[0150] Among the four internal pipeline schemes, a pipeline register is inserted between θ2 and θ3, and the number of logic gates passed by the combinational circuits on both sides of the register in the round function is relatively balanced. From the experimental results, it can be seen that the frequency effect obtained is the best among the four schemes. From the round function formula, it can be seen that the θ3 operation needs to use variable A again. When inserting the register, it is necessary not only to register variable B, but also to use the register to temporarily store variable A. Therefore, this structure consumes more resources, but the overall performance is good. The frequency of inserting pipeline registers between θ and ρ is higher than that between θ1 and θ2. Although the number of logic gates passed by the combinational circuits on both sides of the register in the round function is the same, the frequency, throughput and other effects of the former are better than the latter. The critical path of inserting pipeline registers between χ and ι is relatively long, passing through 9 logic gates and a selector. From the experimental results, it can be seen that the frequency, throughput and efficiency are lower than the other three schemes.
[0151] Choosing a suitable internal pipeline structure can achieve a higher frequency, but it increases the number of delay clocks, which is not conducive to improving throughput. Unfolding is an effective way to improve throughput. Unfolding is to instantiate the round function module multiple times before the state register to implement multiple rounds of operations in one cycle. Although unfolding can reduce the count of clock cycles, it will lead to an overly long critical path. Excessive unfolding to instantiate a large number of round function modules will also increase resources. As the unfolding factor continues to increase, although the throughput increases rapidly, the maximum frequency decreases exponentially. There are two main ways of unfolding: the first is to process continuous rounds at each level. For example, in a two-level unfolding, the first level processes 0 to 11 rounds and the second level processes 12 to 23 rounds. The second is to process non-continuous rounds at each level. For example, in a two-level unfolding, the first level processes even rounds (i.e., 0, 2, 4...) and the second level processes odd rounds (i.e., 1, 3, 5...). The second structure is superior to the first structure in terms of area and efficiency. In order to more effectively improve the design performance, the design of this paper adopts the second way of two-level expansion. The first-level round function processes even rounds, and the second-level round function processes odd rounds. At the same time, the design of this paper uses a round operation pipeline structure in each level of expansion to alleviate the problem of long critical paths caused by expansion. Combining the analysis of pipeline and expansion, the proposed structure is as follows Fig. 20 shown.
[0152] In the designed round function module, the even round uses the initial data or the feedback of the previous round as input, the former passes through a selector, and the latter passes through two selectors before starting the replacement. The odd round only needs to receive the data processed by the previous stage without passing through the selector. Therefore, a new two-stage expansion structure is proposed, in which the even round register is inserted earlier than the odd round, so different internal pipeline structures are used in the odd and even rounds. According to the experiments of four internal pipelines, the structure of inserting the pipeline register between θ2 and θ3 for the even round and between θ and ρ for the odd round is designed. According to the above RC analysis, the 24 groups of RC values are further divided into 12 groups of 7-bit even round constants and 12 groups of 7-bit odd round constants, which not only improves the performance and efficiency, but also achieves a more compact design. The round function of this structure reduces the round processing cycle count by half, and the number of pipeline stages reaches four.
[0153] The input of HMAC is the key (k) shared by both parties and the message (m) to be transmitted. The structure of HMAC can be expressed by the formula HMACk(m) = H((k⊕opad)||H((k⊕ipad)||m)). H represents the hash function, ipad is the bit sequence of 0x36 that is looped continuously to make its length the same as the length of the hash function message block. opad is the bit sequence of 0x5c that is looped continuously to make its length the same as the length of the hash function message block.
[0154] The following is a detailed introduction to the specific steps of the HMAC algorithm. The specific process of the HMAC algorithm is as follows Fig. 22 As shown:
[0155] S1. In the entire HMAC process, before the key is involved in encryption, it is padded to meet the length requirements. There are two padding methods depending on the initial key length. One is that if the key length is greater than the length of the hash function message block, the key needs to be processed by a hash function first. If the processed key length is less than the message block length, "0" is padded at the end to make it the same length as the hash function message block. The other is that if the key length is less than the length of the hash function message block, "0" is directly padded at the end to make it the same length as the hash function message block.
[0156] S2. The padded key is first XORed with an ipad sequence of equal length to obtain a bit sequence ipadkey related to the key; the length of the bit sequence ipadkey is the same as the message block length of the hash function used;
[0157] S3, after obtaining the bit sequence ipadkey, the bit sequence ipadkey is combined with the message, that is, the message is concatenated after the bit sequence ipadkey to obtain the bit sequence ipadkey||m;
[0158] S4, sending the spliced data to the SM3-SHA256 hash function unit or the SHA3-512 hash function unit for processing;
[0159] S5, firstly perform an XOR operation on the padded key and an opad sequence of equal length to obtain a bit sequence opadkey;
[0160] S6, after obtaining the bit sequence opadkey, concatenate the hash value obtained in the S4 process to the end of the bit sequence opadkey;
[0161] S7. Finally, the data obtained in S6 is sent to the SM3-SHA256 hash function unit or the SHA3-512 hash function unit for processing again. The resulting hash value is the final message authentication code value.
[0162] In summary, when hmac_en is "0", data_en is "3" to indicate input data, mode is "1" to indicate that the SM3 hash algorithm is executed, then mode changes to "2" to indicate that the SHA-256 hash algorithm is executed, and finally mode changes to "3" to indicate that the SHA3-512 algorithm is executed. When the same message is input, the results are as follows: Fig.23 As shown, the hardware simulation output results of the algorithm are consistent with the software results, which shows that the HMAC module can normally execute the three hash functions independently.
[0163] When hmac_en is "1", data_en is "1" which means the current key is smaller than the message block length. When the mode signal is "3", it means the HMAC-SHA3-512 function is executed. Then when the mode signal is converted to "2", it means the HMAC-SHA256 function is executed. Finally, when the mode signal is converted to "1", the HMAC-SM3 function is executed. When the same message is input, the result is as follows: Fig.24 As shown, the hardware simulation output results of the algorithm are consistent with the software results, indicating that the HMAC module can normally execute the case where the key is smaller than the message block length.
[0164] When hmac_en is high and data_en is "2", it means that the current key is larger than the message block length, and the key must be processed by a hash function first. Fig.25 The need_data signal in Fig.24When the mode signal is "3", it indicates that the HMAC-SHA3-512 function is executed. Then, when the mode signal is converted to "2", it indicates that the HMAC-SHA256 function is executed. Finally, when the mode signal is converted to "1", the HMAC-SM3 function is executed. When the same message is input, the hardware simulation output results of the algorithm are consistent with the software results, indicating that the HMAC module can normally execute the case where the key is larger than the message block length.
[0165] The simulation verifies that the HMAC module can normally execute six functions: SM3, SHA-256, SHA3-512, HMAC-SM3, HMAC-SHA256, and HMAC-SHA3-512. The frequency resource occupancy is also obtained by comprehensively using the Virtex-5 (XC5VLX110-3fft1760) device on the Xilinx ISE14.7 tool. The results show that the maximum frequency of the HMAC module reaches 164.47M and the occupied resources are 4158 slices.
[0166] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A configurable HMAC message authentication code circuit, characterized in that: It includes a data flow control unit, an SM3-SHA256 hash function unit, and a SHA3-512 hash function unit; The internal modules of the HMAC message authentication code circuit are all controlled by the clock signal input and output terminal clk and the reset signal input terminal rst_n; The mode signal selection circuit of the HMAC message authentication code circuit controls the enable signals of the SHA3-512 hash function unit and the SM3-SHA256 hash function unit through an XOR gate and an AND gate; the enable signal of the SM3-SHA256 hash function unit and mode[0] are used as the selection signal of the SM3-SHA256 module through an AND gate; The data flow control unit includes five input terminals, namely, an HMAC enable signal terminal hmac_en, an input valid signal terminal date_en, a plaintext or key terminal data_in, a last byte input signal terminal msg_is_last_word, and a last byte byte number terminal byte_num, wherein the enable signal terminal hmac_en controls whether the remaining four ports are used as direct data input terminals of the SM3-SHA256 hash function unit and the SHA3-512 hash function unit; The data flow control unit includes seven output terminals, wherein the output valid signal terminal hmac_vld and the data output signal terminal msg_hmac are both connected to the output terminals of the SHA3-512 hash function unit and the SM3-SHA256 hash function unit, and the output terminal need_data is used to output a data request signal; The other four output terminals of the data flow control unit are the data state input terminal in_vld, the input data input terminal data, the byte number input terminal byte_numb and the last byte input terminal last_word, which are connected to the corresponding input terminals of the data flow control unit through a selector, and the control terminal of the selector is connected to the HMAC enable signal input terminal; The data output end out and the out_ready signal output end of the SM3-SHA256 hash function unit and the SHA3-512 hash function unit are respectively connected to a selector at the same time, and the output is controlled by the input mode signal end. The output end of the selector is connected to the output end corresponding to the data flow control unit through the selector, and the final data of the HMAC circuit is output through the selector.
2. A configurable HMAC message authentication code circuit according to claim 1, characterized in that: The SHA3-512 hash function unit includes a padding module and a replacement module; The filling module comprises three output terminals, namely a data output terminal, a last message block indication signal output terminal last_block and an output valid signal output terminal pout_r, wherein the last message block indication signal output terminal and the output valid signal output terminal are connected to the input terminal of the replacement module, and the data output terminal is connected to the little-end conversion module recode1; The replacement module comprises six input terminals, three of which are respectively a data input terminal in, a last message block indication signal input terminal last_block and an input valid signal input terminal in_ready, the data input terminal is connected to the output terminal of the little end conversion module recode1, and the last message block indication signal input terminal and the input valid signal input terminal are connected to the corresponding output terminals of the filling module; The replacement module also includes three output terminals, namely a data output terminal out, an output valid signal output terminal out_ready and an ack signal output terminal, wherein the data output terminal is connected to the input terminal of the little-end conversion module recode2, and the ack signal output terminal is connected to the input terminal of the filling module.
3. A configurable HMAC message authentication code circuit according to claim 2, characterized in that: The permutation module in the SHA3-512 hash function unit includes a round function module. The round function module selects an internal pipeline structure to perform a two-level expansion processing round operation. The first-level round function processes the even-numbered rounds, and the second-level round function processes the odd-numbered rounds.
4. A configurable HMAC message authentication code circuit according to claim 3, characterized in that: The pipeline structure has an even-numbered round with a pipeline register inserted between the θ2 logic circuit and the θ3 logic circuit, and an odd-numbered round with a pipeline register inserted between the θ logic circuit and the ρ logic circuit; Among them, in the round function module, the even-numbered rounds use the initial data or the feedback of the previous round as input. The former passes through a selector, and the latter passes through two selectors before starting the replacement. The odd-numbered rounds only need to receive the data processed by the previous level without passing through the selector.
5. A configurable HMAC message authentication code circuit according to claim 1, characterized in that: The SM3-SHA256 hash function unit includes a message filling module, a message expansion module and an iterative compression module; The message filling module comprises two output terminals, namely a data output terminal P_out and an output valid signal terminal Pout_ready, and is connected to the input terminal of the message expansion module; The message expansion module comprises four output terminals, namely a wj0 data output terminal, a wj1 data output terminal, an out_vld signal output terminal and a ready signal output terminal, wherein the wj0 data output terminal, the wj1 data output terminal and the out_vld signal output terminal are connected to the input terminal of the iterative compression module, and the ready signal output terminal is connected to the output terminal of the message filling module; The iterative compression module comprises two output terminals, namely a data output terminal out and an output valid signal terminal out_ready, which serve as output terminals of the SM3-SHA256 hash function unit.
6. A configurable HMAC message authentication code circuit according to claim 5, characterized in that: The iterative compression module of the SM3-SHA256 hash function unit implements the A register and E register update circuits of the compression functions in the SM3 algorithm and the SHA-256 algorithm using a multiplexing structure, and further multiplexes the 8×32-bit registers A to H required by the SM3 algorithm and the SHA-256 algorithm.
7. A configurable HMAC message authentication method, characterized in that: The following steps are involved: S1. In the entire HMAC process, the key is padded to meet the length requirement before participating in encryption. There are two padding methods depending on the initial key length; S2. The padded key is first XORed with an ipad sequence of equal length to obtain a bit sequence ipadkey related to the key; the length of the bit sequence ipadkey is the same as the message block length of the hash function used; S3, after obtaining the bit sequence ipadkey, the bit sequence ipadkey is combined with the message, that is, the message is concatenated after the bit sequence ipadkey to obtain the bit sequence ipadkey||m; S4, sending the spliced data to the SM3-SHA256 hash function unit or the SHA3-512 hash function unit for processing; S5, firstly perform an XOR operation on the padded key and an opad sequence of equal length to obtain a bit sequence opadkey; S6, after obtaining the bit sequence opadkey, concatenate the hash value obtained in the S4 process to the end of the bit sequence opadkey; S7. Finally, the data obtained in S6 is sent to the SM3-SHA256 hash function unit or the SHA3-512 hash function unit for processing again. The resulting hash value is the final message authentication code value.
8. A configurable HMAC message authentication method according to claim 7, characterized in that: There are two ways to fill it: One is that when the key length is greater than the length of the hash function message block, the data_en signal output is "2", and the key is first processed by the hash function, which delays the need_data signal frequency. The processed key length will be less than the message block length, so "0" is padded at the end to make it the same length as the hash function message block length; Secondly, when the length of the key is less than the length of the hash function message block, the data_en signal output is "1" and "0" is directly filled at the end to make its length the same as the hash function message block length.
Citation Information
Patent Citations
Method and system for realizing reconfiguration of multiple hash algorithms
CN111464308A
Method and device for quickly realizing HMAC algorithm
CN112104462A
HMAC algorithm processing system, method, device and medium
CN115442026A
Heterogeneous encrypted data processing method, system and related device
CN116861448A
Chip hybrid simulation method based on general verification methodology and image processing algorithm
CN117688903A
