Replacement box circuit, encryption method and electronic equipment
By adopting the design of a shared inversion circuit and a multiplexer in the replacement box circuit, the problems of resource waste and low efficiency in the existing technology are solved, and efficient encryption processing that supports multiple encryption methods is achieved.
Patent Information
- Application Number
- CN202310365639.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-29
- Publication Date
- 2024-10-01
AI Technical Summary
Existing replacement box circuits need to set up multiple different algorithm circuits when supporting multiple encryption methods, resulting in waste of resources, increased design complexity, and reduced encryption efficiency.
A replacement box circuit including an input port, an affine transformation circuit, a multiplexer, an inversion circuit and an inverse affine transformation circuit is designed. Data of different encryption standards can be processed through the shared inversion circuit and multiplexer. Performing isomorphic transformation and inverse transformation reduces the number of inversion circuits and circuit area, and performs inversion operations on the Galois field to increase calculation speed.
It supports multiple encryption methods while reducing the circuit area of the replacement box, improving encryption efficiency, simplifying the design process, and reducing resource consumption.
Smart Images

Figure CN118740367A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of security encryption technology, and in particular to a replacement box circuit, an encryption method and an electronic device. Background Art
[0002] Block encryption is a symmetric key algorithm, that is, the same key is used for encryption and decryption, or two keys that can be easily deduced from each other are used. It divides the plaintext (unencrypted data) into multiple data blocks of equal length, and uses a certain algorithm and symmetric key to encrypt and decrypt each group of data blocks separately. Among them, the Rijndael algorithm is widely used in the field of security encryption, including the AES block cipher algorithm corresponding to the advanced encryption standard (AES), the SM4 block cipher algorithm, and the Camellia cipher algorithm. The Rijndael algorithm consists of multiple rounds of operations, and each round of operations is divided into multiple steps. The substitution box S-box is the basic structure for the symmetric key cryptographic algorithm to perform substitution calculations. It is used to blur the relationship between the key and the ciphertext (encrypted data). It has nonlinear characteristics and is the main security performance guarantee of the Rijndael algorithm. It is also the implementation bottleneck of the substitution box encryption and a hot research topic in the industry.
[0003] The replacement box S-Box is the core component of the Rijndael type cryptographic algorithm, which improves the overall security performance of the cryptographic algorithm by providing nonlinear transformation. The S-Box of the Rijndael type algorithm can be derived through mathematical solution. Therefore, in addition to the table lookup method, the Rijndael type S-Box implementation can be solved by the algorithm operation circuit. However, the current replacement box S-Box needs to set different algorithm circuits for different algorithms, which causes a waste of resources, increases the replacement box circuit area, and reduces the efficiency of encryption. Summary of the invention
[0004] The embodiments of the present application provide a replacement box circuit, an encryption method, and an electronic device to reduce the replacement box circuit area and improve encryption efficiency while supporting multiple encryption methods.
[0005] To achieve the above objectives, the embodiments of the present application adopt the following technical solutions:
[0006] In the first aspect, a replacement box circuit is provided, which includes an input port, a first affine transformation circuit, a second affine transformation circuit, a first multiplexer, an inversion circuit, a first inverse affine transformation circuit, a second inverse affine transformation circuit, a second multiplexer and an output port. The input end of the first affine transformation circuit and the input end of the second affine transformation circuit are both coupled to the input port. The output end of the first affine transformation circuit is coupled to the first data input end of the first multiplexer. The output end of the second affine transformation circuit is coupled to the second data input end of the first multiplexer. The input end of the inversion circuit is coupled to the output end of the first multiplexer. The input end of the first inverse affine transformation circuit and the input end of the second inverse affine transformation circuit are both coupled to the output end of the inversion circuit. The output end of the first inverse affine transformation circuit is coupled to the first data input end of the second multiplexer. The output end of the second inverse affine transformation circuit is coupled to the second data input end of the second multiplexer. The output end of the second multiplexer is coupled to the output port. The input data of the input port is a Galois field GF(2 8 ) original data; the output of the first multiplexer is the Galois field GF((2 2 ) 2 ) 2 The output of the inverse circuit is the coded data in the Galois field GF((2 2 ) 2 ) 2 The output data of the output port is the Galois field GF(2 8 )’s encrypted data.
[0007] Through the above structure, the first affine transformation circuit and the second affine transformation circuit can perform different isomorphic transformations on data of two different symmetric encryption standards to map them to the same composite domain; and the two affine transformation circuits can be controlled by the conduction state of the first multiplexer. Secondly, the inversion operation is performed through the shared inversion circuit. Finally, by controlling the conduction state of the second multiplexer, the inverse affine transformation circuits corresponding to the two affine transformation circuits can be used to restore and output the encrypted data. Based on this, the number of inversion circuits used can be reduced, thereby reducing the circuit area of the replacement box. At the same time, the inversion circuit is in the Galois field GF((2 2 ) 2 ) 2 The inversion operation is performed on a normal basis, which reduces the difficulty of the inversion circuit and improves the calculation speed.
[0008] In a possible implementation, the above-mentioned replacement box circuit also includes: a third affine transformation circuit and a third inverse affine transformation circuit. Among them, the input end of the third affine transformation circuit is coupled to the input port. The output end of the third affine transformation circuit is coupled to the third data input end of the first multiplexer. The input ends of the third inverse affine transformation circuit are all coupled to the output end of the inversion circuit. The output end of the third inverse affine transformation circuit is coupled to the third data input end of the second multiplexer. Based on this, when it is necessary to use a third symmetric encryption algorithm to encrypt data, the input data can also be isomorphically transformed by the third affine transformation circuit to map to the same composite domain after the conversion with the other two reflection circuits; and then the inversion operation is performed by the inversion circuit. Finally, the encrypted data is restored and output by the third inverse affine transformation circuit.
[0009] In a possible implementation, the replacement box circuit further includes a first register. The input end of the inversion circuit is coupled to the output end of the first multiplexer through the first register. Based on this, when the replacement box circuit operates in a high-speed data processing environment, the data output by the first multiplexer can be temporarily stored through the first register, so that the inversion circuit can perform inversion operations more orderly.
[0010] In a possible implementation, the replacement box circuit further includes a second register. The input end of the first inverse affine transformation circuit and the input end of the second inverse affine transformation circuit are both coupled to the output end of the inversion circuit through the second register. Based on this, the data output by the inversion circuit can be temporarily stored through the second register, so that the second inverse affine transformation circuit or the second inverse affine transformation circuit can perform inverse affine operations more orderly.
[0011] In a possible implementation, the replacement box circuit further includes a third register. The output end of the second multiplexer is coupled to the output port through the third register. Based on this, the data output by the second multiplexer can be temporarily stored through the third register, and the encrypted data can be output in a more orderly manner.
[0012] In a possible implementation, the first affine transformation circuit includes a first multiplication circuit; the second affine transformation circuit includes a second multiplication circuit and a first addition circuit. The first inverse affine transformation circuit includes a third multiplication circuit and a second addition circuit; the second inverse affine transformation circuit includes a fourth multiplication circuit and a third addition circuit. The input end of the first multiplication circuit and the input end of the second multiplication circuit are both coupled to the input port. The input end of the first addition circuit is coupled to the output end of the second multiplication circuit. The output end of the first multiplication circuit is coupled to the first data input end of the first multiplexer. The output end of the first addition circuit is coupled to the second data input end of the first multiplexer. The input end of the third multiplication circuit and the input end of the fourth multiplication circuit are both coupled to the output end of the inversion circuit. The input end of the second addition circuit is coupled to the output end of the third multiplication circuit. The input end of the third addition circuit is coupled to the output end of the fourth multiplication circuit. The output end of the second addition circuit is coupled to the first data input end of the first multiplexer. The output end of the third addition circuit is coupled to the second data input end of the first multiplexer. Through the structure, each affine transformation circuit can first perform multiplication operation using the affine matrix, and then perform addition operation with another affine matrix, so as to perform isomorphic transformation on the data to be encrypted. Each inverse affine transformation circuit can first perform multiplication operation using the set first inverse affine transformation matrix, and then perform addition operation with the second inverse affine matrix, so as to perform inverse affine transformation on the data after the inverse operation and then output it.
[0013] In a possible implementation, the replacement box circuit further includes a control circuit, wherein the control circuit is coupled to the control end of the first multiplexer and the control end of the second multiplexer respectively. The control circuit can perform gating control on the first multiplexer and the second multiplexer, thereby selecting an algorithm for encrypting data.
[0014] In a second aspect, an encryption method is provided, which is applied to the replacement box circuit in the first aspect. When executing the method, a first control signal can be input to the first multiplexer to connect the first data input terminal and the output terminal of the first multiplexer; and a second control signal can be input to the second multiplexer to connect the first data input terminal and the output terminal of the second multiplexer. Then, the Galois field GF(2 8 ) is mapped to the Galois Field GF((2 2 ) 2 ) 2 Then, the first coded data is obtained by inverting the circuit in the Galois field GF((2 2 ) 2 ) 2The first coded data is inversely operated on a normal basis to obtain the second coded data. Finally, the second coded data is inversely mapped into a Galois field GF(2 8 )’s first encrypted data.
[0015] In a possible implementation, the above method may further include: inputting a third control signal to the first multiplexer to connect the second data input terminal and the output terminal of the first multiplexer; and inputting a fourth control signal to the second multiplexer to connect the second data input terminal and the output terminal of the second multiplexer. 8 ) is mapped to the Galois Field GF((2 2 ) 2 ) 2 Then, through the inversion circuit in the Galois field GF((2 2 ) 2 ) 2 The third coded data is inversely operated on a normal basis to obtain fourth coded data. Finally, the fourth coded data is inversely mapped into a Galois field GF(2 8 )’s second encrypted data.
[0016] In a possible implementation, the second affine transformation circuit multiplies the input data by the first affine transformation matrix, performs an addition operation with the second affine transformation matrix, and outputs third encoded data. The second inverse affine transformation circuit multiplies the fourth encoded data by the first inverse affine transformation matrix, performs an addition operation with the second inverse affine matrix, and outputs second encrypted data.
[0017] In a possible implementation, the first affine transformation circuit performs a multiplication operation on the input data by the third affine transformation matrix, and then outputs the first encoded data. The first inverse affine transformation circuit performs a multiplication operation on the first encoded data by the third inverse affine transformation matrix, and then performs an addition operation with the fourth inverse affine matrix, and then outputs the first encrypted data.
[0018] According to a third aspect, an electronic device is provided. The electronic device includes a circuit board and a replacement box circuit according to any one of the implementations of the first aspect arranged on the circuit board.
[0019] The technical effects brought about by the second to third aspects and possible implementation methods can be found in the description of the technical effects brought about by the first aspect and possible implementation methods mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 A schematic diagram of encryption by table lookup method;
[0021] Figure 2 A schematic diagram of the structure of a replacement box circuit provided in an embodiment of the present application;
[0022] Figure 3 A schematic diagram of the structure of another replacement box circuit provided in an embodiment of the present application;
[0023] Figure 4 A schematic diagram of the structure of another replacement box circuit provided in an embodiment of the present application;
[0024] Figure 5 A schematic diagram of the structure of another replacement box circuit provided in an embodiment of the present application;
[0025] Figure 6 A schematic diagram of the structure of another replacement box circuit provided in an embodiment of the present application;
[0026] Figure 7 A schematic diagram of a flow chart of an encryption method provided in an embodiment of the present application;
[0027] Figure 8 A schematic diagram of an inversion operation provided in an embodiment of the present application;
[0028] Fig. 9 A schematic diagram of a normal basis multiplication operation provided in an embodiment of the present application;
[0029] Fig.10 Another schematic diagram of an inversion operation provided in an embodiment of the present application;
[0030] Fig.11 A schematic diagram of another normal basis multiplication operation provided in an embodiment of the present application;
[0031] Fig.12 A flowchart of another encryption method provided in an embodiment of the present application. DETAILED DESCRIPTION
[0032] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0033] In the description of the present application, unless otherwise specified, " / " indicates that the objects associated before and after are in an "or" relationship, for example, A / B can represent A or B; "and / or" in the present application is only a kind of association relationship describing the associated objects, indicating that there can be three relationships, for example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. In addition, in the description of the present application, unless otherwise specified, "multiple" refers to two or more than two. "At least one of the following" or its similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b, or c can represent: a, b, c, ab, ac, bc, or abc, where a, b, c can be single or multiple. In addition, in order to facilitate the clear description of the technical solution of the embodiment of the present application, in the embodiment of the present application, the words "first" and "second" are used to distinguish the same or similar items with basically the same functions and effects. Those skilled in the art will appreciate that words such as "first" and "second" do not limit the quantity and execution order, and words such as "first" and "second" do not necessarily limit the difference. At the same time, in the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a concrete way for easy understanding.
[0034] Cryptographic algorithms are mainly divided into two categories: symmetric cryptographic algorithms and asymmetric cryptographic algorithms. Among symmetric cryptographic algorithms, block encryption is a more commonly used encryption method, that is, the same key is used for encryption and decryption, or two keys that can be easily deduced from each other are used. It divides the plaintext (unencrypted data) into multiple data blocks of equal length, and uses a certain algorithm and symmetric key to encrypt and decrypt each group of data blocks separately. Among block cipher algorithms, the Rijndael algorithm is a block cipher algorithm designed by Belgian cryptographers JoanDaemen and Vincent Rijmen. It is widely used in the field of security encryption, including the AES block cipher algorithm, the SM4 block cipher algorithm, and the Camellia block cipher algorithm. The Rijndael algorithm consists of multiple rounds of operations, and each round of operations is divided into multiple steps. Among them, the substitution box circuit S-box is the basic structure for the symmetric key cryptographic algorithm to perform substitution calculations. It is used to blur the relationship between the key and the ciphertext (encrypted data). It has nonlinear characteristics and is the main security performance guarantee of the Rijndael algorithm. It is also the implementation bottleneck of the substitution box circuit encryption and a research hotspot in the industry.
[0035] The substitution box S-Box is the core component of the Rijndael algorithm, which improves the overall security of the cryptographic algorithm by providing nonlinear transformations. S-Box mainly implements byte substitution, that is, inputting a 1-byte data, and obtaining another 1-byte data through one-to-one mapping. Figure 1 As shown in the figure, considering that the Rijndael S-Box is a fixed mapping, a table containing 256 bytes (8-bit data can represent up to 256 combinations of byte data) can be constructed, and the replaced bytes can be obtained by looking up the table through the prescribed mapping relationship. However, different irreducible polynomials have different mapping methods, and different standards require special table construction and table lookup methods.
[0036] On the other hand, considering that the S-Box of the Rijndael algorithm can also be derived through mathematical solution. Therefore, in addition to the table lookup method, the S-Box implementation of the Rijndael algorithm type can be solved by the algorithm operation circuit. Its core algorithm includes the Galois field GF(2 8 ) (i.e., multiplicative inverse, which means that any element a in the mathematical group G has a unique inverse a' in G, with the property a×a'=a'×a=e, where e is the identity element of the group, and e is 1 in the GF field). In addition, based on the field mapping reduction to the composite field (such as GF((2 4 ) 2 ))) is also a common implementation of Rijndael S-Box.
[0037] In different standards, algorithms and scenarios, due to the differences in irreducible polynomials (a non-constant polynomial that cannot be decomposed into the product of two non-constant polynomials), the related operations of the S-Box are often not reused, resulting in the need to implement different S-Boxes separately when the replacement box circuit needs to support different encryption methods, resulting in a waste of logic resources (each supporting a set of algorithm circuits), and also increasing the complexity of the design and the development cycle. At the same time, in order to achieve multiple encryption methods, it is necessary to set up multiple algorithm circuits on the replacement box circuit, which increases the area of the replacement box circuit.
[0038] In order to solve the above problems, Figure 2As shown, the embodiment of the present application provides a replacement box circuit 200, which includes an input port 210, a first affine transformation circuit 220, a second affine transformation circuit 230, a first multiplexer 240, an inversion circuit 250, a first inverse affine transformation circuit 260, a second inverse affine transformation circuit 270, a second multiplexer 280 and an output port 290. Among them, the input end of the first affine transformation circuit 220 and the input end of the second affine transformation circuit 230 are both coupled to the input port 210. The output end of the first affine transformation circuit 220 is coupled to the first data input end of the first multiplexer 240. The output end of the second affine transformation circuit 230 is coupled to the second data input end of the first multiplexer 240. The input end of the inversion circuit 250 is coupled to the output end of the first multiplexer 240. The input end of the first inverse affine transformation circuit 260 and the input end of the second inverse affine transformation circuit 270 are both coupled to the output end of the inversion circuit 250. The output terminal of the first inverse affine transformation circuit 260 is coupled to the first data input terminal of the second multiplexer 280. The output terminal of the second inverse affine transformation circuit 270 is coupled to the second data input terminal of the second multiplexer 280. The output terminal of the second multiplexer 280 is coupled to the output port 290.
[0039] Exemplarily, the first affine transformation circuit 220 and the first inverse affine transformation circuit 260 may use the affine transformation circuit and the inverse affine transformation circuit corresponding to the AES block cipher algorithm. The second affine transformation circuit 230 and the second inverse affine transformation circuit 270 may use the affine transformation circuit and the inverse affine transformation circuit corresponding to the SM4 block cipher algorithm.
[0040] During operation, the first data input terminal of the first multiplexer 240 can be connected to the output terminal; the first data input terminal of the second multiplexer 280 can be connected to the output terminal, so that the input data is affine transformed by the first affine transformation circuit 220, the inversion operation is performed by the inversion circuit 250, and then the inverse affine transformation is performed by the first inverse affine transformation circuit 260, so as to output the data encrypted by the AES block cipher algorithm. It can be understood that the second data input terminal of the first multiplexer 240 can also be connected to the output terminal; the second data input terminal of the second multiplexer 280 can be connected to the output terminal, so that the input data is affine transformed by the second affine transformation circuit 230, the inversion operation is performed by the inversion circuit 250, and then the inverse affine transformation is performed by the second inverse affine transformation circuit 270, so as to output the data encrypted by the SM4 block cipher algorithm.
[0041] In one embodiment, the first affine transformation circuit 220, the second affine transformation circuit 230, the first inverse affine transformation circuit 260 and the second inverse affine transformation circuit 270 can be implemented using independently arranged processors. Each processor is coupled to a memory. The memory can store program instructions and data for executing various block encryption algorithms. The memory can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. The non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM) or a flash memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of random access memory (RAM) are available, such as static RAM (SRAM), dynamic random access memory (DRAM), synchronous DRAM (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link DRAM (SLDRAM), and direct rambus RAM (DRRAM).
[0042] In one embodiment, a register may be provided between the memory and the processor, and the memory may store program instructions executed by the processor. After the program instructions are read from the memory, they may be temporarily stored in the register, so that the processor can process more orderly in a high-speed processing environment.
[0043] It is understandable that the above-mentioned affine transformation circuits and inverse affine transformation circuits can also be implemented using logic circuits, and the embodiments of the present application do not impose specific limitations on this.
[0044] In one embodiment, Figure 3As shown, the replacement box circuit 200 further includes a first register 310 . The input end of the inversion circuit 250 is coupled to the output end of the first multiplexer 240 through the first register 310 .
[0045] Furthermore, the replacement box circuit 200 may further include a second register 320. The input end of the first inverse affine transformation circuit 260 and the input end of the second inverse affine transformation circuit 270 are coupled to the output end of the inversion circuit 250 through the second register 320. Based on this, the data output by the inversion circuit 250 can be temporarily stored through the second register 320, so that the second inverse affine transformation circuit 270 or the second inverse affine transformation circuit 270 can perform inverse affine operations more orderly.
[0046] Furthermore, the replacement box circuit 200 may further include a third register 330. The output end of the second multiplexer 280 is coupled to the output port 290 via the third register 330. Based on this, the data output by the second multiplexer 280 can be temporarily stored via the third register 330, and the encrypted data can be output in a more orderly manner.
[0047] It is understandable that the first to third registers 310 , 330 can be selectively set according to the actual use environment of the replacement box circuit 200 , and the number and position of the settings can be adjusted according to actual needs.
[0048] In one embodiment, Figure 4 As shown, the replacement box circuit 200 may further include a control circuit 410; the control circuit 410 is respectively coupled to the control end of the first multiplexer 240 and the control end of the second multiplexer 280. The control circuit 410 may perform gating control on the first multiplexer 240 and the second multiplexer 280, thereby selecting an algorithm for encrypting data.
[0049] Exemplarily, the control circuit 410 may include a processor; and a signal generator coupled to the processor. The signal generator may be a clock signal generator. The processor may be a central processing unit (CPU), a general processor, a network processor (NP), a digital signal processor (DSP), a microprocessor, a microcontroller, a programmable logic device (PLD), or any combination thereof. The processor may also be other devices with processing functions, such as circuits, devices, or software modules, which are not limited in this application.
[0050] In one embodiment, Figure 5 As shown, the first affine transformation circuit 220 includes a first multiplication circuit. The second affine transformation circuit 230 includes a second multiplication circuit 231 and a first addition circuit 232. The first inverse affine transformation circuit 260 includes a third multiplication circuit 261 and a second addition circuit 262. The second inverse affine transformation circuit 270 includes a fourth multiplication circuit 271 and a third addition circuit 272. The input end of the first multiplication circuit and the input end of the second multiplication circuit 231 are both coupled to the input port 210. The input end of the first addition circuit 232 is coupled to the output end of the second multiplication circuit 231. The output end of the first multiplication circuit is coupled to the first data input end of the first multiplexer 240. The output end of the first addition circuit 232 is coupled to the second data input end of the first multiplexer 240. The input end of the third multiplication circuit 261 and the input end of the fourth multiplication circuit 271 are both coupled to the output end of the inversion circuit 250. The input terminal of the second adding circuit 262 is coupled to the output terminal of the third multiplying circuit 261. The input terminal of the third adding circuit 272 is coupled to the output terminal of the fourth multiplying circuit 271. The output terminal of the second adding circuit 262 is coupled to the first data input terminal of the first multiplexer 240. The output terminal of the third adding circuit 272 is coupled to the second data input terminal of the first multiplexer 240.
[0051] Among them, the above-mentioned multiplication circuit and addition circuit can be implemented using independent processors, or using logic circuits with the same functions, and the embodiments of the present application do not impose specific restrictions on this.
[0052] In one embodiment, when performing affine transformation, it is performed on a Galois field (GF). The data can be transformed from a finite field (i.e., a Galois field GF (2 8 )) is mapped to the same Galois Field GF((2 2 ) 2 ) 2 Then find the inverse circuit in the Galois field GF((2 2 ) 2 ) 2 After the inverse operation is performed, the corresponding inverse affine transformation circuit performs inverse affine transformation and then outputs the result. The operation performed by the first multiplication circuit in the first affine transformation circuit 220 is as follows:
[0053] y1=Aαx;
[0054] In the above formula, y1 represents the second data output by the first affine transformation circuit 220; x represents the first data input by the input port 210; α represents the isomorphic affine transformation matrix corresponding to the AES block encryption algorithm; A represents the basic affine transformation matrix corresponding to the AES block encryption algorithm (i.e., the third affine transformation matrix).
[0055] The operation performed by the second multiplication circuit 231 and the first addition circuit 232 in the second affine transformation circuit 230 is as follows:
[0056] y2=β(Bx+W)=B1x+W1;
[0057] In the above formula, y2 represents the second data output by the second affine transformation circuit 230; x represents the first data input by the input port 210; B1 represents the first affine transformation matrix corresponding to the SM4 block cipher algorithm; W1 represents the second affine transformation matrix. Among them, B1 = βB, W1 = βW; β represents the isomorphic affine transformation matrix corresponding to the SM4 block cipher algorithm. B and W represent the basic affine transformation matrix of the SM4 block cipher algorithm.
[0058] Exemplarily, for an 8-bit input data, the first affine transformation circuit 220 can perform matrix multiplication on the data through the first multiplication circuit and then output it. The second affine transformation circuit 230 can first perform matrix multiplication on the data through the second multiplication circuit 231, and then output it through the vector addition operation performed by the first addition circuit 232. Among them, the first affine transformation circuit 220 and the second affine transformation circuit 230 perform the above operations on the Galois field GF(2). For example, an 8-bit data can be regarded as a vector under GF(2). Through the second affine transformation circuit 230, the vector can be multiplied by the corresponding 8×8-bit first affine transformation matrix to obtain a new 8-bit vector. Then, the new 8-bit vector is still subjected to vector addition operation under GF(2). Through the first affine transformation circuit 220, a new 8-bit vector can be obtained by multiplying the corresponding 8×8-bit first affine transformation matrix and then output.
[0059] It is understandable that after performing the matrix multiplication operation, the first affine transformation circuit 220 may also selectively perform the vector addition operation as required, and the embodiment of the present application does not impose any specific limitation on this.
[0060] In one embodiment, the third multiplication circuit 261 and the second addition circuit 262 in the first inverse affine transformation circuit 260 perform the following operations:
[0061] y3=Aα -1 (f(αx))+V=A1f(αx))+V;
[0062] Wherein, y3 represents the fourth data output by the first inverse affine transformation circuit 260; f() represents the inverse function; A1 represents the third inverse affine transformation matrix corresponding to the AES block cipher algorithm; wherein A1=Aα -1 . V represents the fourth inverse affine transformation matrix corresponding to the AES block cipher algorithm.
[0063] In one embodiment, the fourth multiplication circuit 271 and the third addition circuit 272 in the second inverse affine transformation circuit 270 perform the following operations:
[0064] y4=Bβ -1 (f(B1x+W1))+W=B2(f(B1x+W1))+W;
[0065] Wherein, y4 represents the fourth data output by the second inverse affine transformation circuit 270; f() represents the inverse function; B2 represents the first inverse affine transformation matrix corresponding to the SM4 block cipher algorithm; wherein B2==Bβ -1 . W can also be used as the second inverse affine transformation matrix corresponding to the SM4 block cipher algorithm.
[0066] Exemplarily, the first inverse affine transformation circuit 260 may perform a matrix multiplication operation on the data through the third multiplication circuit 261, and then perform a vector addition operation through the second addition circuit 262. The second inverse affine transformation circuit 270 may first perform a matrix multiplication operation on the data through the fourth multiplication circuit 271, and then perform a vector addition operation through the third addition circuit 272. The first inverse affine transformation circuit 260 and the second inverse affine transformation circuit 270 perform the above operations on the Galois field GF(2). For an 8-bit vector output by the inversion circuit, it can be multiplied by the first inverse affine transformation matrix to obtain a new vector; then, the new vector is vector-added with the second inverse affine transformation matrix under GF(2) to obtain the output vector.
[0067] It can be understood that although the matrix multiplication operation in the above calculation process adopts the matrix left multiplication method, the matrix right multiplication method can also be used in the actual calculation, and the embodiment of the present application does not make specific restrictions on this.
[0068] In one embodiment, Figure 6As shown, the above-mentioned replacement box circuit 200 may further include a third affine transformation circuit 610 and a third inverse affine transformation circuit 620. The input end of the third affine transformation circuit 610 is coupled to the input port 210; the output end of the third affine transformation circuit 610 is coupled to the third data input end of the first multiplexer 240. The input ends of the third inverse affine transformation circuit 620 are coupled to the output end of the inversion circuit 250. The output end of the third inverse affine transformation circuit 620 is coupled to the third data input end of the second multiplexer 280.
[0069] Exemplarily, the third affine transformation circuit 610 and the third inverse affine transformation circuit 620 may use the affine transformation circuit and the inverse affine transformation circuit corresponding to the Camellia block cipher algorithm. The third affine transformation circuit 610 may be configured to perform an isomorphic affine transformation on the finite field data to be processed by the Camellia block cipher algorithm, perform an inverse operation through the inversion circuit 250, and then restore the data to the finite field through the third inverse affine transformation circuit 620.
[0070] It is understandable that when the replacement box circuit 200 has affine transformation circuits and inverse affine transformation circuits corresponding to three different block encryption algorithms, the isomorphic affine transformation coefficients can be adjusted accordingly. Further, referring to the above method, the affine transformation circuits of other block encryption algorithms can be extended between the first multiplexer 240 and the input port 210 according to actual use requirements; at the same time, the corresponding inverse affine transformation circuit can also be extended between the second multiplexer 280 and the inversion circuit 250.
[0071] Furthermore, Figure 6 The replacement box circuit 200 can also refer to Figure 3-Figure 5 The first register 310, the second register 320 and the third register 330 are set in the manner described in the embodiment of the present application.
[0072] In one embodiment, Figure 7 As shown, the embodiment of the present application also provides an encryption method for the above-mentioned replacement box circuit 200, and the execution steps of the encryption method are as follows.
[0073] S701, input a first control signal to the first multiplexer 240 to connect the first data input terminal and the output terminal of the first multiplexer 240; and input a second control signal to the second multiplexer 280 to connect the first data input terminal and the output terminal of the second multiplexer 280.
[0074] The first multiplexer 240 and the second multiplexer 280 can be selected as a two-to-one multiplexer. When the first control signal is 0, the first data input terminal and the output terminal of the first multiplexer 240 are connected. When the second control signal is 0, the first data input terminal and the output terminal of the second multiplexer 280 are connected.
[0075] It is understandable that the first control signal and the second control signal can also be set according to actual needs, and the embodiment of the present application does not impose specific restrictions on this. For example, when the first control signal is 0, the first data input terminal of the first multiplexer 240 is connected to the output terminal. When the second control signal is 1, the first data input terminal of the second multiplexer 280 is connected to the output terminal. Alternatively, when the first control signal is 1, the first data input terminal of the first multiplexer 240 is connected to the output terminal. When the second control signal is 1, the first data input terminal of the second multiplexer 280 is connected to the output terminal. Alternatively, when the first control signal is 1, the first data input terminal of the first multiplexer 240 is connected to the output terminal. When the second control signal is 0, the first data input terminal of the second multiplexer 280 is connected to the output terminal.
[0076] S702, transform the Galois field GF(2 8 ) is mapped to the Galois Field GF((2 2 ) 2 ) 2 The first encoded data.
[0077] The first affine transformation circuit 220 can fetch instructions from the memory and execute the corresponding algorithm program, so that the first affine transformation circuit outputs the first encoded data after multiplying the input data through the third affine transformation matrix.
[0078] S703, through the inversion circuit in the Galois field GF((2 2 ) 2 ) 2 The first coded data is inverted using a normal basis to obtain second coded data.
[0079] In one embodiment, the Galois field GF ((2 2 ) 2 ) 2 The inverse calculation principle is as follows Figure 8 As shown, the Galois Field GF(2 8) is an 8-bit data X, which can be split into the upper 4-bit data X1 and the lower 4-bit data X2. Then, X1 and X2 are added together and multiplied by a fixed coefficient in a normal basis, and the result of the 4-bit normal basis multiplication with X1 and X2 is further added together. 2 ) 2 Next, the result of the second addition operation is further inverted. Then the result of the inversion operation is multiplied with X1 and X2 by a 4-bit normal basis to obtain the upper 4-bit data Y1 and the lower 4-bit data Y2. Finally, Y1 and Y2 are combined to obtain the second coded data Y.
[0080] Among them, the principle of 4-bit normal basis multiplication operation is as follows Fig. 9 As shown. When performing a 4-bit normal basis multiplication operation, the two 4-bit input data X and Y can be split into two 2-bit data respectively. Among them, X can be split into the upper 2-bit XH and the lower 2-bit XL; Y can be split into the upper 2-bit YH and the lower 2-bit YL. Secondly, perform a 2-bit normal basis multiplication operation on XH and YH to obtain the operation result A1; perform a 2-bit normal basis multiplication operation on XL and YL to obtain the operation result A2; at the same time, XH and XL can be added and then perform a 2-bit normal basis multiplication operation with the addition result of YH and YL to obtain the operation result A3. Then, A3 is multiplied by a multiplication coefficient and added to A1 and A2 respectively to obtain the upper 2-bit data Zh and the lower two bits of data Zl. Finally, Zh and Zl are combined into 4-bit data Z.
[0081] Furthermore, Galois Field GF(2 2 ) 2 The inverse operation principle is as follows Fig.10 As shown in the figure, a 4-bit input data can be split into the upper 2-bit data x1 and the lower 2-bit data x2. Then, x1 and x2 are added together and multiplied by a fixed coefficient in a normal basis, and the result of the 2-bit normal basis multiplication with x1 and x2 is further added together. 2 ) The result of the second addition operation is further inverted. Then the result of the inversion operation is multiplied with x1 and x2 by a 2-bit normal basis to obtain the upper 2-bit data y1 and the lower 2-bit data y2. Finally, y1 and y2 are combined to obtain 4-bit encoded data y.
[0082] Among them, the principle of 2-bit normal basis multiplication operation is as follows Fig.11As shown. When performing a 2-bit normal basis multiplication operation, the two 2-bit input data x and y can be split into two 1-bit data respectively. Among them, x can be split into the upper 1-bit xH and the lower 1-bit xL; y can be split into the upper 1-bit yH and the lower 1-bit yL. Secondly, perform a multiplication operation on xH and yH to obtain the operation result a1; perform a multiplication operation on xL and yL to obtain the operation result a2; at the same time, xH and xL can be added and then multiplied with the addition result of yH and yL to obtain the operation result a3. Then, a3 is multiplied by a multiplication coefficient and added to a1 and a2 respectively to obtain the upper 1-bit data zh and the lower two bits of data zl. Finally, zh and zl are combined into 2-bit data z.
[0083] In the above implementation process, the inversion circuit 250 can select various commonly used inversion operation circuits or use an independent processor to perform the inversion operation, and the embodiment of the present application does not make any specific restrictions on this.
[0084] Furthermore, in order to ensure that the inversion circuit 250 can perform the inversion operation in a more orderly manner in a high-speed processing environment, the second data may be temporarily stored in the first register 310 and then transmitted to the inversion circuit 250 .
[0085] By the above method, the Galois field GF((2 2 ) 2 ) 2 The inverse operation is performed on the normal basis, which reduces the complexity of the operation and improves the efficiency of the inverse operation; at the same time, the Galois field GF(2 8 ) and the coded data on the Galois Field GF((2 2 ) 2 ) 2 There is an obvious difference in the format of the encoded data on the inversion circuit. By detecting the format of the encoded data output by the inversion circuit, the encoding method of the inversion circuit can be determined.
[0086] S704, inversely map the second coded data into a Galois field GF(2 8 )’s first encrypted data.
[0087] In order to ensure that the first inverse affine transformation circuit 260 can restore the data after the inverse operation in a more orderly manner in a high-speed processing environment, the third data can also be temporarily stored in the second register 320 and then transmitted to the first inverse affine transformation circuit 260.
[0088] Furthermore, in order to output the encrypted data in an orderly manner under a high-speed processing environment, the encrypted data may be temporarily stored in the second register 320 before being output.
[0089] In one embodiment, Fig.12 As shown, the embodiment of the present application also provides an encryption method for the above-mentioned replacement box circuit 200, and the execution steps of the encryption method are as follows.
[0090] S801, input a first control signal to the first multiplexer 240 to connect the second data input terminal and the output terminal of the first multiplexer 240; and input a second control signal to the second multiplexer 280 to connect the second data input terminal and the output terminal of the second multiplexer 280.
[0091] The first multiplexer 240 and the second multiplexer 280 can be selected as a two-to-one multiplexer. When the first control signal is 1, the second data input terminal and the output terminal of the first multiplexer 240 are connected. When the second control signal is 1, the second data input terminal and the output terminal of the second multiplexer 280 are connected.
[0092] It is understandable that the first control signal and the second control signal can also be set according to actual needs, and the embodiment of the present application does not specifically limit this. For example, when the first control signal is 0, the second data input terminal of the first multiplexer 240 is connected to the output terminal. When the second control signal is 1, the second data input terminal of the second multiplexer 280 is connected to the output terminal. Alternatively, when the first control signal is 1, the second data input terminal of the first multiplexer 240 is connected to the output terminal. When the second control signal is 0, the second data input terminal of the second multiplexer 280 is connected to the output terminal. Alternatively, when the first control signal is 0, the second data input terminal of the first multiplexer 240 is connected to the output terminal. When the second control signal is 0, the second data input terminal of the second multiplexer 280 is connected to the output terminal.
[0093] Further, when the number of affine transformation circuits and inverse affine transformation circuits is expanded, the types of the first multiplexer 240 and the second multiplexer 280 may also be adjusted according to the number of affine transformation circuits and inverse affine transformation circuits.
[0094] S802, transform the Galois field GF(2 8 ) is mapped to the Galois Field GF((2 2 ) 2 ) 2 The third encoded data.
[0095] The second affine transformation circuit 230 can fetch instructions from the memory and execute the corresponding algorithm program, thereby multiplying the input data by the first affine transformation matrix, adding the input data with the second affine transformation matrix, and outputting third encoded data.
[0096] S803, through the inversion circuit in the Galois field GF((2 2 ) 2 ) 2 The third coded data is inversely operated using a normal basis to obtain fourth coded data.
[0097] Among them, the inversion circuit 250 can select various commonly used inversion operation circuits or use an independent processor to perform the inversion operation, and the embodiment of the present application does not make any specific restrictions on this.
[0098] Furthermore, in order to ensure that the inversion circuit 250 can perform the inversion operation in a more orderly manner in a high-speed processing environment, the second data may be temporarily stored in the first register 310 and then transmitted to the inversion circuit 250 .
[0099] S804, inversely map the fourth coded data into a Galois field GF(2 8 )’s second encrypted data.
[0100] In order to ensure that the second inverse affine transformation circuit 270 can restore the data after the inverse operation in a more orderly manner in a high-speed processing environment, the third data can also be temporarily stored in the second register 320 and then transmitted to the first inverse affine transformation circuit 260.
[0101] Furthermore, in order to output the encrypted data in an orderly manner under a high-speed processing environment, the encrypted data may be temporarily stored in the second register 320 before being output.
[0102] It can be understood that when the replacement box circuit 200 also includes a third affine transformation circuit 610 and a third inverse affine transformation circuit 620, the input data can be encrypted in accordance with the above method, which is not elaborated in the embodiment of the present application.
[0103] In one embodiment, the present application also provides an electronic device, which includes a circuit board and the above-mentioned replacement box circuit 200 arranged on the circuit board. Exemplarily, the electronic device can be a replacement box S-Box, a communication device, a computer or other electronic devices that need to be provided with the above-mentioned replacement box circuit.
[0104] In one embodiment, the present application also provides a computer-readable storage medium, in which computer program instructions are stored, and when the computer program instructions are executed by the processor, the calculation method performed by each affine transformation circuit, each inverse affine transformation circuit, and the inversion circuit 250 can be implemented. Exemplarily, the computer-readable storage medium can be a read-only memory (ROM), a random access memory (RAM), a compact disc read-only memory (CD-ROM), a magnetic tape, a floppy disk, a USB flash drive, an optical data storage device, etc.
[0105] Through the description of the above implementation methods, technical personnel in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0106] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0107] The units described as separate components may or may not be physically separated, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0108] In addition, each functional module in each embodiment of the present application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of software functional unit.
[0109] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to enable a device, such as a single-chip microcomputer, a replacement box circuit, etc., or a processor (processor) to execute all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard drives, ROM, RAM, disks, or optical disks.
[0110] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A replacement box circuit, It is characterized in that include: An input port, a first affine transformation circuit, a second affine transformation circuit, a first multiplexer, an inversion circuit, a first inverse affine transformation circuit, a second inverse affine transformation circuit, a second multiplexer, and an output port; An input terminal of the first affine transformation circuit and an input terminal of the second affine transformation circuit are both coupled to the input port; an output terminal of the first affine transformation circuit is coupled to a first data input terminal of the first multiplexer; An output terminal of the second affine transformation circuit is coupled to a second data input terminal of the first multiplexer; The input end of the inversion circuit is coupled to the output end of the first multiplexer; the input end of the first inverse affine transformation circuit and the input end of the second inverse affine transformation circuit are both coupled to the output end of the inversion circuit; The output terminal of the first inverse affine transformation circuit is coupled to the first data input terminal of the second multiplexer; the output terminal of the second inverse affine transformation circuit is coupled to the second data input terminal of the second multiplexer; the output terminal of the second multiplexer is coupled to the output port; The input data of the input port is a Galois field GF(2 8 ) of the original data; the output of the first multiplexer is the Galois field GF((2 2 ) 2 ) 2 The output of the inversion circuit is in the Galois field GF((2 2 ) 2 ) 2 The output data of the output port is the Galois field GF(2 8 )’s encrypted data.
2. The replacement box circuit according to claim 1, It is characterized in that Also included: a third affine transformation circuit and a third inverse affine transformation circuit; An input terminal of the third affine transformation circuit is coupled to the input port; an output terminal of the third affine transformation circuit is coupled to a third data input terminal of the first multiplexer; The input terminals of the third inverse affine transformation circuit are coupled to the output terminals of the inversion circuit; the output terminals of the third inverse affine transformation circuit are coupled to the third data input terminals of the second multiplexer.
3. A replacement box circuit according to claim 1 or 2, It is characterized in that Also includes: First register; An input terminal of the inversion circuit is coupled to an output terminal of the first multiplexer through the first register.
4. The replacement box circuit according to any one of claims 1 to 3, It is characterized in that Also includes: Second register; An input terminal of the first inverse affine transformation circuit and an input terminal of the second inverse affine transformation circuit are both coupled to an output terminal of the inversion circuit through the second register.
5. The replacement box circuit according to any one of claims 1 to 4, It is characterized in that Also includes: The third register; The output terminal of the second multiplexer is coupled to the output port through the third register.
6. The replacement box circuit according to any one of claims 1 to 5, It is characterized in that The first affine transformation circuit includes a first multiplication circuit; the second affine transformation circuit includes a second multiplication circuit and a first addition circuit; the first inverse affine transformation circuit includes a third multiplication circuit and a second addition circuit; the second inverse affine transformation circuit includes a fourth multiplication circuit and a third addition circuit; The input end of the first multiplication operation circuit and the input end of the second multiplication operation circuit are both coupled to the input port; the input end of the first addition operation circuit is coupled to the output end of the second multiplication operation circuit; The output terminal of the first multiplication operation circuit is coupled to the first data input terminal of the first multiplexer; the output terminal of the first addition operation circuit is coupled to the second data input terminal of the first multiplexer; The input end of the third multiplication operation circuit and the input end of the fourth multiplication operation circuit are both coupled to the output end of the inversion circuit; the input end of the second addition operation circuit is coupled to the output end of the third multiplication operation circuit; the input end of the third addition operation circuit is coupled to the output end of the fourth multiplication operation circuit; The output terminal of the second adding circuit is coupled to the first data input terminal of the first multiplexer; the output terminal of the third adding circuit is coupled to the second data input terminal of the first multiplexer.
7. The replacement box circuit according to any one of claims 1 to 6, It is characterized in that Also includes: Control circuit; The control circuit is coupled to a control terminal of the first multiplexer and a control terminal of the second multiplexer respectively.
8. An encryption method, applied to the replacement box circuit according to any one of claims 1 to 7, It is characterized in that The method comprises: Inputting a first control signal to the first multiplexer to connect the first data input terminal and the output terminal of the first multiplexer; and inputting a second control signal to the second multiplexer to connect the first data input terminal and the output terminal of the second multiplexer; The Galois field GF(2 8 ) is mapped to the Galois Field GF((2 2 ) 2 ) 2 first coded data of; By inverting the circuit in the Galois field GF((2 2 ) 2 ) 2 performing an inverse operation on the first coded data using a normal basis to obtain second coded data; The second coded data is inversely mapped into a Galois field GF(2 8 )’s first encrypted data.
9. The method according to claim 8, It is characterized in that The method further comprises: Inputting a third control signal to the first multiplexer to connect the second data input terminal and the output terminal of the first multiplexer; and inputting a fourth control signal to the second multiplexer to connect the second data input terminal and the output terminal of the second multiplexer; The Galois field GF(2 8 ) is mapped to the Galois Field GF((2 2 ) 2 ) 2 The third coded data of By inverting the circuit in the Galois field GF((2 2 ) 2 ) 2 performing an inverse operation on the third coded data using a normal basis to obtain fourth coded data; The fourth coded data is inversely mapped into a Galois field GF(2 8 )’s second encrypted data.
10. The method according to claim 9, It is characterized in that The second affine transformation circuit performs multiplication operation on the input data by the first affine transformation matrix, performs addition operation with the second affine transformation matrix, and outputs the third encoded data; The second inverse affine transformation circuit multiplies the fourth encoded data by the first inverse affine transformation matrix, adds the fourth encoded data to the second inverse affine matrix, and outputs the second encrypted data.
11. The method according to any one of claims 8 to 10, It is characterized in that The first affine transformation circuit performs a multiplication operation on the input data by a third affine transformation matrix and outputs the first encoded data; The first inverse affine transformation circuit multiplies the first encoded data by a third inverse affine transformation matrix, adds the matrix to a fourth inverse affine matrix, and outputs the first encrypted data.
12. An electronic device, It is characterized in that The electronic device comprises a circuit board and a replacement box circuit according to any one of claims 1 to 7 arranged on the circuit board.
