Data hashing method and device, electronic equipment and storage medium
Optimizing the SM3 algorithm through the loop iterative computing architecture, the problems of large hardware area and low efficiency in IoT devices are solved, and more efficient data hashing is achieved.
Patent Information
- Application Number
- CN202510906672.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-02
- Publication Date
- 2025-08-01
- Estimated Expiration
- 2045-07-02
AI Technical Summary
In existing IoT devices and host systems, the SM3 algorithm hardware implementation area is large, and the computational path is complex, resulting in low efficiency.
The loop iterative computing architecture is adopted, and 64 iterative rounds are calculated through the same set of logic function circuits. The intermediate state is stored in resettable registers, avoiding multiple sets of registers to save all round results.
It reduces the logical resource consumption of the core of SM3 algorithm, reduces the hardware area, and improves the throughput and efficiency of data hashing.
Smart Images

Figure CN120407240A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of data processing, and in particular, to a data hashing method, apparatus, electronic device, and storage medium. Background Art
[0002] Data hashing is a technology that converts an input of any length (such as a message, a file) into a hash value of a fixed length through a specific algorithm. Its typical application scenarios include data integrity verification (such as file transfer verification), digital signature and identity authentication, blockchain and consensus mechanism (PoW), and data fingerprint, etc.
[0003] Currently, most Internet of Things (IoT) devices or host systems implement the SM3 algorithm in software, and then perform data hashing. This software method is vulnerable to network attacks and has low hashing efficiency. In addition, in a few SM3 algorithm hardware cores, a multi-stage pipeline computing architecture is adopted, and the computing path of the compression function is complex. When the SM3 algorithm core with a multi-stage pipeline computing architecture performs data hashing, it consumes a large amount of logic resources, resulting in a large area of the algorithm core. In addition, the complex computing path of the compression function leads to low throughput of the SM3 algorithm and reduces the efficiency of data hashing. Summary of the Invention
[0004] This application provides a data hashing method, apparatus, electronic device, and storage medium, so as to at least solve the problem in the related art that a large amount of logic resources are consumed during data hashing, resulting in a large area of the algorithm core.
[0005] This application provides a data hashing method, which includes: obtaining at least one group of messages corresponding to the data to be hashed, where each group of messages includes a plurality of message words, and each message word is used as input data in different iteration rounds; respectively expanding and generating new message words according to some of the message words included in each group of messages, so that the number of message words included in each group of messages is a preset number; when the message includes multiple groups, in the first iteration loop, generating an intermediate hash value corresponding to the first iteration loop according to the preset number of message words included in the first group of messages corresponding to the first iteration loop and a plurality of pre-configured initial values.
[0006] Generate the initial value for the first iteration round in the next iteration cycle based on the intermediate hash value corresponding to the first iteration cycle and a plurality of pre-configured initial values, and enter the next iteration cycle, so as to generate an intermediate hash value corresponding to the next iteration cycle within the next iteration cycle according to a preset number of message words included in the message corresponding to the next iteration cycle and the initial value of the first iteration round in the next iteration cycle, where each iteration cycle corresponds to a group of messages; after each iteration cycle is executed, when the current iteration cycle is not the first iteration cycle, generate a final hash value corresponding to the current iteration cycle based on the intermediate hash value corresponding to the current iteration cycle and the intermediate hash value corresponding to the previous iteration cycle; until the current iteration cycle is the last iteration cycle, determine the final hash value corresponding to the current iteration cycle as the target hash value.
[0007] The present application also provides a data hashing device, which includes: an acquisition module, configured to acquire at least one group of messages corresponding to the data to be hashed, where each group of messages includes a plurality of message words, and each message word serves as input data in different iteration rounds; a processing module, configured to respectively expand and generate new message words according to some of the message words included in each group of messages, so that the number of message words included in each group of messages is a preset number; the processing module is further configured to, when there are multiple groups of messages, in the first iteration cycle, generate an intermediate hash value corresponding to the first iteration cycle according to a preset number of message words included in the first group of messages corresponding to the first iteration cycle and a plurality of pre-configured initial values.
[0008] The processing module is further configured to generate the initial value for the first iteration round in the next iteration cycle based on the intermediate hash value corresponding to the first iteration cycle and a plurality of pre-configured initial values, and enter the next iteration cycle, so as to generate an intermediate hash value corresponding to the next iteration cycle within the next iteration cycle according to a preset number of message words included in the message corresponding to the next iteration cycle and the initial value of the first iteration round in the next iteration cycle, where each iteration cycle corresponds to a group of messages; the processing module is further configured to, after each iteration cycle is executed, when the current iteration cycle is not the first iteration cycle, generate a final hash value corresponding to the current iteration cycle based on the intermediate hash value corresponding to the current iteration cycle and the intermediate hash value corresponding to the previous iteration cycle; the processing module is further configured to, until the current iteration cycle is the last iteration cycle, determine the final hash value corresponding to the current iteration cycle as the target hash value.
[0009] The present application also provides an electronic device, including: a memory, configured to store a computer program; a processor, configured to implement the steps of any of the above data hashing methods when executing the computer program.
[0010] The present application also provides a computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the steps of any of the above data hashing methods.
[0011] The present application also provides a computer program product including a computer program, which, when executed by a processor, implements the steps of any of the above data hashing methods.
[0012] With the present application, since the above-mentioned determination of the data to be hashed adopts a cyclic iterative computing architecture, that is, only a set of logic function circuits are required to process 64 iterative rounds of calculations, and the adder of the logic function circuit is repeatedly used for the modulo operation of each round; the intermediate states are stored in a resetable register, and there is no need for multiple sets of registers to save the results of all rounds. Therefore, compared with the related art in which the data hashing process is carried out by adopting a multi-stage pipeline computing architecture, it is possible to avoid the core of the SM3 algorithm consuming a large amount of logic resources and reduce the relatively large area of the algorithm core. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] To more clearly illustrate the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present application, and those of ordinary skill in the art can also obtain other drawings based on these drawings without creative efforts.
[0014] <> Figure 1 It is a topology diagram of a data hashing system provided by an embodiment of the present application; Figure 2 It is a flowchart of a data hashing method provided by an embodiment of the present application; Figure 3 It is a flowchart of another data hashing method provided by an embodiment of the present application; Figure 4 It is a structural diagram of the compression function calculation path corresponding to the data hashing device provided by an embodiment of the present application; Figure 5 It is a schematic structural diagram of the message word expansion corresponding to the data hashing device provided by an embodiment of the present application; Figure 6 It is a schematic diagram of another data hashing method provided by an embodiment of the present application; Figure 7 It is a structural block diagram of a data hashing device provided by an embodiment of the present application; Figure 8 It is a schematic diagram of the hardware structure of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0015] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the protection scope of the present application.
[0016] It should be noted that in the description of the present application, the terms "including", "comprising" or any other variation thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or also includes elements inherent to such process, method, article or device. The terms "first", "second", etc. in the present application are used to distinguish similar objects, rather than to describe a specific order or sequence.
[0017] In order to enable those skilled in the art of the present technology to better understand the solution of the present application, the present application will be further described in detail below in conjunction with the accompanying drawings and specific implementation manners.
[0018] Combined with the specific application environment architecture or specific hardware architecture on which the execution of the data hashing method depends, the specific application environment architecture or specific hardware architecture is described herein.
[0019] The embodiments of the present application are applied to the scenario of performing data hashing on input data based on the SM3 algorithm.
[0020] In the related art, the core of the SM3 algorithm of the multi-stage pipeline computing architecture adopts a multi-stage pipeline computing architecture, and does not optimize the computing path of the complex compression function, but directly performs a register transfer level (RTL) description on the complex combinational logic, resulting in a large area of the algorithm core. In addition, the complex compression function calculation path results in a low throughput of the SM3 algorithm, reducing the efficiency of data hashing.
[0021] To solve the above problems, the embodiments of the present application provide a data hashing method. The core of the SM3 hashing algorithm adopts a loop iteration computing architecture to solve the problem of the large hardware implementation area of the data hashing algorithm in existing IoT devices. The computing reconstruction of the compression function module of the SM3 algorithm core is performed to solve the problem of its limited operating frequency and increase the data hashing throughput.
[0022] Next, taking Figure 1 the data hashing system shown as an example, the method provided by the embodiments of the present application will be described. Figure 1 It is only a schematic diagram and does not constitute a limitation on the applicable scenario of the technical solution provided by the present application.
[0023] As Figure 1 shown Figure 1 is a topology diagram of a data hashing system provided by an embodiment of the present application. Figure 1 In it, the data hashing system 100 may include a central processing unit 101, a data hashing device 102, a memory 103, and a direct memory access device 104.
[0024] Among them, the central processing unit (CPU) 101 can be the core arithmetic and control unit of a computer system, responsible for executing instructions, processing data, and coordinating the work of each component.
[0025] The data hashing device 102, which can also be called the SM3 algorithm core, can be the key hardware infrastructure that supports the efficient operation of the SM3 algorithm. For example, the SM3 algorithm core can be a processor. Among them, the data hashing device 102 includes a preset register and a hash value register. The preset register is used to store the message to be hashed; the hash value register is used to store the hash value corresponding to the message to be hashed.
[0026] The memory 103 can be the key hardware component in a computer system for temporarily storing data and instructions, and its core function is to provide a workspace for the central processing unit 101 for quick access.
[0027] The direct memory access device (DMA) 104 can be a hardware component that allows external devices to directly transfer data to and from the memory without going through the CPU. The DMA can directly access the memory 103 through the system bus (for example, the Advanced High-performance Bus (AHB)).
[0028] Specifically, the CPU passes the DMA configuration information to the DMA through the AHB interface. After the DMA receives the configuration signal from the CPU and completes the startup, it goes to the memory to carry data through the AHB interface, then writes it into the SM3 algorithm core, and finally the SM3 algorithm core performs hashing calculation on the data. After the hashing calculation is completed, the SM3 algorithm core stores the hash value in the hash value register and waits for the CPU to read it.
[0029] Figure 1 The data hashing system 100 shown is only for illustration and is not used to limit the technical solution of the present application. Those skilled in the art should understand that in the specific implementation process, the data hashing system 100 may further include other devices, which are not limited.
[0030] In this embodiment, a data hashing method is provided, which is applied to the above data hashing device. Figure 2The flowchart of the data hashing method provided by the embodiment of the present application is as follows Figure 2 As shown, the process includes the following steps: S201: Obtain at least one group of messages corresponding to the data to be hashed.
[0031] Among them, each group of messages includes multiple message words, and each message word is used as input data in different iteration rounds. Among them, the number of bytes occupied by each group of messages is 512 bit. Each group of messages includes 16 message words. The number of bytes occupied by each message word is 32 bit.
[0032] At least one group of messages includes the data to be hashed. The data to be hashed can be file data or message data.
[0033] In one example, after the DMA obtains the data to be hashed from the memory, it transmits the data to be hashed to the data hashing device. The data hashing device receives the data to be hashed and obtains at least one group of messages corresponding to the data to be hashed.
[0034] S202: Expand and generate new message words respectively according to some of the message words included in each group of messages, so that the number of message words included in each group of messages is a preset number.
[0035] Among them, the preset number is the number of message words required by the SM3 algorithm. The preset number can be 64.
[0036] It can be understood that since each group of messages includes 16 message words, therefore, each group of messages needs to expand and generate 48 new message words according to some of the message words included in each group of messages. Among them, the rule for expanding some message words to generate new message words is determined according to actual needs and is not limited.
[0037] S203: When the messages include multiple groups, in the first iteration loop, generate an intermediate hash value corresponding to the first iteration loop according to the preset number of message words included in the first group of messages corresponding to the first iteration loop and a plurality of pre-configured initial values.
[0038] Among them, the plurality of pre-configured initial values can be the corresponding numerical values of the SM3 algorithm. For example, the plurality of pre-configured initial values are 8 register state values of A, B, C, D, E, F, G, and H.
[0039] The intermediate hash value corresponding to the first iteration loop can be denoted as 、 、 、 、) 、 、 、 .
[0040] In one example, when the message includes multiple groups, in the first iteration loop, the data hashing device performs the compression function calculation corresponding to the first round of the SM3 algorithm based on a preset number of message words included in the first group of messages corresponding to the first iteration loop and a plurality of preconfigured initial values, and generates an intermediate hash value corresponding to the first iteration loop.
[0041] S204: Generate the initial value of the first iteration round in the next iteration loop based on the intermediate hash value corresponding to the first iteration loop and the plurality of initial values, and enter the next iteration loop, so as to generate an intermediate hash value corresponding to the next iteration loop within the next iteration loop based on a preset number of message words included in the message corresponding to the next iteration loop and the initial value of the first iteration round in the next iteration loop.
[0042] Among them, each iteration loop corresponds to a group of messages. Each iteration loop needs to perform 64 iteration rounds.
[0043] In one example, the data hashing device performs an exclusive OR operation on the intermediate hash value corresponding to the first iteration loop and the plurality of initial values to generate the initial value of the first iteration round in the next iteration loop.
[0044] It can be understood that the initial value of the first iteration round in the next iteration loop is also 8 register state values.
[0045] S205: After each iteration loop is executed, when the current iteration loop is not the first iteration loop, generate the final hash value corresponding to the current iteration loop based on the intermediate hash value corresponding to the current iteration loop and the intermediate hash value corresponding to the previous iteration loop.
[0046] In one example, after each iteration loop is executed by the data hashing device, when the current iteration loop is not the first iteration loop, an exclusive OR operation is performed on the intermediate hash value corresponding to the current iteration loop and the intermediate hash value corresponding to the previous iteration loop to generate the final hash value corresponding to the current iteration loop.
[0047] S206: Until the current iteration loop is the last iteration loop, determine the final hash value corresponding to the current iteration loop as the target hash value.
[0048] Among them, the target hash value is the hash value corresponding to the data to be hashed. The target hash value can be used for data integrity verification, digital signature and identity authentication, blockchain and consensus mechanism, and data fingerprint, which is of great significance for information security and improving the independent innovation ability of cryptographic technology.
[0049] Optionally, when the message includes a group, when the data hashing device finishes the first iteration loop, it determines the target hash value as the calculation result of the exclusive OR operation between the intermediate hash value corresponding to the first iteration loop and a plurality of pre-configured initial values.
[0050] Based on the above Figure 2 method, the data hashing device can obtain at least one group of messages corresponding to the data to be hashed, and respectively expand and generate new message words according to some of the message words in the plurality of message words included in each group of messages, so that the number of message words included in each group of messages is a preset number; when the message includes multiple groups, in the first iteration loop, according to the preset number of message words included in the first group of messages corresponding to the first iteration loop and a plurality of pre-configured initial values, generate an intermediate hash value corresponding to the first iteration loop; according to the intermediate hash value corresponding to the first iteration loop and a plurality of pre-configured initial values, generate the initial value of the first iteration round in the next iteration loop, and enter the next iteration loop, so as to generate an intermediate hash value corresponding to the next iteration loop in the next iteration loop according to the preset number of message words included in the message corresponding to the next iteration loop and the initial value of the first iteration round in the next iteration loop, where each iteration loop corresponds to a group of messages; after each iteration loop is executed, when the current iteration loop is not the first iteration loop, based on the intermediate hash value corresponding to the current iteration loop and the intermediate hash value corresponding to the previous iteration loop, generate a final hash value corresponding to the current iteration loop; until the current iteration loop is the last iteration loop, determine the final hash value corresponding to the current iteration loop as the target hash value.
[0051] Since the above determination of the data to be hashed adopts a cyclic iterative computing architecture, that is, only the same set of logic function circuits are needed to process the calculations of 64 iteration rounds, and the adder of the logic function circuit is repeatedly used for the modulo operation of each round; the intermediate state is stored in a resetable register, and there is no need for multiple sets of registers to save the results of all rounds. Therefore, compared with the related art, the process of data hashing using a multi-stage pipeline computing architecture can avoid the core of the SM3 algorithm consuming a large amount of logic resources and reduce the relatively large area of the algorithm core.
[0052] In an optional example, based on the foregoing embodiment, as introduced above, in the first iteration loop, the data hashing device generates an intermediate hash value corresponding to the first iteration loop according to the preset number of message words included in the first group of messages corresponding to the first iteration loop and a plurality of pre-configured initial values. The following method steps are specifically shown in Figure 3 shown as Figure 3 FIG. is a flowchart of another data hashing method provided by an embodiment of the present application, including: S301: In the first iteration round of the first iteration loop, generate multiple intermediate hash values corresponding to the first iteration round from the first message word corresponding to the first iteration round included in the first group of messages and multiple preconfigured initial values.
[0053] It can be understood that the input in the first iteration round of the first iteration loop includes: multiple preconfigured initial values.
[0054] S302: In the i-th iteration round, use all the multiple intermediate hash values generated in the (i - 1)-th iteration round as the initial values corresponding to the i-th iteration round.
[0055] Where i is a positive integer.
[0056] It can be understood that the input in the i-th iteration round of the first iteration loop includes: multiple intermediate hash values generated in the (i - 1)-th iteration round as the initial values.
[0057] S303: Based on the i-th message word corresponding to the i-th iteration round, the multiple initial values corresponding to the i-th iteration round, and the multiple preconfigured initial values, generate the intermediate hash values corresponding to the i-th iteration round.
[0058] In one example, the data hashing device selects at least one initial value corresponding to the q-th intermediate hash value corresponding to the i-th iteration round from the multiple initial values corresponding to the i-th iteration round; performs data hashing processing on the at least one initial value corresponding to the q-th intermediate hash value according to the compression function calculation path corresponding to the q-th intermediate hash value to obtain the q-th intermediate hash value.
[0059] Where the number of compression function calculation paths is 8. Specifically, each intermediate hash value is obtained based on 8 compression function calculation paths. Among them, each compression function calculation path includes at least one sub-path.
[0060] For example, with the initial values being , , , , , , , , and the intermediate hash values being , , , , , , , as an example; the following are the compression function calculation paths corresponding to each intermediate hash value:
[0061]
[0062]
[0063]
[0064]
[0065]
[0066]
[0067]
[0068] The above is the first round function; A is the first initial value among multiple pre-configured initial values; B is the second initial value among multiple pre-configured initial values; C is the third initial value among multiple pre-configured initial values; D is the fourth initial value among multiple pre-configured initial values; E is the fifth initial value among multiple pre-configured initial values; is the round constant; is the j-th message word included in the message group corresponding to each iteration round; is the (j + 4)-th message word included in the message group corresponding to each iteration round; is determined by the (j + 4)-th message word and the j-th message word included in the message group corresponding to each iteration round; is the second round function; is the first permutation function; F is the fifth initial value among multiple pre-configured initial values; is the sixth initial value among multiple pre-configured initial values; is the seventh initial value among multiple pre-configured initial values.
[0069] In some alternative embodiments, the data hashing device obtains the number of addition logics of the compression function calculation path corresponding to each intermediate hash value; and determines the calculation delay of the compression function calculation path corresponding to each intermediate hash value according to the unit calculation delay corresponding to each addition logic and the number of each addition logic.
[0070] Exemplarily, taking the compression function calculation path corresponding to, and the unit calculation delay being T as an example, the data hashing device obtains the number of addition logics of the compression function calculation path corresponding to is 5; and determines the calculation delay 5*T of the compression function calculation path corresponding to each intermediate hash value according to the unit calculation delay T corresponding to each addition logic and the number of each addition logic 5.
[0071] It can be understood that for each compression function calculation path corresponding to an intermediate hash value, in addition to the addition logic, there is also a delay in the relevant Boolean function (shift operation) or permutation function. For example, the calculation delay of is 5 adders (i.e., addition logic) and the delay of the relevant Boolean function, the calculation delay of is 5 adders, some Boolean functions, and the delay of a permutation function. Since the permutation function and Boolean function are mainly wiring delays and can be ignored relative to the addition delay, therefore, for each compression function calculation path corresponding to an intermediate hash value, only the addition logic needs to be considered for the calculation delay.
[0072] Optionally, when the compression function calculation path includes addition logic, a Carry-Save Adder (CSA) is used to process the addition logic.
[0073] It can be understood that when using a Carry-Save Adder CSA to process consecutive operations of multiple addition logics, only the addition operation needs to be performed in the last step, and the others can be implemented through bit operations. Therefore, the delay is approximately the delay of the last adder, which can reduce the calculation delay of each compression function calculation path and thus improve the efficiency of the entire data hashing.
[0074] Furthermore, the data hashing device can determine the calculation delay of each compression function calculation path corresponding to an intermediate hash value; according to the calculation delay of each compression function calculation path, select a target compression function calculation path whose calculation delay is greater than a preset delay threshold; when there are multiple target compression function calculation paths, identify whether the multiple target compression function calculation paths include the same sub-path; when it is determined that at least two target compression function calculation paths include the same sub-path, after the sub-path included in one of the target compression function calculation paths generates a calculation result, the calculation result is reused in the calculation process of other target compression function calculation paths among at least two target compression function calculation paths.
[0075] Among them, at least two target compression function calculation paths include a first target compression function calculation path and a second target compression function calculation path. The expression form of the first target compression function calculation path is as follows:
[0076] The expression form of the second target compression function calculation path is as follows:
[0077] It can be understood that at least two target compression function calculation paths in the compression function calculation path of the intermediate hash value are the longer calculation paths and have a larger calculation delay. Therefore, at least two target compression function calculation paths severely limit the improvement of the working frequency and throughput of the accelerator for data hashing.
[0078] As Figure 4 shown, Figure 4 Figure is the structural intention of the compression function calculation path corresponding to the data hashing device provided by the embodiment of the present application; in Figure 4 , the data hashing device can use carry-save adders CSA1 and CSA2 to perform and addition logic, and then circularly shift the result of CSA2 left by 7 bits and add the result of the CSA1 adder to obtain the value of TT2. Finally, the calculation of is completed through the permutation function . After the corresponding compression function calculation path is reorganized and optimized, its calculation delay includes three adders, some Boolean functions, and a permutation function.
[0079] Since the corresponding compression function calculation path also includes , only one CSA3 is used to perform the three-number addition logic. After CSA2 is calculated, it is XORed with 2 to obtain SS2. Finally, SS2 is added to the result of CSA3 to complete the operation. For the corresponding compression function calculation path, after reorganization and optimization, its calculation delay is reduced to the delay of three adders plus some Boolean functions. Through the above path optimization, the original combinational logic delay of and is reduced, improving the system working frequency and throughput.
[0080] S304: When it is determined that the number of executed iteration rounds is equal to the preset number, it is determined that the first iteration loop operation ends, and the intermediate hash value corresponding to the i-th iteration round is determined to be the intermediate hash value corresponding to the first iteration loop.
[0081] It can be understood that when it is determined that the number of executed iteration rounds is equal to 64, it is determined that the first iteration loop operation ends, and the intermediate hash value corresponding to the 64th iteration round is determined to be the intermediate hash value corresponding to the first iteration loop.
[0082] Optionally, before the data hashing device obtains at least one group of messages corresponding to the data to be hashed, it can also obtain the data to be hashed; identify whether the number of bytes occupied by the data to be hashed meets a preset condition; when the number of bytes occupied by the data to be hashed does not meet the preset condition, perform padding processing on the data to be hashed to generate new data to be hashed to meet the preset condition; and when it is determined that the data to be hashed or the new data to be hashed meets the preset condition, perform grouping processing on the data to be hashed or the new data to be hashed to obtain at least one group of messages.
[0083] Wherein, the preset condition is an integer multiple of 512 bit. That is, if the number of bytes occupied by the data to be hashed does not meet an integer multiple of 512 bit, padding needs to be performed on the data to be hashed so that the generated new data to be hashed meets the preset condition.
[0084] It can be understood that when the data to be hashed or the new data to be hashed meets the preset condition, grouping is performed according to each group of messages being 512 bit to obtain at least one group of messages.
[0085] In some alternative embodiments, the data hashing device inputs the partial message word that matches the h-th new message word into a preconfigured permutation function to expand and generate the h-th new message word, where h is a positive integer.
[0086] Wherein, h is a value greater than the total number of message words included in each group of messages and less than or equal to a preset number. For example, h is a value greater than 17 and less than or equal to 64.
[0087] In some alternative embodiments, the data hashing device inputs the partial message word that matches the h-th new message word into a preconfigured permutation function to expand and generate the h-th new message word, which is represented by the following expression:
[0088] Wherein, is the second permutation function, which is represented by the following expression:
[0089] is the j-th message word included in the message group corresponding to each iteration round; is the (j - 16)-th message word included in the message group corresponding to each iteration round; is the (j - 9)-th message word included in the message group corresponding to each iteration round; is the (j - 3)-th message word included in the message group corresponding to each iteration round; is the (j - 6)-th message word included in the message group corresponding to each iteration round; The (j - 13)-th message word included in the message group corresponding to each iteration round.
[0090] In one example, each of the preset number of message words in the i-th group is stored in a preset register corresponding to the i-th group of messages, and the triggering time for generating a new message word by expanding some of the message words included in the i-th group of messages is the moment after each iteration round corresponding thereto is completed; after the data hashing device generates a new message word each time, it deletes the message word that was stored in the preset register first from the preset register, shifts the remaining message words stored in the preset register one bit to the left, and stores the generated new message word in the last register bit of the preset register.
[0091] Among them, the preset register is 16 registers preset by the data hashing device.
[0092] Among them, the initial values of the 16 registers are pre-configured, and the subsequent message words W16~W67 are obtained by extended calculation of the previously generated message words. The iterative compression and the message word extension are carried out simultaneously. That is, in the first round of iterative compression, the calculation of W16 is completed. The extension method of W16~W67 is as Figure 5 shown. Figure 5 This is the structural schematic diagram of the message word extension corresponding to the data hashing device provided by the embodiment of the present application; when the extension of the new message word is completed, the values of the last 15 registers are shifted 32 bits to the left in sequence and stored in the first 15 registers, and the new message word is stored in the last register. Thus, one round of update of the values of the 16 registers is completed. The value in the register with the smallest serial number is passed to the compression function for compression calculation.
[0093] In addition, the data hashing device also presets a register W' for storing the message word , and based on the message words W0~W67, W0'~W63' can be obtained. These message words update the register W' in sequence and are synchronously transmitted to the compression function calculation path.
[0094] It can be understood that since the data dependence of the message word extended calculation only exists between every 16 consecutive 32-bit message words, therefore, after each round of iterative calculation is completed, the message words in the register will be shifted 32 bits to the left, and the newly calculated message word is stored in the last register, forming a new group of 16 consecutive message words, realizing the reuse of the register and greatly saving the consumption of hardware resources.
[0095] In this embodiment, another data hashing method is provided. Figure 6 This is the schematic diagram of another data hashing method provided by the embodiment of the present application. In Figure 6Among them, the data hashing method includes three parts: padding groups, message expansion, and iterative compression. The message to be hashed is padded into groups by the upper-layer software and then enters the message expansion hardware module. The message expansion passes the expanded message words to the iterative compression for calculation. When calculating the hash of the first group of messages, the initial values are assigned to a total of 8 registers from A to H as the initial values. After 64 rounds of compression calculation, if there is only one group of messages to be hashed, the result after 64 rounds of compression calculation is XORed with the initial value to obtain the hash value. If there are multiple groups, the value obtained by XORing the result after 64 rounds of compression calculation with the initial value will be used as the new initial value and assigned to the registers from A to H, and then it will be used together with the message words obtained by expanding the new group of messages for 64 rounds of compression calculation until the compression of the last group of messages is completed, and the result is XORed with the previous-round initial value V(i) to obtain the final hash value.
[0096] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases, the former is a better implementation method.
[0097] The embodiment of the present application also provides a data hashing device, as Figure 7 shown, Figure 7 is a structural block diagram of a data hashing device provided by an embodiment of the present application; the data hashing device includes: an acquisition module 701, configured to acquire at least one group of messages corresponding to the data to be hashed, where each group of messages includes a plurality of message words, and each message word serves as input data in different iteration rounds. A processing module 702 is configured to respectively generate new message words by expanding some of the message words included in each group of messages, so that the number of message words included in each group of messages is a preset number. The processing module 702 is further configured to, when the message includes multiple groups, in the first iteration loop, generate an intermediate hash value corresponding to the first iteration loop according to the preset number of message words included in the first group of messages corresponding to the first iteration loop and a plurality of pre-configured initial values.
[0098] The processing module 702 is further configured to generate the initial value for the first iteration round in the next iteration cycle based on the intermediate hash value corresponding to the first iteration cycle and a plurality of pre-configured initial values, and enter the next iteration cycle, so as to generate the intermediate hash value corresponding to the next iteration cycle within the next iteration cycle according to the preset number of message words included in the message corresponding to the next iteration cycle and the initial value for the first iteration round in the next iteration cycle, where each iteration cycle corresponds to a group of messages. The processing module 702 is further configured to, after each iteration cycle is executed, when the current iteration cycle is not the first iteration cycle, generate the final hash value corresponding to the current iteration cycle based on the intermediate hash value corresponding to the current iteration cycle and the intermediate hash value corresponding to the previous iteration cycle. The processing module 702 is further configured to determine that the final hash value corresponding to the current iteration cycle is the target hash value until the current iteration cycle is the last iteration cycle.
[0099] In some alternative embodiments, the processing module 702 is specifically configured to, in the first iteration round of the first iteration cycle, generate a plurality of intermediate hash values corresponding to the first iteration round from the first message word corresponding to the first iteration round among the plurality of message words included in the first group of messages and the plurality of pre-configured initial values; in the i-th iteration round, use the plurality of intermediate hash values generated in the (i - 1)-th iteration round as the initial values corresponding to the i-th iteration round, where i is a positive integer; generate the intermediate hash value corresponding to the i-th iteration round based on the i-th message word corresponding to the i-th iteration round, the plurality of initial values corresponding to the i-th iteration round, and the plurality of pre-configured initial values; when it is determined that the number of executed iteration rounds is equal to the preset number, determine that the operation of the first iteration cycle ends, and determine the intermediate hash value corresponding to the i-th iteration round as the intermediate hash value corresponding to the first iteration cycle.
[0100] In some alternative embodiments, there are a plurality of intermediate hash values corresponding to the i-th iteration round. The processing module 702 is specifically configured to select at least one initial value corresponding to the q-th intermediate hash value corresponding to the i-th iteration round from the plurality of initial values corresponding to the i-th iteration round; perform data hashing processing on the at least one initial value corresponding to the q-th intermediate hash value according to the compression function calculation path corresponding to the q-th intermediate hash value to obtain the q-th intermediate hash value.
[0101] In some alternative embodiments, the processing module 702 is specifically configured to determine the calculation delay of the compression function calculation path corresponding to each intermediate hash value; select, according to the calculation delay of each compression function calculation path, a target compression function calculation path whose calculation delay is greater than a preset delay threshold; when there are multiple target compression function calculation paths, identify whether the multiple target compression function calculation paths include the same sub-path; when it is determined that at least two target compression function calculation paths include the same sub-path, after the sub-path included in one of the target compression function calculation paths generates a calculation result, reuse the calculation result in the calculation processes of the other target compression function calculation paths among the at least two target compression function calculation paths.
[0102] In some alternative embodiments, the processing module 702 is further specifically configured to obtain the number of adder logics of the compression function calculation path corresponding to each intermediate hash value; determine the calculation delay of the compression function calculation path corresponding to each intermediate hash value according to the unit calculation delay corresponding to each adder logic and the number of each adder logic.
[0103] In some alternative embodiments, when the compression function calculation path includes an adder logic, a carry-save adder is used to process the adder logic.
[0104] In some alternative embodiments, at least two target compression function calculation paths include a first target compression function calculation path and a second target compression function calculation path, where the expression form of the first target compression function calculation path is shown in the following formula:
[0105] Where is the first intermediate hash value corresponding to each iteration round; is the first round function; A is the first initial value among multiple pre-configured initial values; B is the second initial value among multiple pre-configured initial values; C is the third initial value among multiple pre-configured initial values; D is the fourth initial value among multiple pre-configured initial values; E is the fifth initial value among multiple pre-configured initial values; is the round constant; is the j-th message word included in the message group corresponding to each iteration round; is the (j + 4)-th message word included in the message group corresponding to each iteration round; is determined by the (j + 4)-th message word and the j-th message word included in the message group corresponding to each iteration round.
[0106] The expression form of the second target compression function calculation path is shown in the following formula:
[0107] Among them, is the fifth intermediate hash value corresponding to each iteration round; is the second round function; is the first permutation function; F is the fifth initial value among multiple pre-configured initial values; is the sixth initial value among multiple pre-configured initial values; is the seventh initial value among multiple pre-configured initial values.
[0108] In some alternative embodiments, before obtaining at least one group of messages corresponding to the data to be hashed, the obtaining module 701 is further configured to obtain the data to be hashed; the processing module 702 is further configured to identify whether the number of bytes occupied by the data to be hashed meets a preset condition; when the number of bytes occupied by the data to be hashed does not meet the preset condition, perform padding processing on the data to be hashed to generate new data to be hashed so as to meet the preset condition; and when it is determined that the data to be hashed or the new data to be hashed meets the preset condition, perform grouping processing on the data to be hashed or the new data to be hashed to obtain at least one group of messages.
[0109] In some alternative embodiments, the processing module 702 is further specifically configured to input the partial message word that matches the h-th new message word into a pre-configured permutation function to expand and generate the h-th new message word, where h is a positive integer, and h is a value greater than the total number of message words included in each group of messages and less than or equal to a preset number.
[0110] In some alternative embodiments, inputting the partial message word that matches the h-th new message word into a pre-configured permutation function to expand and generate the h-th new message word is represented by the following expression:
[0111] Among them, is the j-th message word included in the message group corresponding to each iteration round; is the (j - 16)-th message word included in the message group corresponding to each iteration round; is the (j - 9)-th message word included in the message group corresponding to each iteration round; is the (j - 3)-th message word included in the message group corresponding to each iteration round; is the (j - 6)-th message word included in the message group corresponding to each iteration round; is the (j - 13)-th message word included in the message group corresponding to each iteration round; is the second permutation function.
[0112] In some alternative embodiments, the preset number of message words in the i-th group are all stored in a preset register corresponding to the i-th group of messages, and the triggering moment for expanding some of the message words included in the i-th group of messages to generate new message words is the moment after each iteration round corresponding intermediate hash value is executed; the processing module 702 is further configured to, after each new message word is generated, delete the message word that was stored in the preset register first from the preset register.
[0113] In some alternative embodiments, after deleting the message word that was stored in the preset register first from the preset register, the processing module 702 is further configured to shift the remaining message words stored in the preset register one bit to the left, and store the generated new message word in the last register bit of the preset register.
[0114] For the description of the features in the corresponding embodiments of the data hashing device, reference may be made to the relevant description in the corresponding embodiments of the data hashing method, which will not be elaborated here one by one.
[0115] An embodiment of the present application further provides an electronic device, as Figure 8 shown, Figure 8 is a schematic hardware structure diagram of an electronic device provided by an embodiment of the present application. The electronic device includes a processor 10 and a memory 20. A computer program is stored in the memory 20, and the processor 10 is configured to run the computer program to execute the steps in any of the above data hashing method embodiments.
[0116] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored, and wherein the computer program is configured to execute the steps in any of the above data hashing method embodiments when running.
[0117] In an exemplary embodiment, the above computer-readable storage medium may include, but is not limited to: USB flash drives, read-only memories (ROM for short), random access memories (RAM for short), mobile hard disks, magnetic disks, or optical discs, etc., various media that can store computer programs.
[0118] An embodiment of the present application further provides a computer program product, the above computer program product includes a computer program, and the computer program, when executed by a processor, implements the steps in any of the above data hashing method embodiments.
[0119] An embodiment of the present application further provides another computer program product, including a non-volatile computer-readable storage medium, the non-volatile computer-readable storage medium stores a computer program, and the computer program, when executed by a processor, implements the steps in any of the above data hashing method embodiments.
[0120] Those skilled in the art may further realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.
[0121] The above has introduced in detail a data hashing method, apparatus, electronic device, and storage medium provided by this application. Specific examples are used herein to elaborate on the principle and implementation manner of this application. The description of the above embodiments is only used to help understand the method and its core idea of this application. It should be noted that for those of ordinary skill in the art of this technology, without departing from the principle of this application, several improvements and modifications can be made to this application, and these improvements and modifications also fall within the protection scope of the claims of this application.
Claims
1. A data hashing method, characterized in that, The method includes: Obtaining at least one set of messages corresponding to the data to be hashed, where each set of messages includes a plurality of message words, and each of the message words serves as input data in different iteration rounds; Respectively expanding and generating new message words based on some of the message words included in each set of the messages, so that the number of message words included in each set of the messages is a preset number; When there are multiple sets of messages, in the first iteration loop, generating an intermediate hash value corresponding to the first iteration loop according to the preset number of message words included in the first set of messages corresponding to the first iteration loop and a plurality of pre-configured initial values; Generating the initial value of the first iteration round in the next iteration loop according to the intermediate hash value corresponding to the first iteration loop and the plurality of pre-configured initial values, and entering the next iteration loop, so as to generate an intermediate hash value corresponding to the next iteration loop in the next iteration loop according to the preset number of message words included in the message corresponding to the next iteration loop and the initial value of the first iteration round in the next iteration loop, where each iteration loop corresponds to a set of messages; After each iteration loop is executed, when the current iteration loop is not the first iteration loop, generating a final hash value corresponding to the current iteration loop based on the intermediate hash value corresponding to the current iteration loop and the intermediate hash value corresponding to the previous iteration loop; Until the current iteration loop is the last iteration loop, determining the final hash value corresponding to the current iteration loop as the target hash value.
2. The method according to claim 1, characterized in that, The step of generating an intermediate hash value corresponding to the first iteration loop according to the preset number of message words included in the first set of messages corresponding to the first iteration loop and a plurality of pre-configured initial values in the first iteration loop includes: In the first iteration round of the first iteration loop, generating a plurality of intermediate hash values corresponding to the first iteration round by using the first message word corresponding to the first iteration round among the plurality of message words included in the first set of messages and the plurality of pre-configured initial values; In the i-th iteration round, using the plurality of intermediate hash values generated in the (i - 1)-th iteration round as the initial values corresponding to the i-th iteration round, where i is a positive integer; Generating an intermediate hash value corresponding to the i-th iteration round based on the i-th message word corresponding to the i-th iteration round, the plurality of initial values corresponding to the i-th iteration round, and the plurality of pre-configured initial values; When it is determined that the number of executed iteration rounds is equal to the preset number, determining that the operation of the first iteration loop ends, and determining the intermediate hash value corresponding to the i-th iteration round as the intermediate hash value corresponding to the first iteration loop.
3. The method according to claim 2, wherein The intermediate hash value corresponding to the i-th iteration round includes a plurality of values. The step of generating an intermediate hash value corresponding to the i-th iteration round based on the i-th message word corresponding to the i-th iteration round, the plurality of initial values corresponding to the i-th iteration round, and the plurality of pre-configured initial values includes: Select at least one initial value corresponding to the q-th intermediate hash value corresponding to the i-th iteration round from the multiple initial values corresponding to the i-th iteration round; Perform data hashing processing on at least one initial value corresponding to the q-th intermediate hash value according to the compression function calculation path corresponding to the q-th intermediate hash value to obtain the q-th intermediate hash value.
4. The method according to claim 3, characterized in that, The compression function calculation path includes at least one sub-path. Before performing data hashing processing on at least one initial value corresponding to the q-th intermediate hash value according to the compression function calculation path corresponding to the q-th intermediate hash value to obtain the q-th intermediate hash value, the method further includes: Determine the calculation delay of the compression function calculation path corresponding to each intermediate hash value; Select a target compression function calculation path with a calculation delay greater than a preset delay threshold according to the calculation delay of each compression function calculation path; When there are multiple target compression function calculation paths, identify whether the multiple target compression function calculation paths include the same sub-path; When it is determined that at least two target compression function calculation paths include the same sub-path, after the sub-path included in one target compression function calculation path generates a calculation result, reuse the calculation result in the calculation processes of other target compression function calculation paths among at least two target compression function calculation paths.
5. The method according to claim 4, wherein The determining the calculation delay of the compression function calculation path corresponding to each intermediate hash value includes: Obtain the number of addition logics of the compression function calculation path corresponding to each intermediate hash value; Determine the calculation delay of the compression function calculation path corresponding to each intermediate hash value according to the unit calculation delay corresponding to each addition logic and the number of each addition logic.
6. The method according to claim 5, wherein When the compression function calculation path includes an addition logic, use a carry-save adder to process the addition logic.
7. The method according to any one of claims 4-6, characterized in that The at least two target compression function calculation paths include a first target compression function calculation path and a second target compression function calculation path. Among them, the expression form of the first target compression function calculation path is shown in the following formula: Among them, is the first intermediate hash value corresponding to each iteration round; is the first round function; A is the first initial value among the pre-configured multiple initial values; B is the second initial value among the pre-configured multiple initial values; C is the third initial value among the pre-configured multiple initial values; D is the fourth initial value among the pre-configured multiple initial values; E is the fifth initial value among the pre-configured multiple initial values; is the round constant; is the j-th message word included in the message group corresponding to each iteration round; is the (j + 4)-th message word included in the message group corresponding to each iteration round; is determined by the (j + 4)-th message word and the j-th message word included in the message group corresponding to each iteration round; The expression form of the second target compression function calculation path is shown in the following formula: Among them, is the fifth intermediate hash value corresponding to each iteration round; is the second round function; is the first permutation function; F is the fifth initial value among the pre-configured multiple initial values; is the sixth initial value among the pre-configured multiple initial values; is the seventh initial value among the pre-configured multiple initial values.
8. The method according to any one of claims 1-6, characterized in that, Before obtaining at least one group of messages corresponding to the data to be hashed, the method further includes: Obtain the data to be hashed; Identify whether the number of bytes occupied by the data to be hashed meets a preset condition; When the number of bytes occupied by the data to be hashed does not meet the preset condition, perform padding processing on the data to be hashed to generate new data to be hashed to meet the preset condition; And when it is determined that the data to be hashed or the new data to be hashed meets the preset condition, perform grouping processing on the data to be hashed or the new data to be hashed to obtain at least one group of the messages.
9. The method according to any one of claims 1-6, characterized in that, The respectively expanding partial message words among the multiple message words included in each group of messages to generate new message words so that the number of message words included in each group of the messages is a preset number includes: Input the partial message word that matches the h-th new message word into a pre-configured permutation function to expand and generate the h-th new message word, where h is a positive integer, h is greater than the total number of message words included in each group of the messages, and less than or equal to the preset number.
10. The method according to claim 9, wherein The input of the partial message word that matches the h-th new message word into a pre-configured permutation function to expand and generate the h-th new message word is represented by the following expression: wherein, is the j-th message word included in the message group corresponding to each iteration round; is the (j - 16)-th message word included in the message group corresponding to each iteration round; is the (j - 9)-th message word included in the message group corresponding to each iteration round; is the (j - 3)-th message word included in the message group corresponding to each iteration round; is the (j - 6)-th message word included in the message group corresponding to each iteration round; is the (j - 13)-th message word included in the message group corresponding to each iteration round; is the second permutation function.
11. The method according to claim 10, wherein All the message words of the preset number in the i-th group are stored in a preset register corresponding to the i-th group of messages, and the trigger time for expanding and generating a new message word according to the partial message words included in the i-th group of messages is the moment after each execution of the intermediate hash value corresponding to an iteration round; The method further includes: After each new message word is generated, delete the message word that was stored in the preset register first from the preset register.
12. The method according to claim 11, wherein After deleting the message word that was stored in the preset register first from the preset register, the method further includes: Shift the remaining message words stored in the preset register one bit to the left, and store the generated new message word in the last register bit of the preset register.
13. An electronic device, characterized in that, Includes: A memory for storing a computer program; A processor for implementing the steps of the data hashing method according to any one of claims 1 to 12 when executing the computer program.
14. A computer-readable storage medium, characterized in that, A computer program is stored in the computer-readable storage medium, wherein the computer program implements the steps of the data hashing method according to any one of claims 1 to 12 when executed by a processor.
15. A computer program product, comprising a computer program, characterized in that, The computer program implements the steps of the data hashing method according to any one of claims 1 to 12 when executed by a processor.
Citation Information
Patent Citations
Method and system for acquiring data hashes
CN103559458A
Data encryption method and device based on SM3 algorithm, medium and product
CN120165842A
Hashing method, hash calculation system, electronic equipment and storage medium
CN120185797A
Method and apparatus for creating a message digest using a multiple round, one-way hash algorithm
US20020191783A1