Rapid data encryption method and system based on national cryptographic algorithm

By reconstructing the counter mode encryption function of the Guomi algorithm SM4 and building a new encryption function, the performance degradation caused by the high computational complexity of the SM4 algorithm during the encryption process is solved, and the encryption speed is significantly improved and memory usage is achieved. reduce.

CN119483913AActive Publication Date: 2025-02-18SHANDONG UNIV

Patent Information

Application Number
CN202510040308.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-10
Publication Date
2025-02-18
Estimated Expiration
2045-01-10

AI Technical Summary

Technical Problem

In the encryption process, the calculation complexity of the Guomin algorithm SM4 is high, resulting in slow computing speed and occupies computer memory, affecting the speed of encryption and decryption, especially when processing data with integer multiples of the packet length is degraded.

Method used

By reconstructing the counter mode encryption function of the Guomi algorithm SM4, it is divided into two parts: first, the reconstructed encryption function is used to encrypt the encrypted message to obtain the encrypted part of the encrypted ciphertext and the remaining plaintext; then according to the remaining plaintext The new encryption function is constructed to encrypt the remaining plaintext of different lengths to obtain the ciphertext of the remaining plaintext.

Benefits of technology

Reconstructing the encryption function reduces the computational complexity, greatly improves the speed of the SM4 encryption process, achieves higher efficiency and less memory footprint, and ensures encryption security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119483913A_ABST
    Figure CN119483913A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of data encryption, in particular to a rapid data encryption method and system based on a national cryptographic algorithm, and the method comprises the steps: obtaining a plaintext, and employing a counter mode of the national cryptographic algorithm SM4 to carry out encryption processing on the plaintext to obtain a ciphertext; wherein the encryption process of the counter mode of the national cryptographic algorithm SM4 is accelerated by adopting the following mode: reconstructing an encryption function, and encrypting a message to be encrypted through the reconstructed encryption function to obtain an encrypted partial ciphertext and a residual plaintext; and constructing a new encryption function based on different lengths of the residual plaintexts, and encrypting the residual plaintexts with different lengths based on the new encryption function to obtain ciphertexts of the residual plaintexts. The SM4 encryption method has the advantages of being universal, small in memory occupation, high in efficiency, safe in implementation and the like.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data encryption, and in particular to a method and system for fast data encryption based on a national secret algorithm. Background Art

[0002] SM4 (formerly known as SMS4) is a block cipher standard with a data block length of 128 bits and a key block length of 128 bits. The encryption algorithm and key expansion algorithm use a 32-round iteration structure and process data in units of words (32 bits). The SM4 algorithm is widely used in finance, e-commerce and other fields for encryption of various data.

[0003] CTR (counter) mode generates a key stream by encrypting a counter that accumulates successively. The plaintext is XORed with the key stream byte by byte to obtain the ciphertext, and the encryption and decryption functions are the same. Because multiple data blocks can be processed in parallel, it is widely used in real-time encryption of large amounts of data, such as real-time audio and video stream encryption and cloud storage file encryption storage.

[0004] The plaintext of CTR (counter) mode is known and independent of each other, so the Single Data Multiple Instruction (SIMD) extended instruction set can be used to simultaneously perform encryption of multiple groups of data to improve the encryption speed. Currently, methods such as AESNI, Tower Domain and GFNI have been applied to SM4 encryption.

[0005] However, since parallel computing requires regrouping of multiple groups of data, commonly used groups are 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 group length.

[0006] In addition, existing technologies usually focus on the optimization of encryption core functions. The CTR mode needs to XOR with the plaintext to obtain the ciphertext after the core encryption is completed, resulting in the performance of the CTR mode being worse than that of modes such as ECB (electronic code book). In the process of encryption tasks, because the national encryption algorithm SM4 has high computational complexity and slow operation speed, it occupies computer memory and affects the speed of encryption and decryption. Summary of the invention

[0007] In order to solve the deficiencies of the prior art, the present invention provides a method and system for fast data encryption based on a national secret algorithm, thereby improving the speed of data encryption.

[0008] On the one hand, a data fast encryption method based on a national secret algorithm is provided, including: obtaining plain text, using a counter mode of the national secret algorithm SM4, encrypting the plain text to obtain a 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.

[0009] On the other hand, a data fast encryption system based on a national secret algorithm is provided, including: an encryption module, which is configured to: obtain plain text, adopt a counter mode of the national secret algorithm SM4, and encrypt the plain text to obtain a 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.

