Homomorphic encryption method based on national cryptographic algorithm, computer equipment and storage medium
By constructing the correspondence between the receiver and the encrypted information, processing the original plaintext to generate the target ciphertext, the problem that the national secret algorithm cannot provide homomorphic encryption in the cloud environment is solved, and the security and consistency of data transmission in the cloud computing environment is achieved.
Patent Information
- Application Number
- CN202411741279.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-03-04
AI Technical Summary
The existing Guose algorithm cannot provide homomorphic encryption functions under cloud computing and cloud environment conditions.
By obtaining the original plaintext of the message to be sent and the receiver's information of the recipient, the target encryption information is determined based on the correspondence between the recipient and the encryption information predefined by the preset national secret algorithm, and the plaintext data is processed according to the preset length to generate the target ciphertext to achieve homomorphic encryption.
It realizes homomorphic encryption of messages in a cloud computing environment to ensure the security and consistency of data transmission.
Smart Images

Figure CN119561686A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of network security technology, and specifically to a homomorphic encryption method, computer equipment and storage medium based on a national secret algorithm. Background Art
[0002] The national secret algorithm is a series of cryptographic standards developed and promulgated by the State Cryptography Administration, also known as commercial cryptography. Taking the SM2 algorithm as an example, the SM2 algorithm is a public key cryptographic algorithm based on elliptic curves issued by the State Cryptography Administration. It includes key generation, encryption, decryption, and digital signature. The security of this algorithm is mainly based on the elliptic curve discrete logarithm problem, and has the advantages of high security, high efficiency, and good flexibility. It is understandable that in some application scenarios, the national secret algorithm is required to meet the function of homomorphic encryption. However, the existing national secret algorithm does not take into account the conditions of cloud computing and cloud environment, and there is a problem that it cannot provide homomorphic encryption function. Summary of the invention
[0003] The purpose of the embodiments of the present application is to provide a homomorphic encryption method, computer device, machine-readable storage medium and computer program product based on a national secret algorithm, so as to solve the problem that the existing national secret algorithm does not take cloud computing and cloud environment conditions into consideration sufficiently and cannot provide homomorphic encryption function.
[0004] In order to achieve the above-mentioned purpose, the first aspect of the embodiment of the present application provides a homomorphic encryption method based on a national secret algorithm, the method comprising:
[0005] Obtaining the original plaintext of the message to be sent and the recipient information of the recipient of the message to be sent;
[0006] Based on the correspondence between the receiver and the encrypted information predetermined according to the preset national encryption algorithm, the target encrypted information corresponding to the message to be sent is determined according to the receiver information, and the encrypted information includes the first ciphertext, the sender shared key and the symmetric key;
[0007] Processing the original plaintext according to a preset length to obtain plaintext data with a length of the preset length;
[0008] According to the target encrypted information and plaintext data, the target ciphertext corresponding to the original plaintext is generated.
[0009] In an embodiment of the present application, the method further includes: periodically updating the correspondence between the recipient and the encrypted information at preset time intervals.
[0010] In an embodiment of the present application, a target ciphertext corresponding to the original plaintext is generated according to the target encryption information and the plaintext data, including: encrypting the plaintext data according to the target symmetric key in the target encryption information to obtain a second ciphertext; based on a hash algorithm, determining a third ciphertext according to the target sender shared key and the plaintext data in the target encryption information; generating a target ciphertext according to the target first ciphertext, second ciphertext and third ciphertext in the target encryption.
[0011] In an embodiment of the present application, the original plaintext is processed according to a preset length to obtain plaintext data with a preset length, including: when the length of the original plaintext is greater than the preset length, the original plaintext is grouped according to the preset length to obtain multiple groups of plaintext data; when the length of the original plaintext is less than the preset length, the original plaintext is padded to obtain plaintext data.
[0012] In an embodiment of the present application, the recipient information includes the recipient public key, and determining the correspondence between the recipient and the encrypted information according to a preset national secret algorithm includes: determining the sender public key according to the sender private key and the base point of a preset elliptic curve, the sender private key being a random number within a preset range; converting the sender public key into a bit string to obtain a first ciphertext; based on the preset elliptic curve, determining the elliptic curve point according to the recipient public key; judging whether the elliptic curve point is an infinity point; if the elliptic curve point is not an infinity point, determining the sender shared key according to the sender private key and the recipient public key; based on a preset key derivation function, determining the symmetric key according to the sender shared key and a preset length; judging whether the symmetric key is an all-zero bit string; if the symmetric key is not an all-zero bit string, storing the recipient information in association with the first ciphertext, the sender shared key and the symmetric key to obtain the correspondence between the recipient and the encrypted information.
[0013] In an embodiment of the present application, the method further includes: outputting an error prompt when the elliptic curve point is a point at infinity.
[0014] In an embodiment of the present application, the method further includes: when the symmetric key is an all-zero bit string, updating the sender's private key and redetermining the correspondence between the receiver and the encrypted information.
[0015] A second aspect of an embodiment of the present application provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the above-mentioned homomorphic encryption method based on the national secret algorithm when executing the computer program.
[0016] A third aspect of an embodiment of the present application provides a machine-readable storage medium, which stores programs or instructions. When the programs or instructions are executed by a processor, the above-mentioned homomorphic encryption method based on the national secret algorithm is implemented.
[0017] A fourth aspect of an embodiment of the present application provides a computer program product, including a computer program, which implements the above-mentioned homomorphic encryption method based on the national secret algorithm when executed by a processor.
[0018] The above technical solution obtains the original plaintext of the message to be sent and the receiver information of the receiver of the message to be sent, and then determines the target encrypted information corresponding to the message to be sent according to the receiver information based on the correspondence between the receiver and the encrypted information predetermined according to the preset national encryption algorithm, and the encrypted information includes the first ciphertext, the sender's shared key and the symmetric key, and then processes the original plaintext according to the preset length to obtain plaintext data with a preset length, and finally generates the target ciphertext corresponding to the original plaintext according to the target encrypted information and the plaintext data. This application constructs a correspondence between the receiver and the encrypted information, so that the plaintext information sent by the same receiver is encrypted using the same encrypted information, and further enables the ciphertext sent by the same sender and received by the same receiver to realize the function of homomorphic encryption based on the encrypted information.
[0019] Other features and advantages of the embodiments of the present application will be described in detail in the subsequent specific implementation section. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The accompanying drawings are used to provide a further understanding of the embodiments of the present application and constitute a part of the specification. Together with the following specific implementations, they are used to explain the embodiments of the present application, but do not constitute a limitation on the embodiments of the present application. In the accompanying drawings:
[0021] Figure 1 A schematic diagram of a homomorphic encryption method based on a national secret algorithm provided in an embodiment of the present application;
[0022] Figure 2 A schematic diagram of a homomorphic encryption method based on the national secret SM2 algorithm provided for a specific embodiment of the present application;
[0023] Figure 3 A schematic diagram of the structure of a homomorphic encryption device based on a national secret algorithm provided in an embodiment of the present application. DETAILED DESCRIPTION
[0024] In order to make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. It should be understood that the specific implementation methods described herein are only used to illustrate and explain the embodiments of the present application, and are not used to limit the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0025] It should be noted that if the embodiments of the present application involve directional indications (such as up, down, left, right, front, back...), the directional indications are only used to explain the relative position relationship, movement status, etc. between the components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication will also change accordingly.
[0026] In addition, if there are descriptions involving "first", "second", etc. in the embodiments of the present application, the descriptions of "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or suggesting their relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in the field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by this application.
[0027] The national cryptographic algorithm is a series of cryptographic standards developed and promulgated by the State Cryptography Administration, also known as commercial cryptography. The national cryptographic algorithms include SM1, SM2, SM3 and SM4. At present, none of the national cryptographic algorithms can implement homomorphic encryption, which is a special encryption method that allows calculations to be performed in an encrypted state without decrypting the data. This property is very useful for securely processing encrypted data and performing calculations. Considering the demand for homomorphic encryption in cloud computing and cloud environment conditions, it is very necessary to improve the national cryptographic algorithm to meet the homomorphic encryption function.
[0028] The SM2 algorithm in the national secret algorithm is a national secret algorithm based on elliptic curve cryptography (ECC). The ECC algorithm, as an asymmetric encryption algorithm, can be used as the basis for homomorphic encryption. Although ECC itself is not designed for homomorphic encryption, homomorphic encryption can be achieved through some technical means. For example, the addition operation characteristics of ECC and the concept of homomorphic encryption can be used to design a solution that supports homomorphic operations. In this regard, the present application provides a homomorphic encryption method based on the national secret algorithm, which improves the national secret algorithm to support homomorphic encryption based on the implementation principles of the national secret algorithm and the ECC algorithm.
[0029] Figure 1 A schematic diagram of a homomorphic encryption method based on a national encryption algorithm provided in an embodiment of the present application. Figure 1 As shown, an embodiment of the present application provides a homomorphic encryption method based on a national secret algorithm, and the method is illustrated by applying the method to a processor as an example. The method may include the following steps.
[0030] Step S101, obtaining the original plaintext of the message to be sent and the recipient information of the recipient of the message to be sent.
[0031] Step S102, based on the correspondence between the recipient and the encrypted information predetermined according to the preset national encryption algorithm, determine the target encrypted information corresponding to the message to be sent according to the recipient information, and the encrypted information includes the first ciphertext, the sender's shared key and the symmetric key.
[0032] Step S103, processing the original plaintext according to a preset length to obtain plaintext data with a preset length.
[0033] Step S104, generating a target ciphertext corresponding to the original plaintext according to the target encryption information and the plaintext data.
[0034] It can be understood that in order to realize the function of homomorphic encryption on the basis of the national secret algorithm, the embodiment of the present application improves the original national secret algorithm, and takes the preset encryption algorithm as the SM2 algorithm as an example for explanation. After the receiver and the sender establish a connection for the first time, the sender can obtain the receiver information received and sent. At this time, the embodiment of the present application can predetermine the correspondence between the receiver and the encrypted information based on the SM2 algorithm, and the encrypted information is used to encrypt the subsequent messages sent to the corresponding receiver. That is, for the same sender and receiver, the messages sent to the receiver by the sender are encrypted using the same encryption information. Among them, the encrypted information may include a first ciphertext, a sender shared key, and a symmetric key. It can be understood that in the SM2 algorithm, the final output ciphertext is usually composed of three ciphertexts. The first ciphertext in the embodiment of the present application constitutes the first ciphertext in the final output ciphertext of the SM2 algorithm, and the sender shared key and the symmetric key are used to combine with the plaintext data to generate the other two ciphertexts in the final output ciphertext of the SM2 algorithm. In this way, the ciphertexts generated by the same encryption information can be operated based on the form of ciphertext to realize the function of homomorphic encryption.
[0035] Specifically, the encryption process described in the embodiment of the present application is the encryption process of the sender. First, the original plaintext of the message to be sent and the recipient information of the recipient to whom the message is to be sent are obtained, and the recipient information includes the identity of the recipient and the public key of the recipient.
[0036] Further, based on the predetermined correspondence between the recipient and the encrypted information, the target encrypted information corresponding to the message to be sent can be determined according to the recipient information. At the same time, in order to ensure that the encrypted message has a consistent format or size, the original plaintext can be processed according to the preset length to obtain plaintext data with a preset length. Among them, the preset length is a fixed length, which can be set based on actual needs or experience. In one example, the processing of the original plaintext includes truncating, padding and / or splitting the original plaintext to ensure that the length of the obtained plaintext data meets the requirements of the preset length. It can be understood that after processing the original plaintext, a plaintext data with a preset length or multiple plaintext data with a preset length can be obtained.
[0037] Finally, according to the target first ciphertext, the target sender shared key and the target symmetric key in the target encrypted information, based on the preset national secret algorithm, the obtained plaintext data of one or more preset lengths are encrypted to obtain the target ciphertext corresponding to the original plaintext of the message to be sent. Further, the target ciphertext can be sent to the corresponding recipient.
[0038] The above technical solution obtains the original plaintext of the message to be sent and the receiver information of the receiver of the message to be sent, and then determines the target encrypted information corresponding to the message to be sent according to the receiver information based on the correspondence between the receiver and the encrypted information predetermined according to the preset national encryption algorithm, and the encrypted information includes the first ciphertext, the sender's shared key and the symmetric key, and then processes the original plaintext according to the preset length to obtain plaintext data with a preset length, and finally generates the target ciphertext corresponding to the original plaintext according to the target encrypted information and the plaintext data. This application constructs a correspondence between the receiver and the encrypted information, so that the plaintext information sent by the same receiver is encrypted using the same encrypted information, and further enables the ciphertext sent by the same sender and received by the same receiver to realize the function of homomorphic encryption based on the encrypted information.
[0039] In an embodiment of the present application, the method further includes: periodically updating the correspondence between the recipient and the encrypted information at preset time intervals.
[0040] It can be understood that, considering the security of data transmission, in order to prevent the predetermined encrypted information from being cracked, the embodiment of the present application can periodically update the correspondence between the recipient and the encrypted information according to a preset time interval, and the preset time interval can be set according to actual application requirements, experimental results or actual experience. In other words, within the same time interval, the ciphertext data received by the same recipient can achieve the function of homomorphic encryption.
[0041] In an embodiment of the present application, a target ciphertext corresponding to the original plaintext is generated according to the target encryption information and the plaintext data, including: encrypting the plaintext data according to the target symmetric key in the target encryption information to obtain a second ciphertext; based on a hash algorithm, determining a third ciphertext according to the target sender shared key and the plaintext data in the target encryption information; generating a target ciphertext according to the target first ciphertext, second ciphertext and third ciphertext in the target encryption.
[0042] It can be understood that after determining the target encryption information corresponding to the message to be sent and processing the original plaintext of the message to be sent into the corresponding plaintext data of the preset length, the plaintext data can be encrypted using the SM2 encryption algorithm according to the target encryption information to obtain the target ciphertext corresponding to the original plaintext. Specifically, firstly encrypt the plaintext data with a preset length based on the target symmetric key to obtain the second ciphertext. In one example, the plaintext data can be encrypted by the target symmetric key in the form of an or operation. It can be understood that when the bit length of the original plaintext exceeds the preset length, after the original plaintext is grouped according to the preset length, a plurality of plaintext data with a preset length can be obtained, and then the corresponding second ciphertext obtained after the encryption processing is also composed of a plurality of ciphertexts of a plurality of plaintext data. Then, a hash operation is performed according to the target sender shared key and the plaintext data to obtain a third ciphertext. Finally, the target first ciphertext, the second ciphertext and the third ciphertext are encapsulated and combined to obtain the target ciphertext corresponding to the message to be sent. In this way, when the encryption information is predetermined, the encryption processing of the original plaintext of the message to be sent can be quickly realized, thereby improving the data processing efficiency.
[0043] In an embodiment of the present application, the original plaintext is processed according to a preset length to obtain plaintext data with a preset length, including: when the length of the original plaintext is greater than the preset length, the original plaintext is grouped according to the preset length to obtain multiple groups of plaintext data; when the length of the original plaintext is less than the preset length, the original plaintext is padded to obtain plaintext data.
[0044] It can be understood that in order to realize the homomorphic encryption function, it is necessary to ensure that the length of the ciphertext data is consistent. Specifically, the original plaintext of the message to be sent is processed according to the preset length to obtain plaintext data with a bit length of the preset length. In one example, if the length of the original plaintext is greater than the preset length, the original plaintext needs to be grouped into multiple plaintext data with a preset length. If the last group is less than the preset length, padding is performed. Similarly, in another example, if the length of the original plaintext is less than the preset length, the original plaintext needs to be padded and supplemented. The padding method does not change the specific data of the original plaintext, but only changes its bit length. In this way, the length of the encrypted ciphertext data can be guaranteed to be consistent, which is conducive to the realization of the homomorphic encryption function.
[0045] In an embodiment of the present application, the recipient information includes the recipient public key, and determining the correspondence between the recipient and the encrypted information according to a preset national secret algorithm includes: determining the sender public key according to the sender private key and the base point of a preset elliptic curve, the sender private key being a random number within a preset range; converting the sender public key into a bit string to obtain a first ciphertext; based on the preset elliptic curve, determining the elliptic curve point according to the recipient public key; judging whether the elliptic curve point is an infinity point; if the elliptic curve point is not an infinity point, determining the sender shared key according to the sender private key and the recipient public key; based on a preset key derivation function, determining the symmetric key according to the sender shared key and a preset length; judging whether the symmetric key is an all-zero bit string; if the symmetric key is not an all-zero bit string, storing the recipient information in association with the first ciphertext, the sender shared key and the symmetric key to obtain the correspondence between the recipient and the encrypted information.
[0046] In an embodiment of the present application, the method further includes: outputting an error prompt when the elliptic curve point is a point at infinity.
[0047] In an embodiment of the present application, the method further includes: when the symmetric key is an all-zero bit string, updating the sender's private key and redetermining the correspondence between the receiver and the encrypted information.
[0048] Specifically, the correspondence between the receiver and the encrypted information can be predetermined according to a preset national encryption algorithm, that is, after the sender and the receiver establish a connection, the sender will return the receiver's information to the receiver, including the receiver's public key. Further, according to the receiver's public key, a set of encrypted information is determined by the SM2 algorithm, and the encrypted information includes the first ciphertext, the sender's shared key, and the symmetric key generated in the SM2 algorithm encryption process. Finally, the receiver's information is associated with the first ciphertext and the sender's shared key, that is, the symmetric key, and the correspondence between the receiver and the encrypted information is obtained. It can be understood that since the encrypted information in the SM2 algorithm is generated based on random numbers and combined with the receiver's public key, the encrypted information corresponding to each receiver is different.
[0049] Preferably, the correspondence between the receiver and the encrypted information can be periodically updated at a preset time interval, that is, at each preset period, the encrypted information corresponding to the receiver is re-determined according to the receiver information through the SM2 national encryption algorithm. In this way, the encrypted information can be prevented from being cracked by a third party, thereby improving the security of the data.
[0050] In a specific embodiment of the present application, the original national secret SM2 asymmetric encryption algorithm is improved for the cloud environment, and an approximate method of homomorphic encryption is implemented. Figure 2A schematic diagram of a homomorphic encryption method based on the national secret SM2 algorithm is provided for a specific embodiment of the present application. Figure 2 As shown, the homomorphic encryption method based on the national secret SM2 algorithm includes the following steps:
[0051] S1. Group message M into M1, M2, ..., Mi, and fill in when necessary.
[0052] S2. Select a random number k and generate a point kG (temporary key) on the elliptic curve.
[0053] S3. Use k and the recipient's public key to generate kPB (shared key), and use the KDF derivation function to generate t (symmetric key) based on the shared key.
[0054] S4, key t and plain text are used to calculate the encrypted ciphertext C21, C22...C2i; the final combination of C1, C21, C22...C2i and C3 is C.
[0055] S5. Send C to the other user B.
[0056] S6, the ciphertext processing module, can implement an approximate homomorphic encryption algorithm based on the ciphertexts C21, C22...C2i.
[0057] Specifically, user A (sender) needs to send a message to user B (receiver) (assuming that the message to be sent is message M, and message M is plain text) as an example for explanation. The symbols used in the embodiments of the present application are described in advance as follows:
[0058] A and B represent two users, user A and user B, who use the homomorphic encryption approximation method, where user A is the sender and user B is the receiver.
[0059] M represents the message that user A needs to send to user B, which is in plain text.
[0060] PB represents the public key of user B.
[0061] h represents a constant parameter related to the elliptic curve used by the national cryptographic algorithm.
[0062] KDF() is a key derivation function in the national cryptographic algorithm.
[0063] Hash() is a hash function in the national encryption algorithm.
[0064] G represents a base point of the elliptic curve used by the national encryption algorithm, and its order is a prime number.
[0065] n represents the order of the base point G.
[0066] klen is the bit length of the message M. In the SM2 encryption algorithm, klen is an important parameter that determines the generation of the key and the structure of the ciphertext during the encryption process.
[0067] Specifically, in order to encrypt the message M, and adopt the homomorphic encryption approximation method of the national secret SM2 asymmetric encryption algorithm, user A as the encryptor should implement the following operation steps:
[0068] Step 1: User A groups the message M into multiple bit strings of equal length (denoted as: M1, M2, ...Mi); in this process, if the length of the message M does not meet the requirements, it can be adjusted by padding to make it fit the length specification of the grouping.
[0069] Step 2: User A uses a random number generator to generate a random number k; where k∈[1,n-1], n is the order of the base point G.
[0070] Step 3: Calculate the elliptic curve point C1 according to the random number, C1 = [k] G = (x1, y1), convert the data type of C1 into a bit string, and obtain the first ciphertext in the above embodiment. Among them, G is a base point of the elliptic curve, and its order is a prime number; the coordinate (x1, y1) is the bit string representation of the elliptic curve point C1, which can also be called the temporary key of user A. This step is to generate randomness and ensure the security and uniqueness of the key.
[0071] Step 4: Calculate the elliptic curve point S, S = [h] PB. And determine whether S is a point at infinity based on the calculation result. If S is a point at infinity, report an error and exit. Among them, h is a constant parameter related to the elliptic curve used by the national secret algorithm; PB is the public key of user B.
[0072] Step 5: Calculate the elliptic curve point [k]PB, [k]PB = (x2, y2), and convert the data type of [k]PB into a bit string according to the national encryption conversion rules. The coordinates (x2, y2) are the bit string representation of the elliptic curve point [k]PB, which can also be called the shared key calculated by user A.
[0073] Step 6: Calculate t = KDF (x2||y2, klen), if t is a string of all 0 bits, return to step 2. Wherein, KDF() is a key derivation function; klen is the bit length of the message M packet, that is, the preset length in the above implementation; since x2 and y2 represent shared keys, t is a fixed-length symmetric key generated by the key derivation function, and this process can be called "key derivation" or "key derivation result".
[0074] Step 7: Calculate the second ciphertext, which includes C21, C22, ..., C2i. In one embodiment, C21 = M1⊕t, similarly C22 = M2⊕t and C2i = Mi⊕t. That is, the ciphertext corresponding to the grouped plaintext data is the value of the OR operation of the plaintext data and the symmetric key.
[0075] Step 8: Calculate the third ciphertext C3, C3 = Hash(x2||M1||M2||…||Mi||y2); where Hash() is a hash function.
[0076] Step 9: Output the target ciphertext C=C1||C21||C22||…||C2i||C3.
[0077] Step 10: User B receives the final output target ciphertext C.
[0078] It can be understood that the encrypted plaintext M1+M2 is not equal to the ciphertext C21+C22. However, the ciphertext corresponding to the plaintext M1+M2 does not need to be encrypted and sent by the encrypting party. The receiving party can easily use the ciphertext C21 and C22 to combine the ciphertext corresponding to the plaintext M1+M2. That is, the operation result of (C21⊕t+C22⊕t)⊕t is the same as the operation result of (M1+M2)⊕t. Based on this, the function of homomorphic encryption can be realized, that is, there is no need to decrypt the data and perform operations in the state of ciphertext. It can be understood that for plaintext data of the same length encrypted with the same first ciphertext, symmetric key and shared key, the function of homomorphic encryption can be realized between the corresponding ciphertext data.
[0079] Figure 3 A schematic diagram of the structure of a homomorphic encryption device based on a national secret algorithm provided in an embodiment of the present application. Figure 3 As shown, the embodiment of the present application also provides a homomorphic encryption device 300 based on the national secret algorithm, and the homomorphic encryption device 300 includes:
[0080] The data acquisition module 310 is used to acquire the original plaintext of the message to be sent and the recipient information of the recipient of the message to be sent;
[0081] The data determination module 320 is used to determine the target encrypted information corresponding to the message to be sent according to the recipient information based on the correspondence between the recipient and the encrypted information predetermined according to the preset national encryption algorithm, where the encrypted information includes the first ciphertext, the sender shared key and the symmetric key;
[0082] The data processing module 330 is used to process the original plaintext according to a preset length to obtain plaintext data with a preset length;
[0083] The data generation module 340 is used to generate a target ciphertext corresponding to the original plaintext according to the target encryption information and the plaintext data.
[0084] The above-mentioned homomorphic encryption device 300 based on the national secret algorithm obtains the original plaintext of the message to be sent and the receiver information of the receiver of the message to be sent, and then determines the target encrypted information corresponding to the message to be sent according to the receiver information based on the correspondence between the receiver and the encrypted information predetermined according to the preset national secret algorithm, and the encrypted information includes the first ciphertext, the sender's shared key and the symmetric key, and then processes the original plaintext according to the preset length to obtain plaintext data with a preset length, and finally generates the target ciphertext corresponding to the original plaintext according to the target encrypted information and the plaintext data. This application constructs a correspondence between the receiver and the encrypted information, so that the plaintext information sent by the same receiver is encrypted using the same encrypted information, and further enables the ciphertext sent by the same sender and received by the same receiver to realize the homomorphic encryption function based on the encrypted information.
[0085] In an embodiment of the present application, the homomorphic encryption device 300 is also used to: periodically update the correspondence between the recipient and the encrypted information according to a preset time interval.
[0086] In an embodiment of the present application, the data generation module 340 is also used to: encrypt the plaintext data according to the target symmetric key in the target encryption information to obtain a second ciphertext; determine the third ciphertext based on the target sender shared key and plaintext data in the target encryption information based on the hash algorithm; generate the target ciphertext according to the target first ciphertext, second ciphertext and third ciphertext in the target encryption.
[0087] In an embodiment of the present application, the data processing module 330 is also used to: when the length of the original plaintext is greater than a preset length, group the original plaintext according to the preset length to obtain multiple groups of plaintext data; when the length of the original plaintext is less than the preset length, pad the original plaintext to obtain plaintext data.
[0088] In an embodiment of the present application, the recipient information includes the recipient public key, and the data determination module 320 is also used to: determine the sender public key based on the sender private key and the base point of a preset elliptic curve, the sender private key being a random number within a preset range; convert the sender public key into a bit string to obtain a first ciphertext; based on the preset elliptic curve, determine the elliptic curve point based on the recipient public key; determine whether the elliptic curve point is an infinity point; if the elliptic curve point is not an infinity point, determine the sender shared key based on the sender private key and the recipient public key; based on a preset key derivation function, determine the symmetric key based on the sender shared key and a preset length; determine whether the symmetric key is an all-zero bit string; if the symmetric key is not an all-zero bit string, store the recipient information in association with the first ciphertext, the sender shared key and the symmetric key to obtain a corresponding relationship between the recipient and the encrypted information.
[0089] In the embodiment of the present application, the data determination module 320 is further used to: output an error prompt when the elliptic curve point is a point at infinity.
[0090] In the embodiment of the present application, the data determination module 320 is also used to: when the symmetric key is an all-zero bit string, update the sender's private key and redetermine the correspondence between the recipient and the encrypted information.
[0091] An embodiment of the present application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the homomorphic encryption method based on the national secret algorithm in the above-mentioned implementation mode when executing the computer program.
[0092] An embodiment of the present application also provides a machine-readable storage medium, which stores programs or instructions. When the program or instructions are executed by a processor, the homomorphic encryption method based on the national secret algorithm in the above-mentioned implementation is implemented.
[0093] An embodiment of the present application also provides a computer program product, including a computer program, which, when executed by a processor, implements the homomorphic encryption method based on the national secret algorithm in the above-mentioned implementation manner.
[0094] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0095] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0096] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0097] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0098] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0099] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0100] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0101] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity 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, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0102] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.
Claims
1. A homomorphic encryption method based on a national secret algorithm, characterized in that: include: Obtaining the original plaintext of the message to be sent and the recipient information of the recipient of the message to be sent; Based on the correspondence between the recipient and the encrypted information predetermined according to the preset national encryption algorithm, the target encrypted information corresponding to the message to be sent is determined according to the recipient information, and the encrypted information includes the first ciphertext, the sender shared key and the symmetric key; Processing the original plaintext according to a preset length to obtain plaintext data with a length of the preset length; A target ciphertext corresponding to the original plaintext is generated according to the target encryption information and the plaintext data.
2. The method according to claim 1, characterized in that The method further comprises: The correspondence between the receiving party and the encrypted information is periodically updated at preset time intervals.
3. The method according to claim 1, characterized in that The step of generating a target ciphertext corresponding to the original plaintext according to the target encryption information and the plaintext data includes: Encrypting the plaintext data according to the target symmetric key in the target encryption information to obtain a second ciphertext; Determine a third ciphertext based on a hash algorithm according to a target sender shared key in the target encrypted information and the plaintext data; The target ciphertext is generated according to the target first ciphertext, the second ciphertext and the third ciphertext in the target encryption.
4. The method according to claim 1, characterized in that: The processing of the original plaintext according to the preset length to obtain plaintext data having a preset length includes: In the case where the length of the original plaintext is greater than the preset length, grouping the original plaintext according to the preset length to obtain multiple groups of the plaintext data; When the length of the original plaintext is less than the preset length, the original plaintext is padded to obtain the plaintext data.
5. The method according to claim 1, characterized in that The recipient information includes a recipient public key, and determining the correspondence between the recipient and the encrypted information according to the preset national encryption algorithm includes: Determine the sender's public key according to the sender's private key and a base point of a preset elliptic curve, wherein the sender's private key is a random number within a preset range; Convert the sender public key into a bit string to obtain the first ciphertext; Based on the preset elliptic curve, determining an elliptic curve point according to the recipient's public key; Determine whether the elliptic curve point is a point at infinity; In the case where the elliptic curve point is not a point at infinity, determining the sender shared key according to the sender private key and the receiver public key; Determine the symmetric key based on a preset key derivation function and the sender shared key and the preset length; Determining whether the symmetric key is an all-zero bit string; In the case where the symmetric key is not an all-zero bit string, the recipient information is stored in association with the first ciphertext, the sender shared key and the symmetric key to obtain a corresponding relationship between the recipient and the encrypted information.
6. The method according to claim 5, characterized in that The method further comprises: When the elliptic curve point is a point at infinity, an error prompt is output.
7. The method according to claim 5, characterized in that The method further comprises: In the case where the symmetric key is an all-zero bit string, the sender's private key is updated, and the corresponding relationship between the receiver and the encrypted information is re-determined.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the homomorphic encryption method based on the national secret algorithm according to any one of claims 1 to 7 is implemented.
9. A machine-readable storage medium storing a program or instruction, characterized in that: When the program or the instruction is executed by the processor, the homomorphic encryption method based on the national secret algorithm according to any one of claims 1 to 7 is implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, it implements the homomorphic encryption method based on the national secret algorithm according to any one of claims 1 to 7.