A method and device for verifying data integrity
Through the accumulation operation generated in the encryption device and verified in the decryption device and the authentication tag value generated by encryption, the problem of lack of integrity verification of encrypted data by the encryption device in the existing technology is solved, and the efficiency and efficiency of data integrity verification are improved. accuracy.
Patent Information
- Application Number
- CN202311480542.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-08
- Publication Date
- 2024-10-22
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
When existing encryption devices use block cipher algorithms to encrypt data, they lack integrity verification of the encrypted data, resulting in low efficiency and a large amount of program code.
Provides a data integrity verification method that receives ciphertext and authentication tag values, decrypts them, performs cumulative operations and encrypts them to generate authentication tag values, which is used to verify the integrity of message data and improve the device's data integrity verification efficiency.
It is realized that when the encryption device uses the block cipher algorithm to encrypt the message, the authentication tag value is generated, and the decryption device can verify the integrity of the message based on the authentication tag value, which improves the efficiency and accuracy of data integrity verification.
Smart Images

Figure CN117527351B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of information security, and in particular to a method and device for verifying data integrity. Background Art
[0002] In the field of information security, in order to prevent ciphertext from being tampered with, it may be necessary to have an integrity check function in the cryptographic system. At present, there are many ways to implement integrity check. For example, there are three types of solutions to implement integrity check: the first type of solution: using a hash function to calculate the summary of the entire message, the second type of solution: using a special block cipher algorithm with authentication function, and the third type of solution: using a block cipher working mode with authentication function. Among the above three types of solutions, the disadvantage of using a hash function in solution one is low efficiency and large amount of program code. Solutions two and three use special block algorithms or modes with authentication functions, such as CCM (counter with CBC-MAC) and OCB (offset codebook, OCB) modes of block ciphers. However, common modes familiar to programmers, such as electronic codebock mode (ECB), cipher block chaining mode (CBC) or counter mode (CTR), do not have authentication functions.
[0003] Therefore, when current encryption devices use block cipher algorithms to encrypt data, they lack integrity verification of the encrypted data, which needs to be improved. Summary of the invention
[0004] The embodiments of the present application provide a data integrity verification method and apparatus, which enable an encryption device to generate cumulative data for verifying the integrity of message data when encrypting message data using a block cipher algorithm, so that a decryption device can verify the integrity of the message data based on the accumulated data after decrypting the message data, thereby improving the efficiency of the device in verifying the integrity of data.
[0005] In a first aspect, an embodiment of the present application provides a data integrity verification method, comprising:
[0006] A first device receives a message to be verified from a second device, wherein the message to be verified includes a first ciphertext and a first authentication tag value, wherein the first ciphertext is a ciphertext corresponding to a first plaintext, and the first authentication tag value is generated by the second device according to the first plaintext; the first device decrypts the first ciphertext to obtain a second plaintext; the first device verifies the first authentication tag value according to the second plaintext to determine whether the message to be verified has integrity.
[0007] According to the method, a first device can receive a plaintext to be verified from a second device, wherein the plaintext to be verified includes a first ciphertext and a first authentication tag value. The second plaintext determined by the first device after decrypting the first ciphertext is used to verify the first authentication tag value, and the verification result is used to determine whether the plaintext to be verified is credible or whether the message to be verified has integrity, thereby improving the device's efficiency in verifying the integrity of data.
[0008] In one possible design, the first device verifies the first authentication tag value according to the second plaintext, including: the first device determines the second authentication tag value according to the second plaintext through a first rule, wherein the first authentication tag value is generated by the second device according to the first plaintext through the first rule; the first device determines whether the message to be verified has integrity according to a comparison result of the first authentication tag value and the second authentication tag value.
[0009] According to this design, the first device can perform accumulation operations, multiplication, XOR and encryption operations on the second plaintext to obtain a cumulative value ciphertext, and determine the second authentication tag value based on the length of the cumulative value ciphertext and the first authentication tag value, thereby improving the efficiency of the first device in obtaining the second authentication tag value.
[0010] In one possible design, the first device determines a second authentication tag value according to the second plaintext through a first rule, including: the first device determines T grouped plaintexts with a data length equal to a group length according to the second plaintext; the first device determines a first cumulative value corresponding to the T grouped plaintexts through a cumulative value algorithm; the first device determines the second authentication tag value according to a first sequence with a data length equal to the group length and the first cumulative value, wherein the first sequence is related to the plaintext length contained in the last group of the second plaintext and the group length.
[0011] According to this design, the first device can perform multiplication and XOR operations and encryption based on the second plaintext to generate the first cumulative value, which can improve the accuracy of obtaining the first cumulative value.
[0012] In one possible design, the lengths of the first authentication tag value and the second authentication tag value are both the packet length.
[0013] According to this design, the lengths of the first authentication tag value and the second authentication tag value can be determined through negotiation, for example, both are packet lengths.
[0014] In one possible design, the first accumulated value and the T grouped plaintexts satisfy the following relationship: T =(f(x)Y T-1 )⊕P T-1 ; where f(x) represents a function with x as a variable, PT-1 represents the T-th plaintext among the T plaintext groups, ⊕ represents an XOR operation, and Y T represents the first cumulative value, Y T-1 It represents a second cumulative value determined based on the 1st group plaintext to the T-1th group plaintext among the T group plaintexts.
[0015] According to the design, the first device can perform an XOR accumulation operation on the plaintext of the group, and multiply the result of the XOR accumulation operation by a function, and the selection of the function can be determined according to the requirements of the accumulation operation. The function is multiplied by the XOR accumulation operation to obtain a first cumulative value, and the first cumulative value is used to determine the authentication tag value. The flexibility of the accumulation operation process can be adjusted to improve the efficiency of determining the authentication tag value.
[0016] In a possible design, the second authentication tag value is a sequence included in the cumulative value ciphertext; the cumulative value ciphertext satisfies the following relationship: Z = F1 (Y T+1 ); wherein F1 represents an encryption algorithm; the Y T+1 Represents the cumulative value of the first group, satisfying the following relationship: Y T+1 =Y T ⊕L; where Y T is the first cumulative value, and L is the first sequence.
[0017] According to this design, the first device can determine the cumulative value ciphertext through a cumulative algorithm, and determine the second authentication tag value from the cumulative value ciphertext according to the length of the authentication tag value.
[0018] In one possible design, the first device verifies the first authentication tag value according to the second plaintext, including: the first device obtains a third authentication tag value from the message to be verified according to the length of the authentication tag value, and the length of the authentication tag value is the length of the first authentication tag value; the first device decrypts the third authentication tag value to obtain a second group cumulative value; the first device determines T group plaintexts with a data length equal to the group length according to the second plaintext; the first device determines the first cumulative value corresponding to the T group plaintexts through a cumulative value algorithm; the first device determines a second sequence according to the second group cumulative value and the first cumulative value; the first device determines that the message to be verified has integrity when the second sequence meets the set rules.
[0019] According to this design, the first device can perform multiplication and XOR operations and encryption on the first plaintext to generate cumulative value ciphertext, which can improve the accuracy of obtaining the cumulative value ciphertext. Among them, the selection of f(x) can be determined according to the calculation needs. For example, if it is necessary to simplify the calculation process and improve the calculation efficiency, f(x) can be selected as a simple function suitable for fast calculation on a finite field, such as f(x) = x or f(x) = x-1 If you need to obtain a cumulative value ciphertext with a longer data length and the cumulative value needs to be more random, you can choose f(x) as a polynomial function with a large number of terms.
[0020] In one possible design, the method also includes: the first device determines the plaintext length contained in the last group of the second plaintext according to the second sequence; and the first device determines the initial message from the second plaintext according to the plaintext length.
[0021] According to the design, the second sequence is a sequence that satisfies the first rule. For example, the second sequence includes multiple bytes, each byte can be used to indicate the difference between the packet length and the plaintext length contained in the last packet of the second plaintext. The difference is the length of the filling sequence. Therefore, the first device can determine the length of the filling sequence based on the difference, thereby deleting the filling bits from the second plaintext to obtain the initial message.
[0022] In a second aspect, an embodiment of the present application also provides a data integrity verification method, including:
[0023] The second device generates a first authentication tag value according to the first plaintext through the first rule; the second device sends a message to be verified to the first device, and the message to be verified includes a first ciphertext and the first authentication tag value, wherein the first ciphertext is the ciphertext corresponding to the first plaintext, and the first authentication tag value is used to determine whether the message to be verified has integrity.
[0024] The beneficial effects of the second aspect and each possible design of the second aspect can refer to the description of the beneficial effects in the first aspect and the corresponding possible designs, and will not be repeated here.
[0025] In one possible design, the second device generates a first authentication tag value according to the first plaintext through a first rule, including: the second device determines T grouped plaintexts with a data length equal to a group length according to the first plaintext; the second device determines a first cumulative value corresponding to the T grouped plaintexts through a cumulative value algorithm; the second device determines the first authentication tag value according to a first sequence with a data length equal to the group length and the first cumulative value, the first sequence being related to the plaintext length contained in the last group of the first plaintext and the group length, and the first authentication tag value is used to determine whether the message to be verified has integrity together with the second authentication tag value.
[0026] In one possible design, the lengths of the first authentication tag value and the second authentication tag value are both the packet length.
[0027] In one possible design, the first cumulative value and the T group plaintexts satisfy the following relationship: T'=(f(x)'Y T-1 ')⊕P T-1 '; where f(x)' represents a function with x as a variable, P T-1 ' represents the T-th group plaintext among the T group plaintexts, ⊕ represents an XOR operation, Y T ' represents the first cumulative value, Y T-1 ' represents a second cumulative value determined based on the 1st group plaintext to the T-1th group plaintext among the T group plaintexts.
[0028] In a possible design, the first authentication tag value is a sequence included in the cumulative value ciphertext; the cumulative value ciphertext satisfies the following relationship: Z'=F1(Y T+1 '); wherein F1 represents an encryption algorithm; the Y T+1 ' represents the first group cumulative value, satisfying the following relationship: Y T+1 '=Y T '⊕L; where Y T ' is the first cumulative value, and L is the first sequence.
[0029] In a third aspect, an embodiment of the present application also provides a data integrity verification device, including an acquisition module and a processing module.
[0030] An acquisition module is used to receive a message to be verified from a second device, wherein the message to be verified includes a first ciphertext and a first authentication tag value, wherein the first ciphertext is a ciphertext corresponding to a first plaintext, and the first authentication tag value is generated by the second device according to the first plaintext; a processing module is used to decrypt the first ciphertext to obtain a second plaintext; the processing module is also used to verify the first authentication tag value according to the second plaintext to determine whether the message to be verified has integrity.
[0031] In one possible design, the processing module is specifically used to: determine a second authentication tag value according to the second plaintext through a first rule, wherein the first authentication tag value is generated by the second device according to the first plaintext through the first rule; determine whether the message to be verified has integrity according to a comparison result of the first authentication tag value and the second authentication tag value.
[0032] In one possible design, the processing module is specifically used to: determine T grouped plaintexts with a data length equal to the group length based on the second plaintext; determine a first cumulative value corresponding to the T grouped plaintexts through a cumulative value algorithm; determine the second authentication tag value based on a first sequence with a data length equal to the group length and the first cumulative value, wherein the first sequence is related to the plaintext length contained in the last group of the second plaintext and the group length.
[0033] In one possible design, the lengths of the first authentication tag value and the second authentication tag value are both the packet length.
[0034] In one possible design, the first cumulative value and the T group plaintexts satisfy the following relationship: T =(f(x)Y T-1 )⊕P T-1 ; where f(x) represents a function with x as a variable, P T-1 represents the T-th plaintext among the T plaintext groups, ⊕ represents an XOR operation, and Y T represents the first cumulative value, Y T-1 It represents a second cumulative value determined based on the 1st group plaintext to the T-1th group plaintext among the T group plaintexts.
[0035] In a possible design, the second authentication tag value is a sequence included in the cumulative value ciphertext; the cumulative value ciphertext satisfies the following relationship: Z = F1 (Y T+1 ); wherein F1 represents an encryption algorithm; the Y T+1 Represents the cumulative value of the first group, satisfying the following relationship: Y T+1 =Y T ⊕L; where Y T is the first cumulative value, and L is the first sequence.
[0036] In one possible design, the processing module is specifically used to: obtain a third authentication tag value from the message to be verified according to the length of the authentication tag value, and the length of the authentication tag value is the length of the first authentication tag value; decrypt the third authentication tag value to obtain a second group cumulative value; determine T group plaintexts with a data length equal to the group length according to the second plaintext; determine the first cumulative value corresponding to the T group plaintexts through a cumulative value algorithm; determine a second sequence according to the second group cumulative value and the first cumulative value; and determine that the message to be verified has integrity when the second sequence satisfies a set rule.
[0037] In one possible design, the processing module is further used to: determine the plaintext length contained in the last group of the second plaintext according to the second sequence; and determine the initial message from the second plaintext according to the plaintext length.
[0038] In a fourth aspect, an embodiment of the present application further provides a data integrity verification device, including a processing module.
[0039] A processing module is used to generate a first authentication tag value according to a first plaintext through a first rule; the processing module is also used to send a message to be verified to a first device, the message to be verified includes a first ciphertext and the first authentication tag value, wherein the first ciphertext is the ciphertext corresponding to the first plaintext, and the first authentication tag value is used to determine whether the message to be verified has integrity.
[0040] In one possible design, the processing module is specifically used to: determine T grouped plaintexts with a data length equal to a group length based on the first plaintext; determine a first cumulative value corresponding to the T grouped plaintexts through a cumulative value algorithm; determine the first authentication tag value based on a first sequence with a data length equal to the group length and the first cumulative value, the first sequence being related to the plaintext length contained in the last group of the first plaintext and the group length, and the first authentication tag value being used to determine whether the message to be verified has integrity together with the second authentication tag value.
[0041] In one possible design, the lengths of the first authentication tag value and the second authentication tag value are both the packet length.
[0042] In one possible design, the first accumulated value and the T grouped plaintexts satisfy the following relationship: T '=(f(x)'Y T-1 ')⊕P T-1 '; where f(x)' represents a function with x as a variable, P T-1 ' represents the T-th group plaintext among the T group plaintexts, ⊕ represents an XOR operation, Y T ' represents the first cumulative value, Y T-1 ' represents a second cumulative value determined based on the 1st group plaintext to the T-1th group plaintext among the T group plaintexts.
[0043] In a possible design, the first authentication tag value is a sequence included in the cumulative value ciphertext; the cumulative value ciphertext satisfies the following relationship: Z'=F1(Y T+1 '); wherein F1 represents an encryption algorithm; the Y T+1 ' represents the first group cumulative value, satisfying the following relationship: Y T+1 '=Y T '⊕L; where Y T ' is the first cumulative value, and L is the first sequence.
[0044] In a fifth aspect, an embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method of the first aspect, the second aspect, and any one of their designs is implemented.
[0045] In the sixth aspect, an embodiment of the present application further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the computer program is executed by the processor, the processor implements the first aspect, the second aspect, and any one of the designed methods.
[0046] The technical effects brought about by the third to sixth aspects and any one of their designs can refer to the technical effects brought about by the corresponding designs in the first and second aspects, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0048] Figure 1 A flowchart of a data integrity verification method provided in an embodiment of the present application;
[0049] Figure 2 A schematic diagram of a device structure provided in an embodiment of the present application;
[0050] Figure 3 A schematic diagram of another device structure provided in an embodiment of the present application. DETAILED DESCRIPTION
[0051] In order to make the purpose, technical scheme and advantages of the present application clearer, the technical scheme in the embodiment of the present application will be clearly and completely described below in conjunction with the drawings in the embodiment of the present application. Obviously, the described embodiment is only a part of the embodiment of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application. In the absence of conflict, the embodiments in the present application and the features in the embodiments can be arbitrarily combined with each other. In addition, although the logical order is shown in the flow chart, in some cases, the steps shown or described can be performed in an order different from that here.
[0052] The terms "first" and "second" in the specification and claims of the present application and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the term "comprising" and any of their variations are intended to cover non-exclusive protection. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but optionally also includes steps or units that are not listed, or optionally also includes other steps or units inherent to these processes, methods, products or devices. "Multiple" in the present application can mean at least two, for example, two, three or more, and the embodiments of the present application are not limited.
[0053] In the technical solution of this application, the collection, dissemination, and use of data are in compliance with the requirements of relevant national laws and regulations.
[0054] Before introducing a data integrity verification method provided by an embodiment of the present application, in order to facilitate understanding, the technical background of the embodiment of the present application is first introduced in detail below.
[0055] In the field of information security, in order to prevent ciphertext from being tampered with, it may be necessary to have an integrity check function in the cryptographic system. At present, there are many ways to implement integrity check. For example, there are three types of schemes: Scheme 1: using a hash function to calculate the summary of the entire message, Scheme 2: using a special block cipher algorithm with authentication function, and Scheme 3: using a block cipher working mode with authentication function. Among the above three types of schemes, the disadvantage of using a hash function in Scheme 1 is low efficiency and large amount of program code. Schemes 2 and 3 use special block algorithms with authentication functions, such as CCM (counter with CBC-MAC) and OCB (offset codebook, OCB) modes of block ciphers, while common modes familiar to programmers, such as electronic codebock mode (electronic codebock, ECB), cipher block chaining mode (cipher block chaining, CBC), output feedback mode (output feedback, OFB) and counter mode (counter, CTR), do not have authentication functions. Therefore, when the current device uses a block cipher algorithm to encrypt data, it lacks the ability to generate an authentication tag for authenticating the integrity of the data while encrypting, which needs to be improved.
[0056] In order to solve the above problems, the present application provides a data integrity verification method, which enables the encryption device to generate a packet message according to the initial data when encrypting the message with a block cipher algorithm, and the encryption device can perform cumulative operations and encryption according to the packet message to generate a first authentication tag value, and encrypt the packet message to obtain a packet ciphertext, determine the message ciphertext by the packet ciphertext and the first authentication tag value, and send the message ciphertext to the decryption device. The decryption device can obtain the packet ciphertext in the message ciphertext sent by the encryption device as the ciphertext to be verified, perform cumulative operations and encryption according to the plaintext to be verified obtained by decryption to obtain the authentication tag value to be verified, determine whether the message to be verified has integrity according to the authentication tag value sent by the encryption device and the authentication tag value to be verified generated by the decryption device itself, and determine whether the plaintext to be verified is credible, thereby improving the efficiency of the decryption device in verifying the integrity of the message.
[0057] Figure 1 A flow chart of a data integrity verification method is shown exemplarily. Exemplarily, the executor of the method is a first device. Among them, the first device can be a decryption device, and the second device can be an encryption device. In the present application, the first device and the second device can pre-agree on the same data length of the authentication tag value according to the encryption mode. For example, the second device uses the ECB algorithm to determine the data length of the first authentication tag value and generates a first authentication tag value of a certain length. Then, the first device can use the same ECB algorithm to verify the first authentication tag value. In the present application, length and data length can be interchangeable.
[0058] refer to Figure 1 In the process shown, taking the first device as the execution subject as an example, the method provided in the embodiment of the present application may include the following steps:
[0059] Step 101: A first device receives a message to be verified from a second device, where the message to be verified includes a first ciphertext and a first authentication tag value.
[0060] Step 102: the first device decrypts the first ciphertext to obtain a second plaintext;
[0061] Step 103: The first device verifies the first authentication tag value according to the second plaintext to determine whether the message to be verified has integrity.
[0062] Optionally, before step 101, the second device may generate a first ciphertext and send the first ciphertext to the first device.
[0063] Optionally, the following first describes a process in which the second device generates a message to be verified.
[0064] Optionally, the second device may be used as an encryption device, and the first device may be used as a decryption device. The second device and the first device may agree to use the same encryption mode and the same data length of the authentication tag value. The second device and the first device may respectively generate a first authentication tag value and a second authentication tag value according to the same data length of the authentication tag value. The second device may determine the data length of the authentication tag value according to the encryption mode, and obtain the first authentication tag value according to the first plaintext.
[0065] Optionally, the second device may obtain the first plaintext.
[0066] Optionally, the second device and the first device may agree on an encryption mode in advance, and according to the encryption mode, agree on the same data length of the first authentication tag value. Any encryption mode requires an agreed data length of the authentication tag value so that the second device and the first device generate the authentication tag value. For example, the data length of the authentication tag value may be a packet length or less than a packet length, which is not specifically limited.
[0067] Optionally, the second device may agree on an encryption mode with the first device, and in the encryption mode, the second device may pad the first plaintext with bits, and obtain the first ciphertext based on the padded plaintext, so that the length of the padded first plaintext is an integer multiple of the packet length. The second device may agree on other encryption modes with the first device, in which the second device may not pad the first plaintext, that is, it is not required that the length of the first ciphertext before encryption is an integer multiple of the packet length.
[0068] For example, the second device determines that the packet length N is 128 bits, and the second device obtains the first plaintext. The data length of the first plaintext is 1328 bits, and 1328 bits is not an integer multiple of 128 bits. If the second device determines that the encryption formula requires padding of the first plaintext, that is, the second device needs to add 80 bits of "0" to 1328 bits to obtain 1408 bits of data, the second device can determine that the first sequence L is a formatting constant. L can be a formatting constant determined according to the padding bit length 80, for example, it can be expressed in hexadecimal as: 0x50505050505050505050505050505050; for example, L is expanded into bits in binary as 010100000101000001010000……01010000. L can be used to determine the authentication tag value, and the determination method will be described below. The second device may record the first plaintext as m, and concatenate m with the data "0" to obtain m|0...0, where the symbol "|" represents connecting two symbol strings into one string. The second device may concatenate the data 0 at the lower bit of the first plaintext. Alternatively, the second device may concatenate the data 0 before the first plaintext. The second device may divide m|0...0 into 11 groups of plaintext, that is, T is equal to 11.
[0069] For another example, if the data length of the first plaintext is 1280 bits, the second device may divide the first plaintext into 10 groups of plaintext. Each group of plaintext is 128 bits. Alternatively, the second device may determine that the encryption mode is not to fill the plaintext, then the second device may directly divide the 1240-bit initial message into 10 groups of plaintext according to the encryption mode, and the last group of plaintext is 88 bits.
[0070] That is to say, the first sequence is related to the length of the last plaintext packet of the first plaintext and the packet length. Among them, the length of the first sequence is the same as the packet length. In addition, in the case where the first plaintext needs to be filled with bits, the first sequence can be used to indicate the length of the filling bits. For example, when the packet length is 128, the first sequence can contain 16 bytes, and each byte carries the same information to indicate the length of the filling bits. For example, in the above example, the filling bits are 80 bits, and the filling value is 80 bits of "0", that is, each byte of the first sequence L is equal to 0101 0000, and the hexadecimal "0x50" represents the decimal "80", indicating that the filling data is a length of 80 bits of "0".
[0071] Therefore, if the agreed encryption mode is a mode that requires padding when the length of the plaintext of the last block of the first plaintext is less than the block length, and the length of the plaintext contained in the last block of the first plaintext is less than the block length, the length of the first sequence is equal to the block length minus the length of the plaintext contained in the last block of the first plaintext, that is, when the length of the plaintext of the last block of the first plaintext is less than the block length, the length of the plaintext of the last block is padded with "0" to make it a full block. The number of bits padded with "0" is recorded in each byte in the first sequence.
[0072] For example, the last group of the first plaintext contains a plaintext length of 127 bits, and the group length is 128 bits, which needs to be padded with 1 bit "0". The length of the first sequence is 128 bits. The regular sequence of the first sequence of 128 bits is: 00000001 00000001...00000001.
[0073] It can be understood that, in the case where the data length of the initial message is not equal to an integer multiple of the packet length, whether the second device fills the initial message so that its length is equal to an integer multiple of the packet length may be agreed upon by the first device and the second device, or may be related to the encryption method, and this application does not limit it. In addition, if padding is required, the length of the padding sequence may also be agreed upon by the first device and the second device, or may be related to the encryption method, and this application does not limit it; at this time, if the second device does not fill the initial message, the ciphertext is incomplete.
[0074] If the agreed encryption mode is a mode that does not require padding when the length of the plaintext in the last block of the first plaintext is less than the block length, and the length of the plaintext contained in the last block of the first plaintext is less than the block length, the length of the first sequence is still equal to the block length. For example, when the block length is 128, the first sequence can contain 16 bytes, and each byte carries the same information to indicate the missing data length of the last block. For example, if the last block length is 48, the missing data length is 80, that is, each byte is used to indicate 80.
[0075] If the length of the plaintext contained in the last block of the first plaintext is equal to the block length, regardless of whether the encryption mode is a mode that requires padding, the length of the first sequence is equal to the block length. For example, when the block length is 128, the first sequence can contain 16 bytes of "0".
[0076] Optionally, the second device may generate a first authentication tag value according to the first plaintext by using a first rule. The first rule may include grouping and accumulating the first plaintext and encrypting it. The second device may divide the first plaintext into T grouped plaintexts whose data length is the group length, and determine a first cumulative value for the T grouped plaintexts by using a cumulative value algorithm. The second device may determine a first cumulative value corresponding to the T grouped plaintexts by using a cumulative value algorithm for the T grouped plaintexts. The process of determining the first cumulative value is as follows:
[0077] The second device can determine the initial cumulative value. The second device can record T groups of grouped plaintexts as the first group of grouped plaintexts, the second group of grouped plaintexts, ..., the Tth group of grouped plaintexts. The initial cumulative value can be a string of all zeros. The second device can perform a shift XOR operation on the initial cumulative value after a shift process with the first group of grouped plaintexts to obtain a first group of cumulative values. The second device can perform a shift XOR operation on the first group of cumulative values after a shift process with the second group of grouped plaintexts to obtain a second group of cumulative values. In the present application, the shift process can be understood as multiplying f(x) on a finite field. By analogy, the second device can obtain the Tth group of cumulative values, and the Tth group of cumulative values is called the first cumulative value. The second device can perform an XOR operation on the Tth group of cumulative values and the first sequence to obtain the (T+1)th group of cumulative values, and the (T+1)th group of cumulative values is called the first group cumulative value. The second device can determine a cumulative value storage unit and store the cumulative value in the cumulative value storage unit.
[0078] Optionally, the second device may record both the accumulated value and the grouped plaintext as polynomials with coefficients of 0 or 1 and a degree of at most N-1. The second device may convert the accumulated value into a function, and the accumulated value may be recorded as Y i ', the function can be recorded as Y i (x)'=c N-1 x N-1 +c N- 2x N-2+…+c1x+c0, i=0, 1, 2, …T-1. For example, assuming that the second device obtains the group plaintext of the first plaintext, the group plaintext can be represented as P0', P1', …, P9', where the value of P9' can be represented as 128-bit data: 0x1000000010000000 100000000000CCDD, where C represents 1100 and D represents 1101, then the value of P9' is 0x100000001000000010000000 0000(1100)(1100)(1101)(1101). The second device can represent P9' as a polynomial: x 124 +……+x 92 +……+x 60 +……+(1*x 15 +1*x 14 +0*x 13 +0*x 12 )+(1*x 11 +1*x 10 +0*x 9 +0*x 8 )+(1*x 7 +1*x 6 +0*x 5 +1*x 4 )+(1*x 3 +1*x 2 +0*x 1 +1*x 0 ). If the value of a certain bit of P9' is 0, the value of this bit in P9' can be converted to 0*x a +0*x b +0*x c +0*x d If the value of a bit in P9' is 1, the value of that bit in P9' can be converted to 0*x a +0*x b +0*x c +1*x d , it can be understood that a, b, c, d can be determined according to the value of the specific group plaintext. Similarly, the second device can i 'Convert to function Y i (x)'.
[0079] Optionally, the second device can determine the packet length, construct a Galois field according to the packet length, and select an irreducible polynomial of a corresponding order according to the packet length, the irreducible polynomial being the modular polynomial of the Galois field. The second device can perform modular multiplication on the accumulated value according to the irreducible polynomial, so that the accumulated value after the modular operation belongs to an element in the Galois field. If the accumulated value after the modular operation belongs to an element in the Galois field, the accumulated value can be conveniently encrypted or decrypted as a data packet. Multiplication and addition operations on the Galois field can be completed quickly in a computer processor, and if an error occurs on a certain bit, the error can be diffused to multiple bits of the accumulated value of the packet after multiplication on the Galois field.
[0080] Optionally, the second device may compare f(x)' with Y corresponding to the accumulated value in a finite field. i 'The function performs multiplication. If the second device is f(x)'=x, then x and the accumulated value Y i 'Multiply, that is, accumulate the value Y i 'Left shift. For another example, the second device may take f(x)' as f(x)'=x -1 , then x -1 and the cumulative value Y i 'Multiply, that is, accumulate the value Y i 'Shift right. The accumulated value after the shift process can be expressed as Y i+1 '.
[0081] Optionally, the first cumulative value may satisfy the following relationship:
[0082] Y1'=(f(x)'Y0')⊕P0';
[0083] Y2'=(f(x)'Y1')⊕P1';
[0084] ……;
[0085] Y T '=(f(x)'Y T-1 ')⊕P T-1 ';
[0086] Among them, P0'...P T-1 'represent the 1st group of plaintexts ... the Tth group of plaintexts respectively, T is a natural number, Y0', Y1', ..., Y T 'represent the initial cumulative value of the second device, the first group of cumulative values, ..., the Tth group of cumulative values, Y0' can be a zero string, f(x)'Y i ' means to do f(x)' and Y in a finite field i 'Function multiplication operation, f(x)' represents a function with x as a variable, f(x)' is used in the operation iIt is regarded as a polynomial with x as the variable, and ⊕ represents a bitwise XOR operation.
[0087] Optionally, the second device may also take f(x)' as the function corresponding to the variable x. The second device may take f(x)' as an element in the Galois field, that is, the highest degree in the function of f(x)' is less than 128. For example, the second device may take f(x)'=x, or the second device may take f(x)'=x 3 . You can also choose x+1, x 2 、x 2 +1, x 2 +x+1, x 3 +1, ... or x 127 +x 126 +…+1.
[0088] For example, the second device may select f(x)'=x, determine the initial cumulative value Y0'=0, and determine P0'. The second device may convert P0' into a polynomial P0(x)'. The second device may convert Y0' into a function, which may be recorded as Y0(x)', Y0(x)'=0*x0*x a +0*x b +……+0*x d The second device can calculate Y1'=(f(x)'Y0')⊕P0'=(xY0(x)')⊕P0(x)' in the domain. The second device can obtain Y1' and convert Y1' into function Y1(x)'. Assuming that Y1(x)' is A 127 x 127 +A 126 x 126 +…+A1x+A0. The second device can calculate Y1(x)'=(f(x)'Y0')⊕P0'=(xY0(x)')⊕P0(x)' in the domain. The second device can calculate Y2'=(f(x)'Y1')⊕P1'=(xY1(x)')⊕P1(x)' in the domain, that is, Y1(x)'=A 127 x 127 +A 126 x 126 +…+A1x+A0 multiply each term by x to get xY1(x)'=A 127 x 128 +A 126 x 127 +…+A1x 2 +A0x. If A 127 =1, since the number of xY1(x)' is 128, to ensure that the cumulative value is still within the finite field, that is, to ensure that the number of Y1(x)' is not greater than 127, the second device can select q(x) as (x 128 +x 9 +x 8+x 7 +x 5 +x 4 +1), perform a modular operation on Y1(x)', and Y1(x)' after the modular operation can be expressed as Y1(x) 128 ', Y1(x) 128 ' belongs to a finite field.
[0089] Optionally, when the second device takes f(x)=x or f(x)=x -1 When , the process of calculating the cumulative value is relatively simple, easy to implement, and the efficiency of obtaining the cumulative value is high. When f(x) takes a function with a higher degree and a larger number of terms, the security of calculating the cumulative value is higher, which can improve the security of the authentication tag value, but the process of calculating the cumulative value requires multiplication of two larger polynomials and modular operations, resulting in a low efficiency of obtaining the cumulative value. Therefore, both the second device and the first device can determine f(x) as needed.
[0090] The second device will be based on Y1(x) 128 'Continue to perform multiplication and accumulation operations on the grouped plaintext, and the accumulated value obtained satisfies the following relationship:
[0091] Y2(x)'=((xY1(x) 128 )')⊕P2(x)'.
[0092] Similarly, the second device can obtain the accumulated values Y1', Y2', ... Y T '.
[0093] Optionally, the second device may perform an XOR operation on the first cumulative value and the first sequence, and obtain the group cumulative value Y of the second device according to the XOR result. T+1 '. The second device can encrypt the group accumulation value Y according to the group encryption algorithm T+1 'Encrypt to obtain the accumulated value ciphertext of the second device.
[0094] For example, if f(x)=x, the cumulative value ciphertext can satisfy the following relationship:
[0095] Y T+1 '=Y T '⊕L; (Formula 1)
[0096] Z'=ENC K (Y T+1 ');
[0097] Among them, Z' represents the cumulative value ciphertext, ENC K (Y T+1 ') indicates that the group cumulative value is encrypted according to the group encryption algorithm, and L indicates the first sequence.
[0098] For example, if the data length is 1328 bits, the second device takes T as 11, and according to the 11 group plaintexts P0', P1', ... P 10 'Determine the cumulative value Y of group 11 10 ', Y 10 'Multiply left to get xY 10 ', xY 10 'XOR operation with the first sequence L to obtain the 12th group cumulative value Y 11 ', where P0', P1', ... P 10 ' are all 128-bit group plaintext, L is a 128-bit formatting constant: 0x505050505050505050505050505050, indicating the group plaintext P 10 ' 0x50 = 80 bits are filled. The second device can obtain the 12th packet accumulation value Y 11 '. The second device can encrypt the group accumulation value Y according to the group encryption algorithm 11 'Encrypt and get the encryption result ENC K (Y 11 ') as the cumulative value ciphertext. Further, the second device can determine the first authentication tag value that meets the length from the cumulative value ciphertext according to the data length of the authentication tag value.
[0099] Optionally, the second device can use the packet length or data less than the packet length in the cumulative value ciphertext as the first authentication tag value. For example, the second device can pad the 1328-bit first plaintext with 80 bits of L to obtain 1408 bits. The 1408-bit plaintext can be divided into 11 groups of 128 bits, each group of plaintext is 128 bits, and the second device can obtain the cumulative value Y from the 11 groups of grouped plaintexts. 10 ', xY 10 'XOR with L to get Y 11 ', can be used for Y 11 'Encryption is performed to obtain a cumulative value ciphertext Z', and 128 bits of data can be selected from Z' as the first authentication tag value.
[0100] For another example, the second device may divide the 1328-bit first plaintext into 11 groups, the first 10 groups of plaintext are 128 bits, and the 11th group of plaintext is 48 bits. The second device may obtain the group accumulation value Y from the 11 groups of plaintext. 10 ', xY 10 'XOR with L to get Y 11 ', can be used for Y 11'Encrypt to obtain a 128-bit cumulative value ciphertext Z'. The second device and the first device can determine that the length of the authentication tag value is 96 bits according to the encryption mode, and the second device can select the first 96 bits of data from the 128-bit Z' data as the first authentication tag value.
[0101] Optionally, the block encryption algorithm may be ECB, OFB, CFB, CBC or CTR mode. The second device may encrypt the (T+1)th group of accumulated values according to the block encryption algorithm and the encryption mode.
[0102] Optionally, the second device may perform block encryption on the first plaintext to obtain the first ciphertext.
[0103] For example, the second device may obtain the group plaintexts P0', P1', ... P of the first plaintext. 10 '. The second device may use the ECB mode to group the plaintext P0', P1', ... P 10 'Perform block encryption to obtain ciphertext ECB(P0'), ...ECB(P 10 ').
[0104] Optionally, the second device may compose a message ciphertext according to the ciphertext and the first authentication tag value.
[0105] Step 101 is described below.
[0106] Step 101: A first device receives a message to be verified from a second device, where the message to be verified includes a first ciphertext and a first authentication tag value.
[0107] Optionally, the first device may obtain the first ciphertext and the first authentication tag value sent by the second device.
[0108] Optionally, since when the second device sends the first ciphertext and the first authentication tag value to the first device, the first ciphertext received by the first device may not be equal to the first ciphertext sent by the second device due to interference in the transmission process, the message received by the first device is used as the message to be verified, and the first ciphertext received by the first device is used as the ciphertext to be verified, and the second plaintext is obtained by decrypting the ciphertext to be verified.
[0109] Step 102: The first device decrypts the first ciphertext to obtain the second plaintext.
[0110] Optionally, the first device may use the same grouping algorithm and encryption mode as the second device to decrypt T groups of first ciphertexts to obtain the second plaintext. For example, the first device may obtain 11 groups of first ciphertexts ECB(P0)…ECB(P 10 ) and the first authentication tag value. The first device can use the ECB mode to perform ECB(P0)...ECB(P 10) to decrypt, and the decrypted second plaintext P0, P1, ..., P 10 .
[0111] Optionally, the first device performs cumulative calculation and encryption on the second plaintext to generate a second authentication tag value. The first device may determine a first sequence. The first sequence may be denoted as L.
[0112] Optionally, the first device may determine T grouped plaintexts whose data length is the group length according to the second plaintext, and determine the first cumulative value corresponding to the T grouped plaintexts by using a cumulative value algorithm. The first device may perform multiplication and XOR operations on the T grouped plaintexts to obtain T first cumulative values, and then perform XOR operations on the first cumulative value and the first sequence to determine the first grouped cumulative value. Further, the first device may encrypt the first grouped cumulative value to obtain a cumulative value ciphertext.
[0113] Optionally, the cumulative value ciphertext Z satisfies the following relationship:
[0114] Y1=(f(x)Y0)⊕P0;
[0115] Y2=(f(x)Y1)⊕P1;
[0116] Y3=(f(x)Y2)⊕P2;
[0117] ……;
[0118] Y T =(f(x)Y T-1 )⊕P T-1 ;
[0119] Y T+1 =Y T ⊕L;
[0120] Z=F1(Y T+1 ).
[0121] Among them, P i represents the second plaintext of the i-th group, i = 0, 1, 2, ... T-1, T is a natural number, Y0 is a zero string, Y1 represents the cumulative value determined based on the first group plaintext, and Y2 represents the cumulative value determined based on the first group plaintext to the second group plaintext. It can be seen that Y T-1 represents the second cumulative value determined based on the first to the Tth group plaintexts among the T group plaintexts, f(x)Y i Indicates that f(x) and Y are interrelated in a finite field. i Function multiplication operation, f(x) represents any function corresponding to variable x, ⊕ represents bitwise XOR operation, L represents the first sequence. Z represents the accumulated value ciphertext, and F1 represents the encryption algorithm, such as a block encryption algorithm. For example, F1(Y T+1 )=ENCK (Y T+1 ), which means that the first group cumulative value Y is encrypted according to the group encryption algorithm T+1 Encryption is performed.
[0122] For example, the first device may select f(x)=x, determine Y0=0, and determine P0. The first device may convert P0 into a polynomial P0(x). The first device may convert Y0 into a function Y0, which may be recorded as Y0(x), Y0(x)=0*x0*x a +0*x b +……+0*x d The first device can calculate Y1 = (f(x)Y0) ⊕ P0 = (xY0(x)) ⊕ P0(x) in the domain. The first device can obtain Y1 and convert Y1 into function Y1. Function Y1 can be recorded as Y1(x). Assume that Y1(x) is A 127 x 127 +A 126 x 126 +…+A1x+A0. The first device can calculate Y1(x)=(f(x)Y0)⊕P0=(xY0(x))⊕P0(x) in the domain. The first device can calculate Y2=(f(x)Y1)⊕P1=(xY1(x))⊕P1(x) in the domain, that is, Y1(x)=A 127 x 127 +A 126 x 126 Multiply each term in +…+A1x+A0 by x on the left to get xY1(x) equal to A 127 x 128 +A 126 x 127 +…+A1x 2 +A0x. If A 127 =1, since the highest order term of xY1(x) is 128, the highest order term of Y2(x) obtained by xY1(x)⊕P1(x) is equal to 128. To ensure that the accumulated value obtained by Y2(x) is still within the finite field, the first device can select q(x) as (x 128 +x 9 +x 8 +x 7 +x 5 +x 4 +1), and then perform a modular operation on q(x) to obtain Y2(x) 128 , Y2(x) 128 belongs to a finite field. Similarly, Y3(x) can satisfy the following relationship:
[0123] Y3(x)=((xY2(x) 128 ))⊕P2(x).
[0124] Similarly, the first device can obtain the accumulated values Y1, Y2, ... Y T .
[0125] Optionally, for example, when there are 10 plaintext groups, the cumulative value ciphertext Z can satisfy the following relationship:
[0126] Y 11 =Y 10 ⊕L; (Formula 2)
[0127] Z=F1(Y 11 );
[0128] The accumulated value ciphertext is used to generate the second authentication tag value. F1 represents an encryption algorithm, for example, a block encryption algorithm can be used. For example, F1(Y 11 )=ENC K (Y 11 ). ENC K (Y 11 ) can represent the first group cumulative value Y according to the group encryption algorithm 11 L represents the first sequence. The first device may use the sequence in the accumulated value ciphertext that meets the data length requirement of the authentication tag value as the second authentication tag value according to the agreed encryption mode.
[0129] Optionally, the first device may take f(x)=x in the process of determining the accumulated value of the first device, and f(x)Y0 may represent a left shift of the accumulated value Y0. -1 , then f(x)Y0 can represent the right shift of the accumulated value Y0, f(x) = x -1 This is equivalent to multiplying Y0 on the right, that is, Y0f(x). Assume that Y1(x) is A 127 x 127 +A 126 x 126 +…+A1x+A0. The first device can calculate in the domain:
[0130] Y1(x)=(f(x)Y0)⊕P0=(x -1 The first device may calculate Y2=(f(x)Y1)⊕P1=(x) in the domain. -1 Y1(x))⊕P1(x), that is, Y1(x)=A 127 x 127 +A 126 x 126 Divide each term in +…+A1x+A0 by x to get x -1 Y1(x)=A 127 x 126 +A 126 x 125+…+A2x 2 +A2x+A1+A0x -1 If A0=1, x -1 Convert to x 127 +x 8 +x 7 +x 6 +x 4 +x 3 This is because
[0131] x·(x 127 +x 8 +x 7 +x 6 +x 4 +x 3 )=x 128 +x 9 +x 8 +x 7 +x 5 +x 4 ≡1mod(x 128 +x 9 +x 8 +x 7 +x 5 +x 4 +1), ≡ means it is always equal to.
[0132] Optionally, the first device determines whether the message to be verified has integrity based on a comparison result between the first authentication tag value and the second authentication tag value, and may determine whether the plaintext to be verified is credible based on a comparison result between the first authentication tag value and the second authentication tag value.
[0133] Optionally, if the comparison result is that the second authentication tag value is the same as the first authentication tag value, the first device can determine that the message to be verified has integrity and that the plaintext to be verified is credible. If the comparison result is that the second authentication tag value is different from the first authentication tag value, the first device can determine that the message to be verified does not have integrity and that the second plaintext is not credible.
[0134] Optionally, (i) in an exemplary verification method, the first plaintext is exactly an integer multiple of the packet length and does not require padding, that is, L is a sequence of 0s with a length of 128. In this case:
[0135] The second device and the first device agree on the encryption mode and decryption mode. Taking the example that the plaintext has 10 groups and the group length is 128 bits, the initial message of the second device with a length of 1280 bits is exactly divided into 10 groups, and the length of each group is 128 bits. In other words, at this time, the first plaintext contains 10 groups of plaintext with a length of 128 bits, which are respectively counted as: P0', P1', ..., P9'. The second device takes the initial cumulative value Y0'=0, takes f(x)'=x and determines the cumulative value ciphertext Z'. Taking the block encryption algorithm as an example, the cumulative value ciphertext Z' can satisfy the following relationship:
[0136] Y1'=(xY0')⊕P0';
[0137] Y2'=(xY1')⊕P1';
[0138] ……;
[0139] Y 10 ' = (xY9') ⊕ P9';
[0140] Y 11 '=Y 10 '⊕L;
[0141] Z'=ENC K (Y 11 ');
[0142] Taking the example that the length of the authentication tag value is 128 bits, the second device can select 128 bits from Z' as the first authentication tag value, and send a message to be verified to the first device, which may include a first ciphertext and a first authentication tag value. The first ciphertext may be a ciphertext obtained by encrypting the first plaintext. Correspondingly, the first device can obtain the 128-bit first authentication tag value in the message to be verified according to the length of the authentication tag value. The first device decrypts the first ciphertext in the message to be verified, obtains the second plaintext, and determines the cumulative value ciphertext Z based on formula 2. The first device takes the initial cumulative value Y0=0, and takes f(x)=x. Taking the block encryption algorithm as an example, the cumulative value ciphertext Z can satisfy the following relationship:
[0143] Y1=(xY0)⊕P0;
[0144] Y2=(xY1)⊕P1;
[0145] ……;
[0146] Y 10 =(xY9)⊕P9;
[0147] Y 11 =Y 10 ⊕L;
[0148] Z=ENCK (Y 11 );
[0149] The first device can select 128 bits of data from Z as the second authentication tag value. If the message to be verified is accurately transmitted to the first device, the first authentication tag value should be equal to the second authentication tag value, and the first device can compare whether the second authentication tag value is equal to the first authentication tag value to determine whether the message to be verified has integrity. Since the second device in this example does not fill the initial message, that is, the initial message is equal to the first plaintext, the second plaintext should be equal to the initial message. If the second authentication tag value is not equal to the first authentication tag value, the first device can determine that the message to be verified does not have integrity, and that the decrypted P0, ..., P9 is unreliable.
[0150] (II) In an exemplary verification method, the initial message is not an integer multiple of the packet length and needs to be padded with 80 bits, and the first device and the second device have not agreed on the length of the padding bits. In this case, in order to make the initial message a complete block, the second device can fill the end of the initial message with a value to integrate the initial message into a full group, and then encrypt it to obtain the entire ciphertext, and add the authentication tag value after the ciphertext.
[0151] Optionally, the first device can obtain a third authentication tag value from the received message to be verified according to the packet length. If the reception is accurate, the third authentication tag value is equal to the first authentication tag value. The first device can also obtain a second packet cumulative value by decrypting the third authentication tag value. In addition, the first device can also obtain a second plaintext by decrypting the first ciphertext, and determine the first cumulative value according to the second plaintext using the method described in the full text. Further, the first device can try to determine the second sequence according to the second packet cumulative value and the first cumulative value. In the case of correct decryption and reception, the first cumulative value obtained by the first device is equal to the first cumulative value determined by the second device according to the first plaintext. Therefore, the second packet cumulative value, the first cumulative value and the second sequence satisfy Formula 1 (and / or Formula 2). Therefore, the first device can perform an inverse operation through Formula 1 to solve the second sequence corresponding to the second packet cumulative value and the first cumulative value. If a sequence that satisfies the generation rule of the aforementioned second sequence can be solved, the decryption and reception can be verified to be successful, that is, the integrity of the message to be verified can be verified.
[0152] For example, the first device receives the first ciphertext and the third authentication tag value, decrypts the first ciphertext to determine the second plaintext. The first device determines the first cumulative value Y corresponding to the second plaintext according to the first rule T , and the first device decrypts the third authentication tag value to determine the second packet accumulation value Y T+1 For example, if the second device uses ENC K Function Encryption Y T+1 ', then accordingly, the first device can be based on ENCK The inverse function of the function solves the third authentication tag value to obtain the second group accumulation value Y T+1 .
[0153] Furthermore, the first device may convert the first accumulated value Y T and the second group cumulative value Y T+1 Substitute the following relationship:
[0154] Y T+1 =Y T ⊕L;
[0155] Among them, through the above relationship, the first device can calculate the second sequence L and determine whether the second sequence L is a sequence that meets the generation rule. For example, whether the second sequence is a plurality of repeated bytes, and the value of each byte is the same.
[0156] In addition, if the first device can decipher the second sequence that satisfies the generation rule of the aforementioned first sequence, the data length of the padding sequence can also be determined based on the second sequence. For example, according to the description of the generation method of the second sequence, the second sequence can indicate the data length missing from the last block of the second plaintext. If the first device determines that the length of the first ciphertext is an integer multiple of the block length, and the data length missing from the last block of the second plaintext is not zero, it can be determined that the missing data length is the length of the padding bits. For example, the message to be verified is 1536 bits long, the first ciphertext is 1408 bits long, the authentication tag value is 128 bits long, and the first device determines the first cumulative value Y corresponding to the second plaintext. T and the second group cumulative value Y T+1 Through the above relationship, the second sequence L determined is 0x5050505050505050505050505050505050. Then the first device can know that the last group plaintext of the initial message before encryption is less than 80 bits, that is, the initial message length is 1408-80=1328 bits. Correspondingly, the first device can remove 80 bits of padding bits from the second plaintext obtained by decrypting the first ciphertext, and the remaining part is used as valid plaintext.
[0157] (III) In an exemplary verification method, the first device and the second device agree on an encryption mode and a decryption mode. The second device does not pad the initial message, but groups the initial message to obtain grouped plaintext, encrypts the grouped plaintext to obtain the first ciphertext, and the data length of the first ciphertext is consistent with that of the initial message. After the second device adds an authentication tag after the first ciphertext, the plaintext and the ciphertext differ only by the length of the authentication tag. For example, the second device determines that the initial message is 1328 bits, the first ciphertext is 1328 bits, the first authentication tag value is 96 bits, and the message to be verified is 1424 bits. The first device receives the first ciphertext and the first authentication tag value, and obtains a second plaintext length of 1328 bits. Based on the group length of 128 bits, it can be determined that the last grouped plaintext of the second plaintext is 48 bits. Therefore, it can be determined that the length of the first sequence L is 80 bits, and thus a regular sequence of 80 bits is taken as the first sequence. The first device obtains L and can calculate Y from the grouped plaintext of the second plaintext. T , by Y T XOR with L to get Y T+1 , encrypt Y T+1 We get Z = ENCK (Y T+1 ), take 80 bits in Z as the second authentication tag value, even if the length of the authentication tag is shorter than the packet length, the authentication value can be compared.
[0158] For example, when the length of the authentication tag value is 96 bits, the first device obtains that the second plaintext is 1328 bits, and divides the second plaintext by 128 bits to obtain 1280 and a remainder of 48. The difference between 48 bits and 128 bits is 80 bits, so the first device can further know that L is 128 bits: 0x50505050505050505050505050505050. In the case where no padding bits need to be added, the length of the message to be verified is 1328+128=1424 bits.
[0159] The first device can also take a 96-bit value from the message to be verified as the third authentication tag value based on the length of the authentication tag value of 96 bits, and the remaining 1328 bits are the first ciphertext. The first device can also decrypt the first ciphertext to obtain the second plaintext. Further, the first device can refer to the method in the present application, determine the second authentication tag value according to the second plaintext and the first sequence L, and determine whether the message to be verified has integrity when the third authentication tag value is consistent with the second authentication tag value. Otherwise, if the third authentication tag value is inconsistent with the second authentication tag value, it is determined that the message to be verified does not have integrity.
[0160] Based on the same technical concept, the present application exemplarily provides a data integrity verification device. The device can be used to perform the actions described in the above method embodiment. In this embodiment, the structure of the device can be as follows: Figure 2 shown.
[0161] like Figure 2 As shown, the present application exemplarily provides a data integrity verification device which may include an acquisition module 201 and a processing module 202 .
[0162] Among them, when implementing the function of the first device in the present application, the acquisition module 201 is used to receive a message to be verified from a second device, and the message to be verified includes a first ciphertext and a first authentication tag value, wherein the first ciphertext is the ciphertext corresponding to the first plaintext, and the first authentication tag value is generated by the second device based on the first plaintext; the processing module 202 is used to decrypt the first ciphertext to obtain a second plaintext; the processing module 202 is also used to verify the first authentication tag value based on the second plaintext to determine whether the message to be verified has integrity.
[0163] In one possible design, the processing module 202 is specifically used to: determine a second authentication tag value according to the second plaintext through a first rule, wherein the first authentication tag value is generated by the second device according to the first plaintext through the first rule; determine whether the message to be verified has integrity according to a comparison result of the first authentication tag value and the second authentication tag value.
[0164] In one possible design, the processing module 202 is specifically used to: determine T grouped plaintexts with a data length equal to the group length based on the second plaintext; determine a first cumulative value corresponding to the T grouped plaintexts through a cumulative value algorithm; determine the second authentication tag value based on a first sequence with a data length equal to the group length and the first cumulative value, wherein the first sequence is related to the plaintext length contained in the last group of the second plaintext and the group length.
[0165] In one possible design, the lengths of the first authentication tag value and the second authentication tag value are both the packet length.
[0166] In one possible design, the first accumulated value and the T grouped plaintexts satisfy the following relationship: T =(f(x)Y T-1 )⊕P T-1 ; where f(x) represents a function with x as a variable, P T-1 represents the T-th plaintext among the T plaintext groups, ⊕ represents an XOR operation, and Y T represents the first cumulative value, Y T-1 It represents a second cumulative value determined based on the 1st group plaintext to the T-1th group plaintext among the T group plaintexts.
[0167] In a possible design, the second authentication tag value is a sequence included in the cumulative value ciphertext; the cumulative value ciphertext satisfies the following relationship: Z = F1 (Y T+1 ); wherein F1 represents an encryption algorithm; the Y T+1 Represents the cumulative value of the first group, satisfying the following relationship: Y T+1 =Y T ⊕L; where Y T is the first cumulative value, and L is the first sequence.
[0168] In one possible design, the processing module 202 is specifically used to: obtain a third authentication tag value from the message to be verified according to the length of the authentication tag value, wherein the length of the authentication tag value is the data length of the first authentication tag value; decrypt the third authentication tag value to obtain a second group cumulative value; determine T group plaintexts with a data length equal to the group length according to the second plaintext; determine a first cumulative value corresponding to the T group plaintexts through a cumulative value algorithm; determine a second sequence according to the second group cumulative value and the first cumulative value; and determine that the message to be verified has integrity when the second sequence satisfies a set rule.
[0169] In a possible design, the processing module 202 is further used to: determine the plaintext length contained in the last group of the second plaintext according to the second sequence; and determine the initial message from the second plaintext according to the plaintext length.
[0170] Among them, when implementing the function of the second device in the present application, the processing module 202 is used to generate a first authentication tag value according to the first plaintext through the first rule; the processing module 202 is also used to send a message to be verified to the first device, and the message to be verified includes a first ciphertext and the first authentication tag value, wherein the first ciphertext is the ciphertext corresponding to the first plaintext, and the first authentication tag value is used to determine whether the message to be verified has integrity.
[0171] In one possible design, the processing module 202 is specifically used to: determine T grouped plaintexts with a data length equal to a group length based on the first plaintext; determine a first cumulative value corresponding to the T grouped plaintexts by a cumulative value algorithm; determine the first authentication tag value based on a first sequence with a data length equal to the group length and the first cumulative value, the first sequence being related to the plaintext length contained in the last group of the first plaintext and the group length, and the first authentication tag value being used to determine whether the message to be verified has integrity together with the second authentication tag value.
[0172] In one possible design, the lengths of the first authentication tag value and the second authentication tag value are both the packet length.
[0173] In one possible design, the first cumulative value and the T group plaintexts satisfy the following relationship: T '=(f(x)'Y T-1 ')⊕P T-1 '; where f(x)' represents a function with x as a variable, P T-1 ' represents the T-th group plaintext among the T group plaintexts, ⊕ represents an XOR operation, Y T ' represents the first cumulative value, Y T-1 ' represents a second cumulative value determined based on the 1st group plaintext to the T-1th group plaintext among the T group plaintexts.
[0174] In a possible design, the first authentication tag value is a sequence included in the cumulative value ciphertext; the cumulative value ciphertext satisfies the following relationship: Z'=F1(Y T+1 '); wherein F1 represents an encryption algorithm; the Y T+1 ' represents the first group cumulative value, satisfying the following relationship: Y T+1 '=Y T '⊕L; where Y T ' is the first cumulative value, and L is the first sequence.
[0175] Based on the same inventive concept as the above method embodiment, an electronic device is also provided in the embodiment of the present application. The electronic device can be used to perform the actions described in the above method embodiment. In this embodiment, the structure of the electronic device can be as follows: Figure 3 As shown, it includes a memory 301 and one or more processors 302 .
[0176] The memory 301 is used to store computer programs executed by the processor 302. The memory 301 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system and programs required for running the instant messaging function, etc.; the data storage area may store various instant messaging information and operation instruction sets, etc.
[0177] The memory 301 may be a volatile memory, such as a random-access memory (RAM); the memory 301 may also be a non-volatile memory, such as a read-only memory, a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD), or the memory 301 is any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 301 may be a combination of the above memories.
[0178] The processor 302 may include one or more central processing units (CPU) or a digital processing unit, etc. The processor 302 is used to implement the above method when calling the computer program stored in the memory 301.
[0179] The specific connection medium between the memory 301 and the processor 302 is not limited in the embodiment of the present application. Figure 3 In the embodiment, the memory 301 and the processor 302 are connected via a bus 303. The bus 303 is connected to the processor 302 via a bus 303. Figure 3 The connections between other components are shown in bold lines, and are not intended to be limiting. Bus 303 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 3 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0180] Optionally, the processor 302 may be configured to execute any one or more of the above actions executed by the acquisition module 201 and the processing module 202 .
[0181] According to one aspect of the present application, a computer program product or computer program is provided, the computer program product or computer program includes computer instructions, the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the method in the above embodiment.
[0182] The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0183] The above description is only a specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application.
Claims
1. A data integrity verification method, characterized in that: include: The first device receives a message to be verified from the second device, where the message to be verified includes a first ciphertext and a first authentication tag value, wherein the first ciphertext is a ciphertext corresponding to the first plaintext, and the first authentication tag value is generated by the second device according to the first plaintext; The first device decrypts the first ciphertext to obtain a second plaintext; The first device verifies the first authentication tag value according to the second plaintext to determine whether the message to be verified has integrity; The first device verifies the first authentication tag value according to the second plaintext, including: The first device obtains a third authentication tag value from the message to be verified according to the length of the authentication tag value, where the length of the authentication tag value is the length of the first authentication tag value; The first device decrypts the third authentication tag value to obtain a second group accumulation value; The first device determines, according to the second plaintext, T grouped plaintexts whose data length is the group length; The first device determines a first cumulative value corresponding to the T group plaintexts by using a cumulative value algorithm; The first device determines a second sequence according to the second group cumulative value and the first cumulative value, wherein the second sequence indicates the data length missing from the last group plaintext of the second plaintext; The first device determines that the message to be verified has integrity when the second sequence satisfies a set rule.
2. The method according to claim 1, characterized in that The first device may verify the first authentication tag value according to the second plaintext in the following manner: The first device determines a second authentication tag value according to the second plaintext by using a first rule, wherein the first authentication tag value is generated by the second device according to the first plaintext by using the first rule; The first device determines whether the message to be verified has integrity according to a comparison result of the first authentication tag value and the second authentication tag value; if the comparison result is that the first authentication tag value is the same as the second authentication tag value, it is determined that the message to be verified has integrity; if the comparison result is that the first authentication tag value is different from the second authentication tag value, it is determined that the message to be verified does not have integrity; The first device determines a second authentication tag value according to the second plaintext by using a first rule, including: The first device determines, according to the second plaintext, T grouped plaintexts whose data length is the group length; The first device determines a first cumulative value corresponding to the T group plaintexts by using a cumulative value algorithm; The first device determines the second authentication tag value according to a first sequence whose data length is the packet length and the first cumulative value, wherein the first sequence is related to the plaintext length contained in the last packet of the second plaintext and the packet length.
3. The method according to claim 2, characterized in that The lengths of the first authentication tag value and the second authentication tag value are both the packet length.
4. The method according to claim 2, characterized in that The first cumulative value and the T group plaintexts satisfy the following relationship: Y T =(f(x)Y T-1 )⊕P T-1 ; Where f(x) represents a function with x as a variable, P T-1 represents the T-th plaintext among the T plaintext groups, ⊕ represents an XOR operation, and Y T represents the first cumulative value, Y T-1 It represents a second cumulative value determined based on the 1st group plaintext to the T-1th group plaintext among the T group plaintexts.
5. The method according to claim 4, characterized in that The second authentication tag value is a sequence included in the cumulative value ciphertext; The cumulative value ciphertext satisfies the following relationship: Z=F1(Y T+1 ); Wherein, F1 represents the encryption algorithm; The Y T+1 Represents the cumulative value of the first group, satisfying the following relationship: AND T+1 =And T ⊕L; Among them, Y T is the first cumulative value, and L is the first sequence.
6. The method according to claim 1, characterized in that The method further comprises: The first device determines, according to the second sequence, a plaintext length contained in a last group of the second plaintext; The first device determines an initial message from the second plaintext according to the plaintext length.
7. A data integrity verification method, characterized in that: include: The second device generates a first authentication tag value according to the first plaintext using a first rule; The second device sends a message to be verified to the first device, where the message to be verified includes a first ciphertext and the first authentication tag value, wherein the first ciphertext is a ciphertext corresponding to the first plaintext, and the first authentication tag value is used to determine whether the message to be verified has integrity; The second device generates a first authentication tag value according to the first plaintext by using a first rule, including: The second device determines, according to the first plaintext, T grouped plaintexts whose data length is the group length; The second device determines a first cumulative value corresponding to the T group plaintexts by using a cumulative value algorithm; The second device determines the first authentication tag value based on a first sequence with a data length of the packet length and the first cumulative value, wherein the first sequence is related to the plaintext length contained in the last packet of the first plaintext and the packet length, and the first authentication tag value is used to determine whether the message to be verified has integrity together with the second authentication tag value.
8. The method according to claim 7, characterized in that The lengths of the first authentication tag value and the second authentication tag value are both the packet length.
9. The method according to claim 7, characterized in that The first cumulative value and the T group plaintexts satisfy the following relationship: Y T ’=(f(x)’Y T-1 ’)⊕P T-1 ’; Among them, f(x)' represents the function with x as the variable, P T-1 ' represents the T-th group plaintext among the T group plaintexts, ⊕ represents an XOR operation, Y T ' represents the first cumulative value, Y T-1 ' represents a second cumulative value determined based on the 1st group plaintext to the T-1th group plaintext among the T group plaintexts.
10. The method according to claim 9, characterized in that The first authentication tag value is a sequence included in the cumulative value ciphertext; The cumulative value ciphertext satisfies the following relationship: Z’=F1(Y T+1 ’); Wherein, F1 represents the encryption algorithm; The Y T+1 ' represents the first group cumulative value, satisfying the following relationship: AND T+1 '=And T '⊕L; Among them, Y T ' is the first cumulative value, and L is the first sequence.
11. A data integrity verification device, characterized in that: include: an acquisition module, configured to receive a message to be verified from a second device, wherein the message to be verified includes a first ciphertext and a first authentication tag value, wherein the first ciphertext is a ciphertext corresponding to the first plaintext, and the first authentication tag value is generated by the second device according to the first plaintext; A processing module, configured to decrypt the first ciphertext to obtain a second plaintext; The processing module is further configured to verify the first authentication tag value according to the second plaintext to determine whether the message to be verified has integrity; The processing module is specifically used for: Obtaining a third authentication tag value from the message to be verified according to the length of the authentication tag value, wherein the length of the authentication tag value is the data length of the first authentication tag value; Decrypting the third authentication tag value to obtain a second group cumulative value; Determine T grouped plaintexts with a data length equal to the group length according to the second plaintext; Determine a first cumulative value corresponding to the T grouped plaintexts by a cumulative value algorithm; Determine a second sequence according to the second group cumulative value and the first cumulative value, wherein the second sequence indicates the data length missing from the last group plaintext of the second plaintext; When the second sequence satisfies a set rule, it is determined that the message to be verified has integrity.
12. The device according to claim 11, characterized in that The verifying the first authentication tag value according to the second plaintext may also be implemented in the following manner, wherein the processing module is specifically configured to: determining a second authentication tag value according to the second plaintext by using a first rule, wherein the first authentication tag value is generated by the second device according to the first plaintext by using the first rule; Determining whether the message to be verified has integrity according to a comparison result of the first authentication tag value and the second authentication tag value; wherein, if the comparison result is that the first authentication tag value and the second authentication tag value are the same, then determining that the message to be verified has integrity; if the comparison result is that the first authentication tag value and the second authentication tag value are different, then determining that the message to be verified does not have integrity; Determining a second authentication tag value according to the second plaintext by using a first rule, the processing module is specifically configured to: Determine T grouped plaintexts with a data length equal to the group length according to the second plaintext; Determine a first cumulative value corresponding to the T grouped plaintexts by a cumulative value algorithm; The second authentication tag value is determined according to a first sequence whose data length is the packet length and the first cumulative value, wherein the first sequence is related to the plaintext length contained in the last packet of the second plaintext and the packet length.
13. The device according to claim 12, characterized in that The lengths of the first authentication tag value and the second authentication tag value are both the packet length.
14. The device according to claim 12, characterized in that The first cumulative value and the T group plaintexts satisfy the following relationship: Y T =(f(x)Y T-1 )⊕P T-1 ; Where f(x) represents a function with x as a variable, P T-1 represents the T-th plaintext among the T plaintext groups, ⊕ represents an XOR operation, and Y T represents the first cumulative value, Y T-1 It represents a second cumulative value determined based on the 1st group plaintext to the T-1th group plaintext among the T group plaintexts.
15. The device according to claim 14, characterized in that The second authentication tag value is a sequence included in the cumulative value ciphertext; The cumulative value ciphertext satisfies the following relationship: Z=F1(Y T+1 ); Wherein, F1 represents the encryption algorithm; The Y T+1 Represents the cumulative value of the first group, satisfying the following relationship: AND T+1 =And T ⊕L; Among them, Y T is the first cumulative value, and L is the first sequence.
16. The device according to claim 11, characterized in that The processing module is also used for: Determine, according to the second sequence, a plaintext length contained in the last group of the second plaintext; An initial message is determined from the second plaintext according to the plaintext length.
17. A data integrity verification device, characterized in that: include: A processing module, configured to generate a first authentication tag value according to the first plaintext by using a first rule; The processing module is further used to send a message to be verified to the first device, where the message to be verified includes a first ciphertext and the first authentication tag value, wherein the first ciphertext is a ciphertext corresponding to the first plaintext, and the first authentication tag value is used to determine whether the message to be verified has integrity; The processing module is specifically used for: Determine T grouped plaintexts with a data length equal to the group length according to the first plaintext; Determine a first cumulative value corresponding to the T grouped plaintexts by a cumulative value algorithm; The first authentication tag value is determined based on a first sequence whose data length is the packet length and the first cumulative value, wherein the first sequence is related to the plaintext length contained in the last packet of the first plaintext and the packet length, and the first authentication tag value is used to determine, together with the second authentication tag value, whether the message to be verified has integrity.
18. The device according to claim 17, characterized in that The lengths of the first authentication tag value and the second authentication tag value are both the packet length.
19. The device according to claim 17, characterized in that The first cumulative value and the T group plaintexts satisfy the following relationship: Y T ’=(f(x)’Y T-1 ’)⊕P T-1 ’; Among them, f(x)' represents the function with x as the variable, P T-1 ' represents the T-th group plaintext among the T group plaintexts, ⊕ represents an XOR operation, Y T ' represents the first cumulative value, Y T-1 ' represents a second cumulative value determined based on the 1st group plaintext to the T-1th group plaintext among the T group plaintexts.
20. The device according to claim 19, characterized in that The first authentication tag value is a sequence included in the cumulative value ciphertext; The cumulative value ciphertext satisfies the following relationship: Z’=F1(Y T+1 ’); Wherein, F1 represents the encryption algorithm; The Y T+1 ' represents the first group cumulative value, satisfying the following relationship: AND T+1 '=And T '⊕L; Among them, Y T ' is the first cumulative value, and L is the first sequence.
21. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores program codes, and when the program codes are executed by the processor, the processor executes the steps of any one of the methods in claims 1 to 10.
22. A computer-readable storage medium, characterized in that: The method comprises a program code. When the program code is run on an electronic device, the program code is used to enable the electronic device to execute the steps of any method described in claims 1 to 10.
