An improved SM4 encryption system and method for variable length keys

Through the improved key derivation function and key expansion module, the SM4 encryption system supports keys of any length, solving the problem that the SM4 algorithm only supports fixed-length keys, improving its flexibility and security in database applications, making it It is as secure as AES-128bit.

CN117527194BActive Publication Date: 2024-10-01BEIJING XINSHU TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311395073.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-10-26
Publication Date
2024-10-01
Estimated Expiration
2043-10-26

AI Technical Summary

Technical Problem

The existing SM4 encryption algorithm only supports fixed-length keys, which cannot meet the requirements for random keys of different lengths involved in scenarios such as sensitive data protection and data sharing in databases, resulting in non-uniform key lengths and inability to perform efficiently. Symmetric encryption.

Method used

An improved SM4 encryption system is proposed. Through the improved key derivation function, the key expansion algorithm in SM4 supports the input of keys of any length, including a derivation key calculation module, a key expansion module and a plaintext processing module, generating 128-bit length derived key, and the flexibility and security of the key are improved through XOR operation and non-linear transformation function.

Benefits of technology

Supports input keys of any length, increasing the flexibility and security of the SM4 algorithm, allowing it to be applied to more scenarios, and improving the security of the cryptographic algorithm. The SM4 algorithm with a 128bit key length is equivalent to AES-128bit in security , the longer the key length, the more computing resources are required to crack the algorithm.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117527194B_ABST
    Figure CN117527194B_ABST
Patent Text Reader

Abstract

The present invention proposes an improved SM4 encryption system and method for variable-length keys. Based on the improved key derivation function, the key expansion algorithm in SM4 supports the input of keys of any length, and can complete the derived key calculation, key expansion, and plaintext processing. The present invention supports input keys of any length, and the key length should be at least greater than or equal to 128 bits, which increases the flexibility of the national secret commercial cipher SM4, enables SM4 to be applied to more scenarios, has a positive effect on the development and application of domestic cryptographic technology, and enhances the competitiveness of the domestic cryptographic industry; in addition, the input key length is increased, and the security of the cryptographic algorithm is improved. The SM4 algorithm with a key length of 128 bits is equivalent to the security of AES-128 bits. The longer the key length, the more computing resources are required to crack the algorithm, which improves the security of the algorithm.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of encryption, and in particular to the technical field of adaptive database privacy protection. Background Art

[0002] The SM4 algorithm is a widely used encryption algorithm, but it only supports fixed-length keys, which limits its application in certain scenarios. In particular, in databases, for sensitive data protection and data sharing, a symmetric encryption system with random keys of different lengths is required.

[0003] In actual application scenarios, the key lengths are not uniform, and it is not possible to use more efficient symmetric keys for encryption. BRIEF DESCRIPTION OF THE DRAWINGS

[0004] Figure 1 This is the calculation process for deriving the key part.

[0005] Figure 2 It is the key expansion process. Summary of the invention

[0006] In order to solve the above problems existing in the prior art, the present invention proposes an improved SM4 encryption system for variable length keys. Based on the improved key derivation function, the key expansion algorithm in SM4 supports the input of keys of any length. The system includes a derived key calculation module, a key expansion module, and a plaintext processing module. The symmetric key in the SM4 algorithm is MK, 128bit≤len(MK)≤512bit, and a derived key is generated for the symmetric key. Where FK is the derived key, and len(FK) = 128 bits; take n bytes tag1 = 0x01, tag2 = 0x02, ...; for each i from 1 to n, perform the following steps:

[0007] 1. Export the key calculation module, which completes the following operations:

[0008] (1) Calculate K(i) = SM3(tag i ||MK||int(i)), where int(i) is the 32-bit big-endian representation of counter i; calculate Where K(i,j) represents the bit string from the (32(j-1)+1)th bit to the (32j)th bit of K(i), j=1,2,3,4; Where B represents a bit string with a length of 32 bits; calculate K′(i)=K′(i,1)||K′(i,2)||K′(i,3)||K′(i,4), where || represents a concatenation symbol;

