A key expansion method based on the national secret SM3 algorithm and its system and medium
Through the key expansion method based on the National Secret SM3 algorithm, a targeted expansion mode is provided for different plaintext lengths, which solves the problem of low key generation rate in high-load communications, achieving efficient and continuous data transmission and improving user experience.
Patent Information
- Application Number
- CN202211410300.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-11
- Publication Date
- 2025-08-12
- Estimated Expiration
- 2042-11-11
AI Technical Summary
When the existing SM3 algorithm faces communication services with high load and high real-time requirements, the key generation rate is low, resulting in discontinuous communication, poor user experience, and the key expansion process takes a long time and is inefficient.
Based on the National Secret SM3 algorithm, the key expansion mode is determined by judging the clear text length, including expansion processing and preprocessing, and combined with round-robin conditions and preset discard rules, targeted key expansion is provided to ensure that the key quantity matches the clear text length.
It realizes efficient and continuous data transmission under different key quantity requirements, improves the key generation rate, reduces business interruptions, and improves user experience.
Smart Images

Figure CN115865319B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of quantum communication technology, and in particular relates to a key expansion method based on the national secret SM3 algorithm and its system and medium. Background Art
[0002] Today's communications security technology continues to achieve breakthroughs in new areas. Quantum encryption uses quantum keys to encrypt user information, with the key and user information data ratio being 1:1. A one-time pad encryption method ensures data communication security. However, due to the load constraints of conventional networks, when faced with high user traffic demands, such as transmitting attachments or real-time audio and video, relaying keys proportional to user information to the other end of the communication can lead to excessive traffic load and significantly increase communication costs. The traditional SM3 cryptographic hash algorithm, a Chinese commercial cryptographic hash algorithm standard published by the China National Cryptography Administration in 2010, is a one-way algorithm primarily used for digital signatures and verification in commercial cryptographic applications. It is an improvement on SHA-256 and offers comparable security to SHA-256. The SM3 algorithm can be summarized into four steps: message padding, message expansion, iterative compression, and output. The SM3 hashing algorithm divides the input data into several groups of 512 bits. If the final group is less than 512 bits, it is padded to 512 bits according to a rule. After multiple rounds of iterative compression, the output is a 256-bit digest value. This method can be used for multiple rounds of key expansion for services with low key requirements. However, for services with high key requirements, using this algorithm for large-scale key expansion is time-consuming and inefficient, and also poses problems such as low key generation efficiency. This low key generation efficiency can lead to discontinuous real-time communication and a poor user experience. Therefore, to ensure uninterrupted and efficient data transmission in high-load, real-time communication services, a more comprehensive key expansion method is needed. Summary of the Invention
[0003] Purpose of the Invention: The purpose of the present invention is to provide a key expansion method based on the national secret SM3 algorithm, its system, and medium. This method can provide different key expansion modes under different key quantity requirements. For communication services with low key quantity requirements, the key expansion process is effectively shortened, thereby saving time and resources for data transmission. For communication services with high load and high real-time requirements, a targeted key expansion process is provided for different key quantities, thereby ensuring continuous and efficient data transmission. This method can cope with business communications with different requirements and ensure the efficient and complete data transmission process.
[0004] The present invention provides a key expansion method based on the national secret SM3 algorithm, which includes the following steps:
[0005] S1. Determine the length value Sum of the plaintext to be encrypted and the length m of the key key for encrypting the plaintext;
[0006] S2. According to the length value Sum of the plaintext to be encrypted, determine whether the key key meets the cycling condition. If it does not meet the cycling condition, enter S3; if it meets the cycling condition, enter S4;
[0007] S3. Based on the national cryptographic SM3 algorithm, perform an expansion process on the key key to obtain an expanded key key';
[0008] S4. Based on the national cryptographic SM3 algorithm, perform a preprocessing on the key key. The preprocessed key key1 enters a cyclic expansion to obtain an expanded key key".
[0009] As an improvement of the present invention, in step S2, the cycling condition is Sum≥4224.
[0010] As an improvement of the present invention, in step S3, the process of performing an expansion process on the key key based on the national cryptographic SM3 algorithm to obtain an expanded key key' is specifically as follows:
[0011] S3-1: When Sum≤256, use the key key as a parameter of the SM3 hashing algorithm, substitute it into the SM3 hashing algorithm, and select a key with a length equal to the Sum value from the calculation result of the SM3 hashing algorithm as the expanded key key';
[0012] S3-2: When 256<Sum<4224 and m≤256, calculate n1 = Sum÷256. If n1 has only an integer part, then n1' = n1; if n1 has a remainder part, then n1' = [Sum÷256]+1. Use the key key as a parameter of the SM3 hashing algorithm, substitute it into the SM3 hashing algorithm, perform the calculation of the SM3 hashing algorithm for n1' rounds, and select a key with a length equal to the Sum value from the sum of the calculation results of the n1' rounds of the SM3 hashing algorithm as the expanded key key';
[0013] S3-3: When 256<Sum<4224 and m>256, calculate n1 = Sum÷256 and n2 = m÷256:
[0014] If n1 has only an integer part, then n1' = n1; if n1 has a decimal part, then n1' = [Sum÷256]+1;
[0015] If n2 has only an integer part, then n2' = n2, and use the last 256-bit key as a parameter of the SM3 hashing algorithm; if n2 has a remainder part, then n2' = [m÷256], and use the key corresponding to the remainder part as a parameter of the SM3 hashing algorithm;
[0016] Substitute the parameters of the SM3 hash algorithm into the SM3 hash algorithm, perform (n1′-n2′) rounds of SM3 hash algorithm calculation, accumulate the keys calculated in each round, and add them to the key corresponding to the integer part n2′, and select a key with a length equal to the Sum value from the addition result as the extended key key′.
[0017] As an improvement of the present invention, in step S3-2, the key key is used as a parameter of the SM3 hash algorithm, substituted into the SM3 hash algorithm, and n1′ rounds of SM3 hash algorithm calculation are performed. A key with a length equal to the sum value is selected from the sum of the calculation results of the n1′ rounds of SM3 hash algorithm as the extended key key′. The specific process is as follows:
[0018] S3-2-1: Substitute the key key as a parameter of the SM3 cryptographic hash algorithm into the SM3 cryptographic hash algorithm to calculate a hash value H1. Substitute the hash value H1 into the SM3 cryptographic hash algorithm again to calculate a new hash value H2;
[0019] S3-2-2: Repeat step S3-2-1, generating a new set of hash values in each round. In the next round, the hash values of the previous round are used as parameters of the SM3 hash algorithm and substituted into the SM3 hash algorithm. After n1′ rounds of calculation, the keys calculated in each round are accumulated, and the part larger than the Sum value is discarded from the sum of the calculation results of n1′ rounds, leaving a key with a length equal to the Sum value as the extended key key′.
[0020] As an improvement of the present invention, in step S3-3, the parameters of the SM3 hash algorithm are substituted into the SM3 hash algorithm, and (n1′-n2′) rounds of SM3 hash algorithm calculation are performed. The specific process is:
[0021] S3-3-1: Substitute the parameters of the SM3 hash algorithm into the SM3 hash algorithm to calculate a hash value H3, and substitute the hash value H3 into the SM3 cryptographic hash algorithm again to calculate a new hash value H4;
[0022] S3-3-2: Repeat step S3-3-1, generating a new set of hash values in each round. In the next round, the hash values of the previous round are used as parameters of the SM3 hash algorithm and substituted into the SM3 hash algorithm. This is done through (n1′-n2′) rounds of calculation.
[0023] As an improvement of the present invention, in step S4, the key is preprocessed based on the national secret SM3 algorithm, and the specific process is as follows:
[0024] S4-1: When m ≤ 256, first use the key key as a parameter of the SM3 hashing algorithm, substitute it into the SM3 hashing algorithm to calculate the hash value. Subsequently, substitute this hash value into the next round of the SM3 hashing algorithm, and add the results of the two rounds of calculations to obtain the key key1;
[0025] S4-2: When 256 < m < 512, take the part of the key key except the first 256 bits, substitute this part into the SM3 hashing algorithm to calculate the hash value, and add this hash value to the key of the first 256 bits of the original key key to obtain the key key1;
[0026] S4-3: When m ≥ 512, calculate n3 = m ÷ 512. If n3 is an integer, the key key is directly used as the preprocessed key key1; if there is a remainder part in n3, take n3' = [m ÷ 512], and perform S4-1 or S4-2 on the key corresponding to this remainder part to obtain the key key'1, and add the key key'1 to the key corresponding to the integer part n3' to obtain the key key1.
[0027] As an improvement of the present invention, in step S4, the preprocessed key key1 enters the cyclic expansion to obtain the expanded key key″, specifically:
[0028] S4-4: Determine the required number of cyclic expansions N according to the following formula (1):
[0029] m1×8 N ≥Sum (1)
[0030] Where m1 is the length value of key1, N is the number of cycles, and Sum is the plaintext length value;
[0031] S4-5: Divide the key key1 into blocks, each block having a length of 512 bits, to obtain multiple key blocks each having a length of 16 message words, and perform the following processing on each key block:
[0032] S4-6: Perform one cycle on the key block based on the message expansion rule of the national cryptographic SM3 algorithm, and select and discard X message words from the result of one cycle of the key block according to the preset discard rule to obtain the target cycle result;
[0033] S4-7: Accumulate the target cycle results after each key block in step S4-5 executes S4-6, and replace the key key1 in step S4-5 with the accumulated cyclic key before the next cycle;
[0034] S4-8: Continue to execute steps S4-5 to S4-7 until the N cycles end to obtain the key key'1;
[0035] S4-9: Select a key with a length equal to the Sum value from the key key′1 obtained in step S4-8 as the extended key key″.
[0036] As an improvement of the present invention, in step S4-6, the preset discarding rule is specifically: a preset round constant is set, and a message word specified by the round constant is selected from the results of one round of the key block according to the preset round constant and discarded, where the number of round constants is X.
[0037] As an improvement of the present invention, the present invention provides a key expansion system based on the national secret SM3 algorithm, including a microprocessor and a memory connected to each other, and the microprocessor is programmed or configured to execute the steps of the key expansion method based on the national secret SM3 algorithm mentioned above.
[0038] As an improvement of the present invention, the present invention also provides a computer-readable storage medium, which stores a computer program programmed or configured to execute the above-mentioned key expansion method based on the national secret SM3 algorithm.
[0039] The beneficial effects of the present invention are:
[0040] 1. In response to different key quantity requirements, it can provide targeted key expansion processes, effectively saving expansion resources when the key quantity demand is low, and providing efficient, continuous and non-duplicate key expansion solutions when the key quantity demand is high;
[0041] 2. Combined with the national secret SM3 algorithm, it ensures the versatility and reliability of data encryption; at the same time, it omits the iterative compression process of the SM3 algorithm, effectively improving the efficiency of key expansion; at the same time, the difference in each round constant eliminates the symmetry of the key, and the nonlinearity of key expansion eliminates the possibility of the same key;
[0042] 3. The improvement in key expansion efficiency has also increased the key generation rate, effectively reducing business interruptions caused by insufficient keys and greatly improving the user experience when conducting communication services. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] Figure 1 This is a flow chart of the key expansion method based on the national secret SM3 algorithm;
[0044] Figure 2 It is a round-robin message word abandonment diagram;
[0045] Figure 3 This is a schematic diagram of the key expansion method based on the national secret SM3 algorithm;
[0046] Figure 4 It is a schematic diagram of data transmission between user terminals. DETAILED DESCRIPTION
[0047] The present invention will be further described below with reference to the accompanying drawings and specific embodiments. It should be understood that the following specific embodiments are only used to illustrate the present invention and are not used to limit the scope of the present invention.
[0048] The SM3 hashing algorithm divides the input data into several 512-bit groups. Groups shorter than 512 bits are padded to 512 bits according to a rule. After multiple rounds of iterative compression, the output is a 256-bit digest value. This algorithm requires a compression module during data processing, and each round of compression only produces a 256-bit digest value. With one-time pad unconditional secure communication encryption technology, keys cannot be recycled; a new key is required for each transmission. However, in real-world communications, especially for large file transfers and real-time communication, quantum key distribution (QKD) is often insufficient. To meet the demands of high-load communication services, only a portion of the quantum key needs to be expanded to match the plaintext data length to achieve one-time pad secure encryption. This allows for efficient and rapid on-demand quantum key expansion.
[0049] The present invention provides a key expansion method based on the national secret SM3 algorithm, such as Figure 1 As shown, the method includes the following steps:
[0050] S1, determine the length value Sum of the plaintext to be encrypted and the length m of the key key for encrypting the plaintext;
[0051] S2. According to the length value Sum of the plaintext to be encrypted, determine whether the key key meets the round-robin condition. If the round-robin condition is not met, enter S3. If the round-robin condition is met, enter S4, where the round-robin condition is Sum ≥ 4224.
[0052] S3, expand the key key based on the national secret SM3 algorithm to obtain the expanded key key′;
[0053] S4. Preprocess the key key based on the national secret SM3 algorithm. The preprocessed key key1 enters the round-robin expansion to obtain the extended key key".
[0054] It can be seen from the above method steps that when expanding the key, different key schemes can be provided based on different plaintext lengths, and the key is ultimately expanded to an extended key of the required length, thereby improving encryption and decryption efficiency.
[0055] In the embodiment of the present invention, when the plaintext length Sum value is small, step S3 is divided into three cases, including the following:
[0056] S3-1: When Sum ≤ 256, take the key key as a parameter of the SM3 hashing algorithm, substitute it into the SM3 hashing algorithm, calculate to obtain a 256-bit hash value, and select a key with a length equal to the value of Sum from this 256-bit hash value as the extended key key′;
[0057] S3-2: When 256 < Sum < 4224 and m ≤ 256, first calculate n1 = Sum ÷ 256. If n1 has only an integer part, then n1′ = n1. If n1 has a remainder part, then round n1 up by 1, that is, n1′ = [Sum ÷ 256] + 1:
[0058] S3-2-1: Take the key key as a parameter of the SM3 cryptographic hashing algorithm, substitute it into the SM3 hashing algorithm, calculate to obtain a 256-bit hash value H1, and substitute the 256-bit hash value H1 into the SM3 cryptographic hashing algorithm again for calculation to obtain a new 256-bit hash value H2;
[0059] S3-2-2: Repeat step S3-2-1. Each round generates a new set of 256-bit hash values. In the next round, use the 256-bit hash value of the previous round as a parameter of the SM3 hashing algorithm and substitute it into the SM3 hashing algorithm. After such calculation for n1′ rounds, accumulate the calculation results of each round to generate a key key1 with a length of (n1′ × 256) bits, discard the part larger than the value of Sum, and leave a key with a length equal to the value of Sum as the extended key key′;
[0060] S3-3: When 256 < Sum < 4224 and m > 256, first calculate n1 = Sum ÷ 256, n2 = m ÷ 256:
[0061] If n1 has only an integer part, then n1′ = n1. If n1 has a decimal part, then n1′ = [Sum ÷ 256] + 1;
[0062] If n2 has only an integer part, then n2′ = n2, and take the last 256-bit key as a parameter of the SM3 hashing algorithm. If n2 has a remainder part, then n2′ = [m ÷ 256] and take the key corresponding to the remainder part as a parameter of the SM3 hashing algorithm:
[0063] S3-3-1: Substitute the above parameter of the SM3 hashing algorithm into the SM3 hashing algorithm, calculate to obtain a 256-bit hash value H3, and substitute the 256-bit hash value H3 into the SM3 cryptographic hashing algorithm again for calculation to obtain a new 256-bit hash value H4;
[0064] S3-3-2: Repeat step S3-3-1. In each round, a new 256-bit hash value is generated. In the next round, the 256-bit hash value of the previous round is used as the parameter of the SM3 hash algorithm and substituted into the SM3 hash algorithm. After (n1′-n2′) rounds of such calculations, the keys calculated in each round are accumulated and added to the (n2′×256)-bit key key. Then, a key with a length equal to the Sum value is selected from the added result as the expanded key key′.
[0065] In the embodiment of the present invention, through the technical solution provided by the above steps, when the length Sum value of the plaintext is small, the corresponding key amount required is also small. Therefore, step S3 is required to expand the initial key key to avoid repeated expansion from occupying expansion resources and storage resources.
[0066] In the embodiment of the present invention, when the length Sum value of the plaintext is large, for example, when Sum≥4224 (that is, the plaintext to be encrypted is equal to or more than 132 message words), since the message expansion module step of SM3 uses a 512-bit data block as the input value, step S4 needs to perform a preprocessing step on the key first and then perform a cyclic expansion, including the following:
[0067] First, the specific process of preprocessing the key key based on the national standard SM3 algorithm is as follows: First, judge the size of the key key (with a length of m bits):
[0068] S4-1: When m≤256, first use the key key as the parameter of the SM3 hash algorithm and substitute it into the SM3 hash algorithm to calculate a 256-bit hash value. Then, substitute this hash value into the next round of the SM3 hash algorithm. After adding the calculation results of the two rounds, a 512-bit preprocessed key key1 is obtained;
[0069] S4-2: When 256<m<512, take the part of the key key except the first 256 bits, substitute this part into the SM3 hash algorithm to calculate a 256-bit hash value, and add this hash value to the first 256-bit key of the original key key to obtain a 512-bit preprocessed key key1;
[0070] S4-3: When m≥512, calculate n3 = m÷512. If n3 is an integer, the key key is directly used as the preprocessed key key1; if there is a remainder part in n3, take the integer part n3′ of n3, and perform S4-1 or S4-2 on the key corresponding to this remainder part to obtain a 512-bit hash value. Add this 512-bit hash value to the key corresponding to the integer part n3′ to obtain a (n3′+1)×512-bit preprocessed key key1.
[0071] The embodiment of the present invention is a key expansion method based on the national secret SM3 algorithm. The original SM3 message expansion module needs to first divide a 512-bit data packet into 16 message words, and use these as the first 16 of the generated 132 message words. These 16 message words are then used to recursively generate the remaining 116 message words. To meet business needs, it is necessary to modify the values without changing the original SM3 message expansion module algorithm to achieve on-demand expansion of the quantum key. Therefore, steps S4-1 to S4-3 are required to preprocess the key to an integer multiple of 512 bits in length.
[0072] In an embodiment of the present invention, the pre-processed key key1 enters the round-robin extension:
[0073] S4-4: Determine the required number of round-robin extensions N according to the following formula (1):
[0074] m1×8 N ≥Sum (1)
[0075] Where m1 is the length of key1, N is the number of rounds, and Sum is the plaintext length.
[0076] S4-5: Divide the key key1 into blocks, each block is 512 bits long, and obtain multiple key blocks with a length of 16 message words. Each key block is processed in the following steps:
[0077] S4-6: Perform a round robin on the key block based on the message expansion rule of the national secret SM3 algorithm. Select X message words from the round robin result of the key block according to the preset discard rule and discard them to obtain the target round robin result:
[0078] In one embodiment of the present invention, a key block with a length of 16 message words is subjected to a round robin based on the message expansion rule of the national secret SM3 algorithm to generate 132 message words. The round robin multiple R (integer value) is calculated based on these 132 message words: R = 132 ÷ 16 = 8.25 ≈ 8; it should be noted that the round robin multiple R should be an integer value, so the round robin multiple R is rounded off and the remainder of the round robin multiple 0.25 is discarded. The number of discarded words X is calculated in this way: X = 132-16×R = 132-16×8 = 4. The 16 message words that are recursively added are placed at the head end as the first 16 message words of the 132 message words after round robin expansion. According to the preset discarding rule, 4 message words are selected from the first 16 message words of these 132 message words and discarded. The target round robin result is 128 message words, that is, a block of 16 message words can generate 16×8=128 message words in one round robin.
[0079] In an embodiment of the present invention, in order to prevent the 128 message words calculated by the first 16 message words from being repeated with the 128 message words calculated above in the subsequent round robin, 4 message words are selected from the first 16 message words and discarded. The selection rule needs to be based on the round constant rule table. The subscript values of the corresponding 4 message words to be discarded are selected from the prefabricated round constant table, and the message words with the corresponding subscript values are discarded. It should be noted that the subscript value starts from 0, the subscript of the first word is 0, the subscript of the second word is 1... and the subscript of the sixteenth word is 15. In one embodiment of the present invention, the round constant rule table is as follows Table 1:
[0080] Table 1
[0081] Number of rounds Round constant rule table First round 0 2 4 6 Second round 1 3 5 7 Round 3 8 10 12 14 Round 4 9 11 13 15 Fifth round 0 2 4 6 Round 6 1 3 5 7 Round 7 8 10 12 14
[0082] S4-7: Accumulate the target round-robin results after executing S4-6 for each key block in step S4-5 to obtain an accumulated round-robin key, and replace the key key1 in step S4-5 with the accumulated round-robin key before the next round-robin;
[0083] For example, in the second round, the 128 message words are still divided into 8 groups of 16 message words according to the message expansion rule of SM3, and then round-robin is performed. After each group of 16 message words is round-robin and discarded, 128 words are generated, that is, the second round generates (8×8×16) message words.
[0084] S4-8: Continue to execute steps S4-5 to S4-7 until N rounds are completed, and obtain the key key′1;
[0085] For example, in the Nth round: the message words generated in the previous round are still divided into 8 groups of 16 message words according to the message expansion rule of SM3. N-1 The groups are cycled, and each group of 16 message words is cycled and discarded to generate 128 words. After accumulation, it can be seen that the Nth cycle generates (8 N ×16) message words are used as the cumulative round-robin key.
[0086] S4-9: Select a key with a length equal to the Sum value from the key key′1 obtained in step S4-8 as the extended key key″.
[0087] For example, assume that the length of the plaintext to be encrypted is 51200 bits (1600 message words) and the length of the preprocessed key key1 is 512 bits (16 message words):
[0088] Calculation: 16×8 N ≥1600, N=3. Substitute 16 message words into the key expansion method of the present invention and perform three round-robin expansions to obtain (8 3×16) message words, but the actual message words required are 1600 message words. 3 ×16) message words are selected as encryption keys, and the rest are discarded.
[0089] It is worth noting that in the embodiment of the present invention, the process of expanding and round-robining the key is the same as the message expansion module of the national encryption SM3 algorithm in terms of algorithm and input value rules, and will not be repeated here.
[0090] Example:
[0091] This method can be used to scale quantum keys for any type of communication within a quantum-safe environment, especially for high-load services. For example, peer-to-peer (P2P) audio and video applications require high real-time and security performance. Using one-time, proportional encryption, quantum key supply may be insufficient. To ensure the integrity of audio and video services, the key quantity must be scaled 1:1 (to the volume of audio and video data packets). First, both calling and called terminals, Peer A and Peer B, are connected to a quantum-safe network. Using this network, communicating users establish a session key. Peer A uses this key to encrypt the audio and video data packets, which are then relayed to the called terminal via a quantum base station. The called terminal then uses this key to decrypt the data.
[0092] For example, the calling terminal Peer A sends a 56,000-bit audio and video data packet to the called terminal Peer B. The local quantum key pool of the calling terminal Peer A provides a 166-bit quantum key for this type of communication (the specific amount of quantum key provided depends on the type of service). To achieve 1:1 encryption strength, the original SM3 message expansion module uses a 512-bit data packet as an input value. Therefore, before executing the round-robin step of the method of the present invention, the 166-bit key also needs to be preprocessed. The key is calculated by two rounds of the SM3 cryptographic hash algorithm to obtain a 512-bit preprocessed key, and then the extended key is obtained through the round-robin expansion of the method of the present invention. The specific calculation is as follows:
[0093] First, calculate that 166 bits need to be expanded by (56000 ÷ 166) times. According to the existing rules, the key expansion step is calculated by 8 N ×16≥16×(56000÷166), N=3. Substitute the 16 message words into the round-robin step of the method of the present invention and perform round-robin expansion three times to obtain (8 3 × 16 message words), and the actual message words required are 56000÷32=1750 message words (each word is 32 bits). 3×16) message words, and the remaining ones are discarded. Calling terminal Peer A uses the expanded key to encrypt the 56,000-bit audio and video data packet using the encryption algorithm and sends it to the called terminal Peer B. Simultaneously, the quantum base station relays the corresponding original 166-bit quantum key and the expanded multiplication field (56,000 ÷ 166) to the called terminal Peer B.
[0094] It is worth noting that in the embodiment of the present invention, the called terminal Peer B receives the encrypted audio and video data packet, the 166-bit quantum key and the expansion multiple (56000 ÷ 166), and then uses the same preprocessing steps and round-robin expansion steps to obtain the required key. Then, the ciphertext of the audio and video data packet is decrypted using the same algorithm. After obtaining the plaintext, the new ciphertext of the audio and video data packet is sent to Peer A using the same method, thereby realizing p2p encrypted communication.
Claims
1. A key expansion method based on the national secret SM3 algorithm, characterized in that: It includes the following steps: S1. Determine the length value Sum of the plaintext to be encrypted and the length m of the key key for encrypting the plaintext; S2. According to the length value Sum of the plaintext to be encrypted, determine whether the key key meets the cycling condition. If it does not meet the cycling condition, enter S3; if it meets the cycling condition, enter S4; S3. Perform an expansion process on the key key based on the national cipher SM3 algorithm to obtain an expanded key key'; S4. Perform a preprocessing on the key key based on the national cipher SM3 algorithm. The preprocessed key key1 enters the cyclic expansion to obtain an expanded key key"; In step S2, the cycling condition is Sum≥4224; In step S3, the process of performing an expansion process on the key key based on the national cipher SM3 algorithm to obtain an expanded key key' is specifically as follows: S3-1. When Sum≤256, use the key key as a parameter of the SM3 hashing algorithm, substitute it into the SM3 hashing algorithm, and select a key with a length equal to the Sum value from the calculation result of the SM3 hashing algorithm as the expanded key key'; S3-2. When 256<Sum<4224 and m≤256, calculate n1 = Sum÷256. If n1 only has an integer part, then n1' = n1; if n1 has a remainder part, then n1' = [Sum÷256]+1. Use the key key as a parameter of the SM3 hashing algorithm, substitute it into the SM3 hashing algorithm, perform the calculation of the SM3 hashing algorithm for n1' rounds, and select a key with a length equal to the Sum value from the sum of the calculation results of the n1' rounds of the SM3 hashing algorithm as the expanded key key'; S3-3. When 256<Sum<4224 and m>256, calculate n1 = Sum÷256, n2 = m÷256: If n1 only has an integer part, then n1' = n1; if n1 has a decimal part, then n1' = [Sum÷256]+1; If n2 only has an integer part, then n2' = n2, and use the last 256-bit key as a parameter of the SM3 hashing algorithm; if n2 has a remainder part, then n2' = [m÷256], and use the key corresponding to the remainder part as a parameter of the SM3 hashing algorithm; Substitute the parameter of the SM3 hashing algorithm into the SM3 hashing algorithm, perform the calculation of the SM3 hashing algorithm for (n1'-n2') rounds, accumulate the keys calculated in each round, add the key corresponding to the integer part n2', and select a key with a length equal to the Sum value from the added result as the expanded key key'; In step S4, the process of performing a preprocessing on the key key based on the national cipher SM3 algorithm is specifically as follows: S4-1. When m≤256, first use the key key as a parameter of the SM3 hashing algorithm, substitute it into the SM3 hashing algorithm, calculate the hash value, and then substitute this hash value into the next round of the SM3 hashing algorithm. Add the calculation results of the two rounds to obtain the key key1; S4-2: When 256 < m < 512, take the part of the key key except the first 256 bits, substitute this part into the SM3 hashing algorithm, calculate the hash value, and add this hash value to the key of the first 256 bits of the original key key to obtain the key key1; S4-3: When m ≥ 512, calculate n3 = m ÷ 512. If n3 is an integer, the key key is directly used as the preprocessed key key1; if there is a remainder part in n3, then take n3′ = [m ÷ 512], and perform S4-1 or S4-2 on the key corresponding to this remainder part to obtain the key key′1, and add the key key′1 to the key corresponding to the integer part n3′ to obtain the key key1; In step S4, the preprocessed key key1 enters the cyclic expansion to obtain the expanded key key″, specifically: S4-4: Determine the number of cyclic expansions N required according to the following formula (1): m1×8 N ≥Sum (1) where m1 is the length value of key1, N is the number of cycles, and Sum is the plaintext length value; S4-5: Divide the key key1 into blocks, each block having a length of 512 bits, to obtain multiple key blocks each with a length of 16 message words, and perform the following processing on each key block: S4-6: Perform one cycle on the key block based on the message expansion rule of the national cipher SM3 algorithm, and select and discard X message words from the result of one cycle of the key block according to the preset discard rule to obtain the target cyclic result; S4-7: Accumulate the target cyclic results after each key block in step S4-5 performs S4-6, and replace the key key1 in step S4-5 with the accumulated cyclic key before the next cycle; S4-8: Continue to execute steps S4-5 to S4-7 until N cycles end to obtain the key key′1; S4-9: Select the key with a length equal to the Sum value from the key key′1 obtained in step S4-8 as the expanded key key″.
2. The key expansion method based on the national secret SM3 algorithm according to claim 1 is characterized in that: In step S3-2, the process of substituting the key key as a parameter of the SM3 hashing algorithm, substituting it into the SM3 hashing algorithm, performing the calculation of the SM3 hashing algorithm for n1′ rounds, and selecting the key with a length equal to the Sum value from the sum of the calculation results of the n1′ rounds of the SM3 hashing algorithm as the expanded key key′ is as follows: S3-2-1: Substitute the key key as a parameter of the SM3 cryptographic hashing algorithm into the SM3 hashing algorithm to calculate the hash value H1, and substitute the hash value H1 into the SM3 cryptographic hashing algorithm again for calculation to obtain a new hash value H2; S3-2-2: Repeat step S3-2-1. Each round generates a new set of hash values. In the next round, use the hash value of the previous round as a parameter of the SM3 hashing algorithm and substitute it into the SM3 hashing algorithm. After such calculation for n1′ rounds, accumulate the keys calculated in each round, discard the part larger than the Sum value from the sum of the calculation results of the n1′ rounds, and leave the key with a length equal to the Sum value as the expanded key key′.
3. The key expansion method based on the national secret SM3 algorithm according to claim 1 is characterized in that: In step S3-3, the parameters of the SM3 hash algorithm are substituted into the SM3 hash algorithm, and (n1′-n2′) rounds of SM3 hash algorithm calculation are performed. The specific process is as follows: S3-3-1: Substitute the parameters of the SM3 hash algorithm into the SM3 hash algorithm to calculate a hash value H3, and substitute the hash value H3 into the SM3 cryptographic hash algorithm again for calculation to obtain a new hash value H4; S3-3-2: Repeat step S3-3-1, generating a new set of hash values in each round. In the next round, the hash values of the previous round are used as parameters of the SM3 hash algorithm and substituted into the SM3 hash algorithm. This is done through (n1′-n2′) rounds of calculation.
4. The key expansion method based on the national secret SM3 algorithm according to claim 1 is characterized in that: In step S4-6, the preset discarding rule is specifically: preset a round constant, and select a message word specified by the round constant from a round result of the key block according to the preset round constant to discard, wherein the number of the round constant is X.
5. A key expansion system based on the national secret SM3 algorithm, comprising a microprocessor and a memory connected to each other, characterized in that: The microprocessor is programmed or configured to execute the steps of the key expansion method based on the national encryption SM3 algorithm described in any one of claims 1 to 4.
6. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program programmed or configured to execute the key expansion method based on the national encryption SM3 algorithm according to any one of claims 1 to 4.
Citation Information
Patent Citations
File encryption method with chaos-like characteristic
CN110677237A
Key Generation For Advanced Encryption Standard (AES) Decryption And The Like
US20080019504A1