[0010] The above technical solution has the following advantages or beneficial effects: The counter mode of the national secret algorithm SM4 is used to encrypt the plaintext to obtain the ciphertext; wherein, the encryption process of the counter mode of the national secret algorithm SM4 is accelerated in the following manner: the encryption function is reconstructed, and the encrypted message is encrypted by 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. Compared with the previous technology, the method of the present invention reduces the computational complexity by reconstructing the encryption function, greatly improves the speed of the SM4 encryption process, and has the advantages of generality, low memory usage, high efficiency, and security. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] The accompanying drawings in the specification, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.

[0012] Figure 1 This is a flow chart of the method of embodiment 1. DETAILED DESCRIPTION

[0013] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present invention belongs.

[0014] Embodiment 1 like Figure 1 As shown, this embodiment provides a data fast encryption method based on the national secret algorithm, including: obtaining plain text, using the counter mode of the national secret algorithm SM4, encrypting 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: (1-1) Reconstruct the encryption function, and encrypt the message to be encrypted using the reconstructed encryption function to obtain the encrypted partial ciphertext and the remaining plaintext; (1-2) Based on the different lengths of the remaining plaintext, a new encryption function is constructed, and the remaining plaintexts of different lengths are encrypte...

[0015] Furthermore, the counter mode of the national encryption algorithm SM4 includes the following processing steps: (2-1): Change the length to Bytes of plaintext , group by 16-byte rows and get the grouping result (Set serial number ; ), such as the plaintext remainder Bytes, set to ; (2-2): Combine the 96-bit one-time random number Nonce and the 32-bit counter Counter into a 128-bit initialization vector ; (2-3) For the initial vector , call the encryption function Encrypt and obtain the intermediate parameters ; (2-4) If the remaining plaintext length , then XOR The output is ciphertext , otherwise take forward Byte XOR After that, output the ciphertext ; (2-5) , ; (2-6) If , go to step (2-2), otherwise go to step (2-7); (2-7) The end.

[0016] Furthermore, the encryption function ,include: (3-1) Input 128-bit plaintext , the plaintext Decomposed into 4 words , enter 32 round keys , , output 4 words 128-bit ciphertext; (3-2) For each input word Executes endian conversion function .

[0017] ; ; ; ; (3-3) Command To 32, execute 32 round functions ; ; Will Split into 4 bytes ; ; ; in, Represents the exclusive OR operation; (3-4) Output ciphertext : ; ; ; ; ; Indicates a connection.

[0018] Furthermore, the (1-1) reconstructs the encryption function, and encrypts the message to be encrypted by the reconstructed encryption function to obtain the encrypted partial ciphertext and the remaining plaintext; and the above also includes: (1-0) Construct a pre-computed table for updating the 128-bit SIMD register Counter ; 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,16, 32,32,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,48,48, 64,64,64,64, 64,64,64,64, 64,64,64,64, 64,64,64,64,64}.

[0019] Furthermore, the (1-1) reconstructs the encryption function, and uses the reconstructed encryption function to encrypt the initial vector to obtain the ciphertext of the initial vector and the remaining plaintext, including: (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-6), 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.

[0020] (4-6) Let the remaining plaintext length be ,if is 0, end. If it is not 0, go to (1-2).

[0021] Furthermore, the (1-2) constructs a new encryption function based on the different lengths of the remaining plaintexts, and encrypts the remaining plaintexts of different lengths based on the new encryption function to obtain the ciphertext of the remaining plaintext, including: (1-2-1) If the length of the remaining plaintext is less than or equal to 64, construct a new encryption function, encrypt the remaining plaintexts of different lengths based on the new encryption function, and obtain the ciphertext of the remaining plaintext; (1-2-2) If the length of the remaining plaintext is less than or equal to 128, 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; (1-2-3) If the length of the remaining plaintext is less than or equal to 256, 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; (1-2-4) If the length of the remaining plaintext is less than or equal to 512, 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; (1-2-5) If the length of the remaining plaintext is greater than 512, 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.

