Efficient SM4 data encryption method in communication system
By splitting and processing the data in parallel using the national cryptographic SM4 data encryption method, the communication delay problem caused by data length was solved, achieving efficient data encryption and decryption and improving the stability of the communication network.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-28
- Publication Date
- 2026-04-10
AI Technical Summary
When processing large amounts of data, the processing time of the national standard SM4 data encryption method is directly proportional to the data length, leading to communication delays and reduced stability of communication networks.
A data parallel processing method is adopted, which divides the data to be encrypted into multiple data blocks and performs encryption and decryption through multi-threaded parallel processing. The XOR operation is performed for 32 rounds using the first and second round keys to achieve parallel processing of data encryption and decryption.
It significantly improves the stability of communication networks, and the processing time is not limited by the data length, thus improving data processing efficiency.
Smart Images

Figure CN121841597A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of communication technology, in particular to an efficient SM4 data encryption method in a communication system. BACKGROUND
[0002] The SM4 data encryption method processes data in proportion to the data length when processing a large amount of data. In a communication system, the long processing time will cause the accumulation of communication delay, resulting in packet loss and reducing the stability of the entire communication network. SUMMARY
[0003] The present application provides an efficient SM4 data encryption method in a communication system to improve the stability of the communication network.
[0004] In the first aspect of the embodiments of the present application, an efficient SM4 data encryption method in a communication system is provided, comprising:
[0005] Obtaining data to be encrypted;
[0006] Splitting and recombining the data to be encrypted to obtain multiple groups of data blocks;
[0007] Encrypting the multiple groups of data blocks using a first round key to obtain encrypted data;
[0008] Decrypting the encrypted data using a second round key to obtain original data.
[0009] In some optional embodiments of the present application, the splitting and recombining the data to be encrypted to obtain multiple groups of data blocks comprises:
[0010] Splitting the input data to be encrypted by every 16 bytes and obtaining N plaintext blocks, each plaintext block consisting of 128 binary data;
[0011] Recombining the plaintext blocks after S-box transformation into 128 data blocks, wherein the i-th data block is composed of the i-th bit of each plaintext block in order.
[0012] In some optional embodiments of the present application, the encrypting the multiple groups of data blocks using a first round key to obtain encrypted data comprises:
[0013] The data encryption undergoes 32 rounds in total, and the j-th round introduces a round key rkj.
[0014] In the i-th round, the first 32 groups of data blocks are taken to synchronously encrypt N bits of data.
[0015] In some optional embodiments of the present invention, for the j-th data block, the data blocks are sequentially bitwise ANDed with the (j+2)-th, (j+10)-th, (j+18)-th, (j+24)-th data blocks and the round key rk. j Perform an XOR operation on the i-th bit to obtain 32 new data blocks;
[0016] Discard data blocks 0 to 31, and fill the positions of data blocks 96 to 127 with the new 32 data blocks in sequence. Repeat this operation 32 times to obtain N ciphertext blocks after rearranging them bit by bit. Arrange them in order to obtain the encrypted data, so as to realize the parallel processing of data encryption.
[0017] In some optional embodiments of the present invention, the encrypted data is decrypted using a second round key to obtain the original data, including:
[0018] The data decryption process involves 32 rounds, with the round key rk introduced in the j-th round. 31-j ;
[0019] In the j-th round, the first 32 data blocks are taken, and N bits of data are decrypted simultaneously.
[0020] In some optional embodiments of the present invention, for the j-th data block, the data blocks are sequentially bitwise ANDed with the (j+2)-th, (j+10)-th, (j+18)-th, (j+24)-th data blocks and the round key rk. 31-j Perform an XOR operation on the j-th bit to obtain 32 new data blocks;
[0021] Discard data blocks 0 to 31, and fill the positions of data blocks 96 to 127 with the new 32 data blocks in sequence. Repeat this operation 32 times to obtain N ciphertext blocks after rearranging them bit by bit. Arrange them in order to obtain the encrypted data, so as to realize the parallel processing of data encryption.
[0022] In a second aspect of the present invention, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the efficient SM4 data encryption method in the communication system according to any one of the first aspect embodiments.
[0023] In a third aspect of the present invention, a computer-readable storage medium is provided having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the efficient SM4 data encryption method in the communication system described in any one of the first aspect embodiments.
[0024] The beneficial effects provided by this invention are:
[0025] The method of this invention introduces a parallel data processing approach, which can simultaneously encrypt multiple sets of data. The processing time is not limited by the data length, and it can significantly improve the stability of communication networks.
[0026] Advantages of additional aspects of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. Attached Figure Description
[0027] Figure 1 A flowchart of parallel SM4 data encryption provided for an embodiment of the present invention. Detailed Implementation
[0028] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the protection scope of the present invention.
[0029] like Figure 1 As shown in the embodiments of the present invention, an SM4 data encryption method with high-efficiency data processing is provided. This method can improve the stability of communication networks, specifically including:
[0030] 1) Data preprocessing
[0031] Whether it's encrypting or decrypting data, the first step is to split the input data into groups of 16 bytes (128 bits) to obtain N plaintext blocks. Each plaintext block consists of 128 bits of binary data. After performing an S-box transformation on the plaintext blocks, they are recombined into 128 data blocks, where the i-th data block is composed of the i-th bits of each plaintext block arranged in sequence.
[0032] 2) Data encryption
[0033] The data encryption process involves 32 rounds, with the round key rk introduced in the j-th round. j In the j-th round, the first 32 data blocks are taken, and N bits of data are encrypted simultaneously.
[0034] 3) Data decryption
[0035] Data decryption also involves 32 rounds, with the round key rk introduced in the j-th round. 31-j In the j-th round, the first 32 data blocks are taken, and N bits of data are decrypted simultaneously. For the j-th data block, it is sequentially bitwise ANDed with the (j+2)-th, (j+10)-th, (j+18)-th, and (j+24)-th data blocks and the round key rk. 31-jPerform an XOR operation on the j-th bit (taking the remainder if the index exceeds 32) to obtain 32 new data blocks. Discard data blocks 0 to 31, and fill the positions of the new 32 data blocks in order from 96 to 127. Repeat this operation 32 times. After rearranging the bits, N ciphertext blocks are obtained, and the encrypted data is obtained by arranging them in order, thus realizing parallel processing of data encryption.
[0036] The specific implementation method is as follows:
[0037] 1) Data Preprocessing Process
[0038] The input data is split into groups of 16 bytes (128 bits) to obtain N plaintext blocks.
[0039] INPUT input_Data; / / Input the data to be encrypted / decrypted
[0040] int len = sizeof(input_Data); / / Length of data to read
[0041] int N = len / 16 + ((len%16) ? 1 : 0); / / Number of data blocks to be reconstructed
[0042] char Data[N]
[16] = {0}; / / Reconstructed data block
[0043] for(int i = 0, i < N, i++){
[0044] for(int j = 0, j < 16, j++){
[0045] Data[i][j]=input_Data[16*i+j];
[0046] }
[0047] }
[0048] 2) Data encryption process
[0049] A) Create a thread
[0050] Pthresd_t threads[N];
[0051] B) Each thread performs SM4 data encryption separately.
[0052] for(int i = 0; i < N; i++){
[0053] int result=pthread_create(&threads[i], NULL, encode_SM4, &input_Data[i]);
[0054] if (result != 0) {
[0055] fprintf(stderr, "Failed to create thread %d\n", i);
[0056] exit(1);
[0057] }
[0058] }
[0059] C) Wait for all threads to complete.
[0060] for(int i = 0; i < N; i++){
[0061] pthread_join(threads[i], NULL);
[0062] }
[0063] D) Data encryption function
[0064] An encryption function is constructed based on the SM4 data encryption principle: encode_SM4(u8*Data).
[0065] 3) Data decryption process
[0066] A) Create a thread
[0067] Pthresd_t threads[N];
[0068] B) Each thread performs SM4 data decryption separately.
[0069] for(int i = 0; i < N; i++){
[0070] int result=pthread_create(&threads[i], NULL, decode_SM4, &input_Data[i]);
[0071] if (result != 0) {
[0072] fprintf(stderr, "Failed to create thread %d\n", i);
[0073] exit(1);
[0074] }
[0075] }
[0076] C) Wait for all threads to complete.
[0077] for(int i = 0; i < N; i++){
[0078] pthread_join(threads[i], NULL);
[0079] }
[0080] D) Data encryption function
[0081] An encryption function is constructed based on the SM4 data decryption principle: decode_SM4(u8*Data)
[0082] 4) Multi-threaded data merging process
[0083] u8*output_Data
[2048] ; / / Decrypted / encrypted data to be output
[0084] for(int i = 0, i < N, i++){
[0085] for(int j=0,j<16,j++){
[0086] output_Data[16*i+j]=input_Data[i][j];
[0087] }
[0088] }
[0089] It should be understood that in the description of this specification, references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples" refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of the present invention. In this description, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate different embodiments or examples described in this specification, as well as some features of different embodiments or examples.
[0090] Of course, those skilled in the art can make various corresponding changes and modifications based on the present invention without departing from its spirit and essence, but such changes and modifications should all fall within the protection scope of the claims of the present invention.
Claims
1. A highly efficient SM4 data encryption method in a communication system, characterized in that, include: Obtain the data to be encrypted; The data to be encrypted is split and reassembled to obtain multiple data blocks; The multiple data blocks are encrypted using the first-round key to obtain encrypted data. The encrypted data is decrypted using the second round key to obtain the original data.
2. The efficient SM4 data encryption method in a communication system according to claim 1, characterized in that, The process of splitting and recombining the data to be encrypted yields multiple data blocks, including: The input data to be encrypted is split into groups of 16 bytes each, resulting in N plaintext blocks. Each plaintext block consists of 128 bits of binary data. After performing an S-box transformation on the plaintext blocks, they are recombined into 128 data blocks, where the i-th data block is composed of the i-th bit of each group of plaintext blocks arranged in order.
3. The efficient SM4 data encryption method in a communication system according to claim 1, characterized in that, The step of encrypting the multiple data blocks using the first-round key to obtain encrypted data includes: The data encryption process involves 32 rounds, with the round key rkj introduced in the j-th round. In the j-th round, the first 32 data blocks are taken, and N bits of data are encrypted simultaneously.
4. The efficient SM4 data encryption method in a communication system according to claim 3, characterized in that, For the j-th data block, perform bitwise AND operations sequentially with the (j+2)-th data block, the (j+10)-th data block, the (j+18)-th data block, the (j+24)-th data block, and the round key rk. j Perform an XOR operation on the j-th bit to obtain 32 new data blocks; Discard data blocks 0 to 31, and fill the positions of data blocks 96 to 127 with the new 32 data blocks in sequence. Repeat this operation 32 times to obtain N ciphertext blocks after rearranging them bit by bit. Arrange them in order to obtain the encrypted data, so as to realize the parallel processing of data encryption.
5. The efficient SM4 data encryption method in a communication system according to claim 1, characterized in that, The encrypted data is decrypted using the second-round key to obtain the original data, including: The data decryption process involves 32 rounds, with the round key rk introduced in the j-th round. 31-j ; In the j-th round, the first 32 data blocks are taken, and N bits of data are decrypted simultaneously.
6. The efficient SM4 data encryption method in a communication system according to claim 5, characterized in that, For the j-th data block, perform bitwise AND operations sequentially with the (j+2)-th data block, the (j+10)-th data block, the (j+18)-th data block, the (j+24)-th data block, and the round key rk. 31-j Perform an XOR operation on the j-th bit to obtain 32 new data blocks; Discard data blocks 0 to 31, and fill the positions of data blocks 96 to 127 with the new 32 data blocks in sequence. Repeat this operation 32 times to obtain N ciphertext blocks after rearranging them bit by bit. Arrange them in order to obtain the encrypted data, so as to realize the parallel processing of data encryption.
7. An electronic device comprising a memory, a processor, and a computer program stored in the memory, characterized in that, The processor executes the computer program to implement the steps of the efficient SM4 data encryption method in the communication system according to any one of claims 1-6.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the efficient SM4 data encryption method in the communication system according to any one of claims 1-6.