Method and device for switching multiple encryption and decryption modes based on software definition

The software-defined method uses the IIC protocol to control the multiplexer to achieve switching between ECB, CBC, CTR, CFB and OFB modes, solving the problems of inflexibility and large resource occupation of the existing encryption and decryption system, and improving the flexibility of encryption and decryption. performance and resource efficiency.

CN118523902AInactive Publication Date: 2024-08-20ZHEJIANG LAB

Patent Information

Application Number
CN202410977696.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-22
Publication Date
2024-08-20
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The existing encryption and decryption system is not flexible enough in usage scenarios, and takes up too much resources, making it difficult to support flexible switching of multiple encryption and decryption modes.

Method used

Use a software-defined method to control the IIC SLAVE and IIC MASTER modules through the IIC protocol, and configure the multiplexer to switch five encryption and decryption modes, including ECB, CBC, CTR, CFB and OFB, to achieve data encryption and decryption and reduce resource occupation.

Benefits of technology

It improves the flexibility and resource utilization efficiency of encryption and decryption modes, supports the switching of multiple modes, and ensures the security and accuracy of data transmission.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118523902A_ABST
    Figure CN118523902A_ABST
Patent Text Reader

Abstract

The invention provides a method and a device for switching multiple encryption and decryption modes based on software definition, the system comprises an encryption module and a decryption module, the encryption module comprises a multipath selection module, an encryption module, a decryption module, a counter module, an initialization vector module and a configuration module, the multi-path selection module selects to convert multiple inputs into one or two outputs, the encryption module is responsible for converting plaintext data into ciphertext data, the decryption module is responsible for converting the ciphertext data into the plaintext data, the counter module is responsible for counting and is used for CTR mode encryption and decryption, and the initialization vector module is used for initializing calculation parameters of encryption and decryption. The configuration module is connected with the multiplexers and is responsible for configuring the multiplexers. According to the method, five different encryption and decryption modes are switched by adopting a software definition mode, so that the flexibility of encryption and decryption is improved, and the use of FPGA (Field Programmable Gate Array) resources is reduced; and an FPGA chip is adopted, so that the accuracy, the real-time performance and the reliability of data transmission are ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of control, and in particular to a method and device for switching multiple encryption and decryption modes based on software definition. Background Art

[0002] At present, security systems often require multiple encryption modes, but current designs often implement encryption and decryption algorithms of various modes independently in the system. In order to solve the problem that the existing encryption and decryption usage scenarios are not flexible enough and occupy too much resources, the present invention proposes that it can be implemented through the following methods: It uses the commonly used IIC protocol for control and consists of IIC SLAVE and IIC MASTER modules. The software sends IIC protocol messages through the IICMASTER module. The IIC SLAVE module receives the IIC message and parses the configured value and configures it to each module. This greatly improves the flexibility of encryption and decryption.

[0003] It supports flexible switching of 5 commonly used modes of encryption and decryption, including ECB encryption and decryption, CBC encryption and decryption, CTR encryption and decryption, CFB encryption and decryption, and OFB encryption and decryption. It solves the problem of excessive resource usage in security scenarios.

[0004] There are five commonly used encryption and decryption modes: ECB mode (Electronic CodeBook mode), CBC mode (Cipher Block Chaining mode), CFB mode (CipherFeedBack mode), OFB mode (Output FeedBack mode), and CTR mode (CounTeR mode).

[0005] ECB mode encryption, after grouping plaintext, directly encrypts it into ciphertext groups. ECB mode decryption, after grouping ciphertext, directly decrypts it into plaintext groups. When the content of the last plaintext group is less than the group length, it needs to be padded with some specific data.

[0006] In CBC mode encryption, the plaintext is first grouped and then XORed with the previous ciphertext group, and then encrypted. In CBC mode decryption, the ciphertext is first grouped and then decrypted and then XORed with the previous ciphertext group.

