Novel encryption method based on SM3 message digest

By introducing SHA-256 hash processing and hybrid encryption algorithm into the SM3 algorithm, the encryption process is optimized, the problems of low efficiency and insufficient security of the SM3 algorithm are solved, and a more efficient and secure encryption method is achieved.

CN118764209APending Publication Date: 2024-10-11GUANGXI POWER GRID CORP
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410916105.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-09
Publication Date
2024-10-11

AI Technical Summary

Technical Problem

In practical applications, the encryption speed of the SM3 algorithm is slow and the security is not high enough, making it difficult to meet the needs of large-scale data encryption.

Method used

Use the SHA-256 algorithm to hash the input data, and combine it with the SM3 algorithm for encryption. Through the combination of XOR operation, hybrid encryption algorithm and symmetric and asymmetric encryption algorithms, the encryption process is optimized and generated associated with the data to be encrypted. Unique key.

Benefits of technology

It improves encryption efficiency and security, and has flexible scalability to adapt to actual needs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118764209A_ABST
    Figure CN118764209A_ABST
Patent Text Reader

Abstract

The invention discloses a novel encryption method based on SM3 message digests, and relates to the field of information encryption. The implementation process of the method comprises the following steps of: performing hash processing on input data by adopting an SHA-256 algorithm to obtain a 256-bit hash value; encrypting the preprocessed hash value by adopting an SM3 algorithm to obtain a ciphertext; carrying out secondary encryption on the ciphertext by adopting a hybrid encryption algorithm; in the encryption process, generating a unique key associated with the to-be-encrypted data and the encryption algorithm; according to the encryption method provided by the technical scheme of the invention, on the basis of keeping the advantages of the SM3 algorithm, the selection of constants, the XOR operation process, the modular operation process and the secondary encryption process of the ciphertext are optimized and improved, the encryption efficiency and security are improved, and meanwhile, the encryption efficiency is improved. The method can be flexibly expanded and adjusted according to actual requirements, and has high practicability and expandability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of information encryption, and in particular to a novel encryption method based on SM3 message digest. Background Art

[0002] SM3 is a cryptographic hash function independently designed in my country. It is used for digital signature and verification, message authentication code generation and verification, and random number generation in commercial cryptographic applications. It can meet the security requirements of a variety of cryptographic applications.

[0003] Although the SM3 algorithm has high security, there are still the following problems in practical applications: low encryption algorithm efficiency: because the implementation of the SM3 algorithm involves a large number of bit operations and modular operations, the encryption speed is slow and cannot meet the needs of large-scale data encryption; insufficient security: although the SM3 algorithm has undergone multiple security tests, with the development of cryptography, its security still needs to be further improved. To this end, we propose a new encryption method based on the SM3 message digest. Summary of the invention

[0004] The main purpose of the present invention is to provide a new encryption method based on SM3 message digest, which can effectively solve the problems in the background technology.

[0005] In order to achieve the above object, the technical solution adopted by the present invention is:

[0006] A new encryption method based on SM3 message digest, including:

[0007] S1: Use the SHA-256 algorithm to hash the input data and obtain a 256-bit hash value;

[0008] S2: Use the SM3 algorithm to encrypt the preprocessed hash value to obtain the ciphertext. The specific details of the SM3 algorithm are as follows:

[0009]

[0010] In the formula, C represents the encryption result, and a, b, c, d, e, and f are all constants in the encryption process; Represented as an XOR operation, where the XOR operation The detailed description of the implementation process is as follows:

[0011] 1) Data segmentation

[0012] Split the input data into chunks based on the number of available processors or cores and the computational power of each processor;

[0013] 2) Parallel processor or core allocation

[0014] Assign a processor or core to each data block;

[0015] 3) XOR operation execution

[0016] On each processor or core, an XOR operation is performed independently on the assigned data block, calculated as follows:

[0017]

[0018] In the formula, A and B are two data blocks that need to be XORed; A i and B i are the values ​​of the i-th position in A and B respectively; C i is the value of the i-th position in the result C.

[0019] 4) Merge results

[0020] When all processors or cores have completed the XOR operation on their respective data blocks, the calculation results are merged to form the final XOR operation result;

[0021] Constants a, b, c, d, e, and f are all random numbers generated by a certified cryptographically secure random number generator;

