Data encryption method and device, data decryption method and device, equipment and medium
Through the combination of post-quantum key packaging and symmetric encryption algorithms, the problem that post-quantum key packaging algorithm cannot replace the SM2 algorithm is solved, and the encryption and integrity protection of plain text data of arbitrary length is achieved. The function is the same as that of SM2, reducing the development cost of the business system.
Patent Information
- Application Number
- CN202411900399.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-23
- Publication Date
- 2025-03-21
- Estimated Expiration
- 2044-12-23
AI Technical Summary
The existing post-quantum key packaging algorithm cannot directly replace the SM2 algorithm, and cannot achieve encryption and integrity protection of plaintext data of any length.
Through the combination of the post-quantum key packaging algorithm and the post-quantum symmetric encryption algorithm, the first ciphertext and packaging key are generated, and the first hash value is obtained by using the cipher hash function, and the key is split into the symmetric key, the initial vector and the key hash message authentication code function, and the encryption and decryption operations are performed, and the hash value is generated and verified through the key hash message authentication code function.
Asymmetric encryption of plain text data of any length is realized, integrity protection is provided, and its functionality is the same as that of the SM2 public key encryption algorithm. It can replace the existing SM2 algorithm business system and reduce the development costs brought by post-quantum migration.
Smart Images

Figure CN119675864A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data encryption, and in particular to a data encryption method, a data decryption method, a device, a equipment and a medium. Background Art
[0002] At present, the common integrated encryption scheme is SM2 (Elliptic Curve Based Public Key Cryptography Algorithm) public key encryption algorithm. SM2 public key encryption algorithm is an integrated encryption scheme based on ECDLP (Elliptic Curve Discrete Logarithm Problem), which is a variant of ECIES (elliptic curve integrate encrypt scheme). By combining with SM3 algorithm, the same curve points are used to derive bit strings, which are encrypted by XORing the bit strings and plaintext. Finally, the hash values of the curve points and messages are calculated as the basis for integrity verification. When the decryption oracle detects that the integrity is destroyed, it will refuse to output any information. SM2 algorithm can encrypt plaintext data of any length and provide integrity protection, and the overall security reaches IND-CCA. However, with the rapid development of quantum computers, the discrete logarithm problem (ECDLP) based on elliptic curves is facing attacks with quantum computing advantages, and the SM2 algorithm based on ECDLP can be broken by quantum computers. Therefore, cryptographic applications such as security protocols and cryptographic devices that previously used SM2 algorithm need to be replaced with post-quantum secure asymmetric algorithms.
[0003] At present, the academic and industrial circles have proposed a variety of asymmetric post-quantum algorithms based on different theoretical bodies to replace existing algorithms, such as the Kyber algorithm and LAC algorithm (Lattice-based Cryptography) based on the lattice system, and the HQC (Hamming Quasi-Cyclic) algorithm based on coding theory. In order to meet the IND-CCA (Indistinguishability under Chosen Ciphertext Attack) security conditions, the design idea of most mainstream algorithms (such as Kyber, LAC, HQC, etc.) is to first construct an IND-CPA (Indistinguishability under Chosen Plaintext Attack) secure post-quantum public key encryption scheme, and then use Fujisaki-Okamoto transformation to convert it into an IND-CCA secure post-quantum key encapsulation algorithm. The biggest difference between the key encapsulation algorithm and the public key encryption algorithm is that the data encrypted by the key encapsulation each time is a random number, while the public key encryption algorithm can encrypt specified data. At the same time, in order to prevent attackers from obtaining information from the decryption oracle, most post-quantum KEM (Key Encapsulation Mechanism) algorithms do not provide return value information on whether the decapsulation is successful during the decapsulation phase. In other words, the current post-quantum key encapsulation algorithm cannot directly replace the SM2 algorithm. Therefore, how to build an integrated encryption method with the same functionality as SM2 is an urgent problem to be solved. Summary of the invention
[0004] In view of this, the purpose of the present invention is to provide a data encryption method, a data decryption method, a device, an apparatus and a medium, which can construct an integrated encryption method with the same functionality as SM2 and realize encryption of plaintext data of any length. The specific scheme is as follows:
[0005] In a first aspect, the present application provides a data encryption method, which is applied to an encryption party, comprising:
[0006] Obtain a public key generated by a decryption party, generate a first ciphertext and a packaging key using a post-quantum key packaging algorithm and the public key, and input the first ciphertext and the packaging key into a cryptographic hash function to obtain a first hash value output by the cryptographic hash function;
[0007] Splitting the first hash value into a symmetric key, an initial vector, and a key of a key-hash message authentication code function, encrypting plaintext data using the symmetric key and the initial vector to obtain a corresponding second ciphertext;
[0008] Obtaining a corresponding second hash value according to the key of the key-hash message authentication code function, the plaintext data, and the key-hash message authentication code function;
[0009] The second hash value, the first ciphertext and the second ciphertext are concatenated to obtain a corresponding encrypted ciphertext, and the encrypted ciphertext is sent to the decryption party so that the decryption party decrypts the encrypted ciphertext.
[0010] Optionally, the encrypting the plaintext data by using the symmetric key and the initial vector to obtain the corresponding second ciphertext includes:
[0011] The plaintext data is encrypted accordingly using the symmetric key and the initial vector according to a preset encryption mode to obtain a corresponding second ciphertext; the encryption mode includes a ciphertext group linking mode and an authenticated encryption mode.
[0012] Optionally, encrypting the plaintext data using the symmetric key and the initial vector according to a preset encryption mode to obtain a corresponding second ciphertext includes:
[0013] If the encryption mode is the ciphertext block chaining mode, determining whether the length corresponding to the plaintext data meets the condition of the post-quantum symmetric encryption algorithm block length;
[0014] If the conditions are met, directly encrypt the plaintext data using the symmetric key and the initial vector to obtain the second ciphertext;
[0015] If not, a padding operation is performed on the plaintext data, and after the length corresponding to the plaintext data after padding meets the condition of the post-quantum symmetric encryption algorithm packet length, the padded plaintext data is correspondingly encrypted using the symmetric key and the initial vector to obtain the second ciphertext.
[0016] Optionally, encrypting the plaintext data using the symmetric key and the initial vector according to a preset encryption mode to obtain a corresponding second ciphertext includes:
[0017] If the encryption mode is the authenticated encryption mode, the plaintext data is encrypted accordingly based on the authenticated encryption mode, the symmetric key and the initial vector to obtain a corresponding second ciphertext.
[0018] In a second aspect, the present application provides a data decryption method, which is applied to a decryption party, comprising:
[0019] Receiving the encrypted ciphertext sent by the encryption party, splitting the encrypted ciphertext to obtain a first ciphertext, a second ciphertext, and a second hash value, decrypting the first ciphertext using a private key of a post-quantum key encapsulation algorithm to obtain a corresponding encapsulation key;
[0020] Inputting the first ciphertext and the encapsulation key into a cryptographic hash function, obtaining a first hash value output by the cryptographic hash function, and splitting the first hash value to obtain a symmetric key, an initialization vector, and a key of a key-hash message authentication code function;
[0021] Decrypting the second ciphertext using the symmetric key, the initial vector, and a post-quantum symmetric cryptographic algorithm to obtain plaintext data;
[0022] A target hash value is generated based on the plaintext data, the key of the key-hash message authentication code function, and the key-hash message authentication code function, and it is determined whether the target hash value is consistent with the second hash value. According to the corresponding determination result, corresponding information is output to complete data decryption.
[0023] Optionally, the determining whether the target hash value is consistent with the second hash value, and outputting corresponding information according to a corresponding determination result, includes:
[0024] If the target hash value is consistent with the second hash value, outputting the plaintext data;
[0025] If the target hash value is inconsistent with the second hash value, a corresponding error message is output and the process ends directly.
[0026] In a third aspect, the present application provides a data encryption device, which is applied to an encryption party, including:
[0027] A first hash value acquisition module is used to obtain a public key generated by a decryption party, generate a first ciphertext and a packaging key using a post-quantum key encapsulation algorithm and the public key, and input the first ciphertext and the packaging key into a cryptographic hash function to obtain a first hash value output by the cryptographic hash function;
[0028] A second ciphertext acquisition module is used to split the first hash value into a symmetric key, an initial vector, and a key of a key-hash message authentication code function, encrypt the plaintext data using the symmetric key and the initial vector, and obtain a corresponding second ciphertext;
[0029] A second hash value acquisition module, configured to acquire a corresponding second hash value according to a key of the key-hash message authentication code function, the plaintext data, and the key-hash message authentication code function;
[0030] The encrypted ciphertext acquisition module is used to concatenate the second hash value, the first ciphertext and the second ciphertext to obtain the corresponding encrypted ciphertext, and send the encrypted ciphertext to the decryption party so that the decryption party can decrypt the encrypted ciphertext.
[0031] In a fourth aspect, the present application provides a data decryption device, which is applied to a decryption party, comprising:
[0032] The encapsulation key acquisition module is used to receive the encrypted ciphertext sent by the encryption party, split the encrypted ciphertext to obtain a first ciphertext, a second ciphertext and a second hash value, and decrypt the first ciphertext using a private key of the post-quantum key encapsulation algorithm to obtain a corresponding encapsulation key;
[0033] A first hash value splitting module, configured to input the first ciphertext and the encapsulation key into a cryptographic hash function, obtain a first hash value output by the cryptographic hash function, and split the first hash value to obtain a symmetric key, an initialization vector, and a key of a key-hash message authentication code function;
[0034] An encrypted ciphertext decryption module, used to decrypt the second ciphertext using the symmetric key, the initial vector and a post-quantum symmetric cryptographic algorithm to obtain plaintext data;
[0035] An information output module is used to generate a target hash value based on the plaintext data, the key of the key-hash message authentication code function, and the key-hash message authentication code function, determine whether the target hash value is consistent with the second hash value, and output corresponding information according to the corresponding determination result to complete data decryption.
[0036] In a fifth aspect, the present application provides an electronic device, including:
[0037] Memory, used to store computer programs;
[0038] The processor is used to execute the computer program to implement the aforementioned method.
[0039] In a sixth aspect, the present application provides a computer-readable storage medium for storing a computer program; wherein, the computer program implements the aforementioned method when executed by a processor.
[0040] To summarize, when performing data encryption, the present application first obtains a public key produced by a decryption party, uses a post-quantum key encapsulation algorithm and the public key to generate a first ciphertext and an encapsulation key, inputs the first ciphertext and the encapsulation key into a cryptographic hash function to obtain a first hash value output by the cryptographic hash function; splits the first hash value into a symmetric key, an initial vector, and a key of a key-hash message authentication code function, uses the symmetric key and the initial vector to encrypt plaintext data to obtain a corresponding second ciphertext; obtains a corresponding second hash value according to the key of the key-hash message authentication code function, the plaintext data, and the key-hash message authentication code function; concatenates the second hash value, the first ciphertext, and the second ciphertext to obtain a corresponding encrypted ciphertext, and sends the encrypted ciphertext to the decryption party so that the decryption party can decrypt the encrypted ciphertext. It can be seen that the present application generates a first ciphertext and a packaging key based on the public key produced by the decryption party, and obtains the corresponding first hash value through the first ciphertext and the packaging key, decomposes the first hash value to obtain the symmetric key, the initial vector and the key of the key hash message authentication code function, and then encrypts the encrypted information based on the symmetric key and the initial vector to generate a second ciphertext, generates a second hash value according to the key of the key hash message authentication code function and the information to be encrypted, and finally, splices the first ciphertext, the second ciphertext and the second hash value to complete the encryption. That is, the present application can asymmetrically encrypt plaintext of any length through the combination of the post-quantum key packaging algorithm and the post-quantum symmetric encryption algorithm, and is functionally the same as the SM2 public key encryption algorithm. The method of the present application can replace the current business system using the SM2 public key encryption algorithm, avoiding the redesign of the cryptographic protocol for the post-quantum algorithm and reducing the business system development cost caused by the post-quantum migration. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0042] Figure 1 A flow chart of a data encryption method disclosed in this application;
[0043] Figure 2 A flow chart of a first hash value generating method disclosed in the present application;
[0044] Figure 3 A flow chart of a plaintext data encryption method disclosed in this application;
[0045] Figure 4 A flow chart of a data decryption method disclosed in this application;
[0046] Figure 5 A flow chart of a method for splitting encrypted ciphertext disclosed in this application;
[0047] Figure 6 A flow chart of a method for obtaining a first hash value disclosed in the present application;
[0048] Figure 7 A flow chart of a second ciphertext decryption method disclosed in this application;
[0049] Figure 8 A flow chart of a target hash value verification method disclosed in this application;
[0050] Fig. 9 A schematic diagram of the structure of a data encryption device disclosed in this application;
[0051] Fig.10 This is a schematic diagram of the structure of a data decryption device disclosed in this application;
[0052] Fig.11 This is a structural diagram of an electronic device disclosed in this application. DETAILED DESCRIPTION
[0053] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0054] At present, the data actually encrypted by post-quantum asymmetric algorithms is limited, and in many cryptographic application scenarios, it is impossible to achieve functionality similar to SM2. Most post-quantum asymmetric algorithms do not provide native integrity protection, and other cryptographic technologies are required to implement this function. Existing post-quantum algorithms cannot meet the asymmetric encryption requirements of typical cryptographic application systems such as certificate systems, IPSEC, and key management systems. The business systems that originally used national secret algorithms need to make a lot of changes based on the characteristics of post-quantum algorithms. In order to solve the above technical problems, the present application discloses a data encryption method, a data decryption method, an apparatus, a device, and a medium, which can construct an integrated encryption method with the same functionality as SM2 to achieve encryption of plaintext data of any length.
[0055] See also Figure 1 As shown, an embodiment of the present invention discloses a data encryption method, which is applied to an encryption party and includes:
[0056] Step S11, obtaining a public key generated by a decryption party, using a post-quantum key encapsulation algorithm and the public key to generate a first ciphertext and an encapsulation key, and inputting the first ciphertext and the encapsulation key into a cryptographic hash function to obtain a first hash value output by the cryptographic hash function.
[0057] In this embodiment, it is first necessary to obtain the public key generated by the decryption party. The decryption party generates a pair of keys, including a public key and a private key. After the sender obtains the public key from the decryption party, it uses the post-quantum key encapsulation algorithm and the public key to generate the first ciphertext and the encapsulation key. The encapsulation key is a shared key used by the sender and the decryption party for symmetric encrypted communication, and the first ciphertext is the result output by the post-quantum key encapsulation algorithm.
[0058] In this embodiment, the encryption party passes the generated first ciphertext and encapsulation key as input to the cryptographic hash function. The cryptographic hash function processes the first ciphertext and the encapsulation key to generate an output of a fixed length, namely, a first hash value. Among them, the cryptographic hash function includes but is not limited to SHA2-512 (Secure Hash Algorithm2 512-bit, secure hash algorithm) and SHA-3 (Secure Hash Algorithm 3, third-generation secure hash algorithm). The first hash value output by the cryptographic hash function can be used for subsequent data verification, integrity check or encryption operations. As a result, post-quantum key encapsulation ensures that the security of communication is still guaranteed under the threat of quantum computing, and the cryptographic hash function further ensures the integrity and consistency of the data.
[0059] In a specific implementation, the post-quantum key encapsulation algorithm is defined as KEM, and its key encapsulation function is defined as ,in is the ciphertext output by the key encapsulation function, is the wrapped key, is the public key of the KEM algorithm. After obtaining the public key generated by the decryption party, Figure 2 As shown, the KEM public key Input the post-quantum KEM function to obtain the KEM ciphertext and KEM encapsulation key, i.e. the first ciphertext With the wrapping key , then, the first ciphertext With the wrapping key Enter the password hash function and get the first hash value .
[0060] Step S12: split the first hash value into a symmetric key, an initial vector, and a key of a key-hash message authentication code function, and use the symmetric key and the initial vector to encrypt the plaintext data to obtain a corresponding second ciphertext.
[0061] In this embodiment, after obtaining the first hash value, it needs to be split into three parts, namely, the symmetric key, the initial vector And the key of the keyed hash message authentication code function. This first hash value is a fixed-length output, usually 512 bits, which is divided in a predefined way. After the split is completed, the plaintext data is encrypted using the symmetric key and the initialization vector. Among them, the definition To integrate the plaintext that needs to be encrypted in the encryption task, The key of the symmetric algorithm. The plaintext data is encrypted by symmetric encryption algorithms such as AES (Advanced Encryption Standard) to ensure that the encrypted data is secure and random, thereby generating a second ciphertext. This second ciphertext can be transmitted securely. At the same time, due to the initial vector It can also serve as the key for the key-hashed message authentication code function and ensure data integrity and authentication requirements during the encryption process.
[0062] In this embodiment, after obtaining the symmetric key, the initial vector and the key of the key hash message authentication code function, the plaintext data is encrypted accordingly using the symmetric key and the initial vector according to the pre-set encryption mode to obtain the corresponding second ciphertext; the encryption mode includes the ciphertext block chaining mode and the authentication encryption mode. Specifically, the encryption mode can be the ciphertext block chaining mode (CBC, Cipher Block Chaining) and the authentication encryption (GCM, Galois / CounterMode) mode. In the ciphertext block chaining mode, the plaintext data is divided into several plaintext data groups during encryption, and each plaintext data group is XORed with the previous ciphertext group, which increases the security of the data. The initial vector is used to randomize the first plaintext data group to ensure that different ciphertexts are generated each time encryption. In the ciphertext block chaining mode, the second ciphertext is generated step by step by encrypting the plaintext data blocks in sequence. In the authentication encryption mode, in addition to encrypting the data, the authentication code of the message is also generated at the same time, thereby providing data integrity verification and authentication functions. The authentication encryption mode not only ensures confidentiality, but also ensures that the encrypted data has not been tampered with during transmission. In other words, different encryption modes can be selected according to actual needs to ensure that the data encryption process achieves a balance between security, authentication and performance, and ultimately obtain the corresponding second ciphertext.
[0063] In this embodiment, when the plaintext data is encrypted using the CBC mode, if the encryption mode is the ciphertext block chaining mode, it is determined whether the length corresponding to the plaintext data meets the condition of the block length of the post-quantum symmetric encryption algorithm; if it meets the condition, the plaintext data is directly encrypted using the symmetric key and the initial vector to obtain the second ciphertext; if it does not meet the condition, the plaintext data is padded, and after the length corresponding to the plaintext data after the corresponding padding meets the condition of the block length of the post-quantum symmetric encryption algorithm, the padded plaintext data is encrypted using the symmetric key and the initial vector to obtain the second ciphertext. Specifically, if the selected encryption mode is the ciphertext block chaining mode (CBC, Cipher BlockChaining), it is necessary to determine whether the length of the plaintext data meets the block length condition required by the post-quantum symmetric encryption algorithm. The post-quantum symmetric encryption algorithm usually requires the plaintext data to be encrypted in blocks of fixed length, so it is necessary to ensure that the length of the plaintext data meets the block length requirement. If the length of the plaintext data meets the block length condition, the plaintext data is directly encrypted using the symmetric key and the initial vector to generate the corresponding second ciphertext. At this point, no additional operations are required on the plaintext data, and the encryption process is gradually completed according to the relationship between each data block and the initial vector. If the length of the plaintext data does not meet the packet length condition, the plaintext data needs to be padded to make its length reach the packet length required by the post-quantum symmetric encryption algorithm. The padding operation is usually completed by adding a certain number of padding bytes at the end of the last group of plaintext data to ensure that its length is exactly a multiple of the packet length. After the padding operation, when the padded plaintext data meets the packet length requirement, the padded plaintext data is encrypted using the symmetric key and the initial vector to finally generate the second ciphertext. This embodiment can perform asymmetric encryption on plaintext of any length, and the HMAC algorithm constructed based on the post-quantum cryptographic hash algorithm provides integrity protection.
[0064] In this embodiment, when the plaintext data is encrypted using the GCM mode, if the encryption mode is the authenticated encryption mode, the plaintext data is encrypted accordingly based on the authenticated encryption mode, the symmetric key and the initial vector to obtain the corresponding second ciphertext. Specifically, if the encryption mode selects the authenticated encryption mode, the plaintext data is encrypted based on the authenticated encryption mode, the symmetric key and the initial vector to obtain the corresponding second ciphertext. In addition, if the GCM mode is used, it is necessary to set the additional data and the additional data length according to the content pre-negotiated by the encryption party and the decryption party, for example, the additional data is set to a null value and the additional data length is set to 0. In the authenticated encryption mode, encryption not only protects the confidentiality of the data, but also provides data integrity and authenticity verification. It can not only ensure the confidentiality of the data in transmission, but also provide additional security protection through the authenticated encryption mechanism to ensure that the data has not been tampered with and the source can be verified.
[0065] Step S13: Obtain a corresponding second hash value according to the key of the key-hash message authentication code function, the plaintext data and the key-hash message authentication code function.
[0066] In this embodiment, a corresponding second hash value is generated based on the key of the key-hash message authentication code function (HMAC), plaintext data and HMAC function. Specifically, HMAC is an authentication algorithm based on a cryptographic hash function and a key. First, the authentication key obtained by splitting in the previous step is used as the input key, combined with the plaintext data, and passed to the HMAC function. The HMAC function processes the key and data through multiple operation steps, including but not limited to internal and external padding, hash operations, etc., and finally generates an output value of a fixed length, namely the second hash value. The second hash value is mainly used to verify the integrity and authenticity of the data. During the communication process, the recipient can use the same HMAC key and plaintext data to calculate and generate a hash value through the HMAC function, and compare the value with the second hash value provided by the sender to confirm whether the data has been tampered with or forged during transmission. The process of obtaining the second ciphertext and the second hash value is as follows. Figure 3 shown.
[0067] Step S14: concatenate the second hash value, the first ciphertext, and the second ciphertext to obtain a corresponding encrypted ciphertext, and send the encrypted ciphertext to the decryption party so that the decryption party decrypts the encrypted ciphertext.
[0068] In this embodiment, the second hash value, the first ciphertext and the second ciphertext are concatenated to generate the final encrypted ciphertext. After the concatenation is completed, the generated encrypted ciphertext includes the hash value for verifying the integrity of the data, the first ciphertext for protecting the encapsulation key and the encrypted plaintext data. The encrypted ciphertext will be sent to the decryption party, and the decryption party will decrypt it after receiving the encrypted ciphertext.
[0069] It can be seen that the present application generates a first ciphertext and a packaging key based on the public key produced by the decryption party, and obtains the corresponding first hash value through the first ciphertext and the packaging key, decomposes the first hash value to obtain the symmetric key, the initial vector and the key of the key hash message authentication code function, and then encrypts the encrypted information based on the symmetric key and the initial vector to generate a second ciphertext, generates a second hash value according to the key of the key hash message authentication code function and the information to be encrypted, and finally, splices the first ciphertext, the second ciphertext and the second hash value to complete the encryption. That is, the present application can asymmetrically encrypt plaintext of any length through the combination of the post-quantum key packaging algorithm and the post-quantum symmetric encryption algorithm, and is functionally the same as the SM2 public key encryption algorithm. The method of the present application can replace the current business system using the SM2 public key encryption algorithm, avoiding the redesign of the cryptographic protocol for the post-quantum algorithm and reducing the business system development cost caused by the post-quantum migration.
[0070] See also Figure 4 As shown, an embodiment of the present invention discloses a data decryption method, which is applied to a decryption party and includes:
[0071] Step S21, receiving the encrypted ciphertext sent by the encryption party, splitting the encrypted ciphertext to obtain a first ciphertext, a second ciphertext and a second hash value, decrypting the first ciphertext using a private key of a post-quantum key encapsulation algorithm, and obtaining a corresponding encapsulation key.
[0072] In this embodiment, the encrypted ciphertext sent by the encryption party is first received, and then the encrypted ciphertext is split to obtain the first ciphertext, the second ciphertext and the second hash value, such as Figure 5 As shown. The encrypted ciphertext is formed by splicing these three parts of data, so the decryption party splits it into corresponding parts according to a predetermined order or protocol. After the split is completed, the private key of the post-quantum key encapsulation algorithm held by it is used to decrypt the first ciphertext split out. Among them, the decapsulation algorithm is defined as ,in for The first ciphertext is generated by the post-quantum key encapsulation algorithm during the encryption process, which protects the security of the encapsulation key. The first ciphertext is decrypted using the post-quantum private key to recover the encapsulation key generated during the encryption process. The encapsulation key is the core key for subsequent decryption. This embodiment will use the encapsulation key to further decrypt the second ciphertext and recover the plaintext data.
[0073] Step S22: input the first ciphertext and the encapsulation key into a cryptographic hash function, obtain a first hash value output by the cryptographic hash function, and split the first hash value to obtain a symmetric key, an initialization vector, and a key of a key-hash message authentication code function.
[0074] In this embodiment, the decryption party inputs the first ciphertext and the encapsulation key into a cryptographic hash function to generate a corresponding first hash value. A cryptographic hash function is an algorithm that maps input data to a fixed-length output value. By taking the first ciphertext and the encapsulation key as input, a unique and irreversible first hash value is generated. Then, the decryption party splits the generated first hash value to obtain the symmetric key, initial vector, and And the key for the keyed hash message authentication code function. The symmetric key will be used to subsequently decrypt the second ciphertext, the initialization vector provides randomness for symmetric encryption to enhance security, and the HMAC key is used to verify the integrity and authenticity of the data, such as Figure 6 shown.
[0075] Step S23: Decrypt the second ciphertext using the symmetric key, the initial vector and a post-quantum symmetric cryptographic algorithm to obtain plaintext data.
[0076] In this embodiment, the post-quantum symmetric cryptographic algorithm uses the extracted symmetric key and initial vector As input. The decryption process is carried out through the decryption operation of the algorithm, and the second ciphertext is gradually restored to the original plaintext data. The design of the post-quantum symmetric cryptographic algorithm is to resist the threat of quantum computing and provide stronger security. In this embodiment, the second ciphertext is restored to the original plaintext data, and the initial vector ensures the randomness and security of the decryption, so that the complete plaintext data is finally obtained. The specific process is as follows Figure 7 shown.
[0077] Step S24: generating a target hash value based on the plaintext data, the key of the key-hash message authentication code function, and the key-hash message authentication code function, determining whether the target hash value is consistent with the second hash value, and outputting corresponding information according to the corresponding determination result to complete data decryption.
[0078] In this embodiment, after the target hash value is generated based on the plaintext data, the key of the key-hash message authentication code function, and the key-hash message authentication code function, the present application will first determine whether the target hash value is consistent with the second hash value. If the target hash value is consistent with the second hash value, the plaintext data is output; if the target hash value is inconsistent with the second hash value, the corresponding error message is output and the process ends directly. Specifically, the target hash value is calculated using the key-hash message authentication code function, the key of the key-hash message authentication code function, and the plaintext data. Then, the target hash value is compared with the second hash value split from the encrypted ciphertext. The integrity of the data during encryption and decryption is determined based on the comparison result. If the comparison result shows that the target hash value is consistent with the second hash value, it means that the data has not been tampered with during the transmission process, and the decryption party outputs the plaintext data obtained by decryption. At this point, the integrity of the data is guaranteed and the decryption is successfully completed. However, if the target hash value is inconsistent with the second hash value, it means that the data may be modified or damaged during transmission. The decryption party will output the corresponding error message to indicate the error and directly terminate the decryption operation. Through this judgment mechanism, the decryption party can effectively ensure the integrity and security of the data and respond quickly and terminate the processing when inconsistencies are found. The specific process is as follows: Figure 8 shown.
[0079] It can be seen that the embodiment of the present application obtains the first ciphertext, the second ciphertext and the second hash value by decrypting the encrypted ciphertext, and uses the private key to decrypt the first ciphertext, obtains the encapsulation key after decryption, obtains the first hash value based on the encapsulation key and the first ciphertext, and splits the first hash value to obtain the symmetric key, the initial vector and the key of the key-hash message authentication code function, and uses the symmetric key and the initial vector to decrypt the second ciphertext to obtain the plaintext data, and finally, compares the target hash value generated based on the plaintext data and the key of the key-hash message authentication code function with the second hash value for encryption verification. That is, the present application can decrypt plaintext data of any length, and determine whether to output the decrypted data by checking the consistency of the target hash value and the second hash value, thereby ensuring that the decrypted content is credible and has not been tampered with.
[0080] See also Fig. 9 As shown, an embodiment of the present invention discloses a data encryption device, which is applied to an encryption party, comprising:
[0081] A first hash value acquisition module 11 is used to obtain a public key generated by a decryption party, generate a first ciphertext and a packaging key using a post-quantum key encapsulation algorithm and the public key, and input the first ciphertext and the packaging key into a cryptographic hash function to obtain a first hash value output by the cryptographic hash function;
[0082] A second ciphertext acquisition module 12 is used to split the first hash value into a symmetric key, an initial vector, and a key of a key-hash message authentication code function, encrypt the plaintext data using the symmetric key and the initial vector, and obtain a corresponding second ciphertext;
[0083] A second hash value acquisition module 13, configured to acquire a corresponding second hash value according to the key of the key-hash message authentication code function, the plaintext data and the key-hash message authentication code function;
[0084] The encrypted ciphertext acquisition module 14 is used to concatenate the second hash value, the first ciphertext and the second ciphertext to obtain the corresponding encrypted ciphertext, and send the encrypted ciphertext to the decryption party so that the decryption party can decrypt the encrypted ciphertext.
[0085] It can be seen that the present application generates a first ciphertext and a packaging key based on the public key produced by the decryption party, and obtains the corresponding first hash value through the first ciphertext and the packaging key, decomposes the first hash value to obtain the symmetric key, the initial vector and the key of the key hash message authentication code function, and then encrypts the encrypted information based on the symmetric key and the initial vector to generate a second ciphertext, generates a second hash value according to the key of the key hash message authentication code function and the information to be encrypted, and finally, splices the first ciphertext, the second ciphertext and the second hash value to complete the encryption. That is, the present application can asymmetrically encrypt plaintext of any length through the combination of the post-quantum key packaging algorithm and the post-quantum symmetric encryption algorithm, and is functionally the same as the SM2 public key encryption algorithm. The method of the present application can replace the current business system using the SM2 public key encryption algorithm, avoiding the redesign of the cryptographic protocol for the post-quantum algorithm and reducing the business system development cost caused by the post-quantum migration.
[0086] In some specific embodiments, the second ciphertext obtaining module 12 may specifically include:
[0087] The first plaintext data encryption unit is used to encrypt the plaintext data accordingly using the symmetric key and the initial vector according to a preset encryption mode to obtain a corresponding second ciphertext; the encryption mode includes a ciphertext group linking mode and an authenticated encryption mode.
[0088] In some specific embodiments, the second ciphertext obtaining module 12 includes:
[0089] A length judgment unit, configured to judge whether the length corresponding to the plaintext data satisfies the condition of the post-quantum symmetric encryption algorithm block length if the encryption mode is the ciphertext block chaining mode;
[0090] A second plaintext data encryption unit, configured to directly use the symmetric key and the initial vector to encrypt the plaintext data accordingly if the conditions are met, to obtain the second ciphertext;
[0091] The plaintext data padding unit is used to perform padding operation on the plaintext data if the condition is not satisfied, and after the length corresponding to the plaintext data after the padding satisfies the condition of the block length of the post-quantum symmetric encryption algorithm, encrypt the plaintext data after the padding using the symmetric key and the initial vector to obtain the second ciphertext.
[0092] In some specific embodiments, the second ciphertext obtaining module 12 includes:
[0093] The authenticated encryption mode encryption unit is used to, if the encryption mode is the authenticated encryption mode, encrypt the plaintext data accordingly based on the authenticated encryption mode, the symmetric key and the initial vector to obtain a corresponding second ciphertext.
[0094] See also Fig.10 As shown, an embodiment of the present invention discloses a data decryption device, which is applied to a decryption party and includes:
[0095] The encapsulation key acquisition module 21 is used to receive the encrypted ciphertext sent by the encryption party, split the encrypted ciphertext to obtain a first ciphertext, a second ciphertext and a second hash value, and decrypt the first ciphertext using a private key of the post-quantum key encapsulation algorithm to obtain a corresponding encapsulation key;
[0096] A first hash value splitting module 22, configured to input the first ciphertext and the encapsulation key into a cryptographic hash function, obtain a first hash value output by the cryptographic hash function, and split the first hash value to obtain a symmetric key, an initialization vector, and a key of a key-hash message authentication code function;
[0097] The encrypted ciphertext decryption module 23 is used to decrypt the second ciphertext using the symmetric key, the initial vector and the post-quantum symmetric cryptographic algorithm to obtain plaintext data;
[0098] The information output module 24 is used to generate a target hash value based on the plaintext data, the key of the key-hash message authentication code function, and the key-hash message authentication code function, determine whether the target hash value is consistent with the second hash value, and output corresponding information according to the corresponding judgment result to complete data decryption.
[0099] It can be seen that the embodiment of the present application obtains the first ciphertext, the second ciphertext and the second hash value by decrypting the encrypted ciphertext, and uses the private key to decrypt the first ciphertext, obtains the encapsulation key after decryption, obtains the first hash value based on the encapsulation key and the first ciphertext, and splits the first hash value to obtain the symmetric key, the initial vector and the key of the key-hash message authentication code function, and uses the symmetric key and the initial vector to decrypt the second ciphertext to obtain the plaintext data, and finally, compares the target hash value generated based on the plaintext data and the key of the key-hash message authentication code function with the second hash value for encryption verification. That is, the present application can decrypt plaintext data of any length, and determine whether to output the decrypted data by checking the consistency of the target hash value and the second hash value, thereby ensuring that the decrypted content is credible and has not been tampered with.
[0100] In some specific embodiments, the information output module 24 may specifically include:
[0101] a plaintext data output unit, configured to output the plaintext data if the target hash value is consistent with the second hash value;
[0102] The error information output unit is used to output corresponding error information and directly end the process if the target hash value is inconsistent with the second hash value.
[0103] Furthermore, the present application also discloses an electronic device. Fig.11 This is a structural diagram of an electronic device 30 according to an exemplary embodiment. The content in the diagram cannot be regarded as any limitation on the scope of use of the present application.
[0104] Fig.11 The present invention provides a schematic diagram of the structure of an electronic device 30 provided in an embodiment of the present application. The electronic device 30 may specifically include: at least one processor 31, at least one memory 32, a power supply 33, a communication interface 34, an input / output interface 35, and a communication bus 36. The memory 32 is used to store a computer program, which is loaded and executed by the processor 31 to implement the relevant steps in the method disclosed in any of the aforementioned embodiments. In addition, the electronic device 30 in this embodiment may specifically be an electronic computer.
[0105] In this embodiment, the power supply 33 is used to provide working voltage for each hardware device on the electronic device 30; the communication interface 34 can create a data transmission channel between the electronic device 30 and the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface 35 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.
[0106] In addition, the memory 32 as a carrier for resource storage may be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon may include an operating system 321, a computer program 322, etc., and the storage method may be temporary storage or permanent storage.
[0107] The operating system 321 is used to manage and control the hardware devices and computer programs 322 on the electronic device 30, which can be Windows Server, Netware, Unix, Linux, etc. In addition to including computer programs that can be used to complete the method performed by the electronic device 30 disclosed in any of the aforementioned embodiments, the computer program 322 can further include computer programs that can be used to complete other specific tasks.
[0108] Furthermore, the present application also discloses a computer-readable storage medium for storing a computer program; wherein the computer program, when executed by a processor, implements the aforementioned disclosed method. The specific steps of the method can refer to the corresponding contents disclosed in the aforementioned embodiments, and will not be repeated here.
[0109] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0110] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0111] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0112] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0113] The technical solution provided by the present application is introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for general technicians in this field, according to the idea of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A data encryption method, characterized in that: Applicable to encryption, including: Obtain a public key generated by a decryption party, generate a first ciphertext and a packaging key using a post-quantum key packaging algorithm and the public key, and input the first ciphertext and the packaging key into a cryptographic hash function to obtain a first hash value output by the cryptographic hash function; Splitting the first hash value into a symmetric key, an initial vector, and a key of a key-hash message authentication code function, encrypting plaintext data using the symmetric key and the initial vector to obtain a corresponding second ciphertext; Obtaining a corresponding second hash value according to the key of the key-hash message authentication code function, the plaintext data, and the key-hash message authentication code function; The second hash value, the first ciphertext and the second ciphertext are concatenated to obtain a corresponding encrypted ciphertext, and the encrypted ciphertext is sent to the decryption party so that the decryption party decrypts the encrypted ciphertext.
2. The data encryption method according to claim 1, characterized in that: The step of encrypting the plaintext data by using the symmetric key and the initial vector to obtain a corresponding second ciphertext includes: The plaintext data is encrypted accordingly using the symmetric key and the initial vector according to a preset encryption mode to obtain a corresponding second ciphertext; the encryption mode includes a ciphertext group linking mode and an authenticated encryption mode.
3. The data encryption method according to claim 2, characterized in that: The step of encrypting the plaintext data using the symmetric key and the initial vector according to a preset encryption mode to obtain a corresponding second ciphertext includes: If the encryption mode is the ciphertext block chaining mode, determining whether the length corresponding to the plaintext data meets the condition of the post-quantum symmetric encryption algorithm block length; If the conditions are met, directly encrypt the plaintext data using the symmetric key and the initial vector to obtain the second ciphertext; If not, a padding operation is performed on the plaintext data, and after the length corresponding to the plaintext data after padding meets the condition of the post-quantum symmetric encryption algorithm packet length, the padded plaintext data is correspondingly encrypted using the symmetric key and the initial vector to obtain the second ciphertext.
4. The data encryption method according to claim 2, characterized in that: The step of encrypting the plaintext data using the symmetric key and the initial vector according to a preset encryption mode to obtain a corresponding second ciphertext includes: If the encryption mode is the authenticated encryption mode, the plaintext data is encrypted accordingly based on the authenticated encryption mode, the symmetric key and the initial vector to obtain a corresponding second ciphertext.
5. A data decryption method, characterized in that: Applicable to the decryption party, including: Receiving the encrypted ciphertext sent by the encryption party, splitting the encrypted ciphertext to obtain a first ciphertext, a second ciphertext, and a second hash value, decrypting the first ciphertext using a private key of a post-quantum key encapsulation algorithm to obtain a corresponding encapsulation key; Inputting the first ciphertext and the encapsulation key into a cryptographic hash function, obtaining a first hash value output by the cryptographic hash function, and splitting the first hash value to obtain a symmetric key, an initialization vector, and a key of a key-hash message authentication code function; Decrypting the second ciphertext using the symmetric key, the initial vector, and a post-quantum symmetric cryptographic algorithm to obtain plaintext data; A target hash value is generated based on the plaintext data, the key of the key-hash message authentication code function, and the key-hash message authentication code function, and it is determined whether the target hash value is consistent with the second hash value. According to the corresponding determination result, corresponding information is output to complete data decryption.
6. The data decryption method according to claim 5, characterized in that: The determining whether the target hash value is consistent with the second hash value, and outputting corresponding information according to the corresponding determination result, includes: If the target hash value is consistent with the second hash value, outputting the plaintext data; If the target hash value is inconsistent with the second hash value, a corresponding error message is output and the process ends directly.
7. A data encryption device, characterized in that: Applicable to encryption, including: A first hash value acquisition module is used to obtain a public key generated by a decryption party, generate a first ciphertext and a packaging key using a post-quantum key encapsulation algorithm and the public key, and input the first ciphertext and the packaging key into a cryptographic hash function to obtain a first hash value output by the cryptographic hash function; A second ciphertext acquisition module is used to split the first hash value into a symmetric key, an initial vector, and a key of a key-hash message authentication code function, encrypt the plaintext data using the symmetric key and the initial vector, and obtain a corresponding second ciphertext; A second hash value acquisition module, configured to acquire a corresponding second hash value according to a key of the key-hash message authentication code function, the plaintext data, and the key-hash message authentication code function; The encrypted ciphertext acquisition module is used to concatenate the second hash value, the first ciphertext and the second ciphertext to obtain the corresponding encrypted ciphertext, and send the encrypted ciphertext to the decryption party so that the decryption party can decrypt the encrypted ciphertext.
8. A data decryption device, characterized in that: Applicable to the decryption party, including: The encapsulation key acquisition module is used to receive the encrypted ciphertext sent by the encryption party, split the encrypted ciphertext to obtain a first ciphertext, a second ciphertext and a second hash value, and decrypt the first ciphertext using a private key of the post-quantum key encapsulation algorithm to obtain a corresponding encapsulation key; A first hash value splitting module, configured to input the first ciphertext and the encapsulation key into a cryptographic hash function, obtain a first hash value output by the cryptographic hash function, and split the first hash value to obtain a symmetric key, an initialization vector, and a key of a key-hash message authentication code function; An encrypted ciphertext decryption module, used to decrypt the second ciphertext using the symmetric key, the initial vector and a post-quantum symmetric cryptographic algorithm to obtain plaintext data; An information output module is used to generate a target hash value based on the plaintext data, the key of the key-hash message authentication code function, and the key-hash message authentication code function, determine whether the target hash value is consistent with the second hash value, and output corresponding information according to the corresponding determination result to complete data decryption.
9. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the method according to any one of claims 1 to 6.
10. A computer-readable storage medium, characterized in that: Used to store a computer program; wherein, when the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Database encryption method based on quantum random number and national cryptographic algorithm
CN110719160A
Strong authentication method and system based on quantum symmetric key
CN112311554A
Access control encryption and decryption method, device and system for post-quantum security
CN115348006A
Method for realizing end-to-end VoIP encryption communication based on quantum key pre-charging
CN115589288A
Digital security interconnection system architecture
CN118631865A