[0007] In CFB mode encryption, the result of the encryption of the previous ciphertext block is XORed with the next plaintext block. In CFB mode decryption, the result of the encryption of the previous ciphertext block is XORed with the next ciphertext block.

[0008] OFB mode encryption, through multiple encryption of the initialization vector and the plaintext group XOR. OFB mode decryption, through multiple encryption of the initialization vector and the ciphertext group XOR.

[0009] CTR mode encryption, the bit sequence encrypted by the counter is XORed with the plaintext group. CTR mode decryption, the bit sequence encrypted by the counter is XORed with the ciphertext.

[0010] Currently, encryption and decryption only support one or two modes, which limits the usage scenarios. As encryption and decryption scenarios become more complex, there are greater requirements for flexible switching of encryption and decryption modes. At the same time, the more encryption and decryption modes are supported, the greater the requirements are for reducing the amount of resources. Summary of the invention

[0011] In view of the shortcomings of the prior art and in order to solve the problems of inflexibility and excessive resource occupation in the existing encryption and decryption usage scenarios, the present invention proposes a method and device for switching multiple encryption and decryption modes based on software definition. The specific technical solution of the present invention is as follows: A first aspect of the present invention provides a method for switching between multiple encryption and decryption modes based on software definition, comprising the following steps: (1) Select and switch between multiple encryption and decryption modes by configuring each multiplexer; (2) Encrypt data into garbled code to ensure the security of data transmission; (3) Decrypting the data encrypted in step (2) to restore the garbled data to the normal data required by the user; (4) Select two data paths from the multiple input data paths to calculate and initialize the calculation parameters of the encryption and decryption CTR mode.

[0012] Specifically, the configuration is a slave control bus IIC SLAVE module and a master control bus IIC MASTER module. After receiving the IIC message, the slave control bus IIC SLAVE parses it and configures it into each module.

[0013] Specifically, there are five encryption and decryption modes, including ECB mode, CBC mode, CTR mode, CFB mode and OFB mode; free switching of the five encryption and decryption modes of ECB mode, CBC mode, CTR mode, CFB mode and OFB mode is achieved through different configurations; the ECB mode uses KEY to encrypt and decrypt each group of plaintext, and after completion, the groups are connected together in sequence, and the groups will not affect each other during the encryption and decryption process; the CBC mode uses an initialization vector and a first group of plaintext for XOR operation, and then encrypts the XOR result using a key to obtain a first group of ciphertext, and uses the first group of ciphertext as the initialization vector for the second group of operations, repeats the operation, and finally obtains the ciphertext; the CTR mode uses The key encrypts the counter, and XORs the encrypted result with the first group of plaintext to obtain the first group of ciphertext. After the XOR is completed, the counter is incremented to finally obtain the ciphertext; in the CFB mode, the initialization vector is encrypted and XORed with the first group of plaintext to obtain the first group of ciphertext, and the first group of ciphertext is used as the initialization vector for the second group of plaintext operation, and the ciphertext is obtained after repeated operation; in the OFB mode, the result of encrypting the initialization vector once is XORed with the first group of plaintext to obtain the first group of ciphertext, the result of encrypting the initialization vector twice is XORed with the second group of plaintext to obtain the second group of ciphertext, the result of encrypting the initialization vector three times is XORed with the third group of plaintext to obtain the third group of ciphertext, the result of encrypting the initialization vector four times is XORed with the fourth group of plaintext to obtain the fourth group of ciphertext, and finally all the ciphertext groups are sequentially spliced ​​to obtain the ciphertext.

[0014] Specifically, the mode of the counter is: the initial value of the counter of group 1 is 0, and the counter increases by 1 after each group is calculated; the initial value of the counter of group 2 is 1, and the counter increases by 1 after each group is calculated; the initial value of the counter of group 3 is 2, and the counter increases by 1 after each group is calculated; the initial value of the counter of group 4 is 3, and the counter increases by 1 after each group is calculated.

[0015] Specifically, the multiple encryption and decryption mode switches include separate switching of encryption mode and decryption mode.