[0022] S3: Use a hybrid encryption algorithm to perform secondary encryption on the ciphertext. The implementation process specifically includes the following steps:

[0023] S31: input plain text M and key K;

[0024] S32: Perform a hash operation on the plaintext M to obtain a hash value H(M), which is calculated as follows:

[0025] H(M)=(a*M+b)modm

[0026] Where m is a constant, and m is the modulus of a raised to the power of b. The constant m is calculated using a fast power algorithm with a time complexity of O(log b). The calculation process includes the following steps:

[0027] 1) Initialization: Set the result variable res to 1 and pow to the required power, i.e. the constant b;

[0028] 2) Processing exponent: Represent pow in binary form;

[0029] 3) Square and modular operation: multiply the base a by itself, then perform the modular operation, and repeat this step until all the binary bits of pow are processed;

[0030] 4) Result update: If the current processed binary bit is 1, multiply the result res by the current a and perform a modulo operation;

[0031] 5) Iteration: In each iteration, pow is shifted right by one position, a is squared modulo operation is performed, and res is updated;

[0032] 6) Output result: When pow becomes 0, the iteration ends and res is the final result;

[0033] The optimal choice of modulus m includes the following strategies:

[0034] 1) Select a prime number;

[0035] 2) Choose a power of 2;

[0036] 3) Avoid large modulus;

[0037] 4) Consider the factors of the modulus;

[0038] S33: Use a symmetric encryption algorithm to encrypt the hash value H(M) to obtain a symmetric encrypted ciphertext E1, and the calculation formula is: E1=E[K,H(M)], where K is the key;

[0039] S34: Use an asymmetric encryption algorithm to encrypt the key K to obtain an asymmetric encrypted ciphertext E2, calculated as follows: E2 = E(PK, K), where PK is the public key;

[0040] S35: concatenate E1 and E2 together to obtain the final ciphertext C;

[0041] S36: Output the ciphertext C and the asymmetric decryption key used for decryption;

[0042] S4: During the encryption process, a unique key associated with the data to be encrypted and the encryption algorithm is generated;

[0043] S5: Store or transmit the generated ciphertext and key.

[0044] The present invention has the following beneficial effects:

[0045] Compared with the prior art, the encryption method proposed in the technical solution of the present invention optimizes and improves the SM3 algorithm while retaining its advantages, thereby improving encryption efficiency and security. At the same time, the method can also be flexibly expanded and adjusted according to actual needs, and has high practicality and scalability. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] Figure 1 The present invention is a schematic diagram of the implementation process of a new encryption method based on SM3 message digest. DETAILED DESCRIPTION

[0047] The present invention will be further described below in conjunction with specific implementation methods, wherein the accompanying drawings are only used for exemplary descriptions and represent only schematic diagrams rather than actual drawings, and should not be understood as limiting the present invention. In order to better illustrate the specific implementation methods of the present invention, some parts of the accompanying drawings may be omitted, enlarged or reduced, and do not represent the size of the actual product.

[0048] In order to solve the above problems, we propose a new encryption method based on SM3 message digest. The implementation process is as follows: Figure 1 As shown. This method optimizes and improves the SM3 algorithm while retaining its advantages, thereby improving encryption efficiency and security. The implementation process is as follows:

[0049] 1. Hash the input data

[0050] The present invention uses the SHA-256 algorithm to preprocess the data. The following is a detailed description of the implementation process and related formulas of the SHA-256 algorithm:

[0051] 1.1 Data filling

[0052] First, the input data is padded so that its length meets certain conditions. SHA-256 requires that the length of the input data (in bits) modulo 512 is equal to 448. This means that the data needs to be padded to the nearest multiple of 512, and then 448 bits are subtracted.

[0053] Original data: Assume that the original data is M and the length is L bits.

[0054] Filling steps:

[0055] 1) Add a 1 bit, then add several 0s until the total length becomes L'=(L+1) mod 512-448 bits.

[0056] 2) Add a 64-bit representation of the original length L (big endian).

[0057] 1.2 Message Extension

[0058] Next, the padded message M' is divided into 512-bit blocks M i , and then perform message expansion to generate 64 32-bit words W t (t` from 0 to 63).

[0059] Message block: M i Denoted as the i-th block.