[0009] (2) Calculate and derive the key

[0010] (3) Calculate the intermediate key

[0011] 2. Key expansion module, which completes the following operations:

[0012] (1) Input the key MK of any bit, system parameters PK0, PK1, PK2, PK3, and fixed parameters CK0, CK1, ..., CK 31 , where the length of MK is 128 to 512 bits; calculate FK = (FK0, FK1, FK2, FK3) and the intermediate key FK′; calculate the XOR of the derived key and the system parameters: Get the subkey: Where k = 0, 1, 2, ..., 31;

[0013] The calculation process of function T is: Perform nonlinear transformation τ, input A = (a0, a1, a2, a3), output B = τ(A) = (Sbox(a0), Sbox(a1), Sbox(a2), Sbox(a3)), where Sbox() represents an 8-bit input and output S-box; use the output result B as the input of the linear transformation L, and output

[0014] 3. Plaintext processing module: This module completes symmetric encryption. First, the plaintext is divided into four 32-bit words X1, X2, X3, and X4, and 32 rounds of round operations are performed. The four words of the round operation result are reversed to form a 128-bit ciphertext. The round function is basically the same as the T function process in key expansion, except that where k = 0, 1, 2, ..., 31; the T′ function replaces the linear transformation L with

[0015] On the basis of the above, the present invention proposes an improved SM4 encryption method for variable length keys. Based on the improved key derivation function, the key expansion algorithm in SM4 supports the input of keys of arbitrary lengths. The symmetric key in the SM4 algorithm is MK, 128bit≤len(MK)≤512bit, and a derived key is generated for the symmetric key. Where FK is the derived key, and len(FK) = 128 bits; take n bytes tag1 = 0x01, tag2 = 0x02, ...; for each i from 1 to n, perform the following steps:

[0016] 1. Calculate the derived key. The specific steps are:

[0017] (1) Calculate K(i) = SM3(tag i ||MK||int(i)), where int(i) is the 32-bit big-endian representation of counter i; calculate Where K(i,j) represents the bit string from the (32(j-1)+1)th bit to the (32j)th bit of K(i), j=1,2,3,4; Where B represents a bit string with a length of 32 bits; calculate K′(i)=K′(i,1)||K′(i,2)||K′(i,3)||K′(i,4), where || represents a concatenation symbol;

[0018] (2) Calculate and derive the key

[0019] (3) Calculate the intermediate key

[0020] 2. Key expansion, the specific steps are:

[0021] (1) Input the key MK of any bit, system parameters PK0, PK1, PK2, PK3, and fixed parameters CK0, CK1, ..., CK 31 , where the length of MK is 128 to 512 bits; calculate FK = (FK0, FK1, FK2, FK3) and the intermediate key FK′; calculate the XOR of the derived key and the system parameters: Get the subkey: Where k = 0, 1, 2, ..., 31;

[0022] The calculation process of function T is: Perform nonlinear transformation τ, input A = (a0, a1, a2, a3), output B = τ(A) = (Sbox(a0), Sbox(a1), Sbox(a2), Sbox(a3)), where Sbox() represents an 8-bit input and output S-box; use the output result B as the input of the linear transformation L, and output

[0023] 3. Plaintext processing, complete symmetric encryption, first, divide the plaintext into 4 32-bit words X1, X2, X3, X4, and perform 32 rounds of round operations, and then reverse the 4 words of the round operation to form a 128-bit ciphertext. The round function is basically the same as the T function process in key expansion, except that where k = 0, 1, 2, ..., 31; the T′ function replaces the linear transformation L with

[0024] The present invention supports input keys of any length, and the key length should be at least greater than or equal to 128 bits, which increases the flexibility of the national secret commercial cipher SM4, enables SM4 to be applied to more scenarios, plays a positive role in the development and application of domestic cryptographic technology, and enhances the competitiveness of the domestic cryptographic industry; in addition, the input key length is increased to enhance the security of the cryptographic algorithm. The SM4 algorithm with a key length of 128 bits is equivalent to the security of AES-128 bits. The longer the key length, the more computing resources are required to crack the algorithm, thereby improving the security of the algorithm. DETAILED DESCRIPTION

