Encryption Method, Device, Equipment and Storage Medium for Dynamic Group Length

Through the encryption method of dynamically adjusting the packet length and multiple rounds of iterative transformation, the problem of mismatch between the packet length and plain text data in the prior art is solved, and efficient and secure data encryption is achieved.

CN118869192BActive Publication Date: 2025-05-27BEIJING HAITAI FANGYUAN HIGH TECH
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202410894637.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-04
Publication Date
2025-05-27
Estimated Expiration
2044-07-04

AI Technical Summary

Technical Problem

The fixed packet length of the existing lightweight packet cipher algorithm does not match the length of plain text data, resulting in cumbersome encryption process and high data processing pressure.

Method used

The encryption method of dynamic packet length is adopted to dynamically adjust the packet length according to business needs, divide the data to be encrypted into multiple plaintext packets, and encrypted through multiple rounds of iterative transformations. According to the parity of the packet length, the input data for each round is transformed nonlinearly and scrambled based on the round key.

Benefits of technology

It realizes encryption that adapts to different data lengths, shortens encryption processing time, improves data encryption efficiency, avoids the trouble caused by mismatch between fixed packet lengths and plaintext data, and enhances the security of data encryption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118869192B_ABST
    Figure CN118869192B_ABST
Patent Text Reader

Abstract

The present application relates to the field of information security technology, and provides an encryption method, device, equipment and storage medium with a dynamic block length. The method includes: dividing the data to be encrypted according to the block length set based on business requirements to obtain a plurality of plaintext blocks; respectively performing cyclic iterative transformation on each plaintext block, and using the transformation result of the last round as their respective ciphertext blocks: according to the parity of the block length, performing a non-linear transformation on the input data of each round to obtain the non-linear transformation result of each round, wherein the input data of the first round is obtained by preprocessing the plaintext block, and the input data of non-first rounds is the transformation result output by the previous round; scrambling the non-linear transformation result based on the round key of each round to obtain the transformation result of each round. Dynamically adjusting the block length according to the data length of the data to be encrypted is applicable to encrypting shorter data blocks, and avoids the trouble caused by the mismatch between the fixed block length and the block size of the plaintext data.
Need to check novelty before this filing date? Find Prior Art

Description

Background Art

[0002] With the rapid development of information technology, computer technology, and microelectronics technology, resource-constrained devices such as radio frequency identification technology, sensor networks, and contactless smart cards are increasingly widely used. Traditional block cipher algorithms need to achieve the best security under known circumstances through complex mathematical operations and logical structures, but this also consumes a large amount of software and hardware resources, reduces the data encryption and decryption efficiency, and is difficult to be applied to resource-constrained devices such as micro IoT devices. If a too simple logical structure is used, it is difficult to ensure data security. Therefore, in order to protect the data transmitted and processed by these devices, lightweight block cipher algorithms have emerged as the times require.

[0003] However, the block length of current lightweight block cipher algorithms is generally 32 bits (bit) or 64 bit. When encrypting plaintext data whose length is less than the block length or does not meet the multiple of the block length, the encryption process is cumbersome and the data processing pressure is relatively large. Summary of the Invention

[0004] The embodiments of the present application provide an encryption method, device, equipment, and storage medium with a dynamic block length, characterized in that the block length can be changed arbitrarily to solve the problem of difficult encryption caused by the mismatch between the fixed block length and the data length of the plaintext data.

[0005] In a first aspect, the embodiments of the present application provide an encryption method with a dynamic block length, including:

[0006] Dividing the data to be encrypted into multiple plaintext blocks according to the block length set based on service requirements;

[0007] Performing multi-round cyclic iterative transformation on each plaintext block, and taking the transformation result of the last round as the corresponding ciphertext block. Among them, for a plaintext block, the following operations are performed: According to the parity of the block length, performing a non-linear transformation on the input data of each round to obtain the non-linear transformation result of each round, where the input data of the first round is obtained by preprocessing the plaintext block, and the input data of non-first rounds is the transformation result of the previous round; Based on the round key of each round, scrambling the non-linear transformation result of each round to obtain the transformation result output in each round.

[0008] Optionally, the performing a non-linear transformation on the input data of each round according to the parity of the block length to obtain the non-linear transformation result of this round includes:

[0009] When the block length is odd, based on the target transformation base determined by the block length, splitting the input data of each round into two candidate data segments, and combining the two candidate data segments into the non-linear transformation result of each round;

[0010] When the block length is even, the most significant bit of the input data for each round is used as a candidate data segment, and based on the remaining N - 1 bits of the input data for each round and the target transformation base, other candidate data segments are split, and the multiple candidate data segments are combined into the non - linear transformation result for each round, where N is the block length.

[0011] Optionally, splitting the input data for each round into two candidate data segments based on the target transformation base determined according to the block length includes:

[0012] Performing a remainder operation on the input data for each round and the target transformation base determined according to the block length, and using the remainder result as the first candidate data segment;

[0013] Performing a division operation on the input data for each round and the target transformation base, and using the division result as the second candidate data segment;

[0014] Based on a preset odd multiplier, translation amount, and the target transformation base, converting the first candidate data segment into a third candidate data segment.

[0015] Optionally, splitting other candidate data segments based on the remaining N - 1 bits of the input data for each round and the target transformation base includes:

[0016] Performing a remainder operation on the remaining N - 1 bits of the input data for each round and the target transformation base, and using the remainder result as the fourth candidate data segment;

[0017] Performing a division operation on the remaining N - 1 bits of the input data for each round and the target transformation base, and using the division result as the fifth candidate data segment;

[0018] Based on a preset odd multiplier, translation amount, and the target transformation base, converting the fourth candidate data segment into a sixth candidate data segment.

[0019] Optionally, multiple round keys are obtained by performing the following operations:

[0020] Recursively expanding the original key sequence composed of L original key bytes to obtain a target key sequence, where L is a positive integer greater than or equal to 8;

[0021] Performing multiple sequence splits on the target key sequence according to the preset round key length and the number of round keys to obtain the multiple round keys.

[0022] Optionally, recursively expanding the original key sequence composed of L original key bytes to obtain a target key sequence includes:

[0023] Perform the following operations cyclically on the original key sequence composed of the L original key bytes to obtain multiple extended key bytes: perform byte transformation on multiple i - k original key bytes to obtain the i-th extended key byte, where i is a positive integer greater than or equal to L, and k is a positive integer less than or equal to L;

[0024] Concatenate the L original key bytes and multiple extended key bytes in order to obtain the target key sequence.

[0025] In a second aspect, an encryption device with a dynamic block length provided by an embodiment of the present application includes:

[0026] A length adjustment unit for dividing the data to be encrypted into multiple plaintext blocks according to the block length set based on service requirements;

[0027] A data encryption unit for performing multiple rounds of cyclic iterative transformation on each plaintext block, and taking the transformation result of the last round as the corresponding ciphertext block. Among them, for one plaintext block, the following operations are performed: according to the parity of the block length, perform non - linear transformation on the input data of each round to obtain the non - linear transformation result of each round, where the input data of the first round is obtained by pre - processing the one plaintext block, and the input data of non - first rounds is the transformation result output in the previous round; scramble the non - linear transformation result of each round based on the round key of each round to obtain the transformation result output in each round.

[0028] Optionally, the data encryption unit is used for:

[0029] When the block length is odd, based on the target transformation base determined by the block length, split the input data of each round into two candidate data segments, and merge the two candidate data segments into the non - linear transformation result of this round;

[0030] When the block length is even, take the highest bit of the input data of each round as one candidate data segment, split to obtain other candidate data segments based on the remaining N - 1 bits of the input data of each round and the target transformation base, and merge multiple candidate data segments into the non - linear transformation result of each round, where N is the block length.

[0031] Optionally, the data encryption unit is used for:

[0032] Perform a remainder operation on the input data of each round and the target transformation base determined by the block length, and take the remainder result as the first candidate data segment;

[0033] Perform a division operation on the input data of each round and the target transformation base, and take the division result as the second candidate data segment;

[0034] Convert the first candidate data segment into a third candidate data segment based on a preset odd multiplier, translation amount, and the target transformation base.

[0035] Optionally, the data encryption unit is configured to:

[0036] Perform a remainder operation on the remaining N - 1 bits of the input data for each round and the target transformation base, and use the remainder result as the fourth candidate data segment;

[0037] Perform a division operation on the remaining N - 1 bits of the input data for each round and the target transformation base, and use the division result as the fifth candidate data segment;

[0038] Convert the fourth candidate data segment into a sixth candidate data segment based on a preset odd multiplier, translation amount, and the target transformation base.

[0039] Optionally, the data encryption unit obtains a plurality of round keys by performing the following operations:

[0040] Recursively expand the original key sequence composed of L original key bytes to obtain a target key sequence, where L is a positive integer greater than or equal to 8;

[0041] Perform multiple sequence splits on the target key sequence according to a preset round key length and the number of round keys to obtain the plurality of round keys.

[0042] Optionally, the data encryption unit is configured to:

[0043] Perform the following operations on the original key sequence composed of the L original key bytes in a loop to obtain a plurality of extended key bytes: perform a byte transformation on multiple i - k original key bytes to obtain the i-th extended key byte, where i is a positive integer greater than or equal to L, and k is a positive integer less than or equal to L;

[0044] Concatenate the L original key bytes and the plurality of extended key bytes in order to obtain the target key sequence.

[0045] In a third aspect, an embodiment of the present application further provides a computer device, including a processor and a memory. Among them, the memory stores program code, and when the program code is executed by the processor, the processor executes the steps of any one of the above encryption methods with a dynamic block length.

[0046] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, which includes program code. When the program product runs on a computer device, the program code is used to cause the computer device to execute the steps of any one of the above encryption methods with a dynamic block length.

[0047] In a fifth aspect, an embodiment of the present application further provides a computer program product, including computer instructions, and the computer instructions are executed by a processor to perform the steps of any of the above encryption methods with a dynamic block length.

[0048] The beneficial effects of the present application are as follows:

[0049] An embodiment of the present application provides an encryption method, apparatus, device, and storage medium with a dynamic block length. The method includes: dividing the data to be encrypted into multiple plaintext blocks according to the block length set based on service requirements; performing multiple rounds of cyclic iterative transformation on each plaintext block, and using the transformation result output in the last round as the corresponding ciphertext block: performing a non-linear transformation on the input data of each round according to the parity of the block length to obtain the non-linear transformation result of this round, where the input data of the first round is obtained by preprocessing the plaintext block, and the input data of non-first rounds is the transformation result output in the previous round; scrambling the non-linear transformation result based on the round key of each round to obtain the transformation result of each round.

[0050] Dynamically adjust the block length according to the data length of the data to be encrypted, reasonably set the block length of the plaintext block, which is applicable to encrypting shorter data blocks, shortening the encryption processing time, improving the data encryption efficiency, and is easy to implement the reserved format encryption of special type data, and can avoid the troubles caused by the mismatch between the fixed block length and the block size of the plaintext data. In addition, according to the parity of the block length, based on multiple modulo remainder representations, a non-linear transformation is performed on the input data, and an S-box (or permutation table) can be not used, avoiding the trouble of setting and storing the S-box, and also increasing the complexity of data encryption, further ensuring the security of data encryption.