[0060] Word expansion: For each M i , do the following:

[0061] If t is less than or equal to i, Wt =M i ;

[0062] If t is greater than i, then:

[0063] W t = SHA256_Sigma1(W t-2 )+W t-7 +SHA256_Sigma0(W T-15 )+

[0064] W t-16 .

[0065] Here, SHA256_Sigma0 and SHA256_Sigma1 are two different functions, defined as follows:

[0066]

[0067] 1.3 Initialize hash value

[0068] The SHA-256 algorithm has 8 fixed initial hash values, which are 32-bit integers corresponding to eight different rounds.

[0069] H0=0x6a09e667

[0070] H1=0xbb67ae85

[0071] H2 = 0x3c6ef372

[0072] H3=0xa54ff53a

[0073] H4=0x510e527f

[0074] H5=0x9b05688c

[0075] H6=0x1f83d9ab

[0076] H7=0x5be0cd19

[0077] 1.4 Main Loop

[0078] For each message block M i , execute the following 64-step main loop. In each step, an auxiliary function SHA256_F is used, which is defined as follows:

[0079] SHA256_F(X,Y,Z)=(X&Y)|(~X&Z);

[0080] And two other auxiliary functions SHA256_G and SHA256_H, which are defined as follows:

[0081] SHA256_G(X,Y,Z)=(X&Z)|(Y&~Z)

[0082] SHA256_H(X,Y,Z)=X^Y^Z

[0083] There is also a function `SHA256_Maj` that will be used in the main loop, which is defined as follows:

[0084] SHA256_Maj(X,Y,Z)=(X&Y)^(X&Z)^(Y&Z)

[0085] Each round of the main loop uses these functions, as well as a function called `SHA256_Sigma1`, which is different from the `SHA256_Sigma0` function mentioned above and is defined as follows:

[0086] SHA256_Sigma1(X)=(X>>17|X<<15)^(X>>19|X<<13)^(X>>10)

[0087] 1.5 Output hash value

[0088] Finally, the results of all rounds are combined to obtain the final 256-bit hash value. This hash value is of fixed length and is highly sensitive to the input data. Even a small change will result in a significant change in the output hash value.

[0089] 2. Encrypt the hash value

[0090] The SM3 algorithm is used to encrypt the preprocessed hash value to obtain the ciphertext. During the encryption process, the SM3 algorithm is optimized to improve the encryption efficiency and security.

[0091] The SM3 encryption algorithm is as follows:

[0092] C=M⊕[(a*(M⊕b)⊕c)⊕d]⊕e⊕f

[0093] This formula represents a series of encryption operations on M, including XOR operation and encryption operation. Among them, ⊕ represents XOR operation, and a, b, c, d, e and f are constants in the encryption process.

[0094] 2.1 Selection and optimization of constants

[0095] In encryption algorithms, it is very important to choose the appropriate constants a, b, c, d, e, and f. These constants should be carefully selected and tested to ensure that they not only provide adequate security but also optimize computational efficiency. Choose a certified cryptographically secure random number generator (CSPRNG) for random number generation.

[0096] 2.2 Optimization of XOR Operation

[0097] XOR operation ⊕ is a basic bitwise operation that has a wide range of applications in fields such as encryption and error detection. In XOR operation, the corresponding bits of two binary numbers are compared, and the result is 0 if they are the same, and 1 if they are different. The implementation process of XOR operation can be described in detail as follows, especially the optimization when processing large amounts of data in parallel:

[0098] 1) Data segmentation

[0099] First, the input data is split into multiple chunks. The size of these chunks can be determined based on the number of processors or cores available and the computational power of each processor. For example, if there are 4 processors, the data can be split into 4 equal chunks, with each processor processing one chunk.

[0100] 2) Parallel processor or core allocation

[0101] Assign a processor or core to each block of data. In a multi-core processor or multi-processor system, this can be done automatically by the operating system's scheduling mechanism, or it can be managed manually by writing specific parallel computing code.

[0102] 3) XOR operation execution

[0103] On each processor or core, the XOR operation is performed independently on the assigned data block. If there are two data blocks A and B that need to be XORed, the result C can be calculated as follows:

[0104]

[0105] Among them, A i and B i are the values ​​of the i-th position in A and B, respectively, and C i is the value of the i-th position in the result C.

