Data encryption method, device, equipment and storage medium based on hash algorithm
Through the information expansion and wheel key calculation method based on the grid problem framework, the wheel key is calculated using a random matrix, and the existing hash function algorithm is solved for complex calculations and insufficient quantum security resistance, and efficient quantum security resistance and reconfigurability are achieved. The encryption process is suitable for scenarios such as the Internet of Things.
Patent Information
- Application Number
- CN202411522515.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-29
- Publication Date
- 2025-08-19
- Estimated Expiration
- 2044-10-29
AI Technical Summary
The existing hash function algorithm has complex calculation logic and high overhead, which is not suitable for low-power scenarios, and has weak quantum attack resistance and low quantum security resistance.
The information expansion and wheel key calculation method based on the grid problem framework is adopted, and the wheel key is calculated using a random matrix. The information expansion and key calculation process are decoupled. The hash value calculation logic is not related to key expansion, and it supports reconstructibility in scenarios such as the Internet of Things.
It improves the quantum security resistance of the one-way data encryption process, reduces the cost of cryptographic algorithm replacement, and is suitable for scenarios such as the Internet of Things.
Smart Images

Figure CN119402185B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data encryption technology, and in particular to a data encryption method, device, equipment and storage medium based on a hash algorithm. Background Art
[0002] Hash functions, such as hash functions, are a common concept in modern cryptography and are widely used in scenarios such as network security communication protocols, random number generation, identity authentication, evidence storage, and blockchain. Existing hash algorithms include MD5 (Message-Digest Algorithm), SHA1 (Secure Hash Algorithm), SHA256, SHA3, and SM3 (State Encryption Algorithm).
[0003] Although existing hash function technology can be applied to various information encryption scenarios, it still has the following two major problems: the existing hash function algorithm relies on bit operations, modular addition operations and S-box structures, and the calculation logic is relatively complex and the overhead is large, which is not conducive to application in low-power scenarios; secondly, the existing hash algorithm relies on traditional technologies such as bit permutation in message expansion, and has weak resistance to quantum attacks, resulting in low anti-quantum security. Summary of the Invention
[0004] The present invention provides a data encryption method, device, equipment and storage medium method, device, equipment and storage medium based on a hash algorithm to improve the quantum security of a one-way data encryption process.
[0005] According to one aspect of the present invention, a data encryption method based on a hash algorithm is provided, the method comprising:
[0006] Obtaining a current round key in a current hash value calculation cycle; the current round key includes at least one subkey; wherein the current round key is generated based on the obtained plaintext data to be encrypted;
[0007] Obtain the historical hash key for the previous historical hash value calculation cycle;
[0008] Generate a current hash key for the current hash value calculation period based on the historical hash key and each subkey in the current round key;
[0009] If the current hash value calculation period meets a preset period cycle end condition, a hash value of the plaintext data to be encrypted is generated according to the current hash key under the current hash value calculation period and the historical hash keys under each historical hash value calculation period, and the hash value is used as the ciphertext data of the plaintext data to be encrypted.
[0010] According to another aspect of the present invention, there is provided a data encryption device based on a hash algorithm, the device comprising:
[0011] a round key acquisition module, configured to acquire a current round key in a current hash value calculation cycle; the current round key including at least one subkey; wherein the current round key is generated based on the acquired plaintext data to be encrypted;
[0012] A historical hash key acquisition module is used to obtain the historical hash key under the previous historical hash value calculation cycle;
[0013] a current hash key generation module, configured to generate a current hash key for the current hash value calculation period based on the historical hash key and each subkey in the current round key;
[0014] a ciphertext data generation module configured to generate, if the current hash value calculation period satisfies a preset period cycle end condition, a hash value of the plaintext data to be encrypted based on a current hash key in the current hash value calculation period and historical hash keys in each historical hash value calculation period, and use the hash value as ciphertext data of the plaintext data to be encrypted.
[0015] According to another aspect of the present invention, an electronic device is provided, comprising:
[0016] at least one processor; and
[0017] a memory communicatively connected to the at least one processor; wherein,
[0018] The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the data encryption method based on the hash algorithm described in any embodiment of the present invention.
[0019] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the data encryption method based on the hash algorithm described in any embodiment of the present invention when executed.
[0020] The embodiments of the present invention utilize an information expansion and round key calculation method based on a lattice problem framework, using a random matrix to calculate round keys. This method is highly innovative and improves the quantum security of the one-way data encryption process. The information expansion and round key calculation processes are completely decoupled from the hash value calculation process. The information expansion and key calculation modules, as well as the hash value calculation module, can be deployed in different components, offering high reconfigurability and facilitating application in scenarios such as the Internet of Things. The hash value calculation logic rules are independent of key expansion, and the hash calculation is reconfigurable. That is, while the round key calculation and information expansion modules change, the hash value module and code remain unchanged, reducing the cost of replacing the cryptographic algorithm.
[0021] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present invention, nor is it intended to limit the scope of the present invention. Other features of the present invention will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0023] Figure 1 This is a flow chart of a data encryption method based on a hash algorithm provided according to the first embodiment of the present invention;
[0024] Figure 2 2 is a schematic diagram of the structure of a data encryption device based on a hash algorithm according to a second embodiment of the present invention;
[0025] Figure 3 The present invention is a schematic diagram of the structure of an electronic device that implements the data encryption method based on the hash algorithm according to an embodiment of the present invention. DETAILED DESCRIPTION
[0026] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.
[0027] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0028] Example 1
[0029] Figure 1 This is a flowchart of a data encryption method based on a hash algorithm provided in the first embodiment of the present invention. This embodiment is applicable to data encryption and decryption situations where there is a need for one-way encryption of plaintext data to be encrypted, and the encryption process has anti-quantity security. This method can be executed by a data encryption device based on a hash algorithm. The data encryption device based on a hash algorithm can be implemented in the form of hardware and / or software. The data encryption device based on a hash algorithm can be configured in an electronic device. Figure 1 As shown, the method includes:
[0030] S110: Obtain a current round key in a current hash value calculation cycle; the current round key includes at least one subkey; wherein the current round key is generated based on the obtained plaintext data to be encrypted.
[0031] S120: Obtain a historical hash key in a previous historical hash value calculation cycle.
[0032] S130: Generate a current hash key in a current hash value calculation period according to the historical hash key and each subkey in the current round key.
[0033] S140. If the current hash value calculation period satisfies a preset period cycle end condition, a hash value of the plaintext data to be encrypted is generated according to the current hash key in the current hash value calculation period and the historical hash keys in each historical hash value calculation period, and the hash value is used as the ciphertext data of the plaintext data to be encrypted.
[0034] The round key may be a key used for hash value calculation, specifically pre-generated based on the plaintext data to be encrypted. The plaintext data to be encrypted is plaintext data requiring one-way encryption. The round keys generated based on the plaintext data to be encrypted may include at least one set, each set of round keys including at least one subkey used for hash calculation.
[0035] In a specific embodiment, the round key and its subkeys are generated as follows:
[0036] Step a1: Obtain the plaintext data to be encrypted.
[0037] Step a2: dividing the plaintext data to be encrypted according to a preset first unit length to obtain at least one group of intermediate plaintext data and the number of data groups of the intermediate plaintext data.
[0038] Optionally, data segmentation is performed on the plaintext data to be encrypted according to a preset first unit length to obtain at least one group of intermediate plaintext data, including: performing binary conversion on the plaintext data to be encrypted to obtain binary plaintext data; data padding is performed on the binary plaintext data based on a preset padding value according to the data length of the binary plaintext data to obtain padded plaintext data; data segmentation is performed on the padded plaintext data according to the preset first unit length to obtain at least one group of intermediate plaintext data.
[0039] Specifically, the encrypted plaintext data msg is subjected to bit string expansion, i.e., binary conversion, to obtain binary plaintext data. The data length of the binary plaintext data is calculated, and bit padding is performed according to an integer multiple of the preset length W to obtain padded plaintext data. The preset padding value can be pre-set by relevant technical personnel according to actual needs. For example, the preset padding value can be set to 0. The specific padding method is as follows:
[0040] msg||0…0||msg…||…0…;
[0041] The data length of the padded plaintext data is an integer multiple of the preset length W.
[0042] Based on the preset first unit length, the padded plaintext data is split to obtain at least one set of intermediate plaintext data msg i The first unit length can be preset by relevant technical personnel and can be the same as the preset length W mentioned above. The specific segmentation method is as follows:
[0043] msg||0…0||msg…||…0=msg1||…msg i …||msg v ;
[0044] Among them, each group of intermediate plaintext data msg i The length of is exactly W; i=1,...,v.
[0045] Step a3: split each group of intermediate plaintext data according to the preset second unit length to obtain the plaintext sub-data corresponding to each group of intermediate plaintext data.
[0046] The second unit length can be pre-set by relevant technical personnel according to actual needs, and the specific requirement is that the first unit length can be divided by the second unit length. If the second unit length is set to T, the first unit length is W, and W / T=v, then for any set of intermediate plaintext data msg i , for the intermediate plaintext data msg i Perform bit string segmentation to obtain plaintext sub-data (bit string) S 1,i , S 2,i ,…,S N,i , the specific segmentation method is as follows:
[0047] msg i =S 1,i ||S 2,i ||…||S N,i ;
[0048] Each plaintext subdata S 1,i , S 2,i ,…,S N,i The length is T.
[0049] Step a4: Generate subkeys under at least one round key equal to the number of data groups based on the plaintext subdata corresponding to each group of intermediate plaintext data.
[0050] Optionally, based on the plaintext sub-data corresponding to each group of intermediate plaintext data, sub-keys under at least one round key equal to the number of data groups are generated, including: for any group of intermediate plaintext data, generating a plaintext sub-data matrix based on the plaintext sub-data of the group of intermediate plaintext data; generating a lattice basis matrix, and generating a target matrix under the round key generation round corresponding to the group of intermediate plaintext data based on the plaintext sub-data matrix and the lattice basis matrix; generating at least one sub-key under the key generation round based on the matrix value in the target matrix.
[0051] Specifically, for any set of intermediate plaintext data msg i , according to the plaintext sub-data S of the intermediate plaintext data 1,i , S 2,i ,…,S N,i , convert it into integer (decimal) to get the plaintext sub-data S 1,i , S 2,i ,…,S N,i The corresponding integer data a 1,i ,…,a N,i , convert the integer data into vector (matrix) form and obtain the plaintext sub-data matrix a i :
[0052] a i =(a 1,i ,…,aN,i );
[0053] Perform the above operations on each set of intermediate plaintext data to obtain a1, ...a i ......a v .
[0054] Generate a lattice matrix, or read a lattice matrix. The lattice matrix can be generated in advance. The lattice matrix of a random normal integer modulo q can be The integer modulus q is pre-set according to actual needs, where the size of N is the same as the number of elements in the plaintext sub-data matrix.
[0055] According to the plaintext sub-data matrix a i And the lattice matrix B, generate the target matrix Q under the round key generation round corresponding to the group of intermediate plaintext data:
[0056]
[0057] Among them, t represents matrix transpose, not power.
[0058] The matrix value b in the target matrix 1,i , b 2,i ,…,b M,i , converted into M binary bit strings (T 1,i , T 2,i ,…,T M,i )=(b 1,i , b 2,i ,…,b M,i ). Merge the converted binary bit strings to get According to the specified rules, Calculate or extract valid bits to form R subkeys, recorded as Key 1,i ,…,Key R,i , the bit length of each subkey is L. After i=1,…,v are operated in this way, a total of v round keys can be obtained, and each round key includes R subkeys Key 1,i ,…,Key R,i .
[0059] Among them, the current round key in the current hash value calculation cycle can be the i-th round key, and the i-th round key includes R subkeys Key 1,i ,…,Key R,i .
[0060] Get the historical hash key X1,…,X in the previous historical hash value calculation cycle C The initial hash key in the initial hash calculation cycle is generated by randomly generating an initial bit string Z1, ...Z i…, Z C , each bit string Z i The length can be set to L, and the initial bit string is (X1, ..., X C )=(Z1,…,Z C ), each X i are converted into integer form.
[0061] In a specific embodiment, generating a current hash key for a current hash value calculation period based on the historical hash key and each subkey in the current round key includes:
[0062] Step b1: Generate intermediate hash parameters based on the historical hash key.
[0063] If the historical hash key is (X1, ..., X C ), the generation process of the intermediate hash parameter Y is as follows:
[0064] Y=X1+X2+…X C-1 ;
[0065] Among them, "+" is a modular addition operation.
[0066] Step b2: Perform a bit string cyclic shift operation on the intermediate hash parameter to obtain a reference hash parameter.
[0067] Convert the intermediate hash parameter Y into a bit string form, and perform a bit string cyclic shift on the intermediate hash parameter. For example, the low-order bits can be converted to high-order bits by cyclic right shift to obtain a new bit string Y, and convert the bit string Y into an integer to obtain the reference hash parameter Y. * .
[0068] Step b3: Generate the current hash key in the current hash value calculation period based on the reference hash parameter and each subkey in the current round key.
[0069] According to the reference hash parameter Y * , and perform modular addition operations based on each subkey in the current round key. If the current round key is the first round and the subkey is the first subkey, calculate the modular addition U:
[0070] U=Y * +Key 1,1 ;
[0071] Among them, "+" is a modular addition operation.
[0072] Update calculation Update calculation X j =X j-1 , j = 1, 2, ... C; output updated X1, ..., X CAs the calculation result of the first round of small cycle. In the current hash calculation cycle, after R rounds of cycles, the difference between each round is only the different round keys (the order of using the round keys is Key 1,1 ,Key 2,1 ,…,Key R,1 ), and get the output X1,…,X after the R round small cycle update C , as the current hash key in the current hash value calculation period.
[0073] If the current hash value calculation period meets the preset period cycle end condition, a hash value of the plaintext data to be encrypted is generated according to the current hash key under the current hash value calculation period and the historical hash keys under each historical hash value calculation period, and the hash value is used as the ciphertext data of the plaintext data to be encrypted.
[0074] It can be understood that the number of data groups of intermediate plaintext data is v, and it is necessary to complete the loop traversal of each group of intermediate plaintext data. Therefore, the cycle end condition is set based on the number of data groups of the intermediate plaintext data. The input result of each round is the output result of the previous round. After v rounds of loops, the X1...X generated by the last round of loop is obtained. C If the current hash value calculation cycle is the last cycle, then the X1...X generated by the current hash value calculation cycle C Perform splicing to obtain the hash value X=X1||…||X of the plaintext data to be encrypted C The hash value is used as the ciphertext data of the plaintext data to be encrypted.
[0075] The embodiments of the present invention utilize an information expansion and round key calculation method based on a lattice problem framework, using a random matrix to calculate round keys. This method is highly innovative and improves the quantum security of the one-way data encryption process. The information expansion and round key calculation processes are completely decoupled from the hash value calculation process. The information expansion and key calculation modules, as well as the hash value calculation module, can be deployed in different components, offering high reconfigurability and facilitating application in scenarios such as the Internet of Things. The hash value calculation logic rules are independent of key expansion, and the hash calculation is reconfigurable. That is, while the round key calculation and information expansion modules change, the hash value module and code remain unchanged, reducing the cost of replacing the cryptographic algorithm.
[0076] Based on the above embodiment, this embodiment also provides a preferred embodiment, and the specific implementation method is as follows.
[0077] This solution includes five main steps: algorithm initialization, data initialization, data padding and trimming, round key calculation, and hash value calculation. Each step is described in detail below:
[0078] 1. Algorithm Initialization
[0079] Determine the basic parameters of the algorithm: output length = P, typically 128, 256, 512, etc.; data unit length = W; plaintext block length = L, also known as word length, typically 16, 32, etc.; number of blocks P / L = C; modulus = D, typically 2^16, 2^32, etc.; number of iterations = R, typically 16, 32, 48, 64, etc.; lattice parameters q, M, N, i.e., parameters related to the lattice matrix B∈Z_q^(M×N), generally requiring D≤q. This solution imposes no specific restrictions or constraints on these parameters; the parameter values provided in the solution are for reference only.
[0080] 2. Data Initialization
[0081] 1. Generate C initial group bit strings Z1, ..., Z according to the specified length using a pseudo-random number generator or other methods. C , the length of each string is L, Z1,…,Z C After generation, it is stored long-term as the initialization data of the hash function. If this initialization data is updated, it means that the hash function has changed and updated.
[0082] 2. Randomly generate a lattice matrix of integer modulo q After B is generated, it is stored long-term as the initialization data of the hash function. If this initialization data is updated, it means that the hash function has changed and updated.
[0083] 3. Data Filling and Cutting
[0084] 1. The user expands the bit string of the input data msg to be hashed to obtain the input data msg in binary representation. The bit length of msg is calculated and bit-filled according to an integer multiple of W, that is, a certain number of 0s is filled so that the length of msg||0…0 is exactly a multiple of W. The input data after segmentation is recorded as msg||0…0=msg1||…||msg v , satisfy each msg i The length of is exactly W.
[0085] 2. For i=1,…,v, each msg i According to the unit length = T, it is divided into W / T = v sub-bit strings, and the requirement is that W can be divided by T. The sub-bit string is recorded as S 1,i , S 2,i ,…,S N,i , meet msg i =S 1,i ||S 2,i ||…||S N,i The length of each sub-bit string is T.
[0086] 3. Convert each sub-bit string (binary) into an integer (decimal), then (S1,i , S 2,i ,…,S N,i )=(a 1,i ,…,a N,i )=a i The same operation is performed for i=1,…,v.
[0087] 4. Calculate the round key
[0088] 1. Read the lattice matrix
[0089] 2. Calculate the matrix multiplication by the vector t represents matrix transpose, not power, and the addition is modular q addition.
[0090] 3. The integer b 1,i , b 2,i ,…,b M,i Converted into M binary bit strings (T 1,i , T 2,i ,…,T M,i )=(b 1,i , b 2,i ,…,b M,i ).
[0091] 4. Combine the above bit strings to get a long bit string
[0092] 5. According to the specified rules, Calculate or extract valid bits to form R round keys, recorded as Key 1,i ,…,Key R,i , the bit length of each round key is L.
[0093] 6. After following the same operation for i=1, ..., v, a total of R*v round keys (Key 1,i ,…,Key R,i ) i=1,…,v .
[0094] 5. Hash value calculation
[0095] The large cycle is v rounds, and each large cycle is divided into R small cycles. The calculation logic of all cycles is exactly the same. Here we only introduce the first large cycle in detail.
[0096] 1. Read the initial bit string Z1, ..., Z C , each Z i The length L of the loop is (note that only the first large loop needs to read the initial bit string as the starting point of calculation, and the input of other large loops is the output of the previous large loop).
[0097] 2. Let (X1,…,X C )=(Z1,…,Z C ), and each X i are converted into integer form.
[0098] 3. Calculate integer modular addition Y = X1 + v2 + ... X C-1 (mod D).
[0099] 4. Convert Y into a bit string.
[0100] 5. Circularly shift the bit string calculated in the previous step. For example, you can convert the low-order bits to high-order bits by circularly shifting right to obtain a new bit string Y. * , and convert the bit string Y * Convert to an integer.
[0101] 6. Calculate modular addition U=Y * +Key 1,1 (mod D).
[0102] 7. Update calculation (mod D).
[0103] 8. Update calculation X j =X j-1 , j=1,2,…C.
[0104] 9. Output the updated X1,…,X C As the calculation result of the first round of small cycle.
[0105] 10. In this round of large cycle, after R rounds of small cycle calculation, the difference between each round is only the round key (the order of using the round key is Key 1,1 ,Key 2,1 ,…,Key R,1 ), and get the output X1,…,X after the R round small cycle update C , thus completing the first round of the cycle.
[0106] 11. In the subsequent large cycle (for example, the jth large cycle), read the output X1, ..., X1 of the previous large cycle (j-1 rounds). C , execute the algorithm of steps 1-10, using the order of round keys as Key 1,j ,Key 2,j ,…,Key R,j After a total of v rounds of large loops, the final hash output is X = X1||…||X C .
[0107] Example 2
[0108] Figure 2This is a structural diagram of a data encryption device based on a hash algorithm provided in the second embodiment of the present invention. The data encryption device based on a hash algorithm provided in the embodiment of the present invention is applicable to data encryption and decryption situations where there is a need for one-way encryption of plaintext data to be encrypted, and the encryption process has anti-quantity security. The data encryption device based on the hash algorithm can be implemented in the form of hardware and / or software, such as Figure 2 As shown, the device specifically includes: a round key acquisition module 201, a historical hash key acquisition module 202, a current hash key generation module 203 and a ciphertext data generation module 204.
[0109] The round key acquisition module 201 is configured to acquire a current round key in a current hash value calculation cycle; the current round key includes at least one subkey; wherein the current round key is generated based on the acquired plaintext data to be encrypted;
[0110] A historical hash key acquisition module 202 is used to obtain the historical hash key of the previous historical hash value calculation cycle;
[0111] The current hash key generation module 203 is configured to generate a current hash key for the current hash value calculation period based on the historical hash key and each subkey in the current round key;
[0112] The ciphertext data generation module 204 is configured to generate a hash value for the plaintext data to be encrypted based on the current hash key in the current hash value calculation period and the historical hash keys in each historical hash value calculation period if the current hash value calculation period satisfies a preset period cycle end condition, and use the hash value as the ciphertext data for the plaintext data to be encrypted.
[0113] The embodiments of the present invention utilize an information expansion and round key calculation method based on a lattice problem framework, using a random matrix to calculate round keys. This method is highly innovative and improves the quantum security of the one-way data encryption process. The information expansion and round key calculation processes are completely decoupled from the hash value calculation process. The information expansion and key calculation modules, as well as the hash value calculation module, can be deployed in different components, offering high reconfigurability and facilitating application in scenarios such as the Internet of Things. The hash value calculation logic rules are independent of key expansion, and the hash calculation is reconfigurable. That is, while the round key calculation and information expansion modules change, the hash value module and code remain unchanged, reducing the cost of replacing the cryptographic algorithm.
[0114] Optionally, the device further includes a round key generation module; the round key generation module is specifically configured to:
[0115] A plaintext data acquisition unit, used to acquire the plaintext data to be encrypted;
[0116] a plaintext data segmentation unit, configured to segment the plaintext data to be encrypted according to a preset first unit length to obtain at least one group of intermediate plaintext data and the number of data groups of the intermediate plaintext data;
[0117] an intermediate data segmentation unit, configured to segment each group of intermediate plaintext data according to a preset second unit length to obtain plaintext sub-data corresponding to each group of intermediate plaintext data;
[0118] The subkey generation unit is configured to generate, based on the plaintext subdata corresponding to each group of intermediate plaintext data, subkeys under at least one round key equal in number to the number of the data groups.
[0119] Optional, plaintext data segmentation unit, specifically used for:
[0120] Performing binary conversion on the plaintext data to be encrypted to obtain binary plaintext data;
[0121] According to the data length of the binary plaintext data, based on a preset padding value, the binary plaintext data is padded to obtain padded plaintext data;
[0122] The padded plaintext data is segmented according to a preset first unit length to obtain at least one set of intermediate plaintext data.
[0123] Optionally, a subkey generation unit is used to:
[0124] For any set of intermediate plaintext data, generate a plaintext sub-data matrix based on the plaintext sub-data of the set of intermediate plaintext data;
[0125] Generate a lattice basis matrix, and generate a target matrix for a round key generation round corresponding to the group of intermediate plaintext data according to the plaintext sub-data matrix and the lattice basis matrix;
[0126] At least one subkey in the key generation round is generated according to the matrix value in the target matrix.
[0127] Optionally, the current hash key generation module 203 is specifically configured to:
[0128] generating intermediate hash parameters according to the historical hash key;
[0129] performing a bit string cyclic shift operation on the intermediate hash parameter to obtain a reference hash parameter;
[0130] According to the reference hash parameter and based on each subkey in the current round key, a current hash key in the current hash value calculation period is generated.
[0131] Optionally, the periodic cycle end condition is set based on the number of data groups of the intermediate plaintext data.
[0132] The data encryption device based on the hash algorithm provided in the embodiment of the present invention can execute the data encryption method based on the hash algorithm provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0133] Example 3
[0134] Figure 3 A schematic diagram of the structure of an electronic device 30 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or claimed herein.
[0135] like Figure 3 As shown, the electronic device 30 includes at least one processor 31 and a memory, such as a read-only memory (ROM) 32, a random access memory (RAM) 33, etc., which is communicatively connected to the at least one processor 31. The memory stores a computer program that can be executed by the at least one processor. The processor 31 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 32 or the computer program loaded from the storage unit 38 into the random access memory (RAM) 33. Various programs and data required for the operation of the electronic device 30 can also be stored in the RAM 33. The processor 31, ROM 32, and RAM 33 are connected to each other via a bus 34. An input / output (I / O) interface 35 is also connected to the bus 34.
[0136] Multiple components in the electronic device 30 are connected to the I / O interface 35, including an input unit 36, such as a keyboard, a mouse, etc.; an output unit 37, such as various types of displays, speakers, etc.; a storage unit 38, such as a magnetic disk, an optical disk, etc.; and a communication unit 39, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 39 allows the electronic device 30 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.
[0137] The processor 31 can be any general-purpose and / or specialized processing component with processing and computing capabilities. Some examples of the processor 31 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various specialized artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 31 executes the various methods and processes described above, such as a data encryption method based on a hashing algorithm.
[0138] In some embodiments, the data encryption method based on the hash algorithm can be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as the storage unit 38. In some embodiments, part or all of the computer program can be loaded and / or installed on the electronic device 30 via the ROM 32 and / or the communication unit 39. When the computer program is loaded into the RAM 33 and executed by the processor 31, one or more steps of the data encryption method based on the hash algorithm described above can be performed. Alternatively, in other embodiments, the processor 31 can be configured to perform the data encryption method based on the hash algorithm by any other appropriate means (e.g., by means of firmware).
[0139] Various embodiments of the systems and techniques described herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), system-on-chip systems (SOCs), programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer programs that are executable and / or interpreted on a programmable system that includes at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0140] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when the computer program is executed by the processor, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The computer program may be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0141] In the context of the present invention, computer-readable storage media can be tangible media that can contain or store a computer program for use with an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. Computer-readable storage media can include but are not limited to electronic, magnetic, optical, electromagnetic, infrared or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, computer-readable storage media can be machine-readable signal media. More specific examples of machine-readable storage media can include electrical connections based on one or more lines, portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0142] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0143] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0144] A computing system may include clients and servers. The clients and servers are typically remote from each other and typically interact via a communication network. This client-server relationship arises through computer programs running on the respective computers, creating a client-server relationship. The server may be a cloud server, also known as a cloud computing server or cloud host. This server is a hosting product within the cloud computing service ecosystem that addresses the management difficulties and limited scalability of traditional physical hosting and VPS services.
[0145] It should be understood that the various forms of the processes shown above can be used to reorder, add, or delete steps. For example, the steps described in the present invention can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution of the present invention can be achieved. This is not limited herein.
[0146] The above specific embodiments do not limit the scope of protection of the present invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may be made based on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention are intended to be included within the scope of protection of the present invention.
Claims
1. A data encryption method based on a hash algorithm, characterized in that: include: Get the current round key in the current hash value calculation cycle; The current round key includes at least one subkey; wherein the current round key is generated based on the obtained plaintext data to be encrypted; Obtain the historical hash key for the previous historical hash value calculation cycle; Generate a current hash key for the current hash value calculation period based on the historical hash key and each subkey in the current round key; If the current hash value calculation period satisfies a preset period cycle end condition, generating a hash value of the plaintext data to be encrypted based on a current hash key in the current hash value calculation period and historical hash keys in each historical hash value calculation period, and using the hash value as ciphertext data of the plaintext data to be encrypted; The subkeys in the round key are generated as follows: Get the plaintext data to be encrypted; Segmenting the plaintext data to be encrypted according to a preset first unit length to obtain at least one group of intermediate plaintext data and the number of data groups of the intermediate plaintext data; According to the preset second unit length, each group of intermediate plaintext data is divided into data to obtain plaintext sub-data corresponding to each group of intermediate plaintext data; For any set of intermediate plaintext data, generate a plaintext sub-data matrix based on the plaintext sub-data of the set of intermediate plaintext data; Generate a lattice matrix, and generate a target matrix under the round key generation round corresponding to the group of intermediate plaintext data according to the plaintext sub-data matrix and the lattice matrix; wherein the lattice matrix is generated by a random normal integer modulo q to obtain the lattice matrix ; The size of N is the same as the number of elements in the plaintext sub-data matrix; M and the integer modulus q are preset parameters; At least one subkey of the key generation round is generated according to the matrix value in the target matrix.
2. The method according to claim 1, characterized in that The step of dividing the plaintext data to be encrypted according to the preset first unit length to obtain at least one set of intermediate plaintext data includes: Performing binary conversion on the plaintext data to be encrypted to obtain binary plaintext data; According to the data length of the binary plaintext data, based on a preset padding value, the binary plaintext data is padded to obtain padded plaintext data; The padded plaintext data is segmented according to a preset first unit length to obtain at least one set of intermediate plaintext data.
3. The method according to claim 1, characterized in that The generating, according to the historical hash key and based on each subkey in the current round key, a current hash key in the current hash value calculation period includes: generating intermediate hash parameters according to the historical hash key; performing a bit string cyclic shift operation on the intermediate hash parameter to obtain a reference hash parameter; generating, according to the reference hash parameter and based on each subkey in the current round key, a current hash key for the current hash value calculation period; Generating, based on the reference hash parameter and each subkey in the current round key, a current hash key in the current hash value calculation period includes: According to the reference hash parameter , and perform modular addition operations based on each subkey in the current round key; if the current round key is the first round and the subkey is the first subkey, calculate the modular addition U: Among them, "+" is a modular addition operation; Update calculation , update calculation ; Output updated As the calculation result of the first round of small cycle; in the current hash calculation cycle, after R rounds of cycles, the difference between each round is only the different round keys, and the output after the R rounds of small cycles is obtained , as the current hash key in the current hash value calculation period.
4. The method according to claim 1 is characterized in that the cycle end condition is set based on the number of data groups of the intermediate plaintext data.
5. A data encryption device based on a hash algorithm, characterized in that: include: A round key acquisition module is used to obtain the current round key in the current hash value calculation cycle; The current round key includes at least one subkey; wherein the current round key is generated based on the obtained plaintext data to be encrypted; A historical hash key acquisition module is used to obtain the historical hash key under the previous historical hash value calculation cycle; a current hash key generation module, configured to generate a current hash key for the current hash value calculation period based on the historical hash key and each subkey in the current round key; a ciphertext data generation module, configured to generate a hash value of the plaintext data to be encrypted based on a current hash key in the current hash value calculation period and historical hash keys in each historical hash value calculation period, if the current hash value calculation period satisfies a preset period cycle end condition, and use the hash value as ciphertext data of the plaintext data to be encrypted; The device further includes a round key generation module; the round key generation module is specifically configured to: A plaintext data acquisition unit, used to acquire the plaintext data to be encrypted; a plaintext data segmentation unit, configured to segment the plaintext data to be encrypted according to a preset first unit length to obtain at least one group of intermediate plaintext data and the number of data groups of the intermediate plaintext data; an intermediate data segmentation unit, configured to segment each group of intermediate plaintext data according to a preset second unit length to obtain plaintext sub-data corresponding to each group of intermediate plaintext data; a subkey generation unit, configured to generate, based on the plaintext subdata corresponding to each group of intermediate plaintext data, subkeys under at least one round key equal to the number of the data groups; The subkey generation unit is specifically used to: For any set of intermediate plaintext data, generate a plaintext sub-data matrix based on the plaintext sub-data of the set of intermediate plaintext data; Generate a lattice matrix, and generate a target matrix under the round key generation round corresponding to the group of intermediate plaintext data according to the plaintext sub-data matrix and the lattice matrix; wherein the lattice matrix is generated by a random normal integer modulo q to obtain the lattice matrix ; The size of N is the same as the number of elements in the plaintext sub-data matrix; M and the integer modulus q are preset parameters; At least one subkey of the key generation round is generated according to the matrix value in the target matrix.
6. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to perform the data encryption method based on the hash algorithm according to any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the data encryption method based on a hash algorithm according to any one of claims 1 to 4 when executed.
Citation Information
Patent Citations
Message authentication code generation method and device, computer equipment and storage medium
CN116405223A
Anti-quantum ciphertext equivalent test public key encryption method and system based on lattice
CN118400197A