[0051] Other features and advantages of the present application will be described in the subsequent description, and some of them will become obvious from the description, or be understood by implementing the present application. The objectives and other advantages of the present application can be achieved and obtained through the structures specifically pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] The drawings described herein are used to provide a further understanding of the present application, and constitute a part of the present application. The schematic embodiments of the present application and their descriptions are used to explain the present application, and do not constitute an improper limitation to the present application. In the drawings:

[0053] Figure 1A It is a schematic flowchart of block encryption for the data to be encrypted provided by an embodiment of the present application;

[0054] Figure 1B It is a schematic flowchart of cyclic iterative encryption for a plaintext block provided by an embodiment of the present application;

[0055] Figure 1C It is a schematic flow chart provided by an embodiment of the present application for performing a non - linear transformation on the input data in each round when the block length is odd;

[0056] Figure 1D It is a schematic flow chart provided by an embodiment of the present application for performing a non - linear transformation on the input data in each round when the block length is even;

[0057] Figure 2 It is a complete schematic flow chart of an encryption method for encrypting data using a dynamic block length provided by an embodiment of the present application;

[0058] Figure 3 It is a schematic structural diagram of an encryption device with a dynamic block length provided by an embodiment of the present application;

[0059] Figure 4 It is a schematic structural diagram of a composition of a computer device provided by an embodiment of the present application;

[0060] Figure 5 It is a schematic structural diagram of a computing device in an embodiment of the present application. Specific embodiments

[0061] To make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are some, but not all, of the embodiments of the technical solutions of the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments recorded in this application document without making creative efforts belong to the scope of protection of the technical solutions of the present application.

[0062] Some terms in the embodiments of the present application are explained below to facilitate understanding by those skilled in the art.

[0063] 1. Data encryption is to convert information that can be read, understood, and recognized by people or machines (this information can be voice, text, images, symbols, etc.) into obscure or deviated information through certain methods, so as to achieve the purpose of ensuring information security. To facilitate understanding by those skilled in the art, several terms related to the concept of data encryption are introduced below.

[0064] (1) Plaintext: Information that is easy for people or machines to read and understand is called plaintext. Plaintext can be text, digital voice streams, or digital video information, etc.

[0065] (2) Ciphertext: By means of data encryption, the information data obtained by converting plaintext into obscure information is called ciphertext.

[0066] (3) The process of converting plaintext into ciphertext is called the encryption process, and the process of converting ciphertext into plaintext is called the decryption process. The decryption process is the inverse process of the encryption process.

[0067] (4) Key: When encrypting and decrypting, the same parameter or two different but related parameters are referenced. This parameter is called the key. The key used for encryption is the encryption key, and the key used for decryption is the decryption key.

[0068] 2. According to the way of data encryption, cryptographic techniques can be divided into symmetric encryption techniques and asymmetric encryption techniques.

[0069] (1) Symmetric encryption technique: In this technique, the same key is used for both the encryption process and the decryption process, or two keys that can be deduced from each other are used, that is, based on one key, a simple operation is performed to deduce the other key.

[0070] Since symmetric encryption techniques have the advantages of public algorithms, small computational amounts, fast encryption speeds, and high encryption efficiencies, this technique is usually used to encrypt data when the message sender needs to encrypt a large amount of data. However, symmetric encryption techniques also have obvious disadvantages: Before data transmission, the sender and the receiver must agree on the key and each keep the key well. If the key of one of them is accidentally leaked, the security of data encryption cannot be guaranteed.

[0071] (2) Asymmetric encryption technique: In this technique, a pair of different but related keys are used for the encryption process and the decryption process. The encryption key is publicly available, the decryption key is kept confidential, and the decryption key cannot be deduced from the encryption key. An attacker cannot crack the ciphertext even when knowing the encryption key.

[0072] 3. The block cipher algorithm is a type of symmetric encryption technique that uses a key of a fixed length to encrypt a plaintext block of a fixed length to obtain a ciphertext block of the same length. Currently, the commonly used key lengths and block lengths are usually 64bit, 128bit, 256bit, etc.

[0073] The following briefly introduces the design concept of the embodiments of this application:

[0074] With the rapid development of information technology, computer technology, and microelectronics technology, radio frequency identification technology, sensor networks, and resource-constrained devices such as contactless smart cards are increasingly widely used. Traditional block cipher algorithms need to use complex mathematical operations and logical structures to achieve the best security under known circumstances, but this will also consume a large amount of software and hardware resources, reduce the data encryption and decryption efficiency, and it is difficult to be applied to resource-constrained devices such as micro IoT devices. If a too simple logical structure is used, it is difficult to guarantee data security. Therefore, in order to protect the data transmitted and processed by these devices, lightweight block cipher algorithms have emerged.

[0075] However, the block length of current lightweight block cipher algorithms is generally 32 bits or 64 bits. When encrypting plaintext data whose length is less than the block length or does not meet the multiple of the block length, the encryption process is cumbersome and the data processing pressure is relatively large.

[0076] In view of this, to solve the above problems, the embodiments of the present application provide an encryption method with a dynamic block length that has a smaller block length and can arbitrarily select the block length. The method includes: dividing the data to be encrypted into multiple plaintext blocks according to the block length set based on service requirements; performing multiple rounds of cyclic iterative transformation on each plaintext block, and using the transformation results output in the last round as the corresponding ciphertext blocks: performing a non-linear transformation on the input data of each round according to the parity of the block length to obtain the non-linear transformation result of this round, where the input data of the first round is obtained by preprocessing the plaintext block, and the input data of non-first rounds is the transformation result output in the previous round; scrambling the non-linear transformation result based on the round keys of each round to obtain the linear transformation results of each round.

