Data Fast Encryption Method and System Based on SM Cryptography Algorithm
By reconstructing the counter mode encryption function of the Guomi algorithm SM4 and building a new encryption function based on the length of the plain text, the problems of degradation of parallel computing performance and slow speed during the SM4 encryption process are solved, and efficient and secure data encryption is achieved.
Patent Information
- Application Number
- CN202510040308.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-10
- Publication Date
- 2025-06-24
- Estimated Expiration
- 2045-01-10
AI Technical Summary
When using the Guomi algorithm SM4 for data encryption, the prior art has problems such as degradation in parallel computing performance and slow computing speed, especially when processing data with integer multiples of non-packet length.
By reconstructing the counter mode encryption function of the Guomi algorithm SM4, it is divided into two steps: first, using the reconstructed encryption function to encrypt the encrypted message, obtaining the encrypted part of the encrypted ciphertext and the remaining plaintext; then, based on the different lengths of the remaining plaintext, a new encryption function is constructed to encrypt it, and the ciphertext of the remaining plaintext is obtained.
This method significantly reduces the computational complexity, greatly improves the speed of the SM4 encryption process, and has advantages such as versatility, low memory footprint, high efficiency and security.
Smart Images

Figure CN119483913B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data encryption technology, and particularly to a data rapid encryption method and system based on the national cryptographic algorithm. Background Art
[0002] SM4 (formerly SMS4) is a block cipher standard with a data block length of 128 bits, a key block length of 128 bits. The encryption algorithm and the key expansion algorithm adopt a 32-round iterative structure, and data is processed in units of words (32 bits). The SM4 algorithm is widely used in fields such as finance and e-commerce for encrypting various data.
[0003] The CTR (Counter) mode generates a key stream by encrypting a sequentially incremented counter, and the plaintext is XORed with the key stream byte by byte to obtain the ciphertext, and the encryption and decryption functions are the same. Since multiple data blocks can be processed in parallel, it is widely used in large-scale real-time data encryption scenarios such as real-time audio and video stream encryption and cloud storage file encrypted storage.
[0004] In the CTR (Counter) mode, the plaintext is known and independent of each other. Therefore, the single instruction multiple data (SIMD) extension instruction set can be used to simultaneously execute the encryption of multiple groups of data to improve the encryption speed. Currently, methods such as AESNI, Tower Field, and GFNI have been applied to SM4 encryption.
[0005] However, due to the need to re-group multiple groups of data for parallel computing, commonly used groupings include 4 groups of 64 bytes, 8 groups of 128 bytes, 16 groups of 256 bytes, 32 groups of 512 bytes, etc. There will be a significant performance degradation for data processing that is not an integer multiple of the block length.
[0006] In addition, the prior art usually focuses on the optimization of the core encryption function. In the CTR mode, the ciphertext is obtained by XORing with the plaintext after the core encryption is completed, resulting in worse performance of the CTR mode compared to modes such as ECB (Electronic Codebook). During the encryption task, due to the high computational complexity and slow operation speed of the national cryptographic algorithm SM4, it occupies computer memory and affects the encryption and decryption speed. Summary of the Invention
[0007] In order to solve the deficiencies of the prior art, the present invention provides a data rapid encryption method and system based on the national cryptographic algorithm, which improves the data encryption speed.
[0008] On the one hand, a data rapid encryption method based on the national cryptographic algorithm is provided, including: obtaining the plaintext, and using the counter mode of the national cryptographic algorithm SM4 to perform encryption processing on the plaintext to obtain the ciphertext;
[0009] Among them, the encryption process of the counter mode of the national cryptographic algorithm SM4 is accelerated in the following way: the encryption function is reconstructed, and through the reconstructed encryption function, the message to be encrypted is encrypted to obtain the encrypted partial ciphertext and the remaining plaintext; based on the different lengths of the remaining plaintext, a new encryption function is constructed, and based on the new encryption function, the remaining plaintext of different lengths is encrypted to obtain the ciphertext of the remaining plaintext.
[0010] On the other hand, a data fast encryption system based on the national cryptographic algorithm is provided, including: an encryption module, which is configured to: obtain the plaintext, and encrypt the plaintext using the counter mode of the national cryptographic algorithm SM4 to obtain the ciphertext;
[0011] Among them, the encryption process of the counter mode of the national cryptographic algorithm SM4 is accelerated in the following way: the encryption function is reconstructed, and through the reconstructed encryption function, the message to be encrypted is encrypted to obtain the encrypted partial ciphertext and the remaining plaintext; based on the different lengths of the remaining plaintext, a new encryption function is constructed, and based on the new encryption function, the remaining plaintext of different lengths is encrypted to obtain the ciphertext of the remaining plaintext.
[0012] The above technical solution has the following advantages or beneficial effects:
[0013] The plaintext is encrypted using the counter mode of the national cryptographic algorithm SM4 to obtain the ciphertext; among them, the encryption process of the counter mode of the national cryptographic algorithm SM4 is accelerated in the following way: the encryption function is reconstructed, and through the reconstructed encryption function, the message to be encrypted is encrypted to obtain the encrypted partial ciphertext and the remaining plaintext; based on the different lengths of the remaining plaintext, a new encryption function is constructed, and based on the new encryption function, the remaining plaintext of different lengths is encrypted to obtain the ciphertext of the remaining plaintext. Compared with the prior art, the method of the present invention reduces the computational complexity through the reconstructed encryption function, greatly improves the speed of the SM4 encryption process, and has the advantages of generality, low memory occupancy, high efficiency, and secure implementation. Description of the Drawings
[0014] The specification drawings forming a part of the present invention are used to provide a further understanding of the present invention. The schematic embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention.
[0015] Figure 1 It is the flowchart of the method for the first embodiment. Detailed Description of the Invention
[0016] It should be noted that the following detailed description is exemplary and is intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by those of ordinary skill in the technical field to which the present invention belongs.
[0017] Example 1
[0018] As Figure 1 shown, this embodiment provides a data fast encryption method based on the national cryptographic algorithm, including: obtaining the plaintext, and encrypting the plaintext using the counter mode of the national cryptographic algorithm SM4 to obtain the ciphertext;
[0019] Among them, the encryption process of the counter mode of the national cryptographic algorithm SM4 is accelerated in the following way:
[0020] (1-1) Reconstruct the encryption function, and encrypt the message to be encrypted through the reconstructed encryption function to obtain the encrypted partial ciphertext and the remaining plaintext;
[0021] (1-2) Based on the different lengths of the remaining plaintext, construct a new encryption function, and encrypt the remaining plaintext of different lengths based on the new encryption function to obtain the ciphertext of the remaining plaintext.
[0022] Furthermore, the processing process of the counter mode of the national cryptographic algorithm SM4 includes:
[0023] (2-1): Group the plaintext with a length of bytes by 16-byte rows to obtain the grouping result (let the serial number be ; ), such as if there are bytes remaining in the plaintext, set it as ; ;
[0024] (2-2): Combine the 96-bit one-time random number Nonce and the 32-bit counter Counter into a 128-bit initial vector ;
[0025] (2-3) Encrypt the initial vector , and call the encryption function to obtain the intermediate parameter ;
[0026] (2-4) If the length of the remaining plaintext , then XOR with and output it as the ciphertext , otherwise take the first bytes of XOR and output the ciphertext ;
[0027] (2-5) , ;
[0028] (2-6) If , go to step (2-2); otherwise, go to step (2-7);
[0029] (2-7) End.
[0030] Further, the encryption function includes:
[0031] (3-1) Input 128-bit plaintext , decompose the plaintext into 4 words , input 32 round key words , , and output 4 words of 128-bit ciphertext;
[0032] (3-2) Perform an endian conversion function on each input word .
[0033] ; ;
[0034] ; ;
[0035] (3-3) Let go from 1 to 32, and perform the round function 32 times;
[0036] ;
[0037] Split into 4 bytes ;
[0038] ;
[0039] ;
[0040] where represents the exclusive OR operation;
[0041] (3-4) Output the ciphertext : ; ; ; ; ; represents concatenation.
[0042] Further, before the step (1-1) of reconstructing the encryption function and encrypting the message to be encrypted with the reconstructed encryption function to obtain the encrypted partial ciphertext and the remaining plaintext, it also includes:
[0043] (1 - 0) Construct a pre - calculation table for 128 - bit SIMD register Counter update ; Construct a pre - calculation table for 256 - bit SIMD register Counter update ; Construct a pre - calculation table for 512 - bit SIMD register Counter update ; The data width is 32 bits:
[0044] ;
[0045] ;
[0046] ;
[0047] Construct a pre - calculation table IVUpTBL for encryption process IV update, with a data width of 32 bits:
[0048] IVUpTBL
[96] = {4,4,4,4, 4,4,4,4, 4,4,4,4, 4,4,4,4,
[0049] 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
[0050] 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16,
[0051] 32,32,32,32, 32,32,32,32, 32,32,32,32, 32,32,32,32,
[0052] 48,48,48,48, 48,48,48,48, 48,48,48,48, 48,48,48,48,
[0053] 64,64,64,64, 64,64,64,64, 64,64,64,64, 64,64,64,64}。
[0054] Furthermore, in (1 - 1), the encryption function is reconstructed. Through the reconstructed encryption function, the initial vector is encrypted to obtain the ciphertext of the initial vector and the remaining plaintext, including:
[0055] (4 - 1) Create a temporary data storage array with a width of 64 bits ;
[0056] (4 - 2) According to the algorithm standard, for the master key Execute the round key expansion function to generate round keys ;
[0057] (4-3) After converting the initial vector array in big-endian and little-endian order by 32 bits, store it in the 32-bit wide array ;
[0058] (4-4) If , go to step (4-5), otherwise go to step (4-7);
[0059] (4-5) Call the core 64-way encryption function function, set the current data position ; Go to step (4-6); where represents the output ciphertext, represents the round key, represents the input message, represents the initial vector, represents the message length, represents taking the remainder.
[0060] (4-6) Set the remaining plaintext length , if is 0, end. If is not 0, then enter (1-2).
[0061] Further, the (1-2) constructs a new encryption function based on the different lengths of the remaining plaintext, and encrypts the remaining plaintext of different lengths based on the new encryption function to obtain the ciphertext of the remaining plaintext, including:
[0062] (1-2-1) If the length of the remaining plaintext is less than or equal to 64, construct a new encryption function, and encrypt the remaining plaintext of different lengths based on the new encryption function to obtain the ciphertext of the remaining plaintext;
[0063] (1-2-2) If the length of the remaining plaintext is less than or equal to 128, construct a new encryption function, and encrypt the remaining plaintext of different lengths based on the new encryption function to obtain the ciphertext of the remaining plaintext;
[0064] (1-2-3) If the length of the remaining plaintext is less than or equal to 256, construct a new encryption function, and encrypt the remaining plaintext of different lengths based on the new encryption function to obtain the ciphertext of the remaining plaintext;
[0065] (1-2-4) If the length of the remaining plaintext is less than or equal to 512, construct a new encryption function, and encrypt the remaining plaintext of different lengths based on the new encryption function to obtain the ciphertext of the remaining plaintext;
[0066] (1-2-5) If the length of the remaining plaintext is greater than 512, construct a new encryption function, and encrypt the remaining plaintext of different lengths based on the new encryption function to obtain the ciphertext of the remaining plaintext.
[0067] Further, the (1-2-1) If the length of the remaining plaintext is less than or equal to 64, construct a new encryption function, and encrypt the remaining plaintext of different lengths based on the new encryption function to obtain the ciphertext of the remaining plaintext; includes:
[0068] (4-7) If , go to step (4-8), otherwise go to step (1-2-2);
[0069] (4-8) If , go to step (4-9), otherwise go to step (4-10);
[0070] (4-9) Copy the remaining bytes of the plaintext to , call the 4-way encryption function of Class 0 , and copy the bytes in to the output, and end;
[0071] (4-10) If , go to step (4-11), otherwise go to step (4-12);
[0072] (4-11) Copy the remaining bytes of the plaintext to , call the 4-way encryption function of Class 1 , and copy the bytes in to the output , and end;
[0073] (4-12) If , go to step (4-13), otherwise, go to step (4-14);
[0074] (4-13) Copy the remaining bytes of the plaintext to , call the 4-way encryption function of Class 2 , and copy the bytes in to the output , and end;
[0075] (4-14) Copy the remaining bytes of the plaintext to , call the 3-way encryption function of Class 0 , and copy the bytes in Copy the bytes to the output , end.
[0076] Further, for the (1-2-2), if the length of the remaining plaintext is less than or equal to 128, construct a new encryption function, and encrypt the remaining plaintext of different lengths based on the new encryption function to obtain the ciphertext of the remaining plaintext, including:
[0077] (4-15) If , go to step (4-16), otherwise go to step (1-2-3);
[0078] (4-16) If , go to step (4-17), otherwise go to step (4-18);
[0079] (4-17) Copy the remaining bytes of the plaintext to , call the 8-way encryption function of Class 0 , and copy the in bytes to the output , end;
[0080] (4-18) Copy the remaining bytes of the plaintext to , call the 8-way encryption function of Class 1 , and copy the in bytes to the output , end.
[0081] Further, for the (1-2-3), if the length of the remaining plaintext is less than or equal to 256, construct a new encryption function, and encrypt the remaining plaintext of different lengths based on the new encryption function to obtain the ciphertext of the remaining plaintext, including:
[0082] (4-19) If , then go to step (4-20), otherwise go to step (1-2-4);
[0083] (4-20) If , then go to step (4-21), otherwise go to step (4-22);
[0084] (4-21) Copy the remaining bytes of the plaintext to , call the 16-way encryption function of Class 0 , and copy the in bytes to the output , end;
[0085] (4-22) Copy the remaining bytes of the plaintext Copy the bytes to , and call the 16-way encryption function of Class 1 , and copy the bytes in to the output , and end.
[0086] Furthermore, if the length of the remaining plaintext is less than or equal to 512, construct a new encryption function, and encrypt the remaining plaintext of different lengths based on the new encryption function to obtain the ciphertext of the remaining plaintext, including:
[0087] (4-23) If , go to step (4-24), otherwise go to step (1-2-5);
[0088] (4-24) If , go to step (4-25), otherwise go to step (4-26);
[0089] (4-25) Copy the remaining bytes of the plaintext to , and call the 32-way encryption function of Class 0 , and copy the bytes in to the output , and end;
[0090] (4-26) If , go to step (4-27), otherwise go to step (4-28);
[0091] (4-27) Copy the remaining bytes of the plaintext to , and call the 32-way encryption function of Class 1 , and copy the bytes in to the output , and end;
[0092] (4-28) If , go to step (4-29), otherwise go to step (4-30);
[0093] (4-29) Copy the remaining bytes of the plaintext to , and call the 32-way encryption function of Class 2 , and copy the bytes in to the output , and end;
[0094] (4-30) Copy the remaining bytes of the plaintext to Call the 32-way encryption function of Class 3 , and copy the bytes in to the output , and end.
[0095] Furthermore, for the (1-2-5), if the length of the remaining plaintext is greater than 512, construct a new encryption function, and encrypt the remaining plaintext of different lengths based on the new encryption function to obtain the ciphertext of the remaining plaintext, including:
[0096] (4-31) If , go to step (4-32), otherwise go to step (4-33);
[0097] (4-32) Copy the remaining bytes of the plaintext to , call the 64-way encryption function of Class 0 , and copy the bytes in to the output , and end;
[0098] (4-33) If , go to step (4-34), otherwise go to step (4-35);
[0099] (4-34) Copy the remaining bytes of the plaintext to , call the 64-way encryption function of Class 1 , and copy the bytes in to the output , and end;
[0100] (4-35) If , go to step (4-36), otherwise go to step (4-37);
[0101] (4-36) Copy the remaining bytes of the plaintext to , call the 64-way encryption function of Class 2 , and copy the bytes in to the output , and end;
[0102] (4-37) If , go to step (4-38), otherwise go to step (4-39);
[0103] (4-38) Copy the remaining bytes of the plaintext to In it, call the 64-way encryption function of the third type , and copy the bytes in to the output , and end;
[0104] (4 - 39) If , go to step (4 - 40), otherwise go to step (4 - 41);
[0105] (4 - 40) Copy the remaining bytes of the plaintext to , call the 64-way encryption function of the fourth type , and copy the bytes in to the output , and end;
[0106] (4 - 41) If , go to step (4 - 42), otherwise go to step (4 - 43);
[0107] (4 - 42) Copy the remaining bytes of the plaintext to , call the 64-way encryption function of the fifth type , and copy the bytes in to the output , and end;
[0108] (4 - 43) If , go to step (4 - 44), otherwise go to step (4 - 45);
[0109] (4 - 44) Copy the remaining bytes of the plaintext to , call the 64-way encryption function of the sixth type , and copy the bytes in to the output , and end;
[0110] (4 - 45) Copy the remaining bytes of the plaintext to , call the 64-way encryption function of the seventh type , and copy the bytes in to the output , and end.
[0111] Furthermore, the core 64-way encryption function function has the following process:
[0112] The 512-bit register BlkA0 is filled with IV[0]; the 512-bit register BlkB0 is filled with IV[1]; the 512-bit register BlkIV0 is filled with IV[2]; the 512-bit register BlkIV1 is filled with IV[3];
[0113] After grouping BlkIV1 into 32-bit groups, it performs unsigned addition with the 512-bit register corresponding to IVTB2, and the result is saved to BlkIV1;
[0114] Let the serial number j = 0;
[0115] Step CTR64_core:
[0116] Let BlkD = BlkIV1;
[0117] After grouping BlkV1 into 32-bit groups, it performs unsigned addition with the 512-bit register corresponding to IVUpTBL+32, and the output is to BlkH;
[0118] After grouping BlkV1 into 32-bit groups, it performs unsigned addition with the 512-bit register corresponding to IVUpTBL+48, and the output is to BlkL;
[0119] After grouping BlkV1 into 32-bit groups, it performs unsigned addition with the 512-bit register corresponding to IVUpTBL+64, and the output is to BlkP;
[0120] After grouping BlkV1 into 32-bit groups, it performs unsigned addition with the 512-bit register corresponding to IVUpTBL+64, and the output is to BlkV1;
[0121] At this time, only 7 registers are used to save 64 IVs, which are respectively:
[0122] BlkA0, BlkB0, BlkIV0, BlkD, corresponding to the first 16 paths;
[0123] BlkA0, BlkB0, BlkIV0, BlkH, the 16th path - the 31st path;
[0124] BlkA0, BlkB0, BlkIV0, BlkL, the 32nd path - the 47th path;
[0125] BlkA0, BlkB0, BlkIV0, BlkP, the 48th path - the 63rd path;
[0126] After performing 32 rounds of parallel encryption round functions, the ciphertext of 64 IVs is output:
[0127] BlkA, BlkB, BlkC, BlkD correspond to the first 16 channels;
[0128] BlkE, BlkF, BlkG, BlkH, from the 16th channel to the 31st channel;
[0129] BlkI, BlkJ, BlkK, BlkL, from the 32nd channel to the 47th channel;
[0130] BlkM, BlkN, BlkO, BlkP, from the 48th channel to the 63rd channel;
[0131] The groups of registers are grouped into 16 blocks of 32 bits each and the BlkA block 0, BlkB block 0, BlkC block 0, BlkD block 0, BlkA block 1, BlkB block 1, BlkC block 1, BlkD block 1,..., BlkA block 15, BlkB block 15, BlkC block 15, BlkD block 15 are sequentially extracted and saved to the original registers, and then the 32-bit endian conversion is performed and converted to the standard order;
[0132] The 16 registers are sequentially XORed with the 512-bit data starting from the (k = 0, 1,... 15) position of the plaintext in and output to the 512-bit data starting from the (k = 0, 1,... 15) position of the ciphertext out;
[0133] The position of the plaintext is shifted backward by 1024; the position of the ciphertext is shifted backward by 1024;
[0134] j = j + 1024, if j < n, then go to step CTR64_core, otherwise end.
[0135] Furthermore, the function, function, function, function, function, function, function, The function is a single 64-channel encryption execution function, which has the same form, and its core is the same as The difference is in the output part, and its core steps are as follows:
[0136] The 512-bit register BlkA0 is filled with IV[0];
[0137] The 512-bit register BlkB0 is filled with IV[1];
[0138] The 512-bit register BlkIV0 is filled with IV[2];
[0139] The 512-bit register BlkIV1 is filled with IV[3];
[0140] BlkIV1 is grouped by 32 bits and performs an unsigned addition with the 512-bit register corresponding to IVTB2, and the result is saved to BlkD;
[0141] BlkD is grouped by 32 bits and performs an unsigned addition with the 512-bit register corresponding to IVUpTBL+32, and the output is sent to BlkH;
[0142] BlkD is grouped by 32 bits and performs an unsigned addition with the 512-bit register corresponding to IVUpTBL+48, and the output is sent to BlkL;
[0143] BlkD is grouped by 32 bits and performs an unsigned addition with the 512-bit register corresponding to IVUpTBL+64, and the output is sent to BlkP;
[0144] At this time, 7 registers store 64 IVs, which are respectively:
[0145] BlkA0, BlkB0, BlkIV0, BlkD, corresponding to the first 16 paths;
[0146] BlkA0, BlkB0, BlkIV0, BlkH, from the 16th path to the 31st path;
[0147] BlkA0, BlkB0, BlkIV0, BlkL, from the 32nd path to the 47th path;
[0148] BlkA0, BlkB0, BlkIV0, BlkP, from the 48th path to the 63rd path;
[0149] After performing 32 rounds of parallel encryption round functions, the ciphertext of 64 IVs is output:
[0150] BlkA, BlkB, BlkC, BlkD, corresponding to the first 16 paths;
[0151] BlkE, BlkF, BlkG, BlkH, from the 16th path to the 31st path;
[0152] BlkI, BlkJ, BlkK, BlkL, from the 32nd path to the 47th path;
[0153] BlkM, BlkN, BlkO, BlkP, from the 48th path to the 63rd path;
[0154] Group the BlkA, BlkB, BlkC, and BlkD registers into 32-bit chunks to form 16 blocks, and sequentially extract Block 0 of BlkA, Block 0 of BlkB, Block 0 of BlkC, Block 0 of BlkD, Block 1 of BlkA, Block 1 of BlkB, Block 1 of BlkC, Block 1 of BlkD,..., Block 15 of BlkA, Block 15 of BlkB, Block 15 of BlkC, Block 15 of BlkD, and save them to the original registers. Then, perform a 32-bit endian conversion to convert to the standard order.
[0155] BlkA is XORed with the 64-byte data starting from the 0th byte of the plaintext in and output to the 64 bytes starting from the 0th byte of the ciphertext out;
[0156] BlkB is XORed with the data at the 64th byte of the plaintext in and output to the 64 bytes starting from the 64th byte of the ciphertext out;
[0157] BlkC is XORed with the data at the 128th byte of the plaintext in and output to the 64 bytes starting from the 128th byte of the ciphertext out;
[0158] BlkD is XORed with the data at the 192nd byte of the plaintext in and output to the 64 bytes starting from the 192nd byte of the ciphertext out;
[0159] Group the BlkE, BlkF, BlkG, and BlkH registers into 32-bit chunks to form 16 blocks, and sequentially extract Block 0 of BlkA, Block 0 of BlkB, Block 0 of BlkC, Block 0 of BlkD, Block 1 of BlkA, Block 1 of BlkB, Block 1 of BlkC, Block 1 of BlkD,..., Block 15 of BlkA, Block 15 of BlkB, Block 15 of BlkC, Block 15 of BlkD, and save them to the original registers. Then, perform a 32-bit endian conversion to convert to the standard order.
[0160] BlkE is XORed with the 64-byte data starting from the 256th byte of the plaintext in and output to the 64 bytes starting from the 256th byte of the ciphertext out;
[0161] BlkF is XORed with the data at the 320th byte of the plaintext in and output to the 64 bytes starting from the 320th byte of the ciphertext out;
[0162] BlkG is XORed with the data at the 384th byte of the plaintext in and output to the 64 bytes starting from the 384th byte of the ciphertext out;
[0163] BlkH is XORed with the data at the 448th byte of the plaintext in and output to the 64 bytes starting from the 448th byte of the ciphertext out.
[0164] Further, the Output part:
[0165] The 32-bit registers BlkI, BlkJ, BlkK, and BlkL are grouped into 16 blocks. Then, the 0th block of BlkI, the 0th block of BlkJ, the 0th block of BlkK, the 0th block of BlkL, the 1st block of BlkI, the 1st block of BlkJ, the 1st block of BlkK, the 1st block of BlkL,..., the 3rd block of BlkI, the 3rd block of BlkJ, the 3rd block of BlkK, and the 3rd block of BlkL are sequentially extracted and saved to BlkI. After that, a 32-bit endian conversion is performed to convert to the standard order. BlkI is XORed with the 64-byte data in buf and then output to buf.
[0166] Furthermore, the Output part:
[0167] The 32-bit registers BlkI, BlkJ, BlkK, and BlkL are grouped into 16 blocks. Then, the 0th block of BlkI, the 0th block of BlkJ, the 0th block of BlkK, the 0th block of BlkL, the 1st block of BlkI, the 1st block of BlkJ, the 1st block of BlkK, the 1st block of BlkL,..., the 7th block of BlkI, the 7th block of BlkJ, the 7th block of BlkK, and the 7th block of BlkL are sequentially extracted and saved to BlkI and BlkJ. After that, a 32-bit endian conversion is performed to convert to the standard order. BlkI is XORed with the 64-byte data starting from the 512th byte in in and then output to the 64 bytes starting from the 512th byte in out. BlkJ is XORed with the 64-byte data in buf and then output to buf.
[0168] Furthermore, the , Output part:
[0169] The 32-bit registers BlkI, BlkJ, BlkK, and BlkL are grouped into 16 blocks. Then, the 0th block of BlkI, the 0th block of BlkJ, the 0th block of BlkK, the 0th block of BlkL, the 1st block of BlkI, the 1st block of BlkJ, the 1st block of BlkK, the 1st block of BlkL,..., the 11th block of BlkI, the 11th block of BlkJ, the 11th block of BlkK, and the 11th block of BlkL are sequentially extracted and saved to BlkI, BlkJ, and BlkK. After that, a 32-bit endian conversion is performed to convert to the standard order. BlkI is XORed with the 64-byte data starting from the 512th byte in in and then output to the 64 bytes starting from the 512th byte in out. BlkJ is XORed with the 64-byte data starting from the 576th byte in in and then output to the 64 bytes starting from the 576th byte in out. BlkK is XORed with the 64-byte data in buf and then output to buf.
[0170] Furthermore, the , Output part:
[0171] The 32-bit BlkI, BlkJ, BlkK, and BlkL registers are grouped into 16 blocks, and the 0th block of BlkI, the 0th block of BlkJ, the 0th block of BlkK, the 0th block of BlkL, the 1st block of BlkI, the 1st block of BlkJ, the 1st block of BlkK, the 1st block of BlkL,..., the 15th block of BlkI, the 15th block of BlkJ, the 15th block of BlkK, and the 15th block of BlkL are sequentially extracted and saved to BlkI, BlkJ, BlkK, and BlkL, and then a 32-bit endian conversion is performed and converted to the standard order. BlkI is XORed with the 64-byte data starting from the 512th byte in in and output to the 64-byte data starting from the 512th byte in out. BlkJ is XORed with the 64-byte data starting from the 576th byte in in and output to the 64-byte data starting from the 576th byte in out. BlkK is XORed with the 64-byte data starting from the 640th byte in in and output to the 64-byte data starting from the 640th byte in out. BlkL is XORed with the 64-byte data in buf and output to buf.
[0172] Furthermore, the function, , and have a common third set of data output function CTR64_4_Core:
[0173] The 32-bit BlkI, BlkJ, BlkK, and BlkL registers are grouped into 16 blocks, and the 0th block of BlkI, the 0th block of BlkJ, the 0th block of BlkK, the 0th block of BlkL, the 1st block of BlkI, the 1st block of BlkJ, the 1st block of BlkK, the 1st block of BlkL,..., the 15th block of BlkI, the 15th block of BlkJ, the 15th block of BlkK, and the 15th block of BlkL are sequentially extracted and saved to the original registers, and then a 32-bit endian conversion is performed and converted to the standard order.
[0174] BlkI is XORed with the 64-byte data starting from the 512th byte of the plaintext in and output to the 64-byte data starting from the 512th byte of the ciphertext out;
[0175] BlkJ is XORed with the 576th byte of the plaintext in and output to the 64-byte data starting from the 576th byte of the ciphertext out;
[0176] BlkK is XORed with the 640th byte of the plaintext in and output to the 64-byte data starting from the 640th byte of the ciphertext out;
[0177] BlkL is XORed with the 704th byte of the plaintext in and output to the 64-byte data starting from the 704th byte of the ciphertext out.
[0178] Further, the output part:
[0179] Execute CTR64_4_Core;
[0180] Group the BlkM, BlkN, BlkO, and BlkP registers into 32-bit groups of 16 blocks and sequentially extract block 0 of BlkM, block 0 of BlkN, block 0 of BlkO, block 0 of BlkP, block 1 of BlkM, block 1 of BlkN, block 1 of BlkO, block 1 of BlkP,..., block 3 of BlkM, block 3 of BlkN, block 3 of BlkO, block 3 of BlkP and save them to BlkM, then perform a 32-bit endian conversion and convert to the standard order. After XORing BlkM with the 64-byte data in buf, output it to buf.
[0181] Further, the output part of
[0182] Execute CTR64_4_Core;
[0183] Group the BlkM, BlkN, BlkO, and BlkP registers into 32-bit groups of 16 blocks and sequentially extract block 0 of BlkM, block 0 of BlkN, block 0 of BlkO, block 0 of BlkP, block 1 of BlkM, block 1 of BlkN, block 1 of BlkO, block 1 of BlkP,..., block 7 of BlkM, block 7 of BlkN, block 7 of BlkO, block 7 of BlkP and save them to BlkM and BlkN, then perform a 32-bit endian conversion and convert to the standard order.
[0184] After XORing BlkM with the 64-byte data starting from the 768th byte in in, output it to the 64 bytes starting from the 768th byte in out.
[0185] After XORing BlkN with the 64-byte data in buf, output it to buf.
[0186] Further, the , the output part includes:
[0187] Execute CTR64_4_Core;
[0188] Group the BlkM, BlkN, BlkO, and BlkP registers into 32-bit chunks to form 16 blocks, and sequentially extract block 0 of BlkM, block 0 of BlkN, block 0 of BlkO, block 0 of BlkP, block 1 of BlkM, block 1 of BlkN, block 1 of BlkO, block 1 of BlkP,..., block 11 of BlkM, block 11 of BlkN, block 11 of BlkO, block 11 of BlkP and save them to BlkM, BlkN, BlkO. Then perform a 32-bit endian conversion and convert to the standard order.
[0189] XOR the data in the 64 bytes starting from the 768th byte of in with BlkM and output the result to the 64 bytes starting from the 768th byte of out.
[0190] XOR the data in the 64 bytes starting from the 832nd byte of in with BlkN and output the result to the 64 bytes starting from the 832nd byte of out.
[0191] XOR the 64 bytes of data in buf with BlkO and output the result to buf.
[0192] Furthermore, the , includes:
[0193] Execute CTR64_4_Core;
[0194] Group the BlkM, BlkN, BlkO, and BlkP registers into 32-bit chunks to form 16 blocks, and sequentially extract block 0 of BlkM, block 0 of BlkN, block 0 of BlkO, block 0 of BlkP, block 1 of BlkM, block 1 of BlkN, block 1 of BlkO, block 1 of BlkP,..., block 15 of BlkM, block 15 of BlkN, block 15 of BlkO, block 15 of BlkP and save them to BlkM, BlkN, BlkO, BlkP. Then perform a 32-bit endian conversion and convert to the standard order.
[0195] XOR the data in the 64 bytes starting from the 768th byte of in with BlkM and output the result to the 64 bytes starting from the 768th byte of out.
[0196] XOR the data in the 64 bytes starting from the 832nd byte of in with BlkN and output the result to the 64 bytes starting from the 832nd byte of out.
[0197] XOR the data in the 64 bytes starting from the 896th byte of in with BlkO and output the result to the 64 bytes starting from the 896th byte of out.
[0198] XOR the 64 bytes of data in buf with BlkP and output the result to buf.
[0199] Furthermore, the encryption function , encryption function , encryption function , encryption function is a single 32-way encryption execution function. They have the same form, but the difference lies in the output part. The core steps are as follows:
[0200] The 512-bit register BlkA0 is filled with IV[0];
[0201] The 512-bit register BlkB0 is filled with IV[1];
[0202] The 512-bit register BlkIV0 is filled with IV[2];
[0203] The 512-bit register BlkD is filled with IV[3];
[0204] After BlkD is grouped by 32 bits, it performs an unsigned addition with the 512-bit register corresponding to IVTB2, and the result is saved to BlkD;
[0205] After BlkD is grouped by 32 bits, it performs an unsigned addition with the 512-bit register corresponding to IVUpTBL+32, and the output is sent to BlkH;
[0206] At this time, 5 registers store 32-way IVs, which are respectively:
[0207] BlkA0, BlkB0, BlkIV0, BlkD, corresponding to the first 16 ways;
[0208] BlkA0, BlkB0, BlkIV0, BlkH, from the 16th way to the 31st way;
[0209] After executing 32 rounds of parallel encryption round functions, the ciphertexts of 32-way IVs are output:
[0210] BlkA, BlkB, BlkC, BlkD, corresponding to the first 16 ways;
[0211] BlkE, BlkF, BlkG, BlkH, from the 16th way to the 31st way;
[0212] The BlkA, BlkB, BlkC, BlkD registers are grouped into 16 blocks by 32 bits, and then the 0th block of BlkA, the 0th block of BlkB, the 0th block of BlkC, the 0th block of BlkD, the 1st block of BlkA, the 1st block of BlkB, the 1st block of BlkC, the 1st block of BlkD,..., the 15th block of BlkA, the 15th block of BlkB, the 15th block of BlkC, the 15th block of BlkD are sequentially extracted and saved to the original registers, and then a 32-bit endian conversion is performed and converted to the standard order.
[0213] The data of 64 bytes starting from the 0th byte of BlkA is XORed with the plaintext in and output to the 64 bytes starting from the 0th byte of the ciphertext out;
[0214] The data of the 64th byte of BlkB is XORed with the plaintext in and output to the 64 bytes starting from the 64th byte of the ciphertext out;
[0215] The data of the 128th byte of BlkC is XORed with the plaintext in and output to the 64 bytes starting from the 128th byte of the ciphertext out;
[0216] The data of the 192nd byte of BlkD is XORed with the plaintext in and output to the 64 bytes starting from the 192nd byte of the ciphertext out.
[0217] Furthermore, the output part of the encryption function includes:
[0218] The BlkI, BlkJ, BlkK, and BlkL registers are grouped into 16 blocks of 32 bits each, and the 0th block of BlkI, the 0th block of BlkJ, the 0th block of BlkK, the 0th block of BlkL, the 1st block of BlkI, the 1st block of BlkJ, the 1st block of BlkK, the 1st block of BlkL,..., the 3rd block of BlkI, the 3rd block of BlkJ, the 3rd block of BlkK, the 3rd block of BlkL are sequentially extracted and saved to BlkI, and then a 32-bit endian conversion is performed and converted to the standard order. BlkI is XORed with the 64 bytes of data in buf and output to buf.
[0219] Furthermore, the output part of the encryption function includes:
[0220] The BlkI, BlkJ, BlkK, and BlkL registers are grouped into 16 blocks of 32 bits each, and the 0th block of BlkI, the 0th block of BlkJ, the 0th block of BlkK, the 0th block of BlkL, the 1st block of BlkI, the 1st block of BlkJ, the 1st block of BlkK, the 1st block of BlkL,..., the 7th block of BlkI, the 7th block of BlkJ, the 7th block of BlkK, the 7th block of BlkL are sequentially extracted and saved to BlkI and BlkJ, and then a 32-bit endian conversion is performed and converted to the standard order. BlkI is XORed with the 64 bytes of data starting from the 256th byte in in and output to the 64 bytes starting from the 256th byte of out. BlkJ is XORed with the 64 bytes of data in buf and output to buf.
[0221] Furthermore, the output part of the encryption function includes:
[0222] Group the BlkI, BlkJ, BlkK, and BlkL registers into 32-bit chunks to form 16 blocks, and sequentially extract block 0 of BlkI, block 0 of BlkJ, block 0 of BlkK, block 0 of BlkL, block 1 of BlkI, block 1 of BlkJ, block 1 of BlkK, block 1 of BlkL,..., block 11 of BlkI, block 11 of BlkJ, block 11 of BlkK, block 11 of BlkL. Save these blocks to BlkI, BlkJ, and BlkK, then perform a 32-bit endian conversion to convert to the standard order. XOR BlkI with the 64 bytes of data starting from the 256th byte in in and output the result to the 64 bytes starting from the 256th byte in out. XOR BlkJ with the 64 bytes of data starting from the 320th byte in in and output the result to the 64 bytes starting from the 320th byte in out. XOR BlkK with 64 bytes of data in buf and output the result to buf.
[0223] Further, the encryption function 's output part includes:
[0224] Group the BlkI, BlkJ, BlkK, and BlkL registers into 32-bit chunks to form 16 blocks, and sequentially extract block 0 of BlkI, block 0 of BlkJ, block 0 of BlkK, block 0 of BlkL, block 1 of BlkI, block 1 of BlkJ, block 1 of BlkK, block 1 of BlkL,..., block 15 of BlkI, block 15 of BlkJ, block 15 of BlkK, block 15 of BlkL. Save these blocks to BlkI, BlkJ, BlkK, and BlkL, then perform a 32-bit endian conversion to convert to the standard order. XOR BlkI with the 64 bytes of data starting from the 256th byte in in and output the result to the 64 bytes starting from the 256th byte in out. XOR BlkJ with the 64 bytes of data starting from the 320th byte in in and output the result to the 64 bytes starting from the 320th byte in out. XOR BlkK with the 384 bytes of data starting from the 640th byte in in and output the result to the 64 bytes starting from the 384th byte in out. XOR BlkL with 64 bytes of data in buf and output the result to buf.
[0225] Further, the encryption function and the encryption function are single-time 16-way encryption execution functions. They have the same form, with the difference in the output part. The core steps are as follows:
[0226] Fill the 512-bit register BlkA0 with IV[0];
[0227] Fill the 512-bit register BlkB0 with IV[1];
[0228] The 512-bit register BlkIV0 is filled with IV[2];
[0229] The 512-bit register BlkIV1 is filled with IV[3];
[0230] BlkIV1 is grouped into 32-bit chunks and performs unsigned addition with the 512-bit register corresponding to IVTB2, and the result is saved to BlkIV1;
[0231] At this time, 4 registers store 16 IVs, which are respectively:
[0232] BlkA0, BlkB0, BlkIV0, BlkIV1;
[0233] After executing 32 rounds of parallel encryption round functions, the ciphertexts of 16 IVs are output:
[0234] BlkA, BlkB, BlkC, BlkD;
[0235] The registers BlkA, BlkB, BlkC, and BlkD are grouped into 32-bit chunks to form 16 blocks, and the 0th block of BlkA, the 0th block of BlkB, the 0th block of BlkC, the 0th block of BlkD, the 1st block of BlkA, the 1st block of BlkB, the 1st block of BlkC, the 1st block of BlkD,..., the 15th block of BlkA, the 15th block of BlkB, the 15th block of BlkC, and the 15th block of BlkD are sequentially extracted and saved to the original registers, and then the 32-bit endian conversion is performed and converted to the standard order.
[0236] Furthermore, the output part of the encryption function includes:
[0237] BlkA is XORed with the 64-byte data starting from the 0th byte in in and output to the 64-byte data starting from the 0th byte in out. BlkB is XORed with the 64-byte data starting from the 64th byte in in and output to the 64-byte data starting from the 64th byte in out. BlkC is XORed with the 64 bytes in buf and output to buf
[0238] Furthermore, the output part of the encryption function includes:
[0239] The 64 - byte data starting from the 0th byte in BlkA is XORed with the data in in and then output to the 64 - byte area starting from the 0th byte in out. The 64 - byte data starting from the 64th byte in BlkB is XORed with the data in in and then output to the 64 - byte area starting from the 64th byte in out. The 64 - byte data starting from the 128th byte in BlkC is XORed with the data in in and then output to the 64 - byte area starting from the 128th byte in out. The 64 - byte data in BlkD is XORed with the 64 - byte data in buf and then output to buf.
[0240] Further, the encryption function and the encryption function are single - time 8 - way encryption execution functions. They have the same form, and the difference lies in the output part. The core steps are as follows:
[0241] The 256 - bit register blkA0 is filled with IV[0];
[0242] The 256 - bit register blkB0 is filled with IV[1];
[0243] The 256 - bit register blkIV0 is filled with IV[2];
[0244] The 256 - bit register blkIV1 is filled with IV[3];
[0245] blkIV1 is grouped by 32 bits and performs unsigned addition with the corresponding 256 - bit register in IVTB1, and the result is saved to blkIV1;
[0246] At this time, 4 registers store 8 - way IVs, which are respectively:
[0247] blkA0, blkB0, blkIV0, blkIV1;
[0248] After executing 32 rounds of parallel encryption round functions, the ciphertexts of the 8 - way IVs are output:
[0249] blkA, blkB, blkC, blkD;
[0250] The registers blkA, blkB, blkC, and blkD are grouped by 32 bits into 8 blocks, and then the 0th block of blkA, the 0th block of blkB, the 0th block of blkC, the 0th block of blkD, the 1st block of blkA, the 1st block of blkB, the 1st block of blkC, the 1st block of blkD,..., the 7th block of blkA, the 7th block of blkB, the 7th block of blkC, the 7th block of blkD are sequentially extracted and saved to the original registers, and then a 32 - bit endian conversion is performed to convert to the standard order.
[0251] Further, the encryption function The output part includes:
[0252] The 32 bytes of data starting from the 0th byte in blkA are XORed with the 32 bytes of data in in and then output to the 32 bytes starting from the 0th byte in out. The 32 bytes of data starting from the 32nd byte in blkB are XORed with the 32 bytes of data in in and then output to the 32 bytes starting from the 32nd byte in out. The 32 bytes in blkC are XORed with the 32 bytes in buf and then output to buf.
[0253] Furthermore, the encryption function The output part includes:
[0254] The 32 bytes of data starting from the 0th byte in blkA are XORed with the 32 bytes of data in in and then output to the 32 bytes starting from the 0th byte in out;
[0255] The 32 bytes of data starting from the 2nd byte in blkB are XORed with the 32 bytes of data in in and then output to the 32 bytes starting from the 32nd byte in out;
[0256] The 32 bytes of data starting from the 64th byte in blkC are XORed with the 32 bytes of data in in and then output to the 32 bytes starting from the 64th byte in out;
[0257] The 32 bytes in blkD are XORed with the 32 bytes in buf and then output to buf.
[0258] Furthermore, the encryption function the encryption function the 4-way encryption function and the encryption function are all single-time 4-way encryption execution functions. They have the same form, and the difference lies in the output part. The core steps are as follows:
[0259] The 128-bit register blka0 is filled with IV[0];
[0260] The 128-bit register blkb0 is filled with IV[1];
[0261] The 128-bit register blkiv0 is filled with IV[2];
[0262] The 128-bit register blkiv1 is filled with IV[3];
[0263] blkiv1 is grouped by 32 bits and then performs unsigned addition with the 128-bit register corresponding to IVTB0, and the result is saved to blkiv1;
[0264] At this time, the 4 registers store 4-way IVs, which are respectively:
[0265] blka0, blkb0, blkiv0, blkiv1;
[0266] After executing the parallel encryption round function 32 times, the ciphertexts of 4 IVs are output:
[0267] blka, blkb, blkc, blkd.
[0268] Furthermore, the output part of the encryption function includes:
[0269] The 32-bit registers blka, blkb, blkc, and blkd are grouped into 4 blocks, and the 0th block of blka, the 0th block of blkb, the 0th block of blkc, and the 0th block of blkd are sequentially extracted and blka is saved, and then after performing a 32-bit endian conversion, it is converted to the standard order.
[0270] The result of XORing blka with 32 bytes in buf is output to buf.
[0271] Furthermore, the encryption function includes:
[0272] The 32-bit registers blka, blkb, blkc, and blkd are grouped into 4 blocks, and the 0th block of blka, the 0th block of blkb, the 0th block of blkc, the 0th block of blkd, the 1st block of blka, the 1st block of blkb, the 1st block of blkc, and the 1st block of blkd are sequentially extracted and saved to blka and blkb;
[0273] The result of XORing blka with 16 bytes of data starting from the 0th byte in in is output to the 16 bytes starting from the 0th byte in out. The result of XORing blkb with 16 bytes in buf is output to buf.
[0274] Furthermore, the output part of the encryption function includes:
[0275] The 32-bit registers blka, blkb, blkc, and blkd are grouped into 4 blocks, and the 0th block of blka, the 0th block of blkb, the 0th block of blkc, the 0th block of blkd, the 1st block of blka, the 1st block of blkb, the 1st block of blkc, the 1st block of blkd, the 2nd block of blka, the 2nd block of blkb, the 2nd block of blkc, and the 2nd block of blkd are sequentially extracted and saved to blka, blkb, and blkc;
[0276] The 16 - byte data starting from the 0th byte in blka is XORed with the 16 - byte data starting from the 0th byte in in and then output to the 16 - byte data starting from the 0th byte in out. The 16 - byte data starting from the 32nd byte in blkb is XORed with the 16 - byte data starting from the 32nd byte in in and then output to the 16 - byte data starting from the 32nd byte in out. The 16 - byte data in blkc is XORed with the 16 - byte data in buf and then output to buf.
[0277] Further, the encryption function The output part of
[0278] The blka, blkb, blkc, and blkd registers are grouped into 4 blocks of 32 bits each, and the 0th block of blka, the 0th block of blkb, the 0th block of blkc, the 0th block of blkd, the 1st block of blka, the 1st block of blkb, the 1st block of blkc, the 1st block of blkd, the 2nd block of blka, the 2nd block of blkb, the 2nd block of blkc, the 2nd block of blkd, the 3rd block of blka, the 3rd block of blkb, the 3rd block of blkc, and the 3rd block of blkd are sequentially extracted and saved to blka, blkb, blkc, and blkd.
[0279] After blka is XORed with the 16 - byte data starting from the 0th byte in in, it is output to the 16 - byte data starting from the 0th byte in out. After blkb is XORed with the 16 - byte data starting from the 32nd byte in in, it is output to the 16 - byte data starting from the 32nd byte in out. After blkc is XORed with the 16 - byte data starting from the 48th byte in in, it is output to the 16 - byte data starting from the 48th byte in out. After blkd is XORed with the 16 - byte data in buf, it is output to buf.
[0280] Embodiment 2
[0281] This embodiment provides a data fast - encryption system based on the national cryptographic algorithm, including: an encryption module, which is configured to: obtain the plaintext, and use the counter mode of the national cryptographic algorithm SM4 to perform encryption processing on the plaintext to obtain the ciphertext;
[0282] Among them, the encryption process of the counter mode of the national cryptographic algorithm SM4 is accelerated in the following way:
[0283] (1 - 1) Reconstruct the encryption function. Through the reconstructed encryption function, encrypt the message to be encrypted to obtain the encrypted partial ciphertext and the remaining plaintext;
[0284] (1 - 2) Based on the different lengths of the remaining plaintext, construct a new encryption function, and encrypt the remaining plaintext of different lengths based on the new encryption function to obtain the ciphertext of the remaining plaintext.
[0285] The above are only the preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.
Claims
1. A fast data encryption method based on a national secret algorithm, characterized in that: include: Obtain the plaintext, and use the counter mode of the national encryption algorithm SM4 to encrypt the plaintext to obtain the ciphertext; Among them, the encryption process of the counter mode of the national secret algorithm SM4 is accelerated by the following methods: reconstructing the encryption function, encrypting the message to be encrypted by the reconstructed encryption function to obtain the encrypted partial ciphertext and the remaining plaintext; constructing a new encryption function based on the different lengths of the remaining plaintext, encrypting the remaining plaintext of different lengths based on the new encryption function, and obtaining the ciphertext of the remaining plaintext; The encryption function is reconstructed, and the message to be encrypted is encrypted by the reconstructed encryption function to obtain the encrypted partial ciphertext and the remaining plaintext; the previous step also includes: Constructing precomputed tables for 128-bit SIMD register Counter updates ; Build pre-computed table for 256-bit SIMD register Counter update ; Build pre-computed table for 512-bit SIMD register Counter update ; Data width is 32 bits: ; ; ; Construct the pre-calculated table IVUpTBL for the encryption process IV update, with a data width of 32 bits: IVUpTBL[96]= {4,4,4,4, 4,4,4,4, 4,4,4,4, 4,4,4,4, 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8, 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16, 32,32,32,32, 32,32,32,32, 32,32,32,32, 32,32,32,32, 48,48,48,48, 48,48,48,48, 48,48,48,48, 48,48,48,48, 64,64,64,64, 64,64,64,64, 64,64,64,64, 64,64,64,64}; The reconstructing the encryption function and encrypting the initial vector by the reconstructed encryption function to obtain the ciphertext of the initial vector and the remaining plaintext include: (4-1) Create a 64-bit temporary data storage array ; (4-2) Press Algorithm standard for master key Execute the round key expansion function to generate the round key ; (4-3) Initial vector array After converting to 32-bit big-endian, store it in a 32-bit width array middle; (4-4) , then go to step (4-5), otherwise go to step (4-7); (4-5) Call the core 64-way encryption function Function, set the current data position ; Go to step (4-6); wherein, Indicates the output ciphertext, represents the round key, Represents the input message, represents the initial vector, Indicates the message length, Indicates the remainder; (4-6) Let the remaining plaintext length be ,if is 0, end; if If not 0, go to (4-7); (4-7) , go to step (4-8), otherwise go to step (4-15); (4-8) , go to step (4-9), otherwise go to step (4-10); (4-9) The remaining plaintext Bytes copied to In the 4-way encryption function of type 0, ,Will In Bytes are copied to output, end; (4-10) , go to step (4-11), otherwise go to step (4-12); (4-11) The remaining plaintext Bytes copied to In the code, call the first type of 4-way encryption function ,Will In Bytes copied to output ,Finish; (4-12) , go to step (4-13), otherwise, go to step (4-14); (4-13) The remaining plaintext Bytes copied to In the second type of 4-way encryption function, call ,Will In Bytes copied to output ,Finish; (4-14) The remaining plaintext Bytes copied to In the code, call the 3-way encryption function of type 0 ,Will In Bytes copied to output ,Finish; (4-15) If , go to step (4-16), otherwise go to step (4-19); (4-16) If , go to step (4-17), otherwise go to step (4-18); (4-17) The remaining plaintext Bytes copied to In the code, call the 8-way encryption function of type 0 ,Will In Bytes copied to output ,Finish; (4-18) The remaining plaintext Bytes copied to In the code, call the first type of 8-way encryption function ,Will In Bytes copied to output ,Finish; (4-19) If , then go to step (4-20), otherwise go to step (4-23); (4-20) If , then go to step (4-21), otherwise go to step (4-22); (4-21) The remaining Bytes copied to In the 16-way encryption function of type 0, ,Will In Bytes copied to output ,Finish; (4-22) The remaining plaintext Bytes copied to In the code, call the first type 16-way encryption function ,Will In Bytes copied to output ,Finish; (4-23) If , go to step (4-24), otherwise go to step (4-31); (4-24) If , go to step (4-25), otherwise go to step (4-26); (4-25) The remaining plaintext Bytes copied to In the 32-way encryption function of type 0, ,Will In Bytes copied to output ,Finish; (4-26) If , go to step (4-27), otherwise go to step (4-28); (4-27) The remaining plaintext Bytes copied to In the code, call the first type 32-way encryption function ,Will In Bytes copied to output ,Finish; (4-28) If , go to step (4-29), otherwise go to step (4-30); (4-29) The remaining plaintext Bytes copied to In the second class, 32-way encryption function is called ,Will In Bytes copied to output ,Finish; (4-30) The remaining plaintext Bytes copied to In the third category, 32-way encryption function is called ,Will In Bytes copied to output ,Finish; (4-31) If , go to step (4-32), otherwise go to step (4-33); (4-32) The remaining plaintext Bytes copied to In the 64-way encryption function of type 0, ,Will In Bytes copied to output ,Finish; (4-33) , go to step (4-34), otherwise go to step (4-35); (4-34) The remaining plaintext Bytes copied to In the code, call the first type of 64-way encryption function ,Will In Bytes copied to output ,Finish; (4-35) , go to step (4-36), otherwise go to step (4-37); (4-36) The remaining plaintext Bytes copied to In the second type, 64-way encryption function is called ,Will In Bytes copied to output ,Finish; (4-37) , go to step (4-38), otherwise go to step (4-39); (4-38) The remaining plaintext Bytes copied to In the 3rd type 64-way encryption function, call ,Will In Bytes copied to output ,Finish; (4-39) , go to step (4-40), otherwise go to step (4-41); (4-40) The remaining plaintext Bytes copied to In the 4th category, 64-way encryption function is called ,Will In Bytes copied to output ,Finish; (4-41) , go to step (4-42), otherwise go to step (4-43); (4-42) The remaining plaintext Bytes copied to In the 5th category, 64-way encryption function is called ,Will In Bytes copied to output ,Finish; (4-43) , go to step (4-44), otherwise go to step (4-45); (4-44) The remaining plaintext Bytes copied to In the 64-way encryption function of the sixth category, ,Will In Bytes copied to output ,Finish; (4-45) The remaining plaintext Bytes copied to In the 64-way encryption function of the seventh category, ,Will In Bytes copied to output ,Finish.
2. The method for fast data encryption based on the national secret algorithm as claimed in claim 1 is characterized in that: Said function, function, function, function, function, function, function, The function is a single 64-way encryption execution function, its form is the same, its core is the same as The difference lies in the output part. The core steps are as follows: 512-bit register BlkA0 is filled with IV[0]; 512-bit register BlkB0 is filled with IV[1]; The 512-bit register BlkIV0 is filled with IV[2]; The 512-bit register BlkIV1 is filled with IV[3]; BlkIV1 performs unsigned addition on the 512-bit register corresponding to IVTB2 after grouping by 32 bits, and the result is saved in BlkD; BlkD performs unsigned addition on the 512-bit register corresponding to IVUpTBL+32 after grouping by 32 bits, and outputs it to BlkH; BlkD performs unsigned addition on the 512-bit register corresponding to IVUpTBL+48 after grouping by 32 bits, and outputs it to BlkL; BlkD performs unsigned addition on the 512-bit register corresponding to IVUpTBL+64 after grouping by 32 bits, and outputs it to BlkP; At this time, 7 registers save 64 IVs, which are: BlkA0, BlkB0, BlkIV0, BlkD, corresponding to the first 16 paths; BlkA0, BlkB0, BlkIV0, BlkH, 16th to 31st roads; BlkA0, BlkB0, BlkIV0, BlkL, 32nd to 47th Road; BlkA0, BlkB0, BlkIV0, BlkP, 48th to 63rd roads; After executing 32 rounds of parallel encryption round functions, the ciphertext of 64 IVs is output: BlkA, BlkB, BlkC, BlkD, corresponding to the first 16 paths; BlkE, BlkF, BlkG, BlkH, 16th-31st Roads; BlkI, BlkJ, BlkK, BlkL, 32nd to 47th Roads; BlkM, BlkN, BlkO, BlkP, 48th-63rd Road; Group the BlkA, BlkB, BlkC, BlkD registers into 16 blocks by 32 bits and extract BlkA block 0, BlkB block 0, BlkC block 0, BlkD block 0, BlkA block 1, BlkB block 1, BlkC block 1, BlkD block 1, ..., BlkA block 15, BlkB block 15, BlkC block 15, BlkD block 15 in sequence and save them to the original registers, then perform 32-bit big-endian conversion and convert them to standard order; BlkA is XORed with the 64 bytes of plaintext in starting with byte 0 and then output to the 64 bytes of ciphertext out starting with byte 0; BlkB is XORed with the 64th byte of the plaintext in and output to the 64 bytes starting from the 64th byte of the ciphertext out; BlkC is XORed with the 128th byte of the plaintext in and output to the 64 bytes starting from the 128th byte of the ciphertext out; BlkD is XORed with the 192th byte of the plaintext in and output to the 64 bytes starting from the 192th byte of the ciphertext out; Group the BlkE, BlkF, BlkG, and BlkH registers into 16 blocks of 32 bits and extract BlkA block 0, BlkB block 0, BlkC block 0, BlkD block 0, BlkA block 1, BlkB block 1, BlkC block 1, BlkD block 1, ..., BlkA block 15, BlkB block 15, BlkC block 15, and BlkD block 15 in sequence and save them to the original registers, then perform 32-bit endian conversion and convert them to standard order; BlkE is XORed with the 64 bytes starting from the 256th byte of the plaintext in and then output to the 64 bytes starting from the 256th byte of the ciphertext out; BlkF is XORed with the 320th byte of the plaintext in and output to the 64 bytes starting from the 320th byte of the ciphertext out; BlkG is XORed with the 384th byte of the plaintext in and output to the 64 bytes starting from the 384th byte of the ciphertext out; BlkH is XORed with the 448th byte of the plaintext in and output to the 64 bytes starting from the 448th byte of the ciphertext out.
3. The data fast encryption method based on the national secret algorithm as claimed in claim 1 is characterized in that: The encryption function , encryption function , encryption function , encryption function It is a single 32-way encryption execution function. Its form is the same, the difference is in the output part. Its core steps are as follows: 512-bit register BlkA0 is filled with IV[0]; 512-bit register BlkB0 is filled with IV[1]; The 512-bit register BlkIV0 is filled with IV[2]; The 512-bit register BlkD is filled with IV[3]; BlkD performs unsigned addition on the 512-bit register corresponding to IVTB2 after grouping by 32 bits, and saves the result to BlkD; BlkD performs unsigned addition on the 512-bit register corresponding to IVUpTBL+32 after grouping by 32 bits, and outputs it to BlkH; At this time, 5 registers save 32 IVs, which are: BlkA0, BlkB0, BlkIV0, BlkD, corresponding to the first 16 channels; BlkA0, BlkB0, BlkIV0, BlkH, 16th to 31st roads; After executing 32 rounds of parallel encryption round functions, the ciphertext of 32 IVs is output: BlkA, BlkB, BlkC, BlkD, corresponding to the first 16 paths; BlkE, BlkF, BlkG, BlkH, 16th-31st Roads; Group the BlkA, BlkB, BlkC, BlkD registers into 16 blocks by 32 bits and extract BlkA block 0, BlkB block 0, BlkC block 0, BlkD block 0, BlkA block 1, BlkB block 1, BlkC block 1, BlkD block 1, ..., BlkA block 15, BlkB block 15, BlkC block 15, BlkD block 15 in sequence and save them to the original registers, then perform 32-bit big-endian conversion and convert them to standard order; BlkA is XORed with the 64 bytes of plaintext in starting with byte 0 and then output to the 64 bytes of ciphertext out starting with byte 0; BlkB is XORed with the 64th byte of the plaintext in and output to the 64 bytes starting from the 64th byte of the ciphertext out; BlkC is XORed with the 128th byte of the plaintext in and output to the 64 bytes starting from the 128th byte of the ciphertext out; BlkD is XORed with the 192th byte of the plaintext in and output to the 64 bytes starting from the 192th byte of the ciphertext out.
4. A data fast encryption system based on a national secret algorithm using the data fast encryption method based on a national secret algorithm as claimed in claim 1, characterized in that: include: The encryption module is configured to: obtain plain text, and use the counter mode of the national encryption algorithm SM4 to encrypt the plain text to obtain cipher text; Among them, the encryption process of the counter mode of the national secret algorithm SM4 is accelerated in the following way: the encryption function is reconstructed, and the encrypted message is encrypting the reconstructed encryption function to obtain the encrypted partial ciphertext and the remaining plaintext; based on the different lengths of the remaining plaintext, a new encryption function is constructed, and the remaining plaintexts of different lengths are encrypted based on the new encryption function to obtain the ciphertext of the remaining plaintext.
Citation Information
Patent Citations
Block encryption method and system and block decryption method
CN108063760A
Lightweight encryption method capable of accepting any plaintext length
CN114513298A