[0025] After the sensitive data is encrypted by the present invention, it can be stored in a database, and the design of a data sharing solution can be completed by using public key encryption.

[0026] Example 1

[0027] 1. Data encryption. Divide the plaintext into multiple plaintext blocks of 128 bits in length. When the plaintext length is not a multiple of 128 bits, fill the corresponding bits at the end of the plaintext to make the plaintext length an integer multiple of 128 bits. Encrypt each block in turn. Before encryption, perform an XOR operation on the ciphertext of the previous block and the plaintext of the current block. Use the improved SM4 algorithm to encrypt the current plaintext block. Finally, the complete ciphertext of all blocks is obtained: C = C1||C2,...,C l .

[0028] 2. Data sharing. When facing other database visitors, the data visitor provides the data owner with a legal access certificate V DA The key generation center generates the corresponding private key SK for the data accessor's access certificate. DA ; The data owner calculates the ciphertext of Meg based on the access certificate of the data accessor The data accessor obtains the ciphertext C DA Then, use the private key SK DA Decrypt and obtain the symmetric key information contained in the corresponding message Meg; finally, complete the access to the ciphertext data in the database.

[0029] Example 2

[0030] 1. Data encryption

[0031] Divide the plaintext into multiple plaintext blocks of 128 bits in length. When the plaintext length is not a multiple of 128 bits, fill the end of the plaintext with the corresponding bits to make the plaintext length an integer multiple of 128 bits, such as M = (M1, M2, ... M l ),in Encrypt each block in turn. Before encryption, perform XOR operation on the ciphertext of the previous block and the plaintext of the current block. Then use SM4 to symmetric encrypt the current block. Finally, get the complete ciphertext of all blocks C = C1||C2,...,C l .

[0032] 2. Data Sharing

[0033] When facing other database accessors, the data accessor DA provides its own legal access certificate V to the data owner DO. DA The system generates a corresponding private key SK for DA's access certificate. DA DO calculates Meg's ciphertext based on DA's access certificate

[0034] Data accessor DA obtains ciphertext C DA Then, use your own private key SK DA Decrypt and obtain the symmetric key information contained in the corresponding message Meg; finally, complete the access to the ciphertext data in the database.

[0035] Implementation Cases:

[0036] 1. Data encryption

[0037] For plaintext data M=(M1,M2,...M l ),in The length of 128-bit plaintext M p Divide into 4 32-bit words X1, X2, X3, X4, where p = 1, 2, ..., l, perform 32 rounds of operations on the 4 groups of 32-bit words, and finally reverse the order of the obtained 4 words to form a 128-bit ciphertext. In order to increase the difficulty of cracking the encrypted block, each encrypted block is associated using the group chaining mode, and the encryption result of the previous encrypted block is XORed with the next plaintext block to form an encrypted block chain. The system will generate a random 128-bit bit string IV and then perform group encryption:

[0038]

[0039] Finally, we get the complete ciphertext C=C1||C2,...,C l .

[0040] 2. Data Sharing

[0041] The database accessor DA will provide the data owner DO with his / her own legal access certificate V DA ,DO verifies the digital certificate V DA The legitimacy of the DA is verified and a fixed-length access sequence H = Hash (V DA ||Time), where Time represents the time sequence of data DA sending access certificates. The Hash function can choose SM3 hash algorithm. The encryption process of symmetric key MK is completed by SM9 algorithm, and DA's access certificate V DA Generate a private key:

[0042] (1) Initialization

[0043] Input security parameter λ and select bilinear pairing Where N>2 λ , e is a bilinear pairing Randomly select a group and Generators P1 and P2, randomly select s∈[1,N-1], calculate P pub = [s] P1 and g = e (P DA ,P2). Output system master public key MPK=P pub , public parameters Where hid represents the private key generation function identifier, MAC represents the message authentication code, and the system master private key is MSK=s.