[0077] When necessary, the block length can be dynamically adjusted according to the data length of the data to be encrypted, the block length of the plaintext blocks can be reasonably set, which is applicable to encrypting shorter data blocks, shortening the encryption processing time, improving the data encryption efficiency, being easy to implement the reserved format encryption of special type data, and avoiding the trouble caused by the mismatch between the fixed block length and the block size of the plaintext data. Secondly, according to the parity of the block length, a non-linear transformation of the initial ciphertext is implemented based on multiple modulo representations, and the S-box (or permutation table) can be not used, which can avoid the trouble of setting and storing the S-box, and also increases the complexity of data encryption, further ensuring the security of data encryption.

[0078] As Figure 1A shown, the process of encrypting data by using the method provided by the embodiments of the present application is as follows:

[0079] S101: Divide the data to be encrypted into multiple plaintext blocks according to the block length set based on service requirements.

[0080] Currently, the block length of lightweight block cipher algorithms is generally 32 bits or 64 bits. When encrypting plaintext data whose length is less than the block length or does not meet the multiple of the block length, the encryption process is cumbersome and the data processing pressure is relatively large. Therefore, for plaintext data whose encryption data length is less than the block length, or does not meet the multiple of the block length, or special type data that needs to retain a certain data format, the block length can be set according to service requirements, and then, taking the block length as the division criterion, the data to be encrypted is divided into multiple plaintext blocks of the same length.

[0081] For example, according to the data length of the plaintext data, the block length is reasonably set. If the data length of the divided plaintext block is still less than the block length, the data vacancy in the block can be filled by padding with zeros so that the data length after padding is equal to the block length.

[0082] If the block length is greater than 32 bits, due to the limitation of the computer word length, its encryption process may be slightly cumbersome, affecting the lightweight block encryption effect. More importantly, the block lengths from 33 to 63 bits lack practicality; if the block length is less than 6 bits, the plaintext space of a plaintext block obtained according to this block length is too small, and the data volume of the encrypted ciphertext block is also small, which is easily cracked by attackers and it is difficult to ensure the security of data encryption. Therefore, the implementation method proposed in this application controls the value range of the block length between 6 - 32 bits, and determines the block length from 6 - 32 bits according to the data length of the data to be encrypted, which has certain practicality and is easy to implement lightweight encryption.

[0083] S102: Perform multiple rounds of cyclic iterative transformation on each plaintext block, and use the transformation result of the last round as the corresponding ciphertext block. Among them, for a plaintext block, the following operations are performed: according to the parity of the block length, perform a non - linear transformation on the input data of each round to obtain the non - linear transformation result of each round. Among them, the input data of the first round is obtained by pre - processing the plaintext block, and the input data of non - first rounds is the transformation result output in the previous round; based on the round key of each round, scramble the non - linear transformation result of each round to obtain the linear transformation result of each round.

[0084] The same operations are performed for each plaintext block. For the sake of illustration, taking a plaintext block as an example, combined with Figure 1B the shown flow schematic diagram, introduce the process of performing multiple rounds of cyclic iterative transformation on it.

[0085] S1021: Whitenoise a plaintext block to obtain the input data of the first round.

[0086] Specifically, as shown in formula 1, perform an exclusive - OR operation on a plaintext block x and the round key RK 0 of the 0th round to obtain the input data x 0 of the first round.

[0087]

[0088] S1022: According to the parity of the block length, perform a non - linear transformation on the input data of each round to obtain the non - linear transformation result of each round.

[0089] According to the parity of the block length, multiple rules are called and interactively applied to perform a reversible non-linear transformation on the input data, eliminating or weakening the correlation between the output data and the input data, and further ensuring the security of data encryption.

[0090] (1) When the block length is odd, perform Figure 1C the steps shown:

[0091] S10221: Based on the target transformation base determined by the block length, split the input data of each round into two candidate data segments.

[0092] First, when the block length N is odd, based on the formula M = 92 N +1) / 3, determine the corresponding target conversion base M, and appropriately select an odd multiplier A and a translation amount B that are relatively prime to the target transformation base M.

[0093] For example, when N = 15, M = 92 15 +1) / 3 = 10923, and an odd multiplier A = 125 and a translation amount B = 7 that are relatively prime to 10923 can be selected. It can be proved that when N is odd, 2 N +1 is a multiple of 3, M = (2 N +1) / 3 is relatively prime to 5, so the powers of 5 are always relatively prime to M, and thus a certain power of 5 can be selected as the multiplier A.

[0094] Second, when the block length is odd, as shown in Formula 2, perform a remainder operation on the input data x j of the j-th round and the target transformation base M determined based on the block length, and use the remainder result as the first candidate data segment y 0 , where j is a positive integer.

[0095] y 0 = x j mod M Formula 2;

[0096] Third, as shown in Formula 3, perform a division operation on the input data x j of the j-th round and the target transformation base M, and use the division result as the second candidate data segment y 1 .

[0097] y 1 = x j / M Formula 3;

[0098] Finally, as shown in Formula 4, based on the preset odd multiplier A, translation amount B, and target transformation base M, convert the first candidate data segment into the third candidate data segment. Thus, the input data of the j-th round is split into (z 0 , y 1 ).

[0099] z 0 = Ay 0 + B mod M Formula 4;

[0100] S10222: Combine two candidate data segments into the non - linear transformation result for each round.

[0101] Based on the formula y = 3z 0 + y 1 , combine two candidate data segments (z 0 , y 1 ) into the non - linear transformation result y of the j - th round, realizing the non - linear transformation from the input data x j to the non - linear transformation result y.

[0102] (2) When the block length is even, perform the Figure 1D steps shown:

[0103] S10221': Take the highest - order bit of the input data for each round as a candidate data segment, and based on the lowest - order bit of the input data for each round and the target transformation radix, split to obtain other candidate data segments, where N is the block length.