[0106] 4) Merge results

[0107] Once all processors or cores have completed the XOR operation on their respective blocks of data, the results need to be combined. This usually involves collecting the output of each processor and combining them into the final XOR result.

[0108] 2.3 Modular Operation Optimization

[0109] To optimize modular operations, we can take the following measures:

[0110] 2.3.1 Using the Fast Power Algorithm

[0111] The fast power algorithm is an efficient method for calculating a raised to the power of b modulo m, with a time complexity of O(log b). The following are the basic steps of the fast power algorithm:

[0112] 1) Initialization: Set the result variable res to 1 (this is the final product result) and pow to the number to be raised to the power (i.e. the constant b).

[0113] 2) Processing exponent: Represent pow in binary form so that it can be processed bit by bit.

[0114] 3) Square and modular operation: multiply the base a by itself, and then perform the modular operation. Repeat this step until all the binary bits of pow are processed.

[0115] 4) Result update: If the currently processed binary bit is 1, multiply the result res by the current a and perform a modulo operation.

[0116] 5) Iteration: Each iteration shifts pow right by one position (equivalent to division by 2), performs a square modulo operation, and updates res (if necessary).

[0117] 6) Output result: When pow becomes 0, the iteration ends and res is the final result.

[0118] The pseudo code of the fast power algorithm is as follows:

[0119] funct i onmod_pow(a,pow,m):

[0120] res=1

[0121] a=a%m

[0122] when epow>0:

[0123] ifpow%2==1:

[0124] res=(res*a)%m

[0125] a=(a*a)%m

[0126] pow=pow / / 2

[0127] returnres

[0128] 2.3.3 Optimizing module selection

[0129] Choosing the right modulus m is crucial to improving the efficiency of modular operations. Here are some strategies to optimize modulus selection:

[0130] 1) Choose prime numbers: Prime numbers as moduli can prevent certain types of modular arithmetic attacks and can simplify calculations in some algorithms.

[0131] 2) Choose a power of 2: Operations modulo powers of 2 can be implemented using bitwise operations, which are very efficient on most hardware. For example, a mod 2 k It can be achieved through a&(2 k -1) to complete.

[0132] 3) Avoid large moduli: Large moduli may lead to waste of computational resources, especially when they are much larger than the size of the operands.

[0133] 4) Consider the factors of the modulus: In some cases, knowing the factors of the modulus can help us design more efficient algorithms. For example, if the modulus can be decomposed into the product of two smaller coprime factors, we can perform the modular operation separately and then combine the results.

[0134] By combining a fast exponentiation algorithm and optimizing the choice of modulus, we can significantly improve the efficiency of modular operations, which is very important for cryptographic algorithms and other applications that require frequent modular operations. These optimizations can improve performance and responsiveness while maintaining the security of the algorithm.

[0135] 3. Perform secondary encryption on the ciphertext: In order to further improve security, a new hybrid encryption algorithm is used to perform secondary encryption on the ciphertext. This algorithm combines the advantages of symmetric encryption algorithms and asymmetric encryption algorithms, which not only ensures encryption speed but also improves security. The encryption algorithm implementation process is as follows:

[0136] 1) Input plaintext M and key K;

[0137] 2) Perform a hash operation on the plaintext M to obtain a hash value H(M);

[0138] 3) Use the symmetric encryption algorithm to encrypt the hash value H(M) to obtain the symmetric encrypted ciphertext E1;

[0139] 4) Using an asymmetric encryption algorithm to encrypt the key K, obtaining an asymmetric encrypted ciphertext E2;

[0140] 5) Concatenate E1 and E2 together to obtain the final ciphertext C;

[0141] 6) Output the ciphertext C and the asymmetric decryption key used for decryption.

[0142] The relevant formula of the algorithm is as follows:

[0143] Hash operation formula: H(M) = (a*M+b)modm, where M is the plaintext, and a, b, and m are constants;

[0144] Symmetric encryption algorithm formula: E1 = E(K, H(M)), where K is the symmetric key and H(M) is the hash value;

[0145] Asymmetric encryption algorithm formula: E2=E(PK,K), where PK is the public key and K is the secret key.