[0016] Specifically, the multiplexers include: a four-to-two multiplexer, a two-to-one multiplexer and a six-to-two multiplexer; the multiplexers MUX1, MUX2, MUX3, and MUX4 are all four-to-two selectors, and the multiplexers MUX5, MUX6, MUX7, MUX8, MUX9, MUX10, MUX11, MUX12, MUX13, MUX4, and MUX15 are all two-to-one selectors; the multiplexers MUX1, MUX2, MUX3, and MUX4 are all six-to-two selectors, and the multiplexers MUX5, MUX6, MUX7, MUX8, MUX9, MUX10, MUX11, and MUX12 are all two-to-one selectors.

[0017] Furthermore, the data in step (2) is the message data received by the input port, and its data length is 128 bits, which is divided into 4 groups, each with 32 bits. When the last data is less than 32 bits, it needs to be filled with 0.

[0018] The second aspect of the present invention: a device for switching multiple encryption and decryption modes based on software definition, comprising: a configuration module, an encryption module, a decryption module, a multi-way selection module, a counter module and an initialization vector module; The configuration module is controlled by adopting the IIC protocol, and then configures each multiplexer to select and switch multiple encryption and decryption modes; The encryption module is used to encrypt data into garbled code to ensure the security of data transmission; The decryption module is used to restore the garbled data into normal data required by the user; The multi-channel selection module is used to select 1-channel or 2-channel data from the multi-channel input data to perform subsequent operations; The counter module is used to encrypt and decrypt the calculation parameters of the CTR mode; The initialization vector module is used to initialize calculation parameters for encryption and decryption.

[0019] A third aspect of the present invention: an electronic device, comprising: one or more processors; A memory for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the method for switching between multiple encryption and decryption modes based on software definition.

[0020] The fourth aspect of the present invention: a computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the steps of a method for switching between multiple encryption and decryption modes based on software definition.

[0021] The beneficial effects of the present invention are as follows: the present invention uses a symmetric algorithm for encryption and decryption, and is applicable to the AES algorithm, the DES algorithm, etc., and adopts five commonly used encryption and decryption modes, namely, the ECB mode, the CTR mode, the CBC mode, the CFB mode, and the OFB mode. The traditional IIC interface can realize independent reading and writing of multiple address segments, and supports deterministic data transmission. The flexibility of encryption and decryption is greatly improved, and the use of FPGA resources is also reduced; the FPGA chip is used to ensure the accuracy, real-time and reliability of data transmission. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] Figure 1It is a schematic diagram of switching multiple encryption modes based on software definition of the present invention; Figure 2 It is a schematic diagram of switching multiple decryption modes based on software definition of the present invention; Figure 3 It is a schematic diagram of ECB mode encryption of the present invention; Figure 4 It is a schematic diagram of ECB mode decryption of the present invention; Figure 5 It is a schematic diagram of CBC mode encryption of the present invention; Figure 6 It is a schematic diagram of CBC mode decryption of the present invention; Figure 7 It is a schematic diagram of CTR mode encryption of the present invention; Figure 8 It is a schematic diagram of CTR mode decryption of the present invention; Fig. 9 It is a schematic diagram of CFB mode encryption of the present invention; Fig.10 It is a schematic diagram of CFB mode decryption of the present invention; Fig.11 It is a schematic diagram of OFB mode encryption of the present invention; Fig.12 It is a schematic diagram of OFB mode decryption of the present invention. DETAILED DESCRIPTION

[0023] In order to make the purpose, technical scheme and technical effect of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and preferred embodiments. It should be understood that the specific implementation methods described herein are only used to explain the present invention and are not used to limit the present invention.