[0104] First, when the block length N is odd, based on the formula M=(2 N-1 + 1) / 3, determine the corresponding target transformation radix M, and appropriately select an odd multiplier A and a translation amount B that are relatively prime to the target transformation radix M. For example, when the block length N is even, assume N = 10, based on the formula M=(2 N-1 + 1) / 3 = 171, determine the corresponding target transformation radix M, and still take A = 125.

[0105] Second, when the block length is even, denote the highest - order bit of the input data for each round as the seventh candidate data segment y 7 , and as shown in Formula 5, perform a modulo operation on the (N - 1)-th bit s 0 of the input data for the j - th round and the target transformation radix M, and take the modulo result as the fourth candidate data segment y 4 .

[0106] y 4 = s 0 mod M Formula 5;

[0107] Third, as shown in Formula 6, perform an integer division operation on the (N - 1)-th bit s 0 of the input data for each round and the target transformation radix M, and take the integer division result as the fifth candidate data segment y 4 .

[0108] y 5 = s 0 / M formula 6;

[0109] Finally, as shown in formula 7, based on the preset odd multiplier A, translation amount B, and target transformation base M, the fourth candidate data segment y 4 is converted into the sixth candidate data segment y 6 . Thus, the input data x j in the j-th round is split into (z 1 , y 5 , y 7 ).

[0110] z 1 = Ay 4 + B mod M formula 7;

[0111] S10222': Combine multiple candidate data segments into the transformation ciphertext for each round.

[0112] Based on the formula y = 2(3z 1 + y 5 ) + y 7 , combine multiple candidate data segments (z 1 , y 5 , y 7 ) into the non-linear transformation result y of the j-th round, realizing the non-linear transformation from the input data x j to the non-linear transformation result y.

[0113] S1023: Based on the round key for each round, scramble the non-linear transformation result for each round to obtain the transformation result output for each round.

[0114] Specifically, as shown in formula 8, perform an exclusive OR operation on the transformation ciphertext y of the j-th round and the round key RK j of the j-th round to obtain the transformation result of the j-th round, that is, the input data x j+1 of the (j + 1)-th round.

[0115]

[0116] S1024: Determine whether the set iteration rounds have been reached. If so, use the transformation result output in the last round as the corresponding ciphertext block; otherwise, return to step 1022.

[0117] Before encrypting the data, in addition to setting the block length and determining other relevant parameters based on the preset block length, the original key sequence composed of L original key bytes also needs to be recursively extended to obtain the target key sequence, where L is a positive integer greater than or equal to 8; then, according to the preset round key length and the number of round keys, perform multiple sequence splits on the target key sequence to obtain multiple round keys.

[0118] Among them, the specific implementation process of recursive expansion is as follows:

[0119] Perform the following operations on the original key sequence composed of L original key bytes in a loop to obtain multiple extended key bytes: perform byte transformation on multiple i - j original key bytes to obtain the i-th extended key byte, where i is a positive integer greater than or equal to L, and j is a positive integer less than or equal to L.

[0120] Then, splice the L original key bytes and multiple extended key bytes in order to obtain the target key sequence.

[0121] For example, as shown in Formula 9, perform the following operations to obtain the i-th key byte: First, perform a function operation on the (i - 1)-th key byte, the (i - 4)-th key byte, and the (i - 6)-th key byte to obtain the first transformation value; Second, perform a function operation on the (i - 2)-th key byte, the (i - 3)-th key byte, and the (i - 5)-th key byte to obtain the second transformation value; Finally, based on the (i - L)-th key byte and the two transformation values, obtain the i-th key byte.

[0122] RK i = RK i-L + F(RK i-1 , RK i-4 , RK i-6 ) + F(RK i-2 , RK i-3 , RK i-5 ) mod 256 (i = L, L + 1, L + 2, ……) Formula 9;

[0123] Among them, (C <<< 5)). Here, represents taking the inverse code of A, (B <<< 2) represents B circularly shifted left by 2 bits, (C <<< 5) represents C circularly shifted left by 5 bits, ∩ represents taking the intersection, and ∪ represents taking the union.

[0124] For example, if A = 01110001, B = 00110101, C = 11010110, then (B <<< 2) = 11010100, (C <<< 5) = 11011010, then, F(A, B, C) = 11011110.

[0125] Since the steps for obtaining the first transformation value and the second transformation value are the same, taking the first transformation value as an example, take the inverse code of the (i - 1)-th key byte to obtain the inverse code of the (i - 1)-th key byte, and, respectively, circularly shift the (i - 4)-th key byte and the (i - 6)-th key byte to obtain their respective shifted key bytes; then, based on the inverse code key byte of the (i - 1)-th and each shifted key byte, generate a new key byte.

[0126] The encryption method provided by the embodiments of the present application dynamically adjusts the block length according to the data length of the data to be encrypted, reasonably sets the block length of the plaintext block, is applicable to encrypting shorter data blocks, shortens the encryption processing time, improves the data encryption efficiency, is easy to implement the reserved format encryption of special type data, and can avoid the trouble caused by the mismatch between the fixed block length and the block size of the plaintext data. In addition, according to the parity of the block length, a non-linear transformation of the input data is realized based on a variety of modulo-remainder representations, and the S-box (or permutation table) can be not used, avoiding the trouble of setting and storing the S-box, and also increasing the complexity of data encryption, further ensuring the security of data encryption. For the convenience of those skilled in the art to understand, Figure 2 shows the complete process of encrypting data by using the encryption method with a dynamic block length.

[0127] S201: Set the block length according to the data length of the data to be encrypted, then determine the target transformation mechanism based on the block length, and determine an odd multiplier and a translation amount that are relatively prime to the target transformation base.

[0128] S202: Divide the data to be encrypted into multiple plaintext blocks according to the block length.