[0044] (2) Private key generation

[0045] Enter the access credentials V of user DA DA , master private key MSK = s. Calculate h DA =Hash(H||hid,N),t DA =h DA +s(modN), when P DA ≠0, calculate Output user private key SK DA =S DA

[0046] (3) Encryption

[0047] Input the access sequence H of user DA, message Meg = MK||IV and master public key MPK, calculate Q DA =[Hash(H||hid,N)]P1+P pub , select a random number r = [N-1], and calculate w=g r , in Indicates the key length of the block encryption, Indicates the key length in MAC; finally, calculate Output ciphertext

[0048] The system inputs DA's access certificate H and private key SK DA With ciphertext C DA ,calculate but calculate If C3′=C3, the obtained Meg is the correct plaintext, otherwise the decryption fails.

[0049] After DA uses its own private key to obtain the correct message Meg, it takes the last 128 bits as the initial vector IV and the rest as the symmetric key MK, and uses the key to obtain the final valid database plaintext data.

Claims

1. An improved SM4 encryption system for variable length keys, based on an improved key derivation function to enable the key expansion algorithm in SM4 to support the input of keys of arbitrary lengths, characterized in that: The system includes a derived key calculation module, a key expansion module, and a plaintext processing module; the symmetric key in the SM4 algorithm is MK, 128bit≤len(MK)≤512bit, and a derived key is generated for the symmetric key. Where FK is the derived key, and len(FK) = 128 bits; take n bytes tag1 = 0x01, tag2 = 0x02, ...; Perform the following steps:

1. Use the derived key calculation module to complete the following operations: (1) For each i from 1 to n, calculate K(i) = SM3(tag i ||MK||int(i)), where int(i) is the 32-bit big-endian representation of counter i; calculate K′(i,j)=L′(K(i,j))⊕K(i,j+4), where K(i,j) represents the bit string from the (32(j-1)+1)th bit to the (32j)th bit of K(i), j=1,2,3,4; L′(B)=B⊕B<<<2⊕B<<<10⊕B<<<18⊕B<<<24, where B represents a bit string with a length of 32 bits; Calculate K′(i)=K′(i,1)||K′(i,2)||K′(i,3)||K′(i,4), where || represents the concatenation symbol; (2) Calculate and derive the key FK = K′(1)⊕K′(2)⊕…⊕K′(n); (3) Calculate the intermediate key FK′=K′(1,1)⊕…⊕K′(1,4)⊕…⊕K′(n,1)⊕…⊕K′(n,4); 2. Use the key expansion module to complete the following operations: (1) Input the key MK of any bit, system parameters PK0, PK1, PK2, PK3, and fixed parameters CK0, CK1, ..., CK 31 , where the length of MK is 128 to 512 bits; calculate FK = (FK0, FK1, FK2, FK3) and the intermediate key FK′; calculate the XOR of the derived key and the system parameters: (SK0, SK1, SK2, SK3) = (FK0⊕PK0, FK1⊕PK1, FK2⊕PK2, FK3⊕PK3), and obtain the subkey: rk k =SK k+4 =SK k ⊕T(SK k+1 ⊕SK k+2 ⊕SK k+3 ⊕CK k ⊕FK′), where k = 0, 1, 2, …, 31; The calculation process of function T is: Let A = SK k+1 ⊕SK k+2 ⊕SK k+3 ⊕CK k ⊕FK′, perform nonlinear transformation τ, input A = (a0, a1, a2, a3), output B = τ(A) = (Sbox(a0), Sbox(a1), Sbox(a2), Sbox(a3)), where Sbox() represents an 8-bit input and output S-box; use the output result B as the input of the linear transformation L, and output C = T(SK k+1 ⊕SK k+2 ⊕SK k+3 ⊕CK k ⊕FK′)=L(B)=B⊕(B<<<13)⊕(B<<<23); 3. Use the plaintext processing module to complete symmetric encryption. First, divide the plaintext into four 32-bit words X1, X2, X3, and X4, and perform 32 rounds of round operations. The four words of the round operation result are reversed to form a 128-bit ciphertext. The round function is the same as the T function process in key expansion, except that X k+4 =X k ⊕T′(X k+1 ⊕X k+2 ⊕X k+3 ⊕rk k ), where k = 0, 1, 2, …, 31; the T′ function replaces the linear transformation L with L′(B) = B⊕(B<<<2)⊕(B<<<10)⊕(B<<<18)⊕(B<<<24).