[0022] Furthermore, if the length of the remaining plaintext is less than or equal to 64, then construct a new encryption function, encrypt the remaining plaintexts of different lengths based on the new encryption function, and obtain the ciphertext of the remaining plaintext; including: (4-7) , go to step (4-8), otherwise go to step (1-2-2); (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.

[0023] Furthermore, in (1-2-2), if the length of the remaining plaintext is less than or equal to 128, 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, including: (4-15) If , go to step (4-16), otherwise go to step (1-2-3); (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.

[0024] Furthermore, in (1-2-3), if the length of the remaining plaintext is less than or equal to 256, 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, including: (4-19) If , then go to step (4-20), otherwise go to step (1-2-4); (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.

[0025] Furthermore, in (1-2-4), if the length of the remaining plaintext is less than or equal to 512, 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, including: (4-23) If , go to step (4-24), otherwise go to step (1-2-5); (4-24) If , go to step (4-25), otherwise go to step (4-26); (4-25) The remaining plaintext Bytes copied to In the code, call 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.

[0026] Furthermore, in (1-2-5), if the length of the remaining plaintext is greater than 512, 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, including: (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.

[0027] Furthermore, the core 64-way encryption function Function, the process is as follows: 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]; BlkIV1 performs unsigned addition on the 512-bit register corresponding to IVTB2 after grouping by 32 bits, and saves the result to BlkIV1; Let serial number j = 0; Steps CTR64_core: Let BlkD = BlkIV1; After BlkV1 is grouped into 32 bits, unsigned addition is performed on the 512-bit register corresponding to IVUpTBL+32 and output to BlkH; BlkV1 performs unsigned addition on the 512-bit register corresponding to IVUpTBL+48 after grouping by 32 bits, and outputs it to BlkL; BlkV1 performs unsigned addition on the 512-bit register corresponding to IVUpTBL+64 after grouping by 32 bits, and outputs it to BlkP; After BlkV1 is grouped into 32 bits, unsigned addition is performed on the 512-bit register corresponding to IVUpTBL+64 and the output is to BlkV1; At this time, only 7 registers are used to save 64 IVs, which are: BlkA0, BlkB0, BlkIV0, BlkD, corresponding to the first 16 channels; 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; The registers in each group are grouped into 16 blocks of 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, and the 15th block of BlkD are sequentially extracted and saved to the original register, and then the 32-bit endian conversion is performed and converted to the standard order; The 16 registers are sequentially XORed with the 512-bit data starting from the (k = 0, 1,... 15) positions of the plaintext in and then output to the 512-bit starting from the (k = 0, 1,... 15) positions of the ciphertext out; The position of the plaintext is shifted backward by 1024; the position of the ciphertext is shifted backward by 1024; j = j + 1024. If j < n, then go to step CTR64_core, otherwise end.

[0028] Furthermore, the function, function, function, function, function, function, function, The function is a single 64-way encryption execution function. Its form is the same, and its core is the same as and the difference lies in the output part. Its core steps are as follows: 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]; After BlkIV1 is grouped into 32 bits, it performs an unsigned addition with the 512-bit register corresponding to IVTB2, and the result is saved to BlkD; After BlkD is grouped into 32 bits, it performs an unsigned addition with the 512-bit register corresponding to IVUpTBL + 32 and outputs to BlkH; After BlkD is grouped into 32 bits, it performs an unsigned addition with the 512-bit register corresponding to IVUpTBL + 48 and outputs to BlkL; After BlkD is grouped into 32 bits, it performs an unsigned addition with the 512-bit register corresponding to IVUpTBL + 64 and outputs 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, and BlkD 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.

[0029] 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.

[0030] 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. Furthermore, the The output part: Group the BlkI, BlkJ, BlkK, BlkL registers into 16 blocks of 32 bits and extract BlkI block 0, BlkJ block 0, BlkK block 0, BlkL block 0, BlkI block 1, BlkJ block 1, BlkK block 1, BlkL block 1, ..., BlkI block 3, BlkJ block 3, BlkK block 3, BlkL block 3, and save them to BlkI, then perform 32-bit big-endian conversion and convert to standard order. BlkI is XORed with the 64-byte data in buf and output to buf. Furthermore, the The output part: Group the BlkI, BlkJ, BlkK, BlkL registers into 16 blocks of 32 bits and extract BlkI block 0, BlkJ block 0, BlkK block 0, BlkL block 0, BlkI block 1, BlkJ block 1, BlkK block 1, BlkL block 1, ..., BlkI block 7, BlkJ block 7, BlkK block 7, BlkL block 7, and save the blocks to BlkI, BlkJ, and then perform 32-bit big-endian conversion and convert to standard order. BlkI is XORed with the 64 bytes of data starting from the 512th byte in in and output to the 64 bytes starting from the 512th byte in out. BlkJ is XORed with the 64 bytes of data in buf and output to buf.

[0031] Furthermore, the , output part: Group the BlkI, BlkJ, BlkK, BlkL registers into 16 blocks of 32 bits and extract BlkI block 0, BlkJ block 0, BlkK block 0, BlkL block 0, BlkI block 1, BlkJ block 1, BlkK block 1, BlkL block 1, ..., BlkI block 11, BlkJ block 11, BlkK block 11, BlkL block 11, and save the blocks to BlkI, BlkJ, BlkK, and then perform 32-bit big-endian conversion and convert to standard order. BlkI is XORed with the 64 bytes of data starting from the 512th byte in in and output to the 64 bytes starting from the 512th byte in out. BlkJ is XORed with the 64 bytes of data starting from the 576th byte in in and output to the 64 bytes starting from the 576th byte in out. BlkK is XORed with the 64 bytes of data in buf and output to buf.

[0032] Furthermore, the , output part: Group the BlkI, BlkJ, BlkK, BlkL registers into 16 blocks of 32 bits and extract BlkI block 0, BlkJ block 0, BlkK block 0, BlkL block 0, BlkI block 1, BlkJ block 1, BlkK block 1, BlkL block 1, ..., BlkI block 15, BlkJ block 15, BlkK block 15, BlkL block 15, and save them to BlkI, BlkJ, BlkK, BlkL, and then perform 32-bit big-endian conversion and convert them to standard order. BlkI is XORed with the 64 bytes of data starting from the 512th byte in in and output to the 64 bytes starting from the 512th byte in out. BlkJ is XORed with the 64 bytes of data starting from the 576th byte in in and output to the 64 bytes starting from the 576th byte in out. BlkK is XORed with the 64 bytes starting from the 640th byte in in and then output to the 64 bytes starting from the 640th byte in out. BlkL is XORed with the 64 bytes in buf and then output to buf.

[0033] Furthermore, the function, , and There is a common third set of data output function CTR64_4_Core: Group the BlkI, BlkJ, BlkK, BlkL registers into 16 blocks of 32 bits and extract BlkI block 0, BlkJ block 0, BlkK block 0, BlkL block 0, BlkI block 1, BlkJ block 1, BlkK block 1, BlkL block 1, ..., BlkI block 15, BlkJ block 15, BlkK block 15, BlkL block 15 in sequence and save them to the original registers, then perform 32-bit big-endian conversion and convert to standard order.

[0034] BlkI is XORed with the 64 bytes starting from the 512th byte of the plaintext in and then output to the 64 bytes starting from the 512th byte of the ciphertext out; BlkJ is XORed with the 576th byte of the plaintext in and output to the 64 bytes starting from the 576th byte of the ciphertext out; BlkK is XORed with the 640th byte of the plaintext in and output to the 64 bytes starting from the 640th byte of the ciphertext out; BlkL is XORed with the 704th byte of the plaintext in and output to the 64 bytes starting from the 704th byte of the ciphertext out.

[0035] Furthermore, the Output section: Execute CTR64_4_Core; Group the BlkM, BlkN, BlkO, and BlkP registers into 16 blocks of 32 bits each and extract BlkM block 0, BlkN block 0, BlkO block 0, BlkP block 0, BlkM block 1, BlkN block 1, BlkO block 1, BlkP block 1, ..., BlkM block 3, BlkN block 3, BlkO block 3, and BlkP block 3 in sequence and save them to BlkM. Then perform a 32-bit big-endian conversion and convert them to standard order. BlkM is XORed with the 64-byte data in buf and output to buf.

[0036] Furthermore, the The output part: Execute CTR64_4_Core; The BlkM, BlkN, BlkO, and BlkP registers are grouped into 16 blocks of 32 bits and BlkM block 0, BlkN block 0, BlkO block 0, BlkP block 0, BlkM block 1, BlkN block 1, BlkO block 1, BlkP block 1, ..., BlkM block 7, BlkN block 7, BlkO block 7, and BlkP block 7 are extracted in sequence and saved to BlkM and BlkN, then 32-bit big-endian conversion is performed and converted to standard order.

[0037] BlkM is XORed with the 64 bytes starting from the 768th byte in in and then output to the 64 bytes starting from the 768th byte in out.

[0038] BlkN is XORed with the 64-byte data in buf and then output to buf.

[0039] Furthermore, the , the output part includes: Execute CTR64_4_Core; The BlkM, BlkN, BlkO, and BlkP registers are grouped into 16 blocks of 32 bits and BlkM block 0, BlkN block 0, BlkO block 0, BlkP block 0, BlkM block 1, BlkN block 1, BlkO block 1, BlkP block 1, ..., BlkM block 11, BlkN block 11, BlkO block 11, and BlkP block 11 are extracted in sequence and saved to BlkM, BlkN, and BlkO. Then a 32-bit big-endian conversion is performed and converted to standard order.

[0040] BlkM is XORed with the 64 bytes starting from the 768th byte in in and then output to the 64 bytes starting from the 768th byte in out.

[0041] BlkN is XORed with the 64 bytes starting from the 832nd byte in in and then output to the 64 bytes starting from the 832nd byte in out.

[0042] BlkO is XORed with the 64-byte data in buf and then output to buf.

[0043] Furthermore, the ,include: Execute CTR64_4_Core; The BlkM, BlkN, BlkO, and BlkP registers are grouped into 16 blocks of 32 bits and BlkM block 0, BlkN block 0, BlkO block 0, BlkP block 0, BlkM block 1, BlkN block 1, BlkO block 1, BlkP block 1, ..., BlkM block 15, BlkN block 15, BlkO block 15, and BlkP block 15 are extracted in sequence and saved to BlkM, BlkN, BlkO, and BlkP. Then a 32-bit big-endian conversion is performed and converted to standard order.

[0044] BlkM is XORed with the 64 bytes starting from the 768th byte in in and then output to the 64 bytes starting from the 768th byte in out.

[0045] BlkN is XORed with the 64 bytes starting from the 832nd byte in in and then output to the 64 bytes starting from the 832nd byte in out.

[0046] BlkO is XORed with the 64 bytes starting from the 896th byte in in and then output to the 64 bytes starting from the 896th byte in out.

[0047] BlkP is XORed with the 64-byte data in buf and then output to buf.

[0048] Furthermore, 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, and BlkD 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.

[0049] 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.

[0050] Furthermore, the encryption function The output part includes: Group the BlkI, BlkJ, BlkK, BlkL registers into 16 blocks of 32 bits and extract BlkI block 0, BlkJ block 0, BlkK block 0, BlkL block 0, BlkI block 1, BlkJ block 1, BlkK block 1, BlkL block 1, ..., BlkI block 3, BlkJ block 3, BlkK block 3, BlkL block 3, and save them to BlkI, then perform 32-bit big-endian conversion and convert to standard order. BlkI is XORed with the 64-byte data in buf and output to buf. Furthermore, the encryption function The output part includes: Group the BlkI, BlkJ, BlkK, BlkL registers into 16 blocks of 32 bits and extract BlkI block 0, BlkJ block 0, BlkK block 0, BlkL block 0, BlkI block 1, BlkJ block 1, BlkK block 1, BlkL block 1, ..., BlkI block 7, BlkJ block 7, BlkK block 7, BlkL block 7, and save the blocks to BlkI, BlkJ, and then perform 32-bit big-endian conversion and convert to 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 in out. BlkJ is XORed with the 64 bytes of data in buf and output to buf.

[0051] Furthermore, the encryption function The output part includes: Group the BlkI, BlkJ, BlkK, BlkL registers into 16 blocks of 32 bits and extract BlkI block 0, BlkJ block 0, BlkK block 0, BlkL block 0, BlkI block 1, BlkJ block 1, BlkK block 1, BlkL block 1, ..., BlkI block 11, BlkJ block 11, BlkK block 11, BlkL block 11, and save them to BlkI, BlkJ, BlkK, and then perform 32-bit big-endian conversion and convert them to 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 in out. BlkJ is XORed with the 64 bytes of data starting from the 320th byte in in and output to the 64 bytes starting from the 320th byte in out. BlkK is XORed with the 64 bytes of data in buf and output to buf.

[0052] Furthermore, the encryption function The output part includes: Group the BlkI, BlkJ, BlkK, BlkL registers into 16 blocks of 32 bits and extract BlkI block 0, BlkJ block 0, BlkK block 0, BlkL block 0, BlkI block 1, BlkJ block 1, BlkK block 1, BlkL block 1, ..., BlkI block 15, BlkJ block 15, BlkK block 15, BlkL block 15, and save them to BlkI, BlkJ, BlkK, BlkL, and then perform 32-bit big-endian conversion and convert them to standard order. BlkI is XORed with the 64 bytes of data starting from the 256th byte of in and output to the 64 bytes starting from the 256th byte of out. BlkJ is XORed with the 64 bytes of data starting from the 320th byte of in and output to the 64 bytes starting from the 320th byte of out. BlkK is XORed with the 384 bytes starting from the 640th byte in in and output to the 64 bytes starting from the 384th byte in out. BlkL is XORed with the 64 bytes in buf and output to buf.

[0053] Furthermore, the encryption function and encryption function , is a single 16-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 BlkIV1 is filled with IV[3]; BlkIV1 performs unsigned addition on the 512-bit register corresponding to IVTB2 after grouping by 32 bits, and saves the result to BlkIV1; At this time, 4 registers save 16 IVs, which are: BlkA0, BlkB0,BlkIV0, BlkIV1; After executing 32 rounds of parallel encryption round functions, the ciphertext of 16 IVs is output: BlkA, BlkB, BlkC, BlkD; Group the BlkA, BlkB, BlkC, and BlkD 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.

[0054] Furthermore, the encryption function The output part includes: BlkA is XORed with the 64 bytes starting from byte 0 in in and output to the 64 bytes starting from byte 0 in out. BlkB is XORed with the 64 bytes starting from byte 64 in in and output to the 64 bytes starting from byte 64 in out. BlkC is XORed with the 64 bytes in buf and output to buf Furthermore, the encryption function The output part includes: BlkA is XORed with the 64 bytes starting from byte 0 in in and output to the 64 bytes starting from byte 0 in out. BlkB is XORed with the 64 bytes starting from byte 64 in in and output to the 64 bytes starting from byte 64 in out. BlkC is XORed with the 64 bytes starting from byte 128 in in and output to the 64 bytes starting from byte 128 in out. BlkD is XORed with the 64 bytes in buf and output to buf.

[0055] Furthermore, the encryption function and encryption function It is a single 8-way encryption execution function. Its form is the same, the difference is in the output part. Its core steps are as follows: The 256-bit register blkA0 is filled with IV[0]; The 256-bit register blkB0 is filled with IV[1]; The 256-bit register blkIV0 is filled with IV[2]; The 256-bit register blkIV1 is filled with IV[3]; blkIV1 performs unsigned addition on the 256-bit register corresponding to IVTB1 after grouping by 32 bits, and saves the result to blkIV1; At this time, 4 registers save 8-way IV, which are: blkA0, blkB0, blkIV0, blkIV1; After executing 32 rounds of parallel encryption round functions, the ciphertext of 8-way IV is output: blkA, blkB, blkC, blkD; Group the blkA, blkB, blkC, and blkD registers into 8 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 7, blkB block 7, blkC block 7, and blkD block 7 in sequence and save them to the original registers. Then perform 32-bit endian conversion and convert them to standard order.

[0056] Furthermore, the encryption function The output part includes: blkA is XORed with the 32 bytes starting from byte 0 in in and output to the 32 bytes starting from byte 0 in out. blkB is XORed with the 32 bytes starting from byte 32 in in and output to the 32 bytes starting from byte 32 in out. blkC is XORed with the 32 bytes in buf and output to buf. Furthermore, the encryption function The output part includes: blkA is XORed with the 32 bytes starting from byte 0 in in, and then output to the 32 bytes starting from byte 0 in out; blkB is XORed with the 32 bytes starting from the 2nd byte in in, and then output to the 32 bytes starting from the 32nd byte in out; blkC is XORed with the 32 bytes starting from the 64th byte in in, and then output to the 32 bytes starting from the 64th byte in out; blkD is XORed with the 32 bytes in buf and then output to buf.

[0057] Furthermore, the encryption function , encryption function , 4-way encryption function and encryption function , are all single 4-way encryption execution functions, their forms are the same, the difference is in the output part, and their core steps are as follows: The 128-bit register blka0 is filled with IV[0]; The 128-bit register blkb0 is filled with IV[1]; The 128-bit register blkiv0 is filled with IV[2]; The 128-bit register blkiv1 is filled with IV[3]; blkiv1 performs unsigned addition on the 128-bit register corresponding to IVTB0 after grouping by 32 bits, and saves the result to blkiv1; At this time, 4 registers save 4 IVs, which are: blka0, blkb0, blkiv0, blkiv1; After executing 32 rounds of parallel encryption round functions, the ciphertext of the 4-way IV is output: blka , blkb,blkc, blkd. Furthermore, the encryption function The output part includes: 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, and the 0th block of blkd are extracted in sequence and saved. Then, a 32-bit big-endian conversion is performed and the sequence is converted to the standard order.

[0058] blka is XORed with 32 bytes in buf and output to buf.

[0059] Furthermore, the encryption function ,include: Group blka, blkb, blkc, blkd registers into 4 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 and save them to blka, blkb; blka is XORed with the 16 bytes starting from byte 0 in in and output to the 16 bytes starting from byte 0 in out. blkb is XORed with the 16 bytes in buf and output to buf.

[0060] Furthermore, the encryption function The output part includes: Group the blka , blkb , blkc , blkd registers into 4 blocks by 32 bits, and extract 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 and save them to blka , blkb , blkc ; blka is XORed with the 16 bytes starting from byte 0 in in and output to the 16 bytes starting from byte 0 in out. blkb is XORed with the 16 bytes starting from byte 32 in in and output to the 16 bytes starting from byte 32 in out. blkc is XORed with the 16 bytes in buf and output to buf.

[0061] Furthermore, the encryption function The output part includes: Group the blka , blkb , blkc , and blkd registers into 4 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 2, blkb block 2, blkc block 2, blkd block 2, blka block 3, blkb block 3, blkc block 3, blkd block 3 and save them to blka , blkb, blkc, blkd. After blka is XORed with the 16 bytes starting from byte 0 in, it is output to the 16 bytes starting from byte 0 in out. After blkb is XORed with the 16 bytes starting from byte 32 in, it is output to the 16 bytes starting from byte 32 in out. After blkc is XORed with the 16 bytes starting from byte 48 in, it is output to the 16 bytes starting from byte 48 in out. After blkd is XORed with the 16 bytes in buf, it is output to buf.

[0062] Embodiment 2 This embodiment provides a data fast encryption system based on a national secret algorithm, including: an encryption module, which is configured to: obtain plain text, use the counter mode of the national secret algorithm SM4, and 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: (1-1) Reconstruct the encryption function, and encrypt the message to be encrypted using the reconstructed encryption function to obtain the encrypted partial ciphertext and the remaining plaintext; (1-2) Based on the different lengths of the remaining plaintext, a new encryption function is constructed, and the remaining plaintexts of different lengths are encrypte...

[0063] The above description is only a preferred embodiment of the present invention and is 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 in 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 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.

2. The method for fast data encryption based on the national secret algorithm as claimed in claim 1 is characterized in that: 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-6), 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 it is not 0, go to (1-2).

3. The data fast encryption method based on the national secret algorithm as claimed in claim 1 is characterized in that: The method of constructing a new encryption function based on different lengths of the remaining plaintexts, encrypting the remaining plaintexts of different lengths based on the new encryption function, and obtaining the ciphertext of the remaining plaintexts includes: (1-2-1) If the length of the remaining plaintext is less than or equal to 64, construct a new encryption function, encrypt the remaining plaintexts of different lengths based on the new encryption function, and obtain the ciphertext of the remaining plaintext; (1-2-2) If the length of the remaining plaintext is less than or equal to 128, 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; (1-2-3) If the length of the remaining plaintext is less than or equal to 256, 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; (1-2-4) If the length of the remaining plaintext is less than or equal to 512, 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; (1-2-5) If the length of the remaining plaintext is greater than 512, 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.

4. The method for fast data encryption based on the national secret algorithm as claimed in claim 3 is characterized in that: In (1-2-1), if the length of the remaining plaintext is less than or equal to 64, 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; including: (4-7) , go to step (4-8), otherwise go to step (1-2-2); (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; In (1-2-2), if the length of the remaining plaintext is less than or equal to 128, 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, including: (4-15) If , go to step (4-16), otherwise go to step (1-2-3); (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.

5. The method for fast data encryption based on the national secret algorithm as claimed in claim 3 is characterized in that: In (1-2-3), if the length of the remaining plaintext is less than or equal to 256, 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, including: (4-19) If , then go to step (4-20), otherwise go to step (1-2-4); (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; In (1-2-4), if the length of the remaining plaintext is less than or equal to 512, 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, including: (4-23) If , go to step (4-24), otherwise go to step (1-2-5); (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.

6. The method for fast data encryption based on the national secret algorithm as claimed in claim 3 is characterized in that: In (1-2-5), if the length of the remaining plaintext is greater than 512, 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, including: (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.

7. The method for fast data encryption based on the national secret algorithm as claimed in claim 2 is characterized in that: The core 64-way encryption function Function, the process is as follows: 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]; BlkIV1 performs unsigned addition on the 512-bit register corresponding to IVTB2 after grouping by 32 bits, and saves the result to BlkIV1; Let serial number j = 0; Steps CTR64_core: Let BlkD = BlkIV1; After BlkV1 is grouped into 32 bits, unsigned addition is performed on the 512-bit register corresponding to IVUpTBL+32 and output to BlkH; BlkV1 performs unsigned addition on the 512-bit register corresponding to IVUpTBL+48 after grouping by 32 bits, and outputs it to BlkL; BlkV1 performs unsigned addition on the 512-bit register corresponding to IVUpTBL+64 after grouping by 32 bits, and outputs it to BlkP; After BlkV1 is grouped into 32 bits, unsigned addition is performed on the 512-bit register corresponding to IVUpTBL+64 and the output is to BlkV1; At this time, only 7 registers are used to save 64 IVs, which are: BlkA0, BlkB0, BlkIV0, BlkD, corresponding to the first 16 channels; 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; The registers in each group are grouped into 16 blocks of 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; The 16 registers are sequentially connected with the plain text in The 512 bits of data starting at position 1 are XORed and output to the ciphertext out. The first 512 bits of the position; The position of the plaintext is shifted backward by 1024; the position of the ciphertext is shifted backward by 1024; j = j + 1024. If j < n, go to step CTR64_core, otherwise end.

8. The method for fast data encryption based on the national secret algorithm as claimed in claim 6 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: 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]; After BlkIV1 is grouped into 32-bit blocks, an unsigned addition is performed with the 512-bit register corresponding to IVTB2, and the result is saved to BlkD; After BlkD is grouped into 32-bit blocks, an unsigned addition is performed with the 512-bit register corresponding to IVUpTBL + 32, and the output is sent to BlkH; After BlkD is grouped into 32-bit blocks, an unsigned addition is performed with the 512-bit register corresponding to IVUpTBL + 48, and the output is sent to BlkL; After BlkD is grouped into 32-bit blocks, an unsigned addition is performed with the 512-bit register corresponding to IVUpTBL + 64, and the output is sent to BlkP; At this time, 7 registers store 64 IVs, which are respectively: BlkA0, BlkB0, BlkIV0, BlkD, corresponding to the first 16 paths; BlkA0, BlkB0, BlkIV0, BlkH, the 16th path - the 31st path; BlkA0, BlkB0, BlkIV0, BlkL, the 32nd path - the 47th path; BlkA0, BlkB0, BlkIV0, BlkP, the 48th path - the 63rd path; After performing 32 rounds of parallel encryption round functions, the ciphertexts of 64 IVs are output: BlkA, BlkB, BlkC, BlkD, corresponding to the first 16 paths; BlkE, BlkF, BlkG, BlkH, the 16th path - the 31st path; BlkI, BlkJ, BlkK, BlkL, the 32nd path - the 47th path; BlkM, BlkN, BlkO, BlkP, the 48th path - the 63rd path; 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.

9. The method for fast data encryption based on the national secret algorithm as claimed in claim 5 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.

10. The data fast encryption system based on the national secret algorithm is characterized by: 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

  • Data encryption method and device based on SM4 algorithm and computer platform

    CN113282947A

  • Lightweight encryption method capable of accepting any plaintext length

    CN114513298A

  • Implementation method of SM4 algorithm based on super computer

    CN116260570A

  • Message authentication code generation method and device, computer equipment and storage medium

    CN116405223A

Cited By

  • Video encryption and decryption parallel acceleration processing method and system based on national cryptographic algorithm

    CN120711205A

  • Video encryption and decryption parallel acceleration processing method and system based on national secret algorithm

    CN120711205B