[0024] like Figure 1 and Figure 2As shown, the method for switching encryption and decryption modes based on software definition of the present invention includes: a software configuration module, an encryption module, a decryption module, a multi-way selection module, a counter module and an initialization vector module, wherein the configuration module selects and switches multiple encryption and decryption modes by configuring each multi-way selector, the encryption module is used to encrypt data into garbled code to ensure the security of data transmission, the multi-way selection module is used to select 1 or 2 channels of data from multiple input data to perform subsequent operations, the counter module is used to calculate parameters of the encryption and decryption CTR mode, and the initialization vector module is used to initialize the calculation parameters of encryption and decryption. The configuration module adopts the commonly used IIC protocol for control, and is composed of IIC SLAVE and IIC MASTER modules. The software sends IIC protocol messages through the IIC MASTER module, and the IIC SLAVE module receives the IIC message and parses the configured value, and configures it to each module.

[0025] The IIC message format is that when an IIC transmission is performed, the START signal indicates the start of the current data transmission, and the STOP signal indicates the end of the current data transmission. Each transmission in the IIC transmission format is based on 8 bits as a basic transmission unit; The encryption module supports all symmetric encryption algorithms, such as AES encryption algorithm, DES encryption algorithm, SM4 encryption algorithm, 3DES encryption algorithm, etc. The configuration of the encryption algorithm is configured by the software definition module. The encryption process uses symmetric encryption. Symmetric encryption means that both parties to the encryption hold the same key, that is, the encryption party performs the encryption process through the key. Because both parties hold the same key, it is called symmetric encryption.

[0026] The decryption module supports all symmetric decryption algorithms, such as AES decryption algorithm, DES decryption algorithm, SM4 decryption algorithm, 3DES decryption algorithm, etc. The configuration of the decryption algorithm is configured by the software definition module. The decryption process uses symmetric decryption. Symmetric decryption means that both parties to the encryption hold the same private key, that is, the decryption party performs the decryption process through the key. Because both parties hold the same key, it is called symmetric decryption.

[0027] The multi-way selection module is as follows Figure 1 and Figure 2 As shown, in Figure 1 In the encryption diagram, multiplexers MUX1, MUX2, MUX3, and MUX4 are all four-to-two selectors, and multiplexers MUX5, MUX6, MUX7, MUX8, MUX9, MUX10, MUX11, MUX12, MUX13, MUX4, and MUX15 are all two-to-one selectors. Figure 2In the decryption diagram, multiplexers MUX1, MUX2, MUX3, and MUX4 are all six-to-two selectors, and multiplexers MUX5, MUX6, MUX7, MUX8, MUX9, MUX10, MUX11, and MUX12 are all two-to-one selectors.

[0028] In the counter module, the initial value of the counter of group 1 is 0, and the counter increases by 1 after each group is calculated; the initial value of the counter of group 2 is 1, and the counter increases by 1 after each group is calculated; the initial value of the counter of group 3 is 2, and the counter increases by 1 after each group is calculated; the initial value of the counter of group 4 is 3, and the counter increases by 1 after each group is calculated.

[0029] The software switching steps of the multiple encryption modes are as follows: The input plaintext is 128 bits, which are first divided into 4 groups, each of which is 32 bits, namely plaintext group 1, plaintext group 2, plaintext group 3, and plaintext group 4. When the plaintext length is not an integer multiple of 32 bits, it is necessary to fill 0 at the end to reach an integer multiple of 32 bits to make it a full block length.

[0030] like Figure 3 As shown, ECB mode encryption: use software configuration to select input 2 for multiplexer MUX5, and select input 2 for multiplexer MUX12. At this time, the data of plaintext group 1 is directly encrypted to generate ciphertext group 1; select input 2 for multiplexer MUX7, and select input 2 for multiplexer MUX13. At this time, the data of plaintext group 2 is directly encrypted to generate ciphertext group 2; select input 2 for multiplexer MUX9, and select input 2 for multiplexer MUX14. At this time, the data of plaintext group 3 is directly encrypted to generate ciphertext group 3; select input 2 for multiplexer MUX11, and select input 2 for multiplexer MUX15. At this time, the data of plaintext group 4 is directly encrypted to generate ciphertext group 4.

