CN108063760B - Method and system for block encryption and method for block decryption - Google Patents
Method and system for block encryption and method for block decryption Download PDFInfo
- Publication number
- CN108063760B CN108063760B CN201711311192.8A CN201711311192A CN108063760B CN 108063760 B CN108063760 B CN 108063760B CN 201711311192 A CN201711311192 A CN 201711311192A CN 108063760 B CN108063760 B CN 108063760B
- Authority
- CN
- China
- Prior art keywords
- data
- encrypted
- plaintext
- ciphertext
- encryption
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 64
- 238000010586 diagram Methods 0.000 description 9
- 239000000463 material Substances 0.000 description 2
- 230000003252 repetitive effect Effects 0.000 description 2
- 230000008859 change Effects 0.000 description 1
- 230000007547 defect Effects 0.000 description 1
- 230000003993 interaction Effects 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000008569 process Effects 0.000 description 1
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L63/00—Network architectures or network communication protocols for network security
- H04L63/04—Network architectures or network communication protocols for network security for providing a confidential data exchange among entities communicating through data packet networks
- H04L63/0428—Network architectures or network communication protocols for network security for providing a confidential data exchange among entities communicating through data packet networks wherein the data content is protected, e.g. by encrypting or encapsulating the payload
- H04L63/0485—Networking architectures for enhanced packet encryption processing, e.g. offloading of IPsec packet processing or efficient security association look-up
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L9/00—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
- H04L9/06—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols the encryption apparatus using shift registers or memories for block-wise or stream coding, e.g. DES systems or RC4; Hash functions; Pseudorandom sequence generators
- H04L9/0618—Block ciphers, i.e. encrypting groups of characters of a plain text message using fixed encryption transformation
- H04L9/0637—Modes of operation, e.g. cipher block chaining [CBC], electronic codebook [ECB] or Galois/counter mode [GCM]
Landscapes
- Engineering & Computer Science (AREA)
- Computer Security & Cryptography (AREA)
- Computing Systems (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Computer Hardware Design (AREA)
- General Engineering & Computer Science (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
- Storage Device Security (AREA)
Abstract
The invention discloses a method and a system for encrypting a packet and a method for decrypting the packet. The packet encryption method comprises the following steps: acquiring a group of plaintext data to be encrypted; judging whether unused encryption data exists or not, and if yes, performing exclusive OR operation on the unused encryption data and partial data in the plaintext data to be encrypted to obtain first ciphertext subdata; carrying out encryption in a cipher block chaining mode on the remaining plaintext data to be encrypted without carrying out XOR operation to obtain second ciphertext subdata, and combining the first ciphertext subdata with the second ciphertext subdata to obtain ciphertext data; if not, encrypting the plaintext data to be encrypted in a cipher block chaining mode to obtain the third ciphertext subdata, and taking the third ciphertext subdata as ciphertext data.
Description
Technical Field
The present invention relates to a packet encryption method and system and a packet decryption method corresponding to the packet encryption method.
Background
Encryption is to change the original information data by a special algorithm, so that even if an unauthorized user obtains the encrypted information, the content of the information cannot be known because the unauthorized user does not know the decryption method. Therefore, encryption has a role of protecting information data.
The block encryption is a digital sequence obtained by encoding and representing plaintext data, the digital sequence is divided into groups with a certain length, and each group can be converted into a ciphertext digital sequence under the control of a secret key.
Plaintext data is typically much longer than a particular packet size and is encrypted using a variety of different techniques or operations. The existing block encryption mainly comprises four modes, which are respectively: an Electronic Codebook (ECB) mode, a Cipher Block Chaining (CBC) mode, a cipher text feedback (CFB) mode, and an Output Feedback (OFB) mode.
Most of the crypto cards do not support the Output Feedback (OFB) mode, and the soft-implemented Output Feedback (OFB) mode is implemented by combining the Electronic Code Book (ECB) mode with the Output Feedback (OFB) mode. This means that each set of plaintext data is processed and encrypted separately, which is a significant overhead for the cryptographic card.
Disclosure of Invention
In view of the defects in the prior art, the invention aims to provide a method for encrypting a packet, a system thereof and a method for decrypting the packet corresponding to the method for encrypting the packet. The block encryption method utilizes the cipher block chaining mode to realize the output feedback mode, so that all blocks in the output feedback mode encryption method can be encrypted at one time, and for large data blocks, the expense of a cipher card is greatly reduced.
According to an aspect of the present invention, there is provided a method of packet encryption, the method of packet encryption comprising the steps of: s10: acquiring a group of plaintext data to be encrypted; s20: judging whether unused encrypted data exists, if yes, executing step S30 and step S40, otherwise executing step S50; s30: performing exclusive-or operation on the unused encryption data and partial data in the plaintext data to be encrypted to obtain first ciphertext subdata; s40: performing encryption in a cipher block chaining mode on the remaining plaintext data to be encrypted, which is not subjected to the exclusive or operation in the step S30, to obtain second ciphertext sub-data, and combining the first ciphertext sub-data and the second ciphertext sub-data to obtain ciphertext data; s50: performing encryption in a cipher block chaining mode on the plaintext data to be encrypted in the step S10 to obtain third ciphertext sub-data, and using the third ciphertext sub-data as ciphertext data; the encryption of the cipher block chaining mode on the remaining plaintext data to be encrypted or the plaintext data to be encrypted comprises the following steps: s601: acquiring a current initialization vector, and constructing virtual plaintext data; s602: performing exclusive-or operation on the current initialization vector and the virtual plaintext data; s603: performing key encryption on the value obtained by the exclusive-or operation in the step S602 to obtain a set of encrypted data, where the encrypted data includes a plurality of encrypted packet data with the same length, the length of each encrypted packet data is the same as the length of the key encryption, and the length of the encrypted data is greater than or equal to the minimum value of the lengths of the plaintext data to be encrypted or the remaining plaintext data to be encrypted; s604: performing exclusive-or operation on the encrypted data and the remaining plaintext data to be encrypted or the plaintext data to be encrypted to generate second ciphertext subdata or third ciphertext subdata; s605: updating the current initialization vector in the step S601 to be the last encrypted packet data in the encrypted data in the step S603, so that the next group of the remaining plaintext data to be encrypted or the encrypted plaintext data is encrypted in the cipher block chaining mode.
Preferably, the step S605 includes the following steps: s606: judging whether the last encrypted packet data contains unused encrypted data, if yes, executing step S607; s607: the last encrypted packet data is saved as buffered data.
Preferably, the step S20 includes the following steps: judging whether the plaintext data to be encrypted in the step S10 is a first set of plaintext data to be encrypted; if yes, go to step S50; if not, judging whether unused data exists in the cache data after the previous group of plaintext data to be encrypted is encrypted; if yes, the steps S30 and S40 are executed, and if no, the step S50 is executed.
Preferably, when the length of the plaintext data to be encrypted in step S50 is an integer multiple of the length of the encrypted data or the length of the remaining plaintext data to be encrypted in step S40 is an integer multiple of the length of the encrypted data, the determination result in step S606 is that there is no unused encrypted data in the last encrypted packet data, otherwise, the determination result in step S606 is that there is unused encrypted data in the last encrypted packet data.
Preferably, the key encryption is a 16 byte length data encryption.
Preferably, the length of the encrypted packet data is 16 bytes, and the length of the encrypted data is extended according to the length of the plaintext data to be encrypted or the length of the remaining plaintext data to be encrypted by an integral multiple of 16 bytes.
Preferably, the length of the virtual plaintext data is the same as the length of the current initialization vector, and the padding is 0.
Preferably, the step S10 is preceded by the steps of: an output feedback mode encrypted context is created that stores a cipher key for cipher block chaining mode encryption, a current initialization vector, cached data, and unused encrypted data.
According to another aspect of the present invention, there is also provided a packet encryption system, including: the plaintext data acquisition module is used for acquiring plaintext data to be encrypted; the first judgment module is used for judging whether unused encrypted data exists or not; the first operation module is used for performing exclusive-or operation on the unused encrypted data and partial data in the plaintext data to be encrypted to obtain first ciphertext subdata when the first judgment module judges that the unused encrypted data is yes; the first encryption module is used for encrypting the rest plaintext data to be encrypted, which is not subjected to exclusive-or operation in the first operation module, in a cipher block chaining mode to obtain second ciphertext subdata, and combining the first ciphertext subdata and the second ciphertext subdata to obtain ciphertext data; the second encryption module is used for encrypting the to-be-encrypted plaintext data acquired by the plaintext data acquisition module in a cipher block chaining mode to obtain third ciphertext subdata when the first judgment module judges that the to-be-encrypted plaintext data is negative, and taking the third ciphertext subdata as ciphertext data; the first encryption module and the second encryption module both comprise a cipher block chaining mode encryption unit, the cipher block chaining mode encryption unit is used for performing cipher block chaining mode encryption on the remaining plaintext data to be encrypted or the plaintext data to be encrypted, and the encryption unit comprises: the first data acquisition module is used for acquiring a current initialization vector and constructing virtual plaintext data; the second operation module is used for carrying out XOR operation on the current initialization vector and the virtual plaintext data; the third encryption module is used for carrying out key encryption on the XOR operation value in the second operation module to obtain a group of encrypted data, wherein the encrypted data comprises a plurality of encrypted grouped data with the same length, the length of each encrypted grouped data is the same as the length of the encryption of the key, and the length of the encrypted data is greater than or equal to the minimum value of the length of the plaintext data to be encrypted or the length of the remaining plaintext data to be encrypted; a third operation module, configured to perform an exclusive or operation on the encrypted data and the remaining plaintext data to be encrypted or the plaintext data to be encrypted, so as to generate the second ciphertext sub-data or the third ciphertext sub-data; and the data updating module is used for updating the current initialization vector acquired by the first data acquisition module to the last encrypted packet data acquired by the third encryption module in the encrypted data, so that the next group of the remaining plaintext data to be encrypted or the encrypted plaintext data is encrypted in the cipher packet chaining mode.
According to still another aspect of the present invention, there is also provided a packet decryption method, including the steps of: s100: acquiring a group of ciphertext data to be decrypted; s200: judging whether unused decryption data exists, if yes, executing step S300 and step S400, otherwise, executing step S500; s300: performing exclusive-or operation on the unused decryption data and the ciphertext data to be decrypted to obtain first plaintext subdata; s400: performing cipher block chaining mode decryption on the remaining ciphertext data to be decrypted which is not subjected to the exclusive or operation in the step S300 to obtain second plaintext sub-data, and combining the first plaintext sub-data and the second plaintext sub-data to obtain plaintext data; s500: carrying out cipher block chaining mode decryption on the ciphertext data to be decrypted in the step S100 to obtain third plaintext subdata, and taking the third plaintext subdata as plaintext data; wherein, the decryption of the residual ciphertext data to be decrypted or the ciphertext data to be decrypted in the cipher block chaining mode comprises the following steps: s6010: acquiring a current initialization vector, and constructing virtual ciphertext data; s6020: performing exclusive-or operation on the current initialization vector and the virtual ciphertext data; s6030: performing key decryption on the value subjected to the exclusive-or operation in the step S6020 to obtain a group of decrypted data, wherein the decrypted data includes a plurality of decrypted packet data with the same length, the length of each decrypted packet data is the same as the length of the key decryption, and the length of the decrypted data is greater than or equal to the minimum value of the lengths of the ciphertext data to be decrypted or the remaining ciphertext data to be decrypted; s6040: performing exclusive-or operation on the decryption data and the remaining ciphertext data to be decrypted or the ciphertext data to be decrypted to generate second plaintext subdata or third plaintext subdata; s6050: updating the current initialization vector in the step S6010 to be the last decrypted packet data in the decrypted data in the step S6030, so that the next group of the remaining ciphertext data to be decrypted or the decrypted ciphertext data may be decrypted in the cipher packet chaining mode.
Compared with the prior art, in the block encryption method and the system thereof and the block decryption method corresponding to the block encryption method, the block encryption method realizes the output feedback mode through the cipher block chaining mode, so that all blocks in the output feedback mode encryption method can be encrypted at one time, and the overhead of a cipher card is greatly reduced for a large data block.
Drawings
Other features, objects and advantages of the invention will become more apparent upon reading of the detailed description of non-limiting embodiments with reference to the following drawings:
FIG. 1 is a flow diagram of a method of block encryption according to one embodiment of the invention;
FIG. 2 is a flowchart illustrating steps of determining whether unused encrypted data exists in a method for block encryption according to an embodiment of the present invention;
FIG. 3 is a flowchart illustrating the steps of cryptographic block chaining mode encryption in a method of block encryption according to an embodiment of the present invention;
FIG. 4 is a diagram illustrating an algorithm for performing cipher block chaining mode encryption in the block encryption method according to an embodiment of the present invention;
FIG. 5 is a block diagram of a packet encryption system according to one embodiment of the present invention; and
fig. 6 is a block diagram of a cipher block chaining mode encryption unit in the block encryption system according to an embodiment of the present invention.
Detailed Description
Example embodiments will now be described more fully with reference to the accompanying drawings. Example embodiments may, however, be embodied in many different forms and should not be construed as limited to the embodiments set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the concept of example embodiments to those skilled in the art. The same reference numerals in the drawings denote the same or similar structures, and thus their repetitive description will be omitted.
The described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to provide a thorough understanding of embodiments of the invention. One skilled in the relevant art will recognize, however, that the invention may be practiced without one or more of the specific details, or with other methods, components, materials, and so forth. In some instances, well-known structures, materials, or operations are not shown or described in detail to avoid obscuring the invention.
Furthermore, the drawings are merely schematic illustrations of the present disclosure and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and thus their repetitive description will be omitted. Some of the block diagrams shown in the figures are functional entities and do not necessarily correspond to physically or logically separate entities. These functional entities may be implemented in the form of software, or in one or more hardware modules or integrated circuits, or in different networks and/or processor devices and/or microcontroller devices.
The technical contents of the present invention will be further described with reference to the accompanying drawings and examples.
Referring to fig. 1, a flow diagram of a method for packet encryption is shown, according to an embodiment of the present invention. Specifically, the method for block encryption of the embodiment of the invention is mainly directed to the SM1 algorithm of the secure encryption card. Since the SM1_ OFB is not provided in the conventional encryption card, and the OFB (output feedback mode encryption) is usually implemented by using an ECB (electronic code book), which requires encryption once for each block _ size, which greatly increases the number of interactions with the secure encryption card, and the performance loss is serious, the block encryption method of the embodiment of the present invention implements the output feedback mode by using the cipher block chaining mode, so that all the blocks in the output feedback mode encryption method can be encrypted at one time, and for a large data block, the overhead of the cipher card is greatly reduced. As shown in fig. 1, in the embodiment of the present invention, the method for encrypting the packet includes the following steps:
step S10: a set of plaintext data to be encrypted is obtained.
Step S20: it is determined whether there is unused encrypted data. Specifically, please refer to fig. 2, which illustrates a flowchart of steps of determining whether there is unused encrypted data in the method for block encryption according to an embodiment of the present invention. As shown in fig. 2, in the preferred embodiment of the present invention, the step S20 includes the following steps:
step S201: it is determined whether the plaintext data to be encrypted obtained in step S10 is the first set of plaintext data to be encrypted. In other words, it is determined whether other plaintext data to be encrypted is not encrypted before the plaintext data to be encrypted in step S10.
If so, since the cipher block chaining mode encryption is not performed, no encrypted data is generated, and further, unused encrypted data is less likely to exist, and step S202 may be performed: it is directly judged that there is unused encrypted data as a result of the step S20. Further, a subsequent step S50 (see below) is performed.
If not, go to step S203: and judging whether unused data exists in the cache data after the previous group of plaintext data to be encrypted is encrypted (see the following text). If yes, the steps S30 and S40 are executed, and if not, the step S50 is executed.
Step S30: and performing exclusive OR operation on the unused encryption data and partial data in the plaintext data to be encrypted to obtain first ciphertext subdata. Specifically, in the embodiment of the present invention, the unused encrypted data is stored in the buffer to form the buffer data, that is, in this step, the unused encrypted data in the buffer data is subjected to an xor operation with the partial data (the partial data having the same length as the unused encrypted data in the plaintext data to be encrypted) in the plaintext data to be encrypted obtained in step S10, and a value after the xor operation is the first ciphertext sub-data.
Step S40: and performing encryption in a cipher block chaining mode on the remaining plaintext data to be encrypted, which is not subjected to the exclusive or operation in the step S30, to obtain second ciphertext sub-data, and combining the first ciphertext sub-data and the second ciphertext sub-data to obtain ciphertext data. Specifically, the remaining plaintext data to be encrypted in this step is the plaintext data that has not been subjected to the exclusive-or operation in step S30 in the plaintext data to be encrypted in step S10. The combination of the first ciphertext subdata and the second ciphertext subdata means that the first ciphertext subdata and the second ciphertext subdata are directly spliced to form ciphertext data.
Step S50: and encrypting the plaintext data to be encrypted in the step S10 in a cipher block chaining mode to obtain the third ciphertext sub-data, and using the third ciphertext sub-data as ciphertext data.
Further, please refer to fig. 3 and fig. 4, which show a flowchart and an algorithm diagram of each step of performing cipher block chaining mode encryption in the block encryption method according to an embodiment of the present invention. Specifically, as shown in fig. 3, the encrypting the remaining plaintext data to be encrypted or the plaintext data to be encrypted in the cipher block chaining mode includes the following steps:
step S601: and acquiring the current initialization vector and constructing virtual plaintext data. In the embodiment of the present invention, the whole output feedback mode encryption (OFB encryption) is implemented by using the cipher block chaining mode encryption (CBC encryption), and in general, the basic flow of the cipher block chaining mode encryption (CBC encryption) is to use the plaintext packet data to perform the xor operation with the current Initialization Vector (IV) and then to use the key to perform the encryption, and the output feedback mode encryption (OFB encryption) is to use the key to encrypt the current Initialization Vector (IV) and then to perform the xor operation with each plaintext packet data. Therefore, in the embodiment of the present invention, in order to implement the whole output feedback mode encryption (OFB encryption) by using the cipher block chaining mode encryption (CBC encryption), it is necessary to obtain the current initialization vector and construct a virtual plaintext data, and use the virtual plaintext data to replace the actual plaintext packet data in the original cipher block chaining mode encryption (CBC encryption). In the preferred embodiment of the present invention, the dummy plaintext data is data having the same length as the current initialization vector and being padded with 0.
Step S602: and carrying out XOR operation on the current initialization vector and the virtual plaintext data. As described above, in the preferred embodiment of the present invention, the dummy plaintext data has the same length as the current initialization vector and is filled with 0 s, so that the data formed by performing the xor operation on the current initialization vector and the dummy plaintext data is the same as the current initialization vector.
Step S603: and performing key encryption on the value subjected to the exclusive-or operation in the step S602 to obtain a set of encrypted data. Specifically, in this step, the key encryption means that the CBC key and the CBC encryptor are used to perform encryption, and the encrypted data is obtained after encryption, and the encrypted data is used to encrypt plaintext data to be encrypted.
Further, the encrypted data comprises a plurality of encrypted packet data with the same length, the length of each encrypted packet data is the same as the length of encryption of the key, and the length of the encrypted data is greater than or equal to the minimum value of the length of the plaintext data to be encrypted or the length of the remaining plaintext data to be encrypted. Specifically, the embodiment of the invention uses a CBC key and a CBC encryptor to encrypt, wherein the key encryption is data encryption with the length of 16 bytes. Furthermore, the length of the encrypted packet data is 16 bytes, the length of the encrypted data is the same as that of the encrypted data encrypted by the CBC key, the length of the encrypted data is expanded according to the length of the plaintext data to be encrypted or the length of the remaining plaintext data to be encrypted according to the integral multiple of 16 bytes, and the length of the encrypted data is expanded to be greater than or equal to the minimum value of the length of the plaintext data to be encrypted or the length of the remaining plaintext data to be encrypted. For example, if the length of the remaining plaintext data to be encrypted in step S40 or the length of the plaintext data to be encrypted in step S50 is 50 bytes, the length of the encrypted data is extended by 4 times of 16 bytes, that is, the encrypted data includes 4 pieces of encrypted packet data of 16 bytes, on the basis that the above condition is satisfied.
Step S604: and performing exclusive-or operation on the encrypted data and the remaining plaintext data to be encrypted or the plaintext data to be encrypted to generate the second ciphertext subdata or the third ciphertext subdata. Specifically, in step S40, an exclusive or operation is performed on the encrypted data and the remaining plaintext data to be encrypted to generate second ciphertext sub-data; in step S50, an exclusive or operation is performed on the encrypted data and the plaintext data to be encrypted to generate third ciphertext sub-data. Similarly, taking the remaining plaintext data to be encrypted or the plaintext data to be encrypted with a length of 50 bytes as an example, the xor operation is performed on the first 50 bytes of encrypted data in the 64 bytes of encrypted data and the plaintext data to be encrypted or the remaining plaintext data to be encrypted, and further, 14 bytes of data are not used in the last encrypted packet data in the encrypted data.
Step S605: updating the current initialization vector in the step S601 to be the last encrypted packet data in the encrypted data in the step S603, so that the next group of the remaining plaintext data to be encrypted or the encrypted plaintext data is encrypted in the cipher block chaining mode. Specifically, taking the remaining plaintext data to be encrypted or the plaintext data to be encrypted with the length of 50 bytes as an example, the current initialization vector in step S601 is updated to the last encrypted packet data with the length of 16 bytes in the encrypted data, and the last encrypted packet data with the length of 16 bytes includes one encrypted packet data of the encrypted data with the length of 14 bytes of unused data. It should be noted that, in the embodiment of the present invention, the execution sequence of step S604 and step S605 may be interchanged, and is not described herein again.
Further, in the embodiment shown in fig. 3, after the step S605 is completed, the method includes the following steps:
step S606: it is determined whether there is unused encryption data in the last encryption packet data, and if yes, step S607 is executed. Specifically, when the length of the plaintext data to be encrypted in step S50 is an integer multiple of the length of the encrypted data or the length of the remaining plaintext data to be encrypted in step S40 is an integer multiple of the length of the encrypted data, the determination in this step is that there is no unused encrypted data in the last encrypted packet data, otherwise, the determination in step S606 is that there is unused encrypted data in the last encrypted packet data. In the above embodiment, since the key encryption is data encryption with a length of 16 bytes, if there is remaining plaintext data to be encrypted or the length of the plaintext data to be encrypted is 32 bytes, the length of the encrypted data is extended by 2 times of 16 bytes, that is, the encrypted data includes 2 pieces of encrypted packet data with 16 bytes; if the length of the remaining plaintext data to be encrypted or the plaintext data to be encrypted is 30 bytes, the length of the encrypted data is extended by 2 times of 16 bytes, that is, the encrypted data includes 2 encrypted packets of 16 bytes, but there are 2 unused encrypted data in the last encrypted packet of the encrypted data.
Step S607: the last encrypted packet data is saved as the buffered data enc _ data. Specifically, for example, when the remaining plaintext data to be encrypted or the length of the plaintext data to be encrypted is 30 bytes, the encrypted data includes 2 encrypted packets of 16 bytes, but there are 2 unused encrypted data in the last encrypted packet of the encrypted data, and therefore, the next encrypted packet of the 2 unused encrypted data is stored as the cache data enc _ data.
Further, the encryption of the plaintext data to be encrypted each time can be realized by performing the above steps S10 to S50, which are not described herein again.
The following describes the block encryption method according to the embodiment of the present invention by taking two specific sets of plaintext data to be encrypted as an example and combining the steps shown in fig. 1 to fig. 4.
Specifically, for example, when the key is encrypted to obtain 16-byte data, assuming that the received set of plaintext data to be encrypted is a first set of plaintext data to be encrypted (i.e., other plaintext data to be encrypted has not been encrypted before or records of other plaintext data to be encrypted that have been encrypted before are cleared), and the length of the first set of plaintext data to be encrypted is 28-byte data, the encrypted data is expanded 2 times according to 16 bytes according to the steps shown in fig. 1 to 4 to obtain 32 bytes, i.e., two 16-byte encrypted packets. The first 28 bytes of data in the 32 bytes are subjected to exclusive-or operation with plaintext data to be encrypted to obtain ciphertext data corresponding to the first group of plaintext data to be encrypted, and the second group of encrypted packet data contains 4 unused encrypted data. Further, according to step S606, the last encrypted packet data, that is, the next group of encrypted packet data having 4 unused encrypted data, is buffered.
Further, assuming that the length of the received second group of plaintext data to be encrypted is 20 bytes, step S30 is executed according to the determination of step S20, that is, the unused encrypted data with the length of 4 bytes in the buffered data after the encryption of the first group of plaintext data to be encrypted (i.e., the last encrypted packet data in the encrypted data obtained in step S603 during the encryption of the first group of plaintext data to be encrypted) is subjected to the xor operation with the plaintext data to be encrypted with the length of 4 bytes in the second group of plaintext data to be encrypted, so as to obtain the first ciphertext sub-data with the length of 4 bytes, and further, the remaining plaintext data to be encrypted is 16 bytes, and is encrypted in the cipher block chaining mode using steps S601 to S607. Since the 16 bytes of encrypted data encrypted in the cipher block chaining mode are all used, the data does not need to be cached; and the unused encrypted data with the length of 4 bytes existing after the first group of plaintext data to be encrypted is also used, so that the unused encrypted data does not exist in the cache data.
Further, based on the above example, if it is assumed that the length of the first group of plaintext data to be encrypted is 32 bytes, there is no unused encrypted data, and further, when the second group of plaintext data to be encrypted is received subsequently, step S50 is directly executed according to the determination of step S20.
If it is assumed that the length of the first set of plaintext data to be encrypted in the example is still 28 bytes, and the length of the second set of plaintext data to be encrypted is also 28 bytes, after the encryption according to the step shown in fig. 1, there is still unused encrypted data, and the unused encrypted data is still used in the following, for example, a third set of plaintext data to be encrypted.
Further, in an embodiment of the present invention, the method for encrypting packets further includes, before step S10, the following steps: a context for output feedback mode (OFB mode) encryption is created. The output feedback mode (OFB mode) encrypted context is used to store the cipher key encrypted by cipher block chaining mode, the current initialization vector IV, the buffer data enc _ data, and the unused encrypted data.
Further, the invention also provides a system for packet encryption, which is used for realizing the packet encryption method. Specifically, please refer to fig. 5 and fig. 6, which show a block diagram of a block encryption system and a block diagram of a cipher block chaining mode encryption unit in the block encryption system according to an embodiment of the present invention. As shown in fig. 5, the block encryption system at least includes a plaintext data obtaining module 1, a first determining module 2, a first calculating module 3, a first encrypting module 4, and a second encrypting module 5.
Specifically, the plaintext data obtaining module 1 is configured to obtain plaintext data to be encrypted.
The first judging module 2 is used for judging whether unused encryption data exists.
The first operation module 3 is configured to perform an exclusive or operation on the unused encrypted data and partial data in the plaintext data to be encrypted to obtain first ciphertext sub-data when the first determination module 2 determines that the unused encrypted data is yes.
The first encryption module 4 is configured to perform cipher block chaining mode encryption on the remaining plaintext data to be encrypted that is not subjected to the xor operation in the first operation module 3 to obtain second ciphertext sub-data, and combine the first ciphertext sub-data and the second ciphertext sub-data to obtain ciphertext data.
The second encryption module 5 is configured to, when the first determination module 2 determines that the plaintext data to be encrypted is not encrypted, perform encryption in a cipher block chaining mode on the plaintext data to be encrypted acquired by the plaintext data acquisition module to obtain third ciphertext sub-data, and use the third ciphertext sub-data as ciphertext data.
Further, the first encryption module 4 and the second encryption module 5 each include a cipher block chaining mode encryption unit. The cipher block chaining mode encryption unit is configured to perform cipher block chaining mode encryption on the remaining plaintext data to be encrypted or the plaintext data to be encrypted, as shown in fig. 6, the cipher block chaining mode encryption unit includes: a first data acquisition module 61, a second operation module 62, a third encryption module 63, a third operation module 64 and a data update module 65.
The first data obtaining module 61 is configured to obtain a current initialization vector and construct virtual plaintext data.
The second operation module 62 is configured to perform an exclusive or operation on the current initialization vector and the virtual plaintext data.
The third encryption module 63 performs key encryption on the xor operation value in the second operation module 62 to obtain a set of encrypted data. The encrypted data comprises a plurality of encrypted grouped data with the same length, the length of each encrypted grouped data is the same as the length of encryption of the key, and the length of the encrypted data is greater than or equal to the minimum value of the length of the plaintext data to be encrypted or the length of the remaining plaintext data to be encrypted.
The third operation module 64 is configured to perform an exclusive or operation on the encrypted data and the remaining plaintext data to be encrypted or the plaintext data to be encrypted, so as to generate the second ciphertext sub-data or the third ciphertext sub-data.
The data updating module 65 is configured to update the current initialization vector acquired by the first data acquiring module 61 to the last encrypted packet data obtained by the third encrypting module 63 in the encrypted data, so that the next group of remaining plaintext data to be encrypted or the encrypted plaintext data is encrypted in the cipher packet chaining mode.
Further, the present invention also provides a block decryption method, corresponding to the block encryption method, for decrypting the block encrypted ciphertext data. The decryption method is similar to the encryption method shown in fig. 1, and therefore, the specific operation or execution steps are not described in detail. Specifically, the method for decrypting the packet comprises the following steps:
step S100: and acquiring a group of ciphertext data to be decrypted.
Step S200: and judging whether unused decryption data exists, if so, executing the step S300 and the step S400, and otherwise, executing the step S500.
Step S300: and performing exclusive-OR operation on the unused decryption data and partial data in the ciphertext data to be decrypted to obtain first plaintext subdata.
Step S400: and performing cipher block chaining mode decryption on the remaining ciphertext data to be decrypted which is not subjected to the exclusive or operation in the step S300 to obtain second plaintext sub-data, and combining the first plaintext sub-data and the second plaintext sub-data to obtain plaintext data.
Step S500: and decrypting the ciphertext data to be decrypted in the step S100 in a cipher block chaining mode to obtain third plaintext subdata, and taking the third plaintext subdata as plaintext data.
Further, the decryption of the remaining ciphertext data to be decrypted or the ciphertext data to be decrypted in the cipher block chaining mode includes the following steps:
step S6010: and acquiring the current initialization vector and constructing virtual ciphertext data. It should be noted that, when the first group of ciphertext data to be decrypted is decrypted, the current initialization vector obtained in this step is the current initialization vector updated after the step S605 in the process of encrypting the last group of plaintext data to be encrypted in the block encryption method is completed.
Step S6020: and carrying out XOR operation on the current initialization vector and the virtual ciphertext data.
Step S6030: and carrying out key decryption on the value subjected to the exclusive-or operation in the step S6020 to obtain a group of decrypted data. The decryption data comprises a plurality of decryption grouped data with the same length, the length of each decryption grouped data is the same as the decryption length of the key, and the length of the decryption data is greater than or equal to the minimum value of the length of the ciphertext data to be decrypted or the length of the remaining ciphertext data to be decrypted.
Step S6040: and performing exclusive-or operation on the decrypted data and the remaining ciphertext data to be decrypted or the ciphertext data to be decrypted to generate the second plaintext subdata or the third plaintext subdata.
Step S6050: updating the current initialization vector in the step S6010 to be the last decrypted packet data in the decrypted data in the step S6030, so that the next group of the remaining ciphertext data to be decrypted or the decrypted ciphertext data may be decrypted in the cipher packet chaining mode.
In summary, in the block encryption method and system and the block decryption method corresponding to the block encryption method provided in the embodiments of the present invention, the block encryption method implements the output feedback mode through the cipher block chaining mode, so that all blocks in the output feedback mode encryption method can be encrypted at one time, and for a large data block, the overhead of the cipher card is greatly reduced.
Although the invention has been described with respect to alternative embodiments, it is not intended to be limited thereto. Various changes and modifications may be made by those skilled in the art without departing from the spirit and scope of the invention. Therefore, the protection scope of the present invention is subject to the scope defined by the claims.
Claims (10)
1. A method of block encryption, the method comprising the steps of:
s10: acquiring a group of plaintext data to be encrypted;
s20: judging whether unused encrypted data exists, if yes, executing step S30 and step S40, otherwise executing step S50;
s30: performing exclusive-or operation on the unused encryption data and partial data in the plaintext data to be encrypted to obtain first ciphertext subdata;
s40: performing encryption in a cipher block chaining mode on the remaining plaintext data to be encrypted, which is not subjected to the exclusive or operation in the step S30, to obtain second ciphertext sub-data, and combining the first ciphertext sub-data and the second ciphertext sub-data to obtain ciphertext data;
s50: encrypting the plaintext data to be encrypted in the step S10 in a cipher block chaining mode to obtain third ciphertext sub-data, and using the third ciphertext sub-data as ciphertext data;
the encryption of the cipher block chaining mode on the remaining plaintext data to be encrypted or the plaintext data to be encrypted comprises the following steps:
s601: acquiring a current initialization vector, and constructing virtual plaintext data;
s602: performing exclusive-or operation on the current initialization vector and the virtual plaintext data;
s603: performing key encryption on the value obtained by the exclusive-or operation in the step S602 to obtain a set of encrypted data, where the encrypted data includes a plurality of encrypted packet data with the same length, the length of each encrypted packet data is the same as the length of the key encryption, and the length of the encrypted data is greater than or equal to the minimum value of the lengths of the plaintext data to be encrypted or the remaining plaintext data to be encrypted;
s604: performing exclusive-or operation on the encrypted data and the remaining plaintext data to be encrypted or the plaintext data to be encrypted to generate second ciphertext subdata or third ciphertext subdata;
s605: updating the current initialization vector in the step S601 to be the last encrypted packet data in the encrypted data in the step S603, so that the next group of the remaining plaintext data to be encrypted or the encrypted plaintext data is encrypted in the cipher block chaining mode.
2. The method for encrypting packets according to claim 1, wherein the step of S605 includes the following steps:
s606: judging whether the last encrypted packet data contains unused encrypted data, if yes, executing step S607;
s607: the last encrypted packet data is saved as buffered data.
3. The packet encryption method according to claim 2, wherein the step S20 includes the steps of:
judging whether the plaintext data to be encrypted in the step S10 is a first set of plaintext data to be encrypted;
if yes, go to step S50;
if not, judging whether unused data exists in the cache data after the previous group of plaintext data to be encrypted is encrypted;
if yes, the steps S30 and S40 are executed, and if no, the step S50 is executed.
4. The block encryption method according to claim 3, wherein when the length of said plaintext data to be encrypted in said step S50 is an integral multiple of the length of said encrypted data or the length of said remaining plaintext data to be encrypted in said step S40 is an integral multiple of the length of said encrypted data, it is determined in said step S606 that there is no unused encrypted data in the last encrypted packet data, and otherwise, it is determined in said step S606 that there is unused encrypted data in the last encrypted packet data.
5. The method of block encryption according to claim 1, wherein the key encryption is a 16 byte length data encryption.
6. The block encryption method according to claim 5, wherein the length of said encrypted packet data is 16 bytes, and the length of said encrypted data is extended by an integer multiple of 16 bytes based on the length of said plaintext data to be encrypted or said remaining plaintext data to be encrypted.
7. The block encryption method according to claim 1, wherein the length of the virtual plaintext data is the same as the length of the current initialization vector and padding is 0.
8. The packet encryption method according to claim 1, wherein said step S10 is preceded by the steps of: an output feedback mode encrypted context is created that stores a cipher key for cipher block chaining mode encryption, a current initialization vector, cached data, and unused encrypted data.
9. A system for block encryption, the system comprising:
the plaintext data acquisition module is used for acquiring plaintext data to be encrypted;
the first judgment module is used for judging whether unused encrypted data exists or not;
the first operation module is used for performing exclusive-or operation on the unused encrypted data and partial data in the plaintext data to be encrypted to obtain first ciphertext subdata when the first judgment module judges that the unused encrypted data is yes;
the first encryption module is used for encrypting the rest plaintext data to be encrypted, which is not subjected to exclusive-or operation in the first operation module, in a cipher block chaining mode to obtain second ciphertext subdata, and combining the first ciphertext subdata and the second ciphertext subdata to obtain ciphertext data;
the second encryption module is used for encrypting the to-be-encrypted plaintext data acquired by the plaintext data acquisition module in a cipher block chaining mode to obtain third ciphertext subdata when the first judgment module judges that the to-be-encrypted plaintext data is negative, and the third ciphertext subdata is used as ciphertext data;
the first encryption module and the second encryption module both comprise a cipher block chaining mode encryption unit, the cipher block chaining mode encryption unit is used for performing cipher block chaining mode encryption on the remaining plaintext data to be encrypted or the plaintext data to be encrypted, and the encryption unit comprises:
the first data acquisition module is used for acquiring a current initialization vector and constructing virtual plaintext data;
the second operation module is used for carrying out XOR operation on the current initialization vector and the virtual plaintext data;
the third encryption module is used for carrying out key encryption on the XOR operation value in the second operation module to obtain a group of encrypted data, wherein the encrypted data comprises a plurality of encrypted grouped data with the same length, the length of each encrypted grouped data is the same as the length of the encryption of the key, and the length of the encrypted data is greater than or equal to the minimum value of the length of the plaintext data to be encrypted or the length of the remaining plaintext data to be encrypted;
a third operation module, configured to perform an exclusive or operation on the encrypted data and the remaining plaintext data to be encrypted or the plaintext data to be encrypted, so as to generate the second ciphertext sub-data or the third ciphertext sub-data;
and the data updating module is used for updating the current initialization vector acquired by the first data acquisition module to the last encrypted packet data acquired by the third encryption module in the encrypted data, so that the next group of the remaining plaintext data to be encrypted or the encrypted plaintext data is encrypted in the cipher packet chaining mode.
10. A method for packet decryption, the method comprising the steps of:
s100: acquiring a group of ciphertext data to be decrypted;
s200: judging whether unused decryption data exists, if yes, executing step S300 and step S400, otherwise, executing step S500;
s300: performing exclusive-or operation on the unused decryption data and partial data in the ciphertext data to be decrypted to obtain first plaintext subdata;
s400: performing cipher block chaining mode decryption on the remaining ciphertext data to be decrypted which is not subjected to the exclusive or operation in the step S300 to obtain second plaintext sub-data, and combining the first plaintext sub-data and the second plaintext sub-data to obtain plaintext data;
s500: carrying out cipher block chaining mode decryption on the ciphertext data to be decrypted in the step S100 to obtain third plaintext subdata, and taking the third plaintext subdata as plaintext data;
wherein, the decryption of the residual ciphertext data to be decrypted or the ciphertext data to be decrypted in the cipher block chaining mode comprises the following steps:
s6010: acquiring a current initialization vector, and constructing virtual ciphertext data;
s6020: performing exclusive-or operation on the current initialization vector and the virtual ciphertext data;
s6030: performing key decryption on the value subjected to the exclusive-or operation in the step S6020 to obtain a group of decrypted data, wherein the decrypted data includes a plurality of decrypted packet data with the same length, the length of each decrypted packet data is the same as the length of the key decryption, and the length of the decrypted data is greater than or equal to the minimum value of the lengths of the ciphertext data to be decrypted or the remaining ciphertext data to be decrypted;
s6040: performing exclusive-or operation on the decryption data and the remaining ciphertext data to be decrypted or the ciphertext data to be decrypted to generate second plaintext subdata or third plaintext subdata;
s6050: updating the current initialization vector in the step S6010 to be the last decrypted packet data in the decrypted data in the step S6030, so that the next group of the remaining ciphertext data to be decrypted or the decrypted ciphertext data may be decrypted in the cipher packet chaining mode.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201711311192.8A CN108063760B (en) | 2017-12-11 | 2017-12-11 | Method and system for block encryption and method for block decryption |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201711311192.8A CN108063760B (en) | 2017-12-11 | 2017-12-11 | Method and system for block encryption and method for block decryption |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN108063760A CN108063760A (en) | 2018-05-22 |
| CN108063760B true CN108063760B (en) | 2020-06-16 |
Family
ID=62136417
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201711311192.8A Active CN108063760B (en) | 2017-12-11 | 2017-12-11 | Method and system for block encryption and method for block decryption |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN108063760B (en) |
Families Citing this family (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN109660328A (en) * | 2018-12-26 | 2019-04-19 | 中金金融认证中心有限公司 | Symmetric block encryption method, apparatus, equipment and medium |
| CN111400738B (en) * | 2020-03-19 | 2023-05-02 | 杭州小影创新科技股份有限公司 | Data encryption method adopting multidimensional table look-up mode |
| CN112615715A (en) * | 2020-12-16 | 2021-04-06 | 北京天维信通科技有限公司 | One-time cipher-book encryption method and device, equipment and storage medium |
| CN112866288B (en) * | 2021-03-01 | 2022-09-06 | 上海海事大学 | Data symmetric encryption method for double-plaintext transmission |
| CN119483913B (en) * | 2025-01-10 | 2025-06-24 | 山东大学 | Data rapid encryption method and system based on cryptographic algorithm |
Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101710964A (en) * | 2009-11-17 | 2010-05-19 | 深圳国微技术有限公司 | Method for enciphering and deciphering MPEG2 transport stream packets |
| CN102546156A (en) * | 2012-02-01 | 2012-07-04 | 李智虎 | Method, system and device for grouping encryption |
| CN105162580A (en) * | 2015-07-30 | 2015-12-16 | 苏州中科启慧软件技术有限公司 | Lightweight stream cipher technology VHO based on OFB mode and block cipher VH |
Family Cites Families (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| EP2887574A1 (en) * | 2013-12-17 | 2015-06-24 | Nagravision S.A. | Method for converting content with conditional access |
-
2017
- 2017-12-11 CN CN201711311192.8A patent/CN108063760B/en active Active
Patent Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101710964A (en) * | 2009-11-17 | 2010-05-19 | 深圳国微技术有限公司 | Method for enciphering and deciphering MPEG2 transport stream packets |
| CN102546156A (en) * | 2012-02-01 | 2012-07-04 | 李智虎 | Method, system and device for grouping encryption |
| CN105162580A (en) * | 2015-07-30 | 2015-12-16 | 苏州中科启慧软件技术有限公司 | Lightweight stream cipher technology VHO based on OFB mode and block cipher VH |
Non-Patent Citations (1)
| Title |
|---|
| 国密对称密码算法多模式实现与应用;赵新阳等;《冶金自动化》;20160131;第40卷(第1期);全文 * |
Also Published As
| Publication number | Publication date |
|---|---|
| CN108063760A (en) | 2018-05-22 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN108063760B (en) | Method and system for block encryption and method for block decryption | |
| US11722313B2 (en) | State synchronization for post-quantum signing facilities | |
| US9537657B1 (en) | Multipart authenticated encryption | |
| US9571270B2 (en) | Construction and uses of variable-input-length tweakable ciphers | |
| EP3526927B1 (en) | Cipher message with authentication instruction | |
| US20080084996A1 (en) | Authenticated encryption method and apparatus | |
| EP3167569B1 (en) | Method and system for providing a secure update of code on a memory-constrained device | |
| WO1999034548A2 (en) | System and method for deriving an appropriate initialization vector for secure communications | |
| CN115941304B (en) | Data encryption method, device, terminal device and computer-readable storage medium | |
| CN113098675B (en) | Binary data encryption system and method based on polynomial complete homomorphism | |
| US20140317407A1 (en) | Incremental mac tag generation device, method, and program, and message authentication device | |
| CN114826590B (en) | A packet mode encryption method, decryption method, device and equipment thereof | |
| TW201545524A (en) | Technologies for modifying a first cryptographic cipher with operations of a second cryptographic cipher | |
| CN115766244A (en) | Internet of vehicles information encryption method and device, computer equipment and storage medium | |
| JP5689826B2 (en) | Secret calculation system, encryption apparatus, secret calculation apparatus and method, program | |
| US20210135851A1 (en) | Encryption processing system and encryption processing method | |
| CN114124359A (en) | Method and device for preserving format encrypted data, electronic equipment and storage medium | |
| JP2003535362A (en) | Decryption of cryptographic polynomial | |
| US8832450B2 (en) | Methods and apparatus for data hashing based on non-linear operations | |
| WO2020213114A1 (en) | Mac tag list generation device, mac tag list verification device, method, and program | |
| CN114124354A (en) | Deterministic authentication encryption and decryption device and method | |
| CN113541942A (en) | Digital content encryption and decryption method based on ARX white-box block cipher | |
| KR20140028233A (en) | Homomorphic encryption and decryption method using chinese remainder theorem and apparatus using the same | |
| CN114826562B (en) | Data encryption method, device, electronic device and storage medium | |
| JP5431191B2 (en) | Authenticated stream cipher encryption apparatus, authenticated stream cipher decryption apparatus, encryption method, decryption method, and program |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |