A data encryption method, a data decryption method, a device, an apparatus, and a medium
By combining post-quantum key encapsulation algorithm and symmetric encryption algorithm, an encryption method with the same function as SM2 public key encryption algorithm is generated, which solves the security problem of SM2 under quantum computer attack, realizes encryption of plaintext data of arbitrary length, and reduces the system modification cost of post-quantum migration.
Patent Information
- Application Number
- CN202411900399.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-23
- Publication Date
- 2025-12-19
- Estimated Expiration
- 2044-12-23
AI Technical Summary
The existing SM2 public-key encryption algorithm is not secure enough against quantum computer attacks and cannot be directly replaced by a post-quantum secure asymmetric algorithm. This results in large-scale modifications to existing business systems, and the post-quantum asymmetric algorithm cannot provide the same functionality as SM2.
The first ciphertext and the encapsulation key are generated using a post-quantum key encapsulation algorithm. The first hash value is obtained through a cryptographic hash function and split into a symmetric key, an initialization vector, and a key for the key hash message authentication code function. The plaintext data is encrypted using the symmetric key and the initialization vector to generate the second ciphertext. The second hash value is then concatenated with the first and second ciphertexts to form the encrypted ciphertext.
It achieves asymmetric encryption of plaintext data of arbitrary length, and is functionally the same as the SM2 public key encryption algorithm. This avoids large-scale changes to business systems caused by post-quantum migration and reduces development costs.
Smart Images

Figure CN119675864B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of data encryption, and in particular to a data encryption method, a data decryption method, a device, an apparatus and a medium. BACKGROUND
[0002] At present, a common integrated encryption scheme is an SM2 (a public key encryption algorithm based on an elliptic curve) public key encryption algorithm. The SM2 public key encryption algorithm is an integrated encryption scheme based on an ECDLP (Elliptic Curve Discrete Logarithm Problem), and is a variant of an ECIES (elliptic curve integrate encrypt scheme). The SM2 public key encryption algorithm derives a bit string by using the same curve point, encrypts by means of exclusive OR of the bit string and a plaintext, and finally calculates a hash value of the curve point and the message as a basis for checking integrity. When a decryption oracle detects that the integrity is destroyed, it will refuse to output any information. The SM2 algorithm can encrypt any length of plaintext data 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 an elliptic curve is faced with an attack of quantum computing advantage, and the SM2 algorithm based on the ECDLP can be broken by a quantum computer. Therefore, the security protocols, cryptographic devices and other cryptographic applications using the SM2 algorithm need to be replaced by a post-quantum secure asymmetric algorithm.
[0003] At present, the academic and industrial circles have proposed a plurality of asymmetric post-quantum algorithms based on different theories to replace existing algorithms, such as Kyber algorithm and LAC algorithm (Lattice-based Cryptography) based on lattice system, HQC (Hamming Quasi-Cyclic) algorithm based on coding theory, etc. In order to meet the IND-CCA (Indistinguishability under Chosen Ciphertext Attack) security condition, 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 key encapsulation encrypts the data as a random number each time, while the public key encryption algorithm can encrypt specified data. At the same time, in order to avoid attackers from obtaining information from the decryption oracle, most post-quantum KEM (Key Encapsulation Mechanism) algorithms do not provide return value information of whether the encapsulation is successful in the encapsulation stage. That is, the current post-quantum key encapsulation algorithm cannot directly replace the SM2 algorithm. Therefore, how to construct an integrated encryption method with the same functionality as SM2 is a problem to be solved at present. SUMMARY
[0004] Therefore, the purpose of the present application is to provide a data encryption method, a data decryption method, a device, equipment and a medium, which can construct an integrated encryption method with the same functionality as SM2 and realize encryption of arbitrary length of plaintext data. The specific scheme is as follows:
[0005] In a first aspect, the present application provides a data encryption method applied to an encryption party, comprising:
[0006] obtaining a public key generated by a decryption party, generating a first ciphertext and an encapsulation key by using a post-quantum key encapsulation algorithm and the public 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;
[0007] splitting the first hash value into a symmetric key, an initial vector and a key of a keyed-Hash Message Authentication Code (HMAC) function, encrypting plaintext data by using the symmetric key and the initial vector to obtain a corresponding second ciphertext;
[0008] obtaining a second hash value according to the key of the keyed-hash message authentication code function, the plaintext data and the keyed-hash message authentication code function;
[0009] splicing the second hash value, the first ciphertext and the second ciphertext to obtain an encrypted ciphertext, and sending the encrypted ciphertext 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 second ciphertext comprises:
[0011] encrypting the plaintext data by using the symmetric key and the initial vector according to a preset encryption mode to obtain the second ciphertext; the encryption mode comprises a ciphertext block chaining mode and an authenticated encryption mode.
[0012] Optionally, the encrypting the plaintext data by using the symmetric key and the initial vector according to a preset encryption mode to obtain the second ciphertext comprises:
[0013] if the encryption mode is the ciphertext block chaining mode, determining whether the length corresponding to the plaintext data satisfies a condition of a block length of a post-quantum symmetric encryption algorithm;
[0014] if yes, directly encrypting the plaintext data by using the symmetric key and the initial vector to obtain the second ciphertext;
[0015] if no, performing a padding operation on the plaintext data, and encrypting the padded plaintext data by using the symmetric key and the initial vector to obtain the second ciphertext after the length corresponding to the padded plaintext data satisfies the condition of the block length of the post-quantum symmetric encryption algorithm.
[0016] Optionally, the encrypting the plaintext data by using the symmetric key and the initial vector according to a preset encryption mode to obtain the second ciphertext comprises:
[0017] if the encryption mode is the authenticated encryption mode, encrypting the plaintext data by using the symmetric key and the initial vector based on the authenticated encryption mode to obtain the second ciphertext.
[0018] In a second aspect, the present application provides a data decryption method applied to a decryption party, comprising:
[0019] 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, decrypt the first ciphertext by using a private key of a post-quantum key encapsulation algorithm to obtain a corresponding encapsulation key;
[0020] input the first ciphertext and the encapsulation key into a cryptographic hash function to obtain a first hash value output by the cryptographic hash function, and split the first hash value to obtain a symmetric key, an initial vector and a key of a keyed-Hash Message Authentication Code (HMAC) function;
[0021] decrypt the second ciphertext by using the symmetric key, the initial vector and a post-quantum symmetric cipher algorithm to obtain plaintext data;
[0022] generate a target hash value based on the plaintext data, the key of the HMAC function and the HMAC function, judge whether the target hash value is consistent with the second hash value, and output corresponding information according to a corresponding judgment result to complete data decryption.
[0023] Optionally, the judging whether the target hash value is consistent with the second hash value and outputting corresponding information according to a corresponding judgment result comprises:
[0024] if the target hash value is consistent with the second hash value, outputting the plaintext data;
[0025] if the target hash value is not consistent with the second hash value, outputting corresponding error information and directly ending.
[0026] In a third aspect, the present application provides a data encryption device applied to an encryption party, comprising:
[0027] a first hash value obtaining module configured to obtain a public key generated by a decryption party, generate a first ciphertext and an encapsulation key by using a post-quantum key encapsulation algorithm and the public key, and input the first ciphertext and the encapsulation key into a cryptographic hash function to obtain a first hash value output by the cryptographic hash function;
[0028] a second ciphertext obtaining module configured to split the first hash value into a symmetric key, an initial vector and a key of a keyed-Hash Message Authentication Code (HMAC) function, and encrypt plaintext data by using the symmetric key and the initial vector to obtain a corresponding second ciphertext;
[0029] a second hash value obtaining module configured to obtain a corresponding second hash value according to the key of the HMAC function, the plaintext data and the HMAC function;
[0030] The encrypted ciphertext obtaining module is configured to splice the second hash value, the first ciphertext and the second ciphertext to obtain corresponding encrypted ciphertext, and send the encrypted ciphertext to the decryption party so that the decryption party decrypts the encrypted ciphertext.
[0031] In a fourth aspect, the present application provides a data decryption device applied to a decryption party, comprising:
[0032] The encapsulated key obtaining module is configured 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 by using a private key of a post-quantum key encapsulation algorithm to obtain a corresponding encapsulated key.
[0033] The first hash value splitting module is configured to input the first ciphertext and the encapsulated key into a cryptographic hash function to obtain a first hash value output by the cryptographic hash function, and split the first hash value to obtain a symmetric key, an initial vector and a key of a keyed-Hash Message Authentication Code (HMAC) function.
[0034] The encrypted ciphertext decrypting module is configured to decrypt the second ciphertext by using the symmetric key, the initial vector and a post-quantum symmetric cipher algorithm to obtain plaintext data.
[0035] The information outputting module is configured to generate a target hash value based on the plaintext data, the key of the keyed-HMAC function and the keyed-HMAC function, judge whether the target hash value is consistent with the second hash value, and output corresponding information according to a corresponding judgment result to complete data decryption.
[0036] In a fifth aspect, the present application provides an electronic device, comprising:
[0037] The memory is configured to save a computer program.
[0038] The processor is configured to execute the computer program to realize the method described above.
[0039] In a sixth aspect, the present application provides a computer readable storage medium configured to save a computer program; wherein the computer program is executed by a processor to realize the method described above.
[0040] In summary, in the data encryption method, the public key generated by the decryption party is first obtained, the first ciphertext and the encapsulation key are generated by using the post-quantum key encapsulation algorithm and the public key, the first ciphertext and the encapsulation key are input into the cryptographic hash function to obtain the first hash value output by the cryptographic hash function; the first hash value is split into a symmetric key, an initial vector and a key of a keyed-Hash Message Authentication Code function, the plaintext data is encrypted by using the symmetric key and the initial vector to obtain the corresponding second ciphertext; the second hash value, the first ciphertext and the second ciphertext are spliced to obtain the encrypted ciphertext, and the encrypted ciphertext is sent to the decryption party, so that the decryption party decrypts the encrypted ciphertext. As can be seen, the first ciphertext and the encapsulation key are generated based on the public key generated by the decryption party, and the corresponding first hash value is obtained through the first ciphertext and the encapsulation key. The first hash value is decomposed to obtain the symmetric key, the initial vector and the key of the keyed-Hash Message Authentication Code function, and then the second ciphertext is generated by encrypting the to-be-encrypted information based on the symmetric key and the initial vector. The second hash value is generated according to the key of the keyed-Hash Message Authentication Code function and the to-be-encrypted information. Finally, the first ciphertext, the second ciphertext and the second hash value are spliced to complete the encryption. That is, by combining the post-quantum key encapsulation algorithm and the post-quantum symmetric encryption algorithm, any length of plaintext can be asymmetrically encrypted, and the functionality is the same as that of the SM2 public key encryption algorithm. The method of the application can replace the business system using the SM2 public key encryption algorithm, avoid the redesign of the cryptographic protocol for the post-quantum algorithm, and reduce the development cost of the business system due to the post-quantum migration. BRIEF DESCRIPTION OF DRAWINGS
[0041] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed in the embodiments or prior art description will be briefly introduced below. Obviously, the drawings in the following description are only embodiments of the present application, and those skilled in the art can obtain other drawings according to the provided drawings without creative labor.
[0042] Figure 1 A data encryption method flowchart disclosed by the present application;
[0043] Figure 2 A first hash value generation method flowchart disclosed by the present application;
[0044] Figure 3 A plaintext data encryption method flowchart disclosed by the present application;
[0045] Figure 4 A data decryption method flow chart disclosed by the present application;
[0046] Figure 5 A post-encryption ciphertext splitting method flow chart disclosed by the present application;
[0047] Figure 6 A first hash value acquisition method flow chart disclosed by the present application;
[0048] Figure 7 A second ciphertext decryption method flow chart disclosed by the present application;
[0049] Figure 8 A target hash value verification method flow chart disclosed by the present application;
[0050] Figure 9 A data encryption device structure schematic diagram disclosed by the present application;
[0051] Figure 10 A data decryption device structure schematic diagram disclosed by the present application;
[0052] Figure 11 A structure diagram of an electronic device disclosed by the present application. DETAILED DESCRIPTION
[0053] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative labor fall within the scope of protection of the present application.
[0054] At present, the actual encrypted data of the post-quantum asymmetric algorithm is limited, and it cannot achieve similar functionality to SM2 in many cryptographic application scenarios. Most post-quantum asymmetric algorithms do not provide native integrity protection, and other cryptographic techniques need to be used to achieve this function. The existing post-quantum algorithm cannot meet the asymmetric encryption needs of typical cryptographic application systems such as certificate systems, IPSEC, and key management systems. Business systems originally using national cryptographic algorithms need to be greatly changed in view of 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, a device, equipment and a medium, which can construct an integrated encryption method with the same functionality as SM2, and realize encryption of encrypted plaintext data of any length.
[0055] Referring to Figure 1 The embodiments of the present application disclose a data encryption method, applied to an encryption party, comprising:
[0056] Step S11, obtaining a public key generated by a decryption party, generating a first ciphertext and an encapsulation key by using a post-quantum key encapsulation algorithm and the public 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 the embodiment, first, a public key generated by a decryption party needs to be obtained. 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, the sender generates a first ciphertext and an encapsulation key by using a post-quantum key encapsulation algorithm and the public key. The encapsulation key is a shared key used by the sender and the decryption party for symmetric encryption communication, and the first ciphertext is a result output by the post-quantum key encapsulation algorithm.
[0058] In the embodiment, the encryption party inputs the generated first ciphertext and encapsulation key into a cryptographic hash function. The cryptographic hash function processes the first ciphertext and the encapsulation key to generate an output of a fixed length, i.e., a first hash value. The cryptographic hash function includes but is not limited to SHA2-512 (Secure Hash Algorithm 2 512-bit) and SHA-3 (Secure Hash Algorithm 3). The first hash value output by the cryptographic hash function can be used for subsequent data verification, integrity check, or encryption operation. Thus, the post-quantum key encapsulation ensures the security of communication under the threat of quantum computing, and the cryptographic hash function further ensures the integrity and consistency of data.
[0059] In a specific implementation, the post-quantum key encapsulation algorithm is defined as KEM, and a key encapsulation function of the KEM is defined as , wherein is a ciphertext output by the key encapsulation function, is a key to be encapsulated, is a public key of the KEM algorithm. After obtaining the public key generated by the decryption party, the KEM public key Figure 2 is input into a post-quantum KEM function to obtain KEM ciphertext and a KEM encapsulation key, i.e., a first ciphertext and an encapsulation key , and then the first ciphertext and the encapsulation key are input into a cryptographic hash function to obtain a first hash value .
[0060] Step S12, splitting the first hash value into a symmetric key, an initial vector, and a key of a keyed-Hash Message Authentication Code function, encrypting plaintext data by using the symmetric key and the initial vector to obtain a corresponding second ciphertext.
[0061] In this embodiment, after obtaining the first hash value, it needs to be split into three parts, which are 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 by a predefined way. After splitting, the plaintext data is encrypted using the symmetric key and the initial vector. Among them, the definition is the plaintext that needs to be encrypted in the integrated encryption task, is the key of the symmetric algorithm. By using symmetric encryption algorithms such as AES (Advanced Encryption Standard), the plaintext data is encrypted to ensure that the encrypted data has security and randomness, thereby generating the second ciphertext. This second ciphertext can be safely transmitted, and at the same time, due to the role of the initial vector and the key of the keyed-hash message authentication code function, it can also ensure the data integrity and authentication requirements in the encryption process.
[0062] In this embodiment, after obtaining the symmetric key, the initial vector, and the key of the keyed-hash message authentication code function, the plaintext data is encrypted according to the pre-set encryption mode using the symmetric key and the initial vector to obtain the corresponding second ciphertext; the encryption mode includes the ciphertext block chaining mode and the authenticated encryption mode. Specifically, the encryption mode can be the ciphertext block chaining mode (CBC, Cipher Block Chaining) and the authenticated 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 exclusive-ORed with the previous ciphertext block to increase the security of the data. The initial vector is used for randomization processing of the first plaintext data group to ensure that different ciphertexts are generated each time. In the ciphertext block chaining mode, the second ciphertext is generated by encrypting the plaintext data block in sequence. In the authenticated encryption mode, in addition to encrypting the data, it also generates a message authentication code to provide data integrity verification and authentication function. The authenticated encryption mode not only ensures confidentiality, but also ensures that the encrypted data has not been tampered with during transmission. That is, different encryption modes can be selected according to actual needs to ensure that the data encryption process is balanced between security, authentication, and performance, and finally the corresponding second ciphertext is obtained.
[0063] In the embodiment, when the plaintext data is encrypted by using the CBC mode, if the encryption mode is the cipher block chaining mode, it is judged whether the length corresponding to the plaintext data satisfies the condition of the post-quantum symmetric encryption algorithm packet length; if yes, the corresponding encryption is directly performed on the plaintext data by using the symmetric key and the initial vector to obtain the second ciphertext; if not, the padding operation is performed on the plaintext data, and after the length corresponding to the padded plaintext data satisfies the condition of the post-quantum symmetric encryption algorithm packet length, the corresponding encryption is performed on the padded plaintext data by using the symmetric key and the initial vector to obtain the second ciphertext. Specifically, if the selected encryption mode is the cipher block chaining mode (CBC), it is needed to judge whether the length of the plaintext data satisfies the condition of the required packet length of the post-quantum symmetric encryption algorithm. The post-quantum symmetric encryption algorithm usually requires that the plaintext data is encrypted in a fixed-length packet, and thus it is needed to ensure that the length of the plaintext data meets the requirement of the packet length. If the length of the plaintext data satisfies the condition of the packet length, the encryption is directly performed on the plaintext data by using the symmetric key and the initial vector to generate the corresponding second ciphertext. At this time, no additional operation is needed to be performed on the plaintext data, and the encryption process is completed step by step according to the relationship between each data block and the initial vector. If the length of the plaintext data does not satisfy the condition of the packet length, the padding operation is needed to be performed on the plaintext data to make the length reach the required packet length of 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 the length is exactly a multiple of the packet length. After the padding operation, when the padded plaintext data satisfies the requirement of the packet length, the encryption is performed on the padded plaintext data by using the symmetric key and the initial vector to finally generate the second ciphertext. The embodiment can perform the asymmetric encryption on plaintexts of any length, and the HMAC algorithm constructed based on the post-quantum password hash algorithm provides the integrity protection.
[0064] In the embodiment, when the plaintext data is encrypted by using the GCM mode, if the encryption mode is the authenticated encryption mode, the corresponding encryption is performed on the plaintext data 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 encryption is performed on the plaintext data 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, the additional data and the additional data length need to be set according to the content previously negotiated by the encryption party and the decryption party, for example, the additional data is set to be a null value, and the additional data length is set to be 0. In the authenticated encryption mode, the encryption not only protects the confidentiality of the data, but also provides the integrity and authenticity verification of the data, which can not only guarantee the confidentiality of the data in the transmission, but also provide additional security protection through the mechanism of the authenticated encryption to ensure that the data is not tampered and the source can be verified.
[0065] Step S13, a second hash value is obtained 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 second hash value is generated according to the key of the key hash message authentication code function (HMAC, Hash-based Message Authentication Code), the plaintext data, and the HMAC function. Specifically, the 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 an input key, combined with the plaintext data, and passed to the HMAC function. The HMAC function will process the key and data through multiple operation steps, including but not limited to internal and external padding, hash operation, etc., and finally generate a fixed-length output value, i.e., the second hash value. The function of the second hash value is mainly to verify the integrity and authenticity of the data. In the communication process, the receiver 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 in the transmission process. The process of obtaining the second ciphertext and the second hash value is shown in FIG. 4. Figure 3
[0067] Step S14, the second hash value, the first ciphertext, and the second ciphertext are spliced to obtain the corresponding encrypted ciphertext, and the encrypted ciphertext is sent 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 spliced to generate the final encrypted ciphertext, and after splicing, the generated encrypted ciphertext contains 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 the encrypted ciphertext after receiving it.
[0069] Therefore, this application generates a first ciphertext and a sealing key based on the public key produced by the decryptor. A first hash value is obtained from the first ciphertext and the sealing key. This first hash value is then decomposed to obtain a symmetric key, an initialization vector, and a key for the key hash message authentication code function. Next, the information to be encrypted is encrypted using the symmetric key and the initialization vector to generate a second ciphertext. A second hash value is then generated based on the key for the key hash message authentication code function and the information to be encrypted. Finally, the first ciphertext, the second ciphertext, and the second hash value are concatenated to complete the encryption. In other words, this application, through a combination of a post-quantum key encapsulation algorithm and a post-quantum symmetric encryption algorithm, can asymmetrically encrypt plaintext of arbitrary length. Functionally, it is identical to the SM2 public-key encryption algorithm. This method can replace current business systems using the SM2 public-key encryption algorithm, avoiding the need to redesign cryptographic protocols for post-quantum algorithms and reducing the development costs of business systems due to post-quantum migration.
[0070] See Figure 4 As shown, this embodiment of the invention discloses a data decryption method, applied to a decryption party, comprising:
[0071] Step S21: Receive the encrypted ciphertext sent by the encryptor, split the encrypted ciphertext to obtain the first ciphertext, the second ciphertext, and the second hash value, and decrypt the first ciphertext using the private key of the post-quantum key encapsulation algorithm to obtain the corresponding encapsulation key.
[0072] In this embodiment, the encrypted ciphertext sent by the encryptor 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 concatenating these three data parts. Therefore, the decryptor divides it into corresponding parts according to a predetermined order or protocol. After the division, the decryptor uses the private key of the post-quantum key encapsulation algorithm to decrypt the first ciphertext. The decapsulation algorithm is defined as follows: ,in for The algorithm's private key. The first ciphertext is generated during the encryption process using a post-quantum key encapsulation algorithm, protecting the security of the encapsulation key. By decrypting the first ciphertext using the post-quantum private key, the encapsulation key generated during the encryption process can be recovered. The encapsulation key is the core key for subsequent decryption; in this embodiment, the encapsulation key will be used to further decrypt the second ciphertext to recover the plaintext data.
[0073] Step S22: Input the first ciphertext and the encapsulation key into the cryptographic hash function, obtain the first hash value output by the cryptographic hash function, and split the first hash value to obtain the symmetric key, the initialization vector, and the key of the key hash message authentication code function.
[0074] In this embodiment, the decryptor inputs the first ciphertext and the wrapping key into a cryptographic hash function to generate a corresponding first hash value. The cryptographic hash function is an algorithm that maps input data to a fixed-length output value. By taking the first ciphertext and the wrapping key as input, a unique and irreversible first hash value is generated. Then, the decryptor splits the generated first hash value to obtain the symmetric key, the initial vector and the key for the keyed-Hash Message Authentication Code function contained therein. The symmetric key will be used for subsequent decryption of the second ciphertext, the initial vector provides randomness for symmetric encryption to enhance security, and the HMAC key is used to verify the integrity and authenticity of the data, as shown in Figure 6 .
[0075] Step S23, decrypt the second ciphertext using the symmetric key, the initial vector, and the post-quantum symmetric cryptographic algorithm to obtain the plaintext data.
[0076] In this embodiment, the post-quantum symmetric cryptographic algorithm takes the extracted symmetric key and initial vector as input. The decryption process is performed through the decryption operation of the algorithm, which gradually restores the second ciphertext to the original plaintext data. The post-quantum symmetric cryptographic algorithm is designed to resist the threat of quantum computing, providing 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 decryption, so that the complete plaintext data is finally obtained, as shown in Figure 7 .
[0077] Step S24, generate a target hash value based on the plaintext data, the key for the keyed-Hash Message Authentication Code function, and the keyed-Hash Message Authentication Code function, and determine whether the target hash value is consistent with the second hash value. According to the corresponding determination result, the corresponding information is outputted to complete the data decryption.
[0078] In this embodiment, after generating the target hash value based on the plaintext data, the key of the keyed-Hash Message Authentication Code function and the keyed-Hash Message Authentication Code function, the application first determines 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 not consistent with the second hash value, the corresponding error information is output and the process is directly ended. Specifically, the target hash value is calculated by using the keyed-Hash Message Authentication Code function, the key of the keyed-Hash Message Authentication Code function and the plaintext data. Then, the target hash value is compared with the second hash value which is separated from the encrypted ciphertext. According to the comparison result, the integrity of the data in the encryption and decryption process is determined. 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 in the transmission process, and the decrypted plaintext data is output. At this time, the integrity of the data is guaranteed, and the decryption is successfully completed. However, if the target hash value is not consistent with the second hash value, it means that the data may have been modified or damaged in the transmission. The decryption party outputs the corresponding error information for error prompt and directly ends the decryption operation. Through this judgment mechanism, the decryption party can effectively ensure the integrity and security of the data, and quickly respond and terminate the process when inconsistency is found. The specific process is shown in Figure 8
[0079] As can be seen, the application of the embodiment decrypts the encrypted ciphertext to obtain the first ciphertext, the second ciphertext and the second hash value, and decrypts the first ciphertext by using the private key to obtain the encapsulation key. The first hash value is obtained based on the encapsulation key and the first ciphertext, and the first hash value is split to obtain the symmetric key, the initial vector and the key of the keyed-Hash Message Authentication Code function. The second ciphertext is decrypted by using the symmetric key and the initial vector to obtain the plaintext data. Finally, the target hash value generated based on the plaintext data, the key of the keyed-Hash Message Authentication Code function and the keyed-Hash Message Authentication Code function is compared with the second hash value for encryption verification. That is, the application can decrypt plaintext data of any length, and determine whether to output the decrypted data by consistency check of the target hash value and the second hash value, so as to ensure that the decrypted content is credible and has not been tampered with.
[0080] Referring to Figure 9 The application embodiment discloses a data encryption device applied to an encryption party, which comprises:
[0081] The first hash value acquisition module 11 is configured to obtain a public key generated by a decryption party, generate a first ciphertext and an encapsulation key by using a post-quantum key encapsulation algorithm and the public key, and input the first ciphertext and the encapsulation key into a password hash function to obtain a first hash value output by the password hash function.
[0082] The second ciphertext obtaining module 12 is configured to split the first hash value into a symmetric key, an initial vector, and a key of a keyed-hash message authentication code function, encrypt the plaintext data by using the symmetric key and the initial vector, and obtain a corresponding second ciphertext.
[0083] The second hash value obtaining module 13 is configured to obtain a corresponding second hash value according to the key of the keyed-hash message authentication code function, the plaintext data, and the keyed-hash message authentication code function.
[0084] The encrypted ciphertext obtaining module 14 is configured to splice 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.
[0085] Therefore, the first ciphertext and the encapsulation key are generated based on the public key generated by the decryption party, the first hash value is obtained by using the first ciphertext and the encapsulation key, the symmetric key, the initial vector, and the key of the keyed-hash message authentication code function are obtained by splitting the first hash value, the second ciphertext is generated by encrypting the to-be-encrypted information based on the symmetric key and the initial vector, the second hash value is generated according to the key of the keyed-hash message authentication code function and the to-be-encrypted information, and finally, the first ciphertext, the second ciphertext, and the second hash value are spliced to complete the encryption. That is, the combination of the post-quantum key encapsulation algorithm and the post-quantum symmetric encryption algorithm can be used to asymmetrically encrypt plaintexts of any length, and the function is the same as that of the SM2 public key encryption algorithm. The method of the application can replace the business system using the SM2 public key encryption algorithm, avoid the redesign of the cryptographic protocol for the post-quantum algorithm, and reduce the development cost of the business system due to the post-quantum migration.
[0086] In some embodiments, the second ciphertext obtaining module 12 specifically can include:
[0087] The first plaintext data encryption unit is configured to encrypt the plaintext data according to a pre-set encryption mode by using the symmetric key and the initial vector to obtain a corresponding second ciphertext. The encryption mode includes a cipher block chaining mode and an authenticated encryption mode.
[0088] In some embodiments, the second ciphertext obtaining module 12 includes:
[0089] The length judgment unit is 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 cipher block chaining mode.
[0090] a second plaintext data encryption unit, configured to, if the condition is met, directly encrypt the plaintext data using the symmetric key and the initial vector to obtain the second ciphertext;
[0091] a plaintext data padding unit, configured to, if the condition is not met, perform a padding operation on the plaintext data, and, if the length of the corresponding padded plaintext data meets the condition of the post-quantum symmetric encryption algorithm block length, encrypt the padded plaintext data using the symmetric key and the initial vector to obtain the second ciphertext.
[0092] In some embodiments, the second ciphertext obtaining module 12 comprises:
[0093] an authenticated encryption mode encryption unit, configured to, if the encryption mode is the authenticated encryption mode, encrypt plaintext data based on the authenticated encryption mode, the symmetric key and the initial vector to obtain corresponding second ciphertext.
[0094] Referring to Figure 10 The embodiment of the present application discloses a data decryption device, applied to a decryption party, comprising:
[0095] an encapsulated key obtaining module 21, configured to receive encrypted ciphertext sent by an encryption party, split the encrypted ciphertext to obtain first ciphertext, second ciphertext and second hash value, and decrypt the first ciphertext using a private key of a post-quantum key encapsulation algorithm to obtain a corresponding encapsulated key;
[0096] a first hash value splitting module 22, configured to input the first ciphertext and the encapsulated key into a cryptographic hash function to obtain a first hash value output by the cryptographic hash function, and split the first hash value to obtain a symmetric key, an initial vector and a key of a keyed-Hash Message Authentication Code function;
[0097] an encrypted ciphertext decryption module 23, configured to decrypt the second ciphertext using the symmetric key, the initial vector and a post-quantum symmetric cryptographic algorithm to obtain plaintext data;
[0098] an information output module 24, configured to generate a target hash value based on the plaintext data, the key of the keyed-Hash Message Authentication Code function and the keyed-Hash Message Authentication Code function, judge 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] Therefore, the embodiment of the present application can decrypt any length of plaintext data, and determine whether to output the decrypted data by consistency check of the target hash value and the second hash value, thereby ensuring that the decrypted content is trusted and has not been tampered with.
[0100] In some specific embodiments, the information output module 24 can specifically include:
[0101] The plaintext data output unit is 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 configured to output corresponding error information and directly end if the target hash value is inconsistent with the second hash value.
[0103] Further, the embodiment of the present application also discloses an electronic device, Figure 11 The electronic device 30 shown in the figure is not considered as any limitation on the use range of the present application.
[0104] Figure 11 The electronic device 30 provided by the embodiment of the present application is shown in a structural schematic diagram. The electronic device 30 can 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 configured to store a computer program, and the processor 31 is configured to load and execute the computer program to implement the related steps in the method disclosed in any of the preceding embodiments. In addition, the electronic device 30 in the embodiment can be an electronic computer.
[0105] In the embodiment, the power supply 33 is configured 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 external devices, and the communication protocol followed by the communication interface 34 can be any communication protocol applicable to the technical solution of the present application, which is not limited specifically herein; the input / output interface 35 is configured to obtain external input data or output data to the outside world, and the specific interface type can be selected according to the specific application needs, which is not limited specifically herein.
[0106] In addition, the memory 32 can be a read-only memory, a random access memory, a magnetic or optical disk, etc., as a carrier for storing resources, and the resources stored thereon can include an operating system 321, a computer program 322, etc., and the storage mode can be temporary storage or permanent storage.
[0107] The operating system 321 is used to manage and control each hardware device on the electronic device 30 and the computer program 322, and can be Windows Server, Netware, Unix, Linux, etc. In addition to the computer program capable of completing the method executed by the electronic device 30 disclosed in any of the foregoing embodiments, the computer program 322 can further include a computer program capable of completing other specific work.
[0108] Further, the present application also discloses a computer readable storage medium for storing a computer program, wherein the computer program is executed by a processor to implement the method disclosed above. For the specific steps of the method, refer to the corresponding content disclosed in the foregoing embodiments, which will not be described here.
[0109] The embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. For the same or similar parts between the embodiments, refer to each other. For the device disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple, and refer to the method part for the relevant part.
[0110] The skilled person can further realize that the units and algorithm steps of the examples described in combination with the embodiments disclosed herein can be realized by electronic hardware, computer software or a combination of the two. In order to clearly show the interchangeability of hardware and software, the components and steps of each example have been described in the above description. Whether the functions are executed in hardware or software depends on the specific application and design constraints of the technical solution. The skilled person can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.
[0111] The steps of the method or algorithm described in combination with the embodiments disclosed herein can be directly implemented by hardware, a software module executed by a processor, or a combination of the two. The software module can 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 needs to be pointed out that in this document, relational terms such as first and second and the like can only be intended to distinguish one entity or operation from another entity or operation without necessarily requiring or implying any actual such relationship or order between such entities or operations. Moreover, the terms "comprising", "including", or any other variant thereof are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but can also include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without more limitations, an element defined by the statement "comprising a" does not exclude the existence of additional identical elements in the process, method, article, or apparatus including the stated element.
[0113] The above detailed description of the technical solutions provided by the present application has been provided, and the principles and implementation modes of the present application have been described by applying specific examples. The above description of the examples is only for the purpose of helping to understand the method of the present application and its core idea; at the same time, for those skilled in the art, according to the idea of the present application, the specific implementation mode and application range will be changed, and the above description of the content of the specification should not be understood as a limitation of the present application.
Claims
1. A data encryption method characterized by, Applied to an encryption party, comprising: Obtaining a public key generated by a decryption party, generating a first ciphertext and an encapsulation key using a post-quantum key encapsulation algorithm and the public 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; Splitting the first hash value into a symmetric key, an initial vector, and a key of a keyed-hash message authentication code function, encrypting plaintext data using the symmetric key and the initial vector to obtain corresponding second ciphertext; Obtaining a corresponding second hash value according to the key of the keyed-hash message authentication code function, the plaintext data, and the keyed-hash message authentication code function; Splicing the second hash value, the first ciphertext, and the second ciphertext to obtain corresponding encrypted ciphertext, and sending the encrypted ciphertext to the decryption party so that the decryption party decrypts the encrypted ciphertext.
2. The data encryption method of claim 1, wherein, The encryption of the plaintext data using the symmetric key and the initial vector to obtain the corresponding second ciphertext comprises: According to a pre-set encryption mode, the plaintext data is encrypted using the symmetric key and the initial vector to obtain the corresponding second ciphertext; the encryption mode includes a ciphertext block chaining mode and an authenticated encryption mode.
3. The data encryption method of claim 2, wherein, The encryption of the plaintext data using the symmetric key and the initial vector to obtain the corresponding second ciphertext comprises: If the encryption mode is the ciphertext block chaining mode, it is judged whether the length corresponding to the plaintext data satisfies the condition of the post-quantum symmetric encryption algorithm block length; If yes, the plaintext data is directly encrypted using the symmetric key and the initial vector to obtain the second ciphertext; If not, the plaintext data is padded, and after the length corresponding to the padded plaintext data satisfies the condition of the post-quantum symmetric encryption algorithm block length, the padded plaintext data is encrypted using the symmetric key and the initial vector to obtain the second ciphertext.
4. The data encryption method of claim 2, wherein, The encryption of the plaintext data using the symmetric key and the initial vector to obtain the corresponding second ciphertext comprises: If the encryption mode is 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.
5. A data decryption method characterized by, Applied to a decryption party, comprising: Receiving the encrypted ciphertext sent by the encryption party, splitting the encrypted ciphertext to obtain the first ciphertext, the second ciphertext, and the second hash value, and decrypting the first ciphertext using a private key of the post-quantum key encapsulation algorithm to obtain a corresponding encapsulation key; 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, and splitting the first hash value to obtain a symmetric key, an initial vector, and a key of a keyed-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 keyed-hash message authentication code function and the keyed-hash message authentication code function, and it is determined whether the target hash value is consistent with the second hash value, and corresponding information is output according to the corresponding determination result, so as to complete data decryption.
6. The data decryption method of claim 5, wherein, The determination of whether the target hash value is consistent with the second hash value and the output of corresponding information according to the corresponding determination result include: If the target hash value is consistent with the second hash value, the plaintext data is output; If the target hash value is not consistent with the second hash value, corresponding error information is output and the process is directly ended.
7. A data encryption device, characterized by comprising: Applied to an encryption party, comprising: A first hash value acquisition module is configured to acquire a public key generated by a decryption party, generate a first ciphertext and an encapsulation key by using a post-quantum key encapsulation algorithm and the public key, and input the first ciphertext and the encapsulation key into a cryptographic hash function to acquire a first hash value output by the cryptographic hash function; A second ciphertext acquisition module is configured to split the first hash value into a symmetric key, an initial vector and a key of a keyed-hash message authentication code function, encrypt plaintext data by using the symmetric key and the initial vector to acquire corresponding second ciphertext; A second hash value acquisition module is configured to acquire corresponding second hash value according to the key of the keyed-hash message authentication code function, the plaintext data and the keyed-hash message authentication code function; An encrypted ciphertext acquisition module is configured to splice the second hash value, the first ciphertext and the second ciphertext to acquire corresponding encrypted ciphertext, and send the encrypted ciphertext to the decryption party so that the decryption party decrypts the encrypted ciphertext.
8. A data decryption apparatus, characterized by comprising: Applied to a decryption party, comprising: An encapsulation key acquisition module is configured to receive encrypted ciphertext sent by an encryption party, split the encrypted ciphertext to acquire first ciphertext, second ciphertext and second hash value, and decrypt the first ciphertext by using a private key of a post-quantum key encapsulation algorithm to acquire corresponding encapsulation key; A first hash value splitting module is configured to input the first ciphertext and the encapsulation key into a cryptographic hash function to acquire a first hash value output by the cryptographic hash function, and split the first hash value to acquire a symmetric key, an initial vector and a key of a keyed-hash message authentication code function; An encrypted ciphertext decryption module is configured to decrypt the second ciphertext by using the symmetric key, the initial vector and a post-quantum symmetric cipher algorithm to acquire plaintext data; An information output module is configured to generate a target hash value based on the plaintext data, the key of the keyed-hash message authentication code function and the keyed-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, so as to complete data decryption.
9. An electronic device, comprising: Comprising: A memory is configured to save a computer program; A processor is configured to execute the computer program to realize the method according to any one of claims 1 to 6.
10. A computer-readable storage medium, characterized in that, A computer program product for saving a computer program; wherein the computer program, when executed by a processor, implements the method according to any one of claims 1 to 6.
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