[0129] S203: Perform multi-round cyclic iterative encryption on each plaintext block respectively, and use the transformation results of the last round as their respective ciphertext blocks. Among them, for a plaintext block, the following operations are performed: According to the parity of the block length, a non-linear transformation of the input data of each round is achieved through a split transformation and a merge transformation to obtain the non-linear transformation result of each round. Among them, the input data of the first round is obtained by preprocessing the plaintext block, and the input data of non-first rounds is the transformation result output by the previous round; Based on the round key of each round, scramble the non-linear transformation result of each round to obtain the transformation result output by each round.

[0130] For example, when N = 15, M = (2 15 +1) / 3 = 10923, A = 125, B = 7 are selected. Assume that five round keys represented in hexadecimal have been recursively obtained as: RK 0 = 0x140f, RK 1 = 0x2bab, RK 2 = 0x31d7, RK 3 = 0c0b41, RK 4 = 0x5ea2. Then, a number from 0 to 32767 can be encrypted through 4 rounds of iteration. For example, if the plaintext data 2 (i.e., 2 = 0x0002) needs to be encrypted, the steps are as follows:

[0131] In the first step, the plaintext 0x0002 is combined with RK 0= XOR with 0x140f, getting the preprocessed plaintext 0x0002 ^ 0x140f = 0x140d.

[0132] In the second step, start the first-round transformation. Split 0x140d as 0x140d = 0×M + 0x140d into (0, 0x140d). Calculate 0x140d × A + B mod 2 15 = 0x140d × 125 + 7 mod 2 15 = 0x1fa2. Combine 0x1fa2 with 0 to get 0x1fa2 × 3 + 0 mod 2 15 = 0x5ee6. Finally, XOR 0x5ee6 with the round key RK 1 = 0x2bab to get 0x5ee6 ⊕ 0x2bab = 0x754d, where the symbol "⊕" represents the XOR operation. Thus, 0x754d is the transformation result output after the first round.

[0133] In the third step, start the second-round transformation. Split 0x754d as 0x754d = 2×M + 0x1ff7 into (2, 0x1ff7). Calculate 0x1ff7 × A + B mod 2 15 = 0x1ff7 × 125 + 7 mod 2 15 = 0x1b83. Combine 0x1b83 with 2 to get 0x1b83 × 3 + 2 mod 2 15 = 0x528b. Finally, XOR 0x528b with the round key RK 2 = 0x31d7 to get 0x528b ⊕ 0x31d7 = 0x635c. Thus, 0x635c is the transformation result output after the second round.

[0134] In the fourth step, start the third-round transformation. Split 0x635c as 0x635c = 2×M + 0x0e06 into (2, 0x0e06). Calculate 0x0e06 × A + B mod 2 15 = 0x0392. After combination, get 0x0392 × 3 + 2 mod 2 15 = 0x0ab8. XOR 0x0ab8 with the round key RK 3 = 0x0b41 to get 0x0ab8 ⊕ 0x0b41 = 0x01f9. Thus, 0x01f9 is the transformation result output after the third round.

[0135] In the fifth step, start the fourth-round transformation. Split 0x01f9 as 0x01f9 = 0×M + 0x01f9 into (0, 0x01f9). Calculate 0x01f9 × A + B mod 2 15 = 0x2145. After combination, get 0x2145 × 3 + 0 mod 2 15= 0x63cf, XOR 0x63cf with the round key RK 4 = 0x5ea2 to get 0x63cf ⊕ 0x5ea2 = 0x3d6d. Thus, 0x3d6d is the finally obtained ciphertext block.

[0136] During decryption, XOR the ciphertext 0x3d6d with the round key RK 4 = 0x5ea2 to get 0x63cf. By dividing 0x63cf by 3 and taking the modulus 3, we get 0x2145 and 0. Since 125×1136≡1 mod 2 15 , calculate 0x2145 - 1136×7 mod 2 15 = 0x2145 - 7952 mod 2 15 = 0x01f9. After combining 0x01f9 with 0, we get 0×M + 0x01f9 = 0x01f9. Thus, 0x01f9 is the input of the 4th round and also the output of the 3rd round. Similarly, from 0x01f9, we deduce the input 0x635c of the 3rd round, and from 0x635c, we deduce the input 0x754d of the 2nd round, and the input 0x140d of the 1st round. XOR 0x140d with the round key RK 0 = 0x140f to obtain the plaintext 0x0002 = 2.

[0137] Based on the same inventive concept as the above method embodiment, the embodiment of the present application also provides an encryption device with a dynamic block length. As Figure 3 shown, the encryption device 300 with a dynamic block length may include:

[0138] A length adjustment unit 301, configured to divide the data to be encrypted into multiple plaintext blocks according to the block length set based on service requirements;

[0139] A data encryption unit 302, configured to perform multiple rounds of cyclic iterative transformation on each plaintext block, and use the transformation result of the last round as the corresponding ciphertext block. Among them, for a plaintext block, the following operations are performed: According to the parity of the block length, perform a non - linear transformation on the input data of each round to obtain the non - linear transformation result of each round, where the input data of the first round is obtained by pre - processing a plaintext block, and the input data of non - first rounds is the transformation result of the previous round; Based on the round key of each round, scramble the non - linear transformation result of each round to obtain the transformation result of each round output.

[0140] Optionally, the data encryption unit 302 is used for:

[0141] When the block length is odd, based on the target transformation base determined by the block length, split the input data of each round into two candidate data segments, and combine the two candidate data segments into the non - linear transformation result of this round;

[0142] When the block length is even, the most significant bit of the input data for each round is used as a candidate data segment. Based on the remaining N - 1 bits of the input data for each round and the target transformation base, other candidate data segments are split, and multiple candidate data segments are merged into the non - linear transformation result for each round, where N is the block length.

[0143] Optionally, the data encryption unit 302 is used for:

[0144] Perform a modulo operation on the input data for each round and the target transformation base determined based on the block length, and use the modulo result as the first candidate data segment;

[0145] Perform a division operation on the input data for each round and the target transformation base, and use the division result as the second candidate data segment;

[0146] Based on a preset odd multiplier, translation amount, and target transformation base, convert the first candidate data segment into a third candidate data segment.

[0147] Optionally, the data encryption unit 302 is used for:

[0148] Perform a modulo operation on the remaining N - 1 bits of the input data for each round and the target transformation base, and use the modulo result as the fourth candidate data segment;

[0149] Perform a division operation on the remaining N - 1 bits of the input data for each round and the target transformation base, and use the division result as the fifth candidate data segment;

[0150] Based on a preset odd multiplier, translation amount, and target transformation base, convert the fourth candidate data segment into a sixth candidate data segment.

[0151] Optionally, the data encryption unit 302 obtains multiple round keys by performing the following operations:

[0152] Recursively expand the original key sequence composed of L original key bytes to obtain the target key sequence, where L is a positive integer greater than or equal to 8;

[0153] According to the preset round key length and number of round keys, perform multiple sequence splits on the target key sequence to obtain multiple round keys.

[0154] Optionally, the data encryption unit 302 is used for:

[0155] Perform the following operations on the original key sequence composed of L original key bytes in a loop to obtain multiple extended key bytes: perform a byte transformation on multiple i - k original key bytes to obtain the i - th extended key byte, where i is a positive integer greater than or equal to L, and k is a positive integer less than or equal to L;

[0156] Concatenate L original key bytes and multiple extended key bytes in sequence to obtain a target key sequence.

[0157] For the convenience of description, the above parts are divided into respective modules (or units) according to functions and described separately. Of course, when implementing this application, the functions of the respective modules (or units) can be implemented in the same or multiple software or hardware.

[0158] After introducing the encryption method and device with dynamic block lengths of the exemplary embodiments of this application, next, a computer device according to another exemplary embodiment of this application is introduced.

[0159] Those skilled in the art can understand that various aspects of this application can be implemented as a system, method, or program product. Therefore, various aspects of this application can be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or an implementation combining hardware and software aspects, which can be collectively referred to as "circuitry", "module", or "system" here.

[0160] Based on the same inventive concept as the above method embodiment, an embodiment of this application also provides a computer device. Refer to Figure 4 As shown, the computer device 400 may at least include a processor 401 and a memory 402. Among them, the memory 402 stores program code, and when the program code is executed by the processor 401, the processor 401 is caused to execute the steps of any of the above encryption methods with dynamic block lengths.

[0161] In some possible implementation manners, the computing device according to this application may at least include at least one processor and at least one memory. Among them, the memory stores program code, and when the program code is executed by the processor, the processor is caused to execute the steps in the encryption method with dynamic block lengths according to various exemplary embodiments of this application described above in this specification. For example, the processor may execute the steps as shown in Figure 1A shown.

[0162] Next, refer to Figure 5 to describe the computing device 500 according to this embodiment of this application. Figure 5 The computing device 500 is only an example and should not impose any limitation on the functions and usage scope of the embodiments of this application.

[0163] As Figure 5 shown, the computing device 500 is presented in the form of a general-purpose computing device. The components of the computing device 500 may include but are not limited to: the above at least one processing unit 501, the above at least one storage unit 502, and a bus 503 connecting different system components (including the storage unit 502 and the processing unit 501).

[0164] The bus 503 represents one or more of several types of bus architectures, including a memory bus or memory controller, a peripheral bus, a processor bus, or a local bus using any of the various bus architectures.

[0165] The storage unit 502 may include a readable medium in the form of volatile memory, such as random access memory (RAM) 5021 and / or a cache storage unit 5022, and may further include a read-only memory (ROM) 5023.

[0166] The storage unit 502 may also include a program / utility 5025 having a set (at least one) of program modules 5024. Such program modules 5024 include, but are not limited to: an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment.

[0167] The computing device 500 may also communicate with one or more external devices 504 (such as a keyboard, a pointing device, etc.), may also communicate with one or more devices that enable a user to interact with the computing device 500, and / or may communicate with any device that enables the computing device 500 to communicate with one or more other computing devices (such as a router, a modem, etc.). Such communication may be through an input / output (I / O) interface 505. Further, the computing device 500 may communicate with one or more networks (such as a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through a network adapter 506. As shown in the figure, the network adapter 506 communicates with other modules for the computing device 500 through the bus 503. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the computing device 500, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, etc.

[0168] Based on the same inventive concept as the above method embodiments, various aspects of the encryption method with a dynamic packet length provided in this application may also be implemented in the form of a program product, which includes program code. When the program product runs on a computer device, the program code is used to cause the computer device to execute the steps in the encryption method with a dynamic packet length according to various exemplary embodiments described above in this specification. For example, an electronic device may execute the steps as shown in Figure 1A shown in.

[0169] The program product may employ any combination of one or more readable media. The readable media may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the readable storage medium include: an electrical connection having 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0170] Although the preferred embodiments of the present application have been described, additional changes and modifications can be made to these embodiments by those skilled in the art once they learn of the basic inventive concept. Therefore, the appended claims are intended to be construed to include the preferred embodiments as well as all changes and modifications that fall within the scope of the present application.

[0171] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalent technologies, the present application is also intended to include these modifications and variations.

Claims

1. A dynamic packet length encryption method, characterized in that: include: Divide the data to be encrypted into multiple plaintext groups according to the group length set based on business requirements; Perform multiple rounds of cyclic iterative transformation on each plaintext group, and use the transformation result of the last round as the corresponding ciphertext group, wherein the following operations are performed for a plaintext group: when the group length is an odd number, the input data of each round is split into two candidate data segments based on the target transformation system determined by the group length, and the two candidate data segments are merged into the nonlinear transformation result of each round; when the group length is an even number, the highest bit of the input data of each round is used as a candidate data segment, and other candidate data segments are split based on the remaining N-1 bits of the input data of each round and the target transformation system, and multiple candidate data segments are merged into the nonlinear transformation result of each round, wherein N is the group length, the input data of the first round is obtained by preprocessing the plaintext group, and the input data of the non-first round is the transformation result output by the previous round; based on the round key of each round, the nonlinear transformation result of each round is scrambled to obtain the transformation result output by each round.

2. The method according to claim 1, characterized in that The target transformation system determined based on the packet length, splitting the input data of each round into two candidate data segments, comprises: Performing a remainder operation on the input data of each round and a target conversion system determined based on the packet length, and using the remainder result as the first candidate data segment; Performing an integer division operation on the input data of each round and the target transformation system, and using the integer division result as the second candidate data segment; Based on a preset odd multiplier, a translation amount and the target transformation base, the first candidate data segment is converted into a third candidate data segment.

3. The method according to claim 1, characterized in that The remaining N-1 bits of the input data of each round are converted into the target system, and the other candidate data segments are obtained by splitting, including: Performing a modulo operation on the remaining N-1 bits of the input data of each round and the target conversion system, and using the modulo operation result as the fourth candidate data segment; Performing an integer division operation on the remaining N-1 bits of the input data of each round and the target conversion system, and using the integer division result as the fifth candidate data segment; Based on a preset odd multiplier, a translation amount and the target transformation base, the fourth candidate data segment is converted into a sixth candidate data segment.

4. The method according to any one of claims 1 to 3, characterized in that: Multiple round keys are obtained by performing the following operations: Recursively expand an original key sequence consisting of L original key bytes to obtain a target key sequence, where L is a positive integer greater than or equal to 8; According to the preset round key length and the number of round keys, the target key sequence is segmented multiple times to obtain the multiple round keys.

5. The method according to claim 4, characterized in that The recursive expansion of the original key sequence consisting of L original key bytes to obtain the target key sequence includes: The following operations are cyclically performed on the original key sequence consisting of the L original key bytes to obtain a plurality of extended key bytes: byte transformation is performed on a plurality of ik original key bytes to obtain an i-th extended key byte, wherein i is a positive integer greater than or equal to L, and k is a positive integer less than or equal to L; The L original key bytes are sequentially concatenated with a plurality of extended key bytes to obtain the target key sequence.

6. A dynamic packet length encryption device, characterized in that: include: A length adjustment unit, used to divide the data to be encrypted into a plurality of plaintext packets according to the packet length set based on business requirements; The data encryption unit is used to perform multiple rounds of cyclic iterative transformation on each plaintext group, and use the transformation result of the last round as the respective ciphertext group, wherein the following operations are performed for one plaintext group: when the group length is an odd number, based on the target transformation system determined by the group length, the input data of each round is split into two candidate data segments, and the two candidate data segments are merged into the nonlinear transformation result of each round; when the group length is an even number, the highest bit of the input data of each round is used as a candidate data segment, and based on the remaining N-1 bits of the input data of each round and the target transformation system, other candidate data segments are split, and multiple candidate data segments are merged into the nonlinear transformation result of each round, wherein N is the group length, the input data of the first round is obtained by preprocessing the one plaintext group, and the input data of the non-first round is the transformation result output by the previous round; based on the round key of each round, the nonlinear transformation result of each round is scrambled to obtain the transformation result output by each round.

7. The device according to claim 6, characterized in that The data encryption unit is used for: Performing a remainder operation on the input data of each round and a target conversion system determined based on the packet length, and using the remainder result as the first candidate data segment; Performing an integer division operation on the input data of each round and the target transformation system, and using the integer division result as the second candidate data segment; Based on a preset odd multiplier, a translation amount and the target transformation base, the first candidate data segment is converted into a third candidate data segment.

8. The device according to claim 6, characterized in that The data encryption unit is used for: Performing a modulo operation on the remaining N-1 bits of the input data of each round and the target conversion system, and using the modulo operation result as the fourth candidate data segment; Performing an integer division operation on the remaining N-1 bits of the input data of each round and the target conversion system, and using the integer division result as the fifth candidate data segment; Based on a preset odd multiplier, a translation amount and the target transformation base, the fourth candidate data segment is converted into a sixth candidate data segment.

9. The device according to any one of claims 6 to 8, characterized in that: The data encryption unit obtains a plurality of round keys by performing the following operations: Recursively expand an original key sequence consisting of L original key bytes to obtain a target key sequence, where L is a positive integer greater than or equal to 8; According to the preset round key length and the number of round keys, the target key sequence is segmented multiple times to obtain the multiple round keys.

10. The device according to claim 9, characterized in that The data encryption unit is used for: The following operations are cyclically performed on the original key sequence consisting of the L original key bytes to obtain a plurality of extended key bytes: byte transformation is performed on a plurality of ik original key bytes to obtain an i-th extended key byte, wherein i is a positive integer greater than or equal to L, and k is a positive integer less than or equal to L; The L original key bytes are sequentially concatenated with a plurality of extended key bytes to obtain the target key sequence.

11. An electronic device, characterized in that: It 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 the method according to any one of claims 1 to 5.

12. A computer-readable storage medium, characterized in that: It stores program codes, and when the program codes are run on a computer device, the program codes are used to make the computer device execute the steps of the method according to any one of claims 1 to 5.

13. A computer program product, characterized in that The method comprises computer instructions, which implement the steps of the method according to any one of claims 1 to 5 when executed by a processor.

Citation Information

Patent Citations

  • Lightweight block cipher GFCS implementation method and device and readable storage medium

    CN112202547A