[0031] like Figure 7As shown, CTR mode encryption: use software configuration to select inputs 3 and 4 of multiplexer MUX1, and select input 1 of multiplexer MUX12. At this time, the encrypted result of counter 0 is XORed with plaintext group 1 to obtain ciphertext group 1; select inputs 3 and 4 of multiplexer MUX2, and select input 1 of multiplexer MUX13. At this time, the encrypted result of counter 1 is XORed with plaintext group 2 to obtain ciphertext group 2; select inputs 3 and 4 of multiplexer MUX3, and select input 1 of multiplexer MUX14. At this time, the encrypted result of counter 2 is XORed with plaintext group 3 to obtain ciphertext group 3; select inputs 3 and 4 of multiplexer MUX4, and select input 1 of multiplexer MUX15. At this time, the encrypted result of counter 3 is XORed with plaintext group 4 to obtain ciphertext group 4.

[0032] like Figure 5 As shown, CBC mode encryption: use software configuration to select inputs 1 and 4 for multiplexer MUX1, select input 1 for multiplexer MUX5, select input 2 for multiplexer MUX12, then plaintext group 1 is XORed with the initialization vector, and the XORed result is encrypted to obtain ciphertext group 1; select input 2 for multiplexer MUX6, select inputs 1 and 4 for multiplexer MUX2, select input 1 for multiplexer MUX7, and select input 2 for multiplexer MUX13, then plaintext group 2 is XORed with ciphertext group 1, and the XORed result is encrypted to obtain ciphertext group 2; Select input 2 for multiplexer MUX8, select input 1 and 4 for multiplexer MUX3, select input 1 for multiplexer MUX9, select input 2 for multiplexer MUX14, then XOR plaintext group 3 with ciphertext group 2, encrypt the XOR result to obtain ciphertext group 3; select input 2 for multiplexer MUX10, select input 1 and 4 for multiplexer MUX4, select input 1 for multiplexer MUX11, select input 2 for multiplexer MUX15, then XOR plaintext group 4 with ciphertext group 3, encrypt the XOR result to obtain ciphertext group 4.

[0033] like Fig. 9As shown, CFB mode encryption: use software configuration to select inputs 2 and 4 for multiplexer MUX1, and select input 1 for multiplexer MUX12. At this time, the encrypted result of the initialization vector is XORed with plaintext group 1 to obtain ciphertext group 1; select input 1 for multiplexer MUX6, select input 1 and 4 for multiplexer MUX2, and select input 1 for multiplexer MUX13. At this time, the encryption result of ciphertext group 1 is different from plaintext group 2 or ciphertext group 2 is obtained; select input 1 for multiplexer MUX8, select input 1 and 4 for multiplexer MUX3, and select input 1 for multiplexer MUX14. At this time, the encryption result of ciphertext group 2 is different from plaintext group 3 or ciphertext group 3 is obtained; select input 1 for multiplexer MUX10, select input 1 and 4 for multiplexer MUX4, and select input 1 for multiplexer MUX15. At this time, the encryption result of ciphertext group 3 is different from plaintext group 4 or ciphertext group 4 is obtained.

[0034] like Fig.11 As shown, OFB mode encryption: use software configuration to select inputs 4 and 2 for multiplexer MUX1, and select input 1 for multiplexer MUX12. At this time, the result of initialization vector encryption is XORed with plaintext group 1 to obtain ciphertext group 1; select inputs 2 and 4 for multiplexer MUX2, and select input 1 for multiplexer MUX13. At this time, the result of initialization vector encryption twice is XORed with plaintext group 2 to obtain ciphertext group 2; select inputs 2 and 4 for multiplexer MUX3, and select input 1 for multiplexer MUX14. At this time, the result of initialization vector encryption three times is XORed with plaintext group 3 to obtain ciphertext group 3; select inputs 2 and 4 for multiplexer MUX4, and select input 1 for multiplexer MUX15. At this time, the result of initialization vector encryption four times is XORed with plaintext group 4 to obtain ciphertext group 4.

