Function multiplexing SM4 encryption circuit based on assembly line mode
By using pipeline mode and time-sharing multiplexing technology of key expansion module and wheel scrambling module in the SM4 encryption circuit, the problem of resource consumption and efficiency imbalance in the FPGA implementation of SM4 algorithm is solved, and low logic consumption and low latency are achieved scramble processing at the time.
Patent Information
- Application Number
- CN202411155361.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-22
- Publication Date
- 2024-11-15
AI Technical Summary
The SM4 algorithm implemented based on FPGA is difficult to balance efficiency and resource consumption, the data processing efficiency of the cyclic SM4 algorithm is low, while the resource occupancy rate of the pipelined SM4 cryptographic algorithm is too high.
The SM4 encryption circuit based on pipeline mode is adopted to achieve low logic consumption and low processing delay through time-sharing multiplexing of the key expansion module and the wheel scrambling module. The circuit includes a multiplexing control module, a cascading functional multiplexing module and a key storage module. The register gate circuit and a wheel counter control a two-choice data selector to realize the functional multiplexing of key expansion and wheel scrambling.
It greatly reduces logic resource consumption and reduces data scrambling delay, and realizes SM4 scrambling circuit with low logic consumption and low processing delay.
Smart Images

Figure CN118972040A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of symmetric scrambling algorithm circuits, and in particular to an SM4 encryption circuit with low resource consumption and low delay, which is realized by time-division multiplexing of a key expansion module and a round scrambling module based on a pipeline mode. Background Art
[0002] Digitalization, networking and intelligence are the characteristics of the information age. In the development of the Internet of Things and cloud computing, a large amount of data is generated and stored in various storage devices. These storage devices carry a large amount of important data. Scrambling the data before storage is an important means to prevent data leakage in storage devices. The core technology of data scrambling is the data scrambling algorithm. The SM4 cryptographic algorithm has become an international standard and is suitable for encryption and decryption of large amounts of data in storage systems.
[0003] Through specific programming, the hardware circuit of the SM4 algorithm can be implemented inside the FPGA, which can avoid the low efficiency caused by the serial operation of the processor and the unstable performance in different scenarios, and can also avoid the high cost of tape-out and the problem of unchangeable after tape-out caused by the use of dedicated chips. In view of the hardware implementation of FPGA and the programmable, reconfigurable and easy-to-iterate characteristics, the use of FPGA to implement the SM4 algorithm is an efficient and feasible method. However, the SM4 algorithm based on FPGA is difficult to achieve a balance between efficiency and resource consumption. The data processing efficiency of the cyclic SM4 algorithm is low, and the resource occupancy rate of the pipeline SM4 cryptographic algorithm is too high. Summary of the invention
[0004] In view of this, the present invention proposes a function multiplexing SM4 encryption circuit based on pipeline mode. The present invention is based on pipeline mode and realizes low logic consumption and low processing delay by time-division multiplexing of key expansion module and round scrambling module.
[0005] The technical solution adopted by the present invention is:
[0006] A function multiplexing SM4 encryption circuit based on a pipeline mode comprises a multiplexing control module, 32 cascaded function multiplexing modules, and 32 key storage modules, wherein the 32 function multiplexing modules and the 32 key storage modules are connected in a one-to-one correspondence;
[0007] The function multiplexing module includes Conversion circuit, L conversion circuit, L' conversion circuit, two-choice data selector, L conversion circuit and L' conversion circuit are connected in parallel Between the conversion circuit and the two-to-one data selector;
[0008] The key storage module includes a round key generation parameter storage space and a round key storage space;
[0009] The multiplexing control module includes a round counter circuit and a register gating circuit, and the register gating circuit outputs a 32-bit signal;
[0010] After the round counter circuit is reset, the count is 0. After that, the count is accumulated with the clock signal, and the count is maintained after it accumulates to 32. When the round counter circuit counts to 0, the 32-bit signal output by the register gating circuit is 0. When the round counter circuit counts to n ≥ 1, the 32-bit signal output by the register gating circuit is 2 in binary representation. n-1 +2 n-2 +...+2 0 ;
[0011] The 32-bit signal output by the register selection circuit corresponds to 32 control bits, and the 32 control bits control the two-to-one data selectors of the 32 function multiplexing modules from the primary stage of the cascade to the final stage of the cascade in order from low to high; when the control bit is 0, the two-to-one data selector selects the L' conversion circuit, the function multiplexing module reads the round key generation parameter from the round key generation parameter storage space of the corresponding key storage module, performs an expansion operation on the incoming key, stores the generated round key in the round key storage space of the corresponding key storage module, and transmits the key expansion operation value backward; when the control bit is 1, the two-to-one data selector selects the L conversion circuit, the function multiplexing module reads the round key from the round key storage space of the corresponding key storage module, performs round scrambling on the incoming data, and transmits the scrambled data backward.
[0012] Furthermore, the key storage module is a BRAM storage circuit.
[0013] The beneficial effects of the present invention are:
[0014] 1. In the present invention, the round scrambling module and the key generation module are functionally reused, thereby greatly reducing the consumption of logic resources.
[0015] 2. The present invention utilizes the pipeline follow-up mode of keys and data, which greatly reduces the data scrambling delay.
[0016] In summary, the present invention is based on the pipeline mode and realizes the SM4 scrambling circuit with low logic consumption and low processing delay by time-division multiplexing of the key expansion module and the round scrambling module. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 It is a schematic diagram of the overall structure of an embodiment of the present invention.
[0018] Figure 2 It is a structural diagram of the function reuse module.
[0019] Figure 3 It is a structural diagram of the multiplexing control module. DETAILED DESCRIPTION
[0020] The present invention is further described in detail below in conjunction with the accompanying drawings.
[0021] A functional multiplexing SM4 encryption circuit based on pipeline mode, such as Figure 1 As shown, it includes a multiplexing control module, 32 cascaded function multiplexing modules 1 to 32, and 32 key storage modules. Among them:
[0022] Function multiplexing module, which can be time-division multiplexed into round scrambling module or round key generation module;
[0023] The multiplexing control module is used to respond to external key update control information and control the 32-level function multiplexing module through 32 control bits to determine whether it implements the round scrambling function or the round key generation function;
[0024] The key storage module includes a round key generation parameter storage space and a round key storage space, which are used to provide round key generation parameters and round key storage during the key generation process, and provide round scrambling during the round scrambling process. When the multiplexing control module is implemented as a round scrambling function, the round key storage space of the key storage module is output externally, and when the multiplexing control module is implemented as a round key generation function, the round key generation parameter storage space of the key storage module is output externally, and at the same time, the round key storage space receives input data and stores the round key.
[0025] like Figure 2 As shown, the function reuse module contains The conversion circuit, L conversion circuit, L' conversion circuit and two-to-one data selector are implemented by a multiple-to-one MUX circuit. Each level of multiple-to-one MUX circuit realizes gating control through a control bit of a multiplexing control module.
[0026] When the control bit SeL of the multiplexing control module is 0, the multiple-select-one MUX circuit selects the L' conversion circuit, and the function multiplexing module implements the round key generation function. At this time, the input Datain of the primary function multiplexing module is the external input key, and each level of the function multiplexing module reads the round key generation parameter Cki from the round key generation parameter storage space, performs an expansion operation on the input key, and stores the round key Rki generated at this level in the round key storage space of the key storage module, and passes the key expansion operation value of this level backward.
[0027] When the control bit SeL of the multiplexing control module is 1, the multiple-select MUX circuit selects the L conversion circuit, and the function multiplexing module implements the round scrambling function. At this time, the input Datain of the primary function multiplexing module is the plain text input from the outside, and the input Datain of the subsequent function multiplexing module is the scrambled data output by the upper function multiplexing module. Each level of function multiplexing module reads the round key Rki from the round key storage space of the key storage module at this level, performs round scrambling on the input data at this level, and outputs the scrambled data backwards. The output Dataout of the final level function multiplexing module is the final ciphertext.
[0028] like Figure 3 As shown, the multiplexing control module includes a round counter circuit and a register gating circuit. The register gating circuit is implemented by the RTL_REG circuit and outputs a 32-bit signal SeL[31:0] corresponding to 32 control bits. The 32 control bits control the multiple-select-one MUX circuits of the 32 functional multiplexing modules from the primary stage of the cascade to the final stage of the cascade in sequence from low to high.
[0029] The data input externally to this SM4 encryption circuit are the key and plain text. When the key is input externally, the reset signal Rst is transmitted to the round counter circuit, and the count is 0 at this time. Thereafter, the count is accumulated with the clock signal Clk, and the count is maintained after it accumulates to 32.
[0030] When the round counter circuit counts to 0, the 32-bit signal output by the register gating circuit is 0; when the round counter circuit counts to n ≥ 1, the 32-bit signal output by the register gating circuit is 2 in binary representation. n-1 +2 n-2 +...+2 0 .
[0031] The specific working process of this circuit is as follows:
[0032] First, the key is updated, the reset signal Rst is set high, and the key is read at the first clock. At this time, the 32-level multiplexing module is used as a key generation module.
[0033] Then, the data sets the reset signal Rst to low at the second clock, and the plaintext data is input at the same time. Under the action of the multiplexing control module, the first-level function multiplexing module is used as a round scrambling module, and the subsequent 31-level function multiplexing modules are used as key generation modules.
[0034] At the third clock, under the action of the multiplexing control module, the first two levels of function multiplexing modules are used as round scrambling modules, and the last 30 levels of function multiplexing modules are used as key generation modules.
[0035] At the fourth clock, under the action of the multiplexing control module, the first three levels of function multiplexing modules are used as round scrambling modules, and the last 29 levels of function multiplexing modules are used as key generation modules.
[0036] At the fifth clock, under the action of the multiplexing control module, the first 4 levels of function multiplexing modules are used as round scrambling modules, and the last 28 levels of function multiplexing modules are used as key generation modules.
[0037] At the sixth clock, under the action of the multiplexing control module, the first five levels of function multiplexing modules are used as round scrambling modules, and the last 27 levels of function multiplexing modules are used as key generation modules.
[0038] At the 7th clock, under the action of the multiplexing control module, the first 6-level function multiplexing module is used as a round scrambling module, and the last 26-level function multiplexing module is used as a key generation module.
[0039] At the 8th clock, under the action of the multiplexing control module, the first 7-level function multiplexing module is used as a round scrambling module, and the last 25-level function multiplexing module is used as a key generation module.
[0040] At the 9th clock, under the action of the multiplexing control module, the first 8-level function multiplexing module is used as a round scrambling module, and the last 24-level function multiplexing module is used as a key generation module.
[0041] At the 10th clock, under the action of the multiplexing control module, the first 9-level function multiplexing module is used as a round scrambling module, and the last 23-level function multiplexing module is used as a key generation module.
[0042] At the 11th clock, under the action of the multiplexing control module, the first 10-level function multiplexing modules are used as round scrambling modules, and the last 22-level function multiplexing modules are used as key generation modules.
[0043] At the 12th clock, under the action of the multiplexing control module, the first 11 levels of function multiplexing modules are used as round scrambling modules, and the last 21 levels of function multiplexing modules are used as key generation modules.
[0044] At the 13th clock, under the action of the multiplexing control module, the first 12 levels of functional multiplexing modules are used as round scrambling modules, and the last 20 levels of functional multiplexing modules are used as key generation modules.
[0045] At the 14th clock, under the action of the multiplexing control module, the first 13 levels of functional multiplexing modules are used as round scrambling modules, and the last 19 levels of functional multiplexing modules are used as key generation modules.
[0046] At the 15th clock, under the action of the multiplexing control module, the first 14-level function multiplexing modules are used as round scrambling modules, and the last 18-level function multiplexing modules are used as key generation modules.
[0047] At the 16th clock, under the action of the multiplexing control module, the first 15 levels of function multiplexing modules are used as round scrambling modules, and the last 17 levels of function multiplexing modules are used as key generation modules.
[0048] At the 17th clock, under the action of the multiplexing control module, the first 16-level function multiplexing modules are used as round scrambling modules, and the last 16-level function multiplexing modules are used as key generation modules.
[0049] At the 18th clock, under the action of the multiplexing control module, the first 17 levels of functional multiplexing modules are used as round scrambling modules, and the last 15 levels of functional multiplexing modules are used as key generation modules.
[0050] At the 19th clock, under the action of the multiplexing control module, the first 18-level function multiplexing modules are used as round scrambling modules, and the last 14-level function multiplexing modules are used as key generation modules.
[0051] At the 20th clock, under the action of the multiplexing control module, the first 19-level function multiplexing modules are used as round scrambling modules, and the last 13-level function multiplexing modules are used as key generation modules.
[0052] At the 21st clock, under the action of the multiplexing control module, the first 20 levels of function multiplexing modules are used as round scrambling modules, and the last 12 levels of function multiplexing modules are used as key generation modules.
[0053] At the 22nd clock, under the action of the multiplexing control module, the first 21 levels of function multiplexing modules are used as round scrambling modules, and the last 11 levels of function multiplexing modules are used as key generation modules.
[0054] At the 23rd clock, under the action of the multiplexing control module, the first 22 levels of function multiplexing modules are used as round scrambling modules, and the last 10 levels of function multiplexing modules are used as key generation modules.
[0055] At the 24th clock, under the action of the multiplexing control module, the first 23 levels of functional multiplexing modules are used as round scrambling modules, and the last 9 levels of functional multiplexing modules are used as key generation modules.
[0056] At the 25th clock, under the action of the multiplexing control module, the first 24 levels of functional multiplexing modules are used as round scrambling modules, and the last 8 levels of functional multiplexing modules are used as key generation modules.
[0057] At the 26th clock, under the action of the multiplexing control module, the first 25 levels of functional multiplexing modules are used as round scrambling modules, and the last 7 levels of functional multiplexing modules are used as key generation modules.
[0058] At the 27th clock, under the action of the multiplexing control module, the first 26 levels of function multiplexing modules are used as round scrambling modules, and the last 6 levels of function multiplexing modules are used as key generation modules.
[0059] At the 28th clock, under the action of the multiplexing control module, the first 27 levels of functional multiplexing modules are used as round scrambling modules, and the last 5 levels of functional multiplexing modules are used as key generation modules.
[0060] At the 29th clock, under the action of the multiplexing control module, the first 28 levels of function multiplexing modules are used as round scrambling modules, and the last 4 levels of function multiplexing modules are used as key generation modules.
[0061] At the 30th clock, under the action of the multiplexing control module, the first 29 levels of function multiplexing modules are used as round scrambling modules, and the last 3 levels of function multiplexing modules are used as key generation modules.
[0062] At the 31st clock, under the action of the multiplexing control module, the first 30 levels of function multiplexing modules are used as round scrambling modules, and the last 2 levels of function multiplexing modules are used as key generation modules.
[0063] At the 32nd clock, under the action of the multiplexing control module, the first 31 levels of function multiplexing modules are used as round scrambling modules, and the last level of function multiplexing modules is used as a key generation module.
[0064] At the 33rd clock, under the action of the multiplexing control module, all level function multiplexing modules are used as round scrambling modules.
[0065] At the 34th clock, the scrambling of the plaintext data entering the module at the 2nd clock is completed.
[0066] When the key needs to be updated, it is necessary to wait for the current data to pass through all multiplexing modules before outputting the ciphertext. Then, Rst is set high to reset each circuit. The above process is repeated. All multiplexing modules are used as key generation modules, and under the action of the multiplexing control module, they are gradually transformed into round scrambling modules with clock counting. The scrambled data will be continuously output after the 33rd clock after the plaintext data enters the circuit.
[0067] The multiplexing control module of the present invention outputs 32 control bits according to the clock relationship with the 1 control bit, realizes the function multiplexing module as the round scrambling function one by one, and realizes the key storage module as the round key providing function one by one, thereby performing a multiplexing design in the module composition, making full use of the similarity of the round scrambling module and the key expansion module, and multiplexing the two to save resource consumption. At the same time, by analyzing the time-sharing multiplexing relationship between the two, the round scrambling process is followed by the key expansion process, thereby achieving a low latency effect.
Claims
1. A functional multiplexing SM4 encryption circuit based on pipeline mode, characterized in that: It includes a multiplexing control module, 32 cascaded function multiplexing modules, and 32 key storage modules, and the 32 function multiplexing modules and the 32 key storage modules are connected one by one; The function multiplexing module includes Conversion circuit, L conversion circuit, L' conversion circuit, two-choice data selector, L conversion circuit and L' conversion circuit are connected in parallel Between the conversion circuit and the two-to-one data selector; The key storage module includes a round key generation parameter storage space and a round key storage space; The multiplexing control module includes a round counter circuit and a register gating circuit, and the register gating circuit outputs a 32-bit signal; After the round counter circuit is reset, the count is 0. After that, the count is accumulated with the clock signal, and the count is maintained after it reaches 32; When the round counter circuit counts to 0, the 32-bit signal output by the register gating circuit is 0; when the round counter circuit counts to n ≥ 1, the 32-bit signal output by the register gating circuit is 2 in binary representation. n-1 +2 n-2 +...+2 0 ; The 32-bit signal output by the register gating circuit corresponds to 32 control bits, and the 32 control bits control the two-to-one data selectors of the 32 function multiplexing modules from the primary stage of the cascade to the final stage of the cascade in order from the low bit to the high bit; When the control bit is 0, the two-choice data selector enables the L' transformation circuit, and the function multiplexing module reads the round key generation parameters from the round key generation parameter storage space of the corresponding key storage module, performs an expansion operation on the incoming key, stores the generated round key in the round key storage space of the corresponding key storage module, and passes the key expansion operation value backward; when the control bit is 1, the two-choice data selector enables the L transformation circuit, and the function multiplexing module reads the round key from the round key storage space of the corresponding key storage module, performs round scrambling on the incoming data, and passes the scrambled data backward.
2. The function multiplexing SM4 encryption circuit based on pipeline mode according to claim 1, characterized in that: The key storage module is a BRAM storage circuit.