2. An improved SM4 encryption method for variable-length keys, based on an improved key derivation function to enable the key expansion algorithm in SM4 to support the input of keys of arbitrary lengths, characterized in that: The symmetric key in the SM4 algorithm is MK, 128bit≤len(MK)≤512bit, and a derived key is generated for the symmetric key. Where FK is the derived key, and len(FK) = 128 bits; take n bytes tag1 = 0x01, tag2 = 0x02, ...; Perform the following steps:

1. Calculate the derived key. The specific steps are: (1) For each i from 1 to n, calculate K(i) = SM3(tag i ||MK||int(i)), where int(i) is the 32-bit big-endian representation of counter i; calculate K′(i,j)=L′(K(i,j))⊕K(i,j+4), where K(i,j) represents the bit string from the (32(j-1)+1)th bit to the (32j)th bit of K(i), j=1,2,3,4; L′(B)=B⊕B<<<2⊕B<<<10⊕B<<<18⊕B<<<24, where B represents a bit string with a length of 32 bits; Calculate K′(i)=K′(i,1)||K′(i,2)||K′(i,3)||K′(i,4), where || represents the concatenation symbol; (2) Calculate and derive the key FK = K′(1)⊕K′(2)⊕…⊕K′(n); (3) Calculate the intermediate key FK′=K′(1,1)⊕…⊕K′(1,4)⊕…⊕K′(n,1)⊕…⊕K′(n,4); 2. Key expansion, the specific steps are: (1) Input the key MK of any bit, system parameters PK0, PK1, PK2, PK3, and fixed parameters CK0, CK1, ..., CK 31 , where the length of MK is 128 to 512 bits; calculate FK = (FK0, FK1, FK2, FK3) and the intermediate key FK′; calculate the XOR of the derived key and the system parameters: (SK0, SK1, SK2, SK3) = (FK0⊕PK0, FK1⊕PK1, FK2⊕PK2, FK3⊕PK3), and obtain the subkey: rk k =SK k+4 =SK k ⊕T(SK k+1 ⊕SK k+2 ⊕SK k+3 ⊕CK k ⊕FK′), where k = 0, 1, 2, …, 31; The calculation process of function T is: Let A = SK k+1 ⊕SK k+2 ⊕SK k+3 ⊕CK k ⊕FK′, perform nonlinear transformation τ, input A = (a0, a1, a2, a3), output B = τ(A) = (Sbox(a0), Sbox(a1), Sbox(a2), Sbox(a3)), where Sbox() represents an 8-bit input and output S-box; use the output result B as the input of the linear transformation L, and output C = T(SK k+1 ⊕SK k+2 ⊕SK k+3 ⊕CK k ⊕FK′)=L(B)=B⊕(B<<<13)⊕(B<<<23); 3. Plaintext processing, complete symmetric encryption, first, the plaintext is divided into 4 32-bit words X1, X2, X3, X4, and 32 rounds of round operations are performed. The 4 words of the round operation result are reversed to form a 128-bit ciphertext; the round function is the same as the T function process in key expansion, the difference is that X k+4 =X k ⊕T′(X k+1 ⊕X k+2 ⊕X k+3 ⊕rk k ), where k = 0, 1, 2, …, 31; the T′ function replaces the linear transformation L with L′(B) = B⊕(B<<<2)⊕(B<<<10)⊕(B<<<18)⊕(B<<<24).