[0035] The software switching steps of the multiple decryption modes are as follows: The input ciphertext is 128 bits, which is first divided into 4 groups, each with 32 bits, namely plaintext group 1, plaintext group 2, plaintext group 3, and plaintext group 4.

[0036] like Figure 4As shown, ECB mode decryption: use software configuration to select input 2 for multiplexer MUX5, and select input 2 for multiplexer MUX9. At this time, the data of ciphertext group 1 is directly decrypted to generate plaintext group 1; select input 2 for multiplexer MUX6, and select input 2 for multiplexer MUX10. At this time, the data of ciphertext group 2 is directly decrypted to generate plaintext group 2; select input 2 for multiplexer MUX7, and select input 2 for multiplexer MUX11. At this time, the data of ciphertext group 3 is directly decrypted to generate plaintext group 3; select input 2 for multiplexer MUX8, and select input 2 for multiplexer MUX12. At this time, the data of ciphertext group 4 is directly decrypted to generate plaintext group 4.

[0037] like Figure 8 As shown, CTR mode decryption: use software configuration to select inputs 4 and 5 of multiplexer MUX1, and select input 1 of multiplexer MUX9. At this time, counter 0 is encrypted and XORed with ciphertext group 1 to obtain plaintext group 1; select inputs 4 and 5 of multiplexer MUX2, and select input 1 of multiplexer MUX10. At this time, counter 1 is encrypted and XORed with ciphertext group 2 to obtain plaintext group 2; select inputs 4 and 5 of multiplexer MUX3, and select input 1 of multiplexer MUX11. At this time, counter 2 is encrypted and XORed with ciphertext group 3 to obtain plaintext group 3; select inputs 4 and 5 of multiplexer MUX4, and select input 1 of multiplexer MUX12. At this time, counter 3 is encrypted and XORed with ciphertext group 4 to obtain plaintext group 4.

[0038] like Figure 6 As shown, CBC mode decryption: use software configuration to select inputs 3 and 6 for multiplexer MUX1, and select input 1 for multiplexer MUX9. At this time, the decryption result of ciphertext group 1 is XORed with the initialization vector to obtain plaintext group 1; select inputs 1 and 6 for multiplexer MUX2, and select input 1 for multiplexer MUX10. At this time, the decryption result of ciphertext group 2 is XORed with the ciphertext group to obtain plaintext group 2; select inputs 1 and 6 for multiplexer MUX3, and select input 1 for multiplexer MUX11. At this time, the decryption result of ciphertext group 3 is XORed with ciphertext group 2 to obtain plaintext group 3; select inputs 1 and 6 for multiplexer MUX4, and select input 1 for multiplexer MUX12. At this time, the decryption result of ciphertext group 4 is XORed with ciphertext group 3 to obtain plaintext group 4.

[0039] like Fig.10As shown, CFB mode decryption: use software configuration to select inputs 2 and 5 for multiplexer MUX1, and select input 1 for multiplexer MUX9. At this time, the result of decryption of the initialization vector is XORed with the ciphertext group 1 to obtain plaintext group 1; select inputs 2 and 5 for multiplexer MUX2, and select input 1 for multiplexer MUX10. At this time, the result of decryption of ciphertext group 1 is XORed with the ciphertext group 2 to obtain plaintext group 2; select inputs 2 and 5 for multiplexer MUX3, and select input 1 for multiplexer MUX11. At this time, the result of decryption of ciphertext group 2 is XORed with the ciphertext group 3 to obtain plaintext group 3; select inputs 2 and 5 for multiplexer MUX4, and select input 1 for multiplexer MUX12. At this time, the result of decryption of ciphertext group 3 is XORed with the ciphertext group 4 to obtain plaintext group 4.