[0146] 4. Generate key: During the encryption process, a unique key is generated. This key is associated with the encrypted data and the encryption algorithm, ensuring the security of encryption.

[0147] 5. Output ciphertext and key: Store or transmit the generated ciphertext and key for subsequent decryption.

[0148] The above shows and describes the basic principles and main features of the present invention and the advantages of the present invention. It should be understood by those skilled in the art that the present invention is not limited to the above embodiments. The above embodiments and descriptions are only for explaining the principles of the present invention. Without departing from the spirit and scope of the present invention, the present invention may have various changes and improvements, which fall within the scope of the present invention to be protected. The scope of protection of the present invention is defined by the attached claims and their equivalents.

Claims

1. A new encryption method based on SM3 message digest, characterized in that: include: S1: Use the SHA-256 algorithm to hash the input data and obtain a 256-bit hash value; S2: Use the SM3 algorithm to encrypt the preprocessed hash value to obtain the ciphertext; S3: Use a hybrid encryption algorithm to encrypt the ciphertext twice; S4: During the encryption process, a unique key associated with the data to be encrypted and the encryption algorithm is generated; S5: Store or transmit the generated ciphertext and key.

2. A novel encryption method based on SM3 message digest according to claim 1, characterized in that: In step S3, the implementation process of the hybrid encryption algorithm is as follows: S31: input plain text M and key K; S32: Perform a hash operation on the plaintext M to obtain a hash value H(M), which is calculated as follows: H(M)=(a*M+b)mod m Where m is a constant, and m is the modulus of a raised to the power of b; S33: Use a symmetric encryption algorithm to encrypt the hash value H(M) to obtain a symmetric encrypted ciphertext E1, and the calculation formula is: E1=E[K,H(M)], where K is the key; S34: Use an asymmetric encryption algorithm to encrypt the key K to obtain an asymmetric encrypted ciphertext E2, calculated as follows: E2 = E(PK, K), where PK is the public key; S35: concatenate E1 and E2 together to obtain the final ciphertext C; S36: Output the ciphertext C and the asymmetric decryption key used for decryption.

3. A novel encryption method based on SM3 message digest according to claim 1, characterized in that: In step S2, the SM3 algorithm is specifically as follows: In the formula, C represents the encryption result, and a, b, c, d, e, and f are all constants in the encryption process; Represents an XOR operation.

4. A novel encryption method based on SM3 message digest according to claim 3, characterized in that: The constants a, b, c, d, e, and f in the encryption process are all random numbers generated by a certified cryptographically secure random number generator.

5. A novel encryption method based on SM3 message digest according to claim 2, characterized in that: The constant m is calculated using the fast power algorithm with a time complexity of O(log b). The calculation process includes the following steps: 1) Initialization: Set the result variable res to 1 and pow to the required power, i.e. the constant b; 2) Processing exponent: Represent pow in binary form; 3) Square and modular operation: multiply the base a by itself, then perform the modular operation, and repeat this step until all the binary bits of pow are processed; 4) Result update: If the current processed binary bit is 1, multiply the result res by the current a and perform a modulo operation; 5) Iteration: In each iteration, pow is shifted right by one position, a is squared modulo operation is performed, and res is updated; 6) Output result: When pow becomes 0, the iteration ends and res is the final result.

6. A novel encryption method based on SM3 message digest according to claim 2, characterized in that: The optimal choice of modulus m includes the following strategies: 1) Select a prime number; 2) Choose a power of 2; 3) Avoid large modulus; 4) Consider the factors of the modulus.

7. A novel encryption method based on SM3 message digest according to claim 3, characterized in that: XOR operation The detailed description of the implementation process is as follows: 1) Data segmentation Split the input data into chunks based on the number of available processors or cores and the computational power of each processor; 2) Parallel processor or core allocation Assign a processor or core to each data block; 3) XOR operation execution On each processor or core, an XOR operation is performed independently on the assigned data block, calculated as follows: In the formula, A and B are two data blocks that need to be XORed; A i and B i are the values ​​of the i-th position in A and B respectively; C i is the value of the i-th position in the result C. 4) Result merging When all processors or cores have completed the XOR operation on their respective data blocks, the calculation results are merged to form the final XOR operation result.

Citation Information

Cited By

  • Electric power communication network transmission optimization system based on Internet of Things

    CN119995997A