[0040] like Fig.12 As shown, OFB mode decryption: use software configuration to select inputs 1 and 5 of multiplexer MUX1, and select input 1 of multiplexer MUX9. At this time, the result of the initialization vector encrypted once is XORed with the ciphertext group 1 to obtain plaintext group 1; select inputs 3 and 5 of multiplexer MUX2, and select input 1 of multiplexer MUX10. At this time, the result of the initialization vector after two encryptions is XORed with the ciphertext group 2 to obtain plaintext group 2; select inputs 3 and 5 of multiplexer MUX3, and select input 1 of multiplexer MUX11. At this time, the result of the initialization vector after three encryptions is XORed with the ciphertext group 3 to obtain plaintext group 3; select inputs 3 and 5 of multiplexer MUX4, and select input 1 of multiplexer MUX12. At this time, the result of the initialization vector after four encryptions is XORed with the ciphertext group 4 to obtain plaintext group 4.

[0041] The present invention further provides a device for switching multiple encryption and decryption modes based on software definition, comprising: a configuration module, an encryption module, a decryption module, a multi-way selection module, a counter module and an initialization vector module; The configuration module is controlled by adopting the IIC protocol, and then configures each multiplexer to select and switch multiple encryption and decryption modes; The encryption module is used to encrypt data into garbled code to ensure the security of data transmission; The decryption module is used to restore the garbled data into normal data required by the user; The multi-channel selection module is used to select 1-channel or 2-channel data from the multi-channel input data to perform subsequent operations; The counter module is used to encrypt and decrypt the calculation parameters of the CTR mode; The initialization vector module is used to initialize calculation parameters for encryption and decryption.

[0042] The present invention also provides an electronic device, comprising: one or more processors; A memory for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the method for switching between multiple encryption and decryption modes based on software definition.

[0043] A computer-readable storage medium is provided, on which computer instructions are stored. When the instructions are executed by a processor, the steps of the method for switching between multiple encryption and decryption modes based on software definition are implemented.

[0044] Those skilled in the art can understand that the above are only preferred examples of the invention and are not intended to limit the invention. Although the invention is described in detail with reference to the above examples, those skilled in the art can still modify the technical solutions recorded in the above examples or replace some of the technical features therein with equivalents. Any modification, equivalent replacement, etc. made within the spirit and principle of the invention shall be included in the protection scope of the invention.

Claims

1. A method for switching between multiple encryption and decryption modes based on software definition, characterized in that: The following steps are involved: (1) Select and switch between multiple encryption and decryption modes by configuring each multiplexer; (2) Encrypt data into garbled code to ensure the security of data transmission; (3) Decrypting the data encrypted in step (2) to restore the garbled data to the normal data required by the user; (4) Select two data paths from the multiple input data paths to calculate and initialize the calculation parameters of the encryption and decryption CTR mode.

2. A method for switching between multiple encryption and decryption modes based on software definition as claimed in claim 1, characterized in that: The configuration is a slave control bus IIC SLAVE module and a master control bus IIC MASTER module. After receiving the IIC message, the slave control bus IICSLAVE parses it and configures it to each module.

3. The method for switching between multiple encryption and decryption modes based on software definition as claimed in claim 1, characterized in that: There are five encryption and decryption modes, including ECB mode, CBC mode, CTR mode, CFB mode and OFB mode; free switching of the five encryption and decryption modes of ECB mode, CBC mode, CTR mode, CFB mode and OFB mode is achieved through different configurations; the ECB mode uses KEY to encrypt and decrypt each group of plaintext, and after completion, the groups are connected together in sequence, and the groups will not affect each other during the encryption and decryption process; the CBC mode uses the initialization vector and the first group of plaintext for XOR operation, and then encrypts the XOR result with the key to obtain the first group of ciphertext, and uses the first group of ciphertext as the initialization vector of the second group of operations, repeats the operation, and finally obtains the ciphertext; the CTR mode uses ke y encrypts the counter, and XORs the encrypted result with the first group of plaintext to obtain the first group of ciphertext. After the XOR is completed, the counter is incremented to finally obtain the ciphertext; in the CFB mode, the initialization vector is encrypted and XORed with the first group of plaintext to obtain the first group of ciphertext, and the first group of ciphertext is used as the initialization vector for the second group of plaintext operation, and the ciphertext is obtained after repeated operation; in the OFB mode, the result of encrypting the initialization vector once is XORed with the first group of plaintext to obtain the first group of ciphertext, the result of encrypting the initialization vector twice is XORed with the second group of plaintext to obtain the second group of ciphertext, the result of encrypting the initialization vector three times is XORed with the third group of plaintext to obtain the third group of ciphertext, the result of encrypting the initialization vector four times is XORed with the fourth group of plaintext to obtain the fourth group of ciphertext, and finally all the ciphertext groups are sequentially spliced ​​to obtain the ciphertext.

4. The method for switching between multiple encryption and decryption modes based on software definition as claimed in claim 3, characterized in that: The mode of the counter is: the initial value of the counter of group 1 is 0, and the counter increases by 1 after each group is calculated; the initial value of the counter of group 2 is 1, and the counter increases by 1 after each group is calculated; the initial value of the counter of group 3 is 2, and the counter increases by 1 after each group is calculated; the initial value of the counter of group 4 is 3, and the counter increases by 1 after each group is calculated.

5. The method for switching between multiple encryption and decryption modes based on software definition as claimed in claim 1, characterized in that: The multiple encryption and decryption mode switching includes separate switching of the encryption mode and the decryption mode.

6. The method for switching between multiple encryption and decryption modes based on software definition as claimed in claim 1, characterized in that: The multiplexers include: a four-to-two multiplexer, a two-to-one multiplexer and a six-to-two multiplexer; the multiplexers MUX1, MUX2, MUX3, and MUX4 are all four-to-two selectors, and the multiplexers MUX5, MUX6, MUX7, MUX8, MUX9, MUX10, MUX11, MUX12, MUX13, MUX4, and MUX15 are all two-to-one selectors; the multiplexers MUX1, MUX2, MUX3, and MUX4 are all six-to-two selectors, and the multiplexers MUX5, MUX6, MUX7, MUX8, MUX9, MUX10, MUX11, and MUX12 are all two-to-one selectors.

7. The method for switching between multiple encryption and decryption modes based on software definition as claimed in claim 1, characterized in that: The data in step (2) is the message data received by the input port, and its data length is 128 bits. It is divided into 4 groups, each with 32 bits. When the last data is less than 32 bits, it needs to be filled with 0.

8. A device for switching multiple encryption and decryption modes based on software definition, characterized in that: include: Configuration module, encryption module, decryption module, multi-way selection module, counter module and initialization vector module; The configuration module is controlled by adopting the IIC protocol, and then configures each multiplexer to select and switch multiple encryption and decryption modes; The encryption module is used to encrypt data into garbled code to ensure the security of data transmission; The decryption module is used to restore the garbled data into normal data required by the user; The multi-channel selection module is used to select 1-channel or 2-channel data from the multi-channel input data to perform subsequent operations; The counter module is used to encrypt and decrypt the calculation parameters of the CTR mode; The initialization vector module is used to initialize calculation parameters for encryption and decryption.

9. An electronic device, characterized in that: include: one or more processors; A memory for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement a software-defined method for switching multiple encryption and decryption modes as described in any one of claims 1 to 7.

10. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the instruction is executed by the processor, the steps of a method for switching between multiple encryption and decryption modes based on software definition as described in any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Encryption and decryption device based on AES (Advanced Encryption Standard) algorithm

    CN105007154A

  • Software encryption method

    CN109902453A

  • Encrypting / decrypting device and method, encrypting device and method, decrypting device and method, and transmitting / receiving device

    CN1675877A

  • Decrypting block encrypted data

    CN1747380A

  • Encryption circuit and decryption circuit

    US20100002869A1

Cited By

  • Data encryption working mode detection method and device in CPA mode

    CN121441601A

  • A data encryption working mode detection method and device in CPA mode

    CN121441601B