A data hashing method, apparatus, electronic device and storage medium

By optimizing the SM3 algorithm through a cyclic iterative computing architecture, the problems of large hardware area and low throughput in IoT devices are solved, and more efficient data hashing processing is achieved.

CN120407240BActive Publication Date: 2025-10-31SHANDONG YUNHAI GUOCHUANG CLOUD COMPUTING EQUIP IND INNOVATION CENT CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510906672.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-07-02
Publication Date
2025-10-31
Estimated Expiration
2045-07-02

AI Technical Summary

Technical Problem

The hardware implementation of the SM3 algorithm in existing IoT devices and host systems has a large area and low throughput, resulting in low data hashing efficiency.

Method used

It adopts a cyclic iterative computing architecture, which performs 64 iterations of calculation through logic function circuits. The intermediate states are stored in resettable registers, avoiding the logic resource consumption of multi-stage pipeline computing architectures.

Benefits of technology

This reduces the area requirement of the SM3 algorithm core and improves the throughput and efficiency of data hashing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120407240B_ABST
    Figure CN120407240B_ABST
Patent Text Reader

Abstract

This application discloses a data hashing method, apparatus, electronic device, and storage medium, relating to the field of data processing technology. The method includes: acquiring at least one set of messages corresponding to the data to be hashed; generating new message words by expanding a portion of the message words in each set of messages; when there are multiple sets of messages, in the first iteration loop, generating a corresponding intermediate hash value based on a 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 for 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 pre-configured initial values, and entering the next iteration loop, until the current iteration loop is the last, and determining the final hash value corresponding to the current iteration loop as the target hash value. This application can solve the problem that data hashing requires a large amount of logical resources, resulting in a large algorithm core area.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, and in particular to a data hashing method, apparatus, electronic device and storage medium. Background Technology

[0002] Data hashing is a technique that transforms inputs of arbitrary length (such as messages or files) into fixed-length output hash values ​​using a specific algorithm. Typical applications include data integrity verification (such as file transfer verification), digital signatures and identity authentication, blockchain and consensus mechanisms (PoW), and data fingerprinting.

[0003] Currently, most Internet of Things (IoT) devices or host systems implement the SM3 algorithm in software to hash data. This software approach is vulnerable to network attacks and has low hashing efficiency. Furthermore, some SM3 algorithm hardware cores employ multi-stage pipelined computing architectures with complex computational paths for the compression function. Multi-stage pipelined SM3 algorithm cores consume significant logic resources during data hashing, resulting in a large algorithm core area. In addition, the complex compression function computation path leads to low throughput in the SM3 algorithm, reducing data hashing efficiency. Summary of the Invention

[0004] This application provides a data hashing method, apparatus, electronic device, and storage medium to at least solve the problem in related technologies that data hashing requires a large amount of logic resources, resulting in a large algorithm core area.

[0005] This application provides a data hashing method, which includes: obtaining at least one set of messages corresponding to the data to be hashed, wherein each set of messages includes multiple message words, and each message word is used as input data in different iteration rounds; generating new message words by expanding on a portion of the multiple message words included in each set of messages, so that the number of message words included in each set of 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 based on the preset number of message words included in the first set of messages corresponding to the first iteration loop and multiple pre-configured initial values.

[0006] Based on the intermediate hash value corresponding to the first iteration loop and multiple pre-configured initial values, the initial value for the first iteration round in the next iteration loop is generated, and the next iteration loop is entered. In the next iteration loop, based on 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, the intermediate hash value corresponding to the next iteration loop is generated. Each iteration loop corresponds to a set of messages. After each iteration loop is executed, if the current iteration loop is not the first iteration loop, the final hash value corresponding to the current iteration loop is generated based on the intermediate hash value corresponding to the current iteration loop and the intermediate hash value corresponding to the previous iteration loop. This process continues until the current iteration loop is the last iteration loop, at which point the final hash value corresponding to the current iteration loop is determined to be the target hash value.

[0007] This application also provides a data hashing device, comprising: an acquisition module, configured to acquire at least one set of messages corresponding to the data to be hashed, wherein each set of messages includes multiple message words, and each message word is used as input data in different iteration rounds; a processing module, configured to generate new message words by expanding a portion of the message words included in each set of messages, so that the number of message words included in each set of messages is a preset number; and the processing module is further configured to, when the messages include multiple sets, generate an intermediate hash value corresponding to the first iteration loop in the first iteration loop based on the preset number of message words included in the first set of messages corresponding to the first iteration loop and multiple pre-configured initial values.

[0008] The processing module is further configured to generate the initial value of the first iteration in the next iteration based on the intermediate hash value corresponding to the first iteration and multiple pre-configured initial values, and enter the next iteration. In the next iteration, it generates the intermediate hash value corresponding to the next iteration based on the preset number of message words included in the message corresponding to the next iteration and the initial value of the first iteration in the next iteration. Each iteration corresponds to a set of messages. The processing module is also configured to generate the final hash value corresponding to the current iteration after each iteration, when the current iteration is not the first iteration, based on the intermediate hash value corresponding to the current iteration and the intermediate hash value corresponding to the previous iteration. Finally, the processing module determines the final hash value corresponding to the current iteration as the target hash value until the current iteration is the last iteration.

[0009] This application also provides an electronic device, including: a memory for storing a computer program; and a processor for implementing any of the above-described data hashing methods when executing the computer program.

[0010] This 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-described data hashing methods.

[0011] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of any of the above-described data hashing methods.

[0012] Through this application, because the above-mentioned determination of the data to be hashed adopts a cyclic iterative computation architecture, that is, only the same set of logic function circuits is needed to process the calculation for 64 iterations. The adder of the logic function circuit is repeatedly used for the modulo operation in each round; the intermediate state is stored in a resettable register, eliminating the need for multiple sets of registers to store the results of all rounds. Therefore, compared with the multi-stage pipelined computation architecture used in related technologies for data hashing, the SM3 algorithm core can avoid consuming a large amount of logic resources and reduce the large area of ​​the algorithm core. Attached Figure Description

[0013] To more clearly illustrate the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0014] Figure 1 A topology diagram of a data hashing system provided in an embodiment of this application;

[0015] Figure 2 A flowchart of the data hashing method provided in the embodiments of this application;

[0016] Figure 3 A flowchart illustrating yet another data hashing method provided in this application embodiment;

[0017] Figure 4 This is a schematic diagram of the structure of the compression function calculation path corresponding to the data hashing device provided in the embodiments of this application;

[0018] Figure 5 This is a schematic diagram of the structure of the message word extension corresponding to the data hashing device provided in the embodiments of this application;

[0019] Figure 6 A schematic diagram illustrating another data hashing method provided in an embodiment of this application;

[0020] Figure 7 A structural block diagram of a data hashing device provided in an embodiment of this application;

[0021] Figure 8This is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0022] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of this application.

[0023] It should be noted that, in the description of this application, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. The terms "first," "second," etc., in this application are used to distinguish similar objects and are not used to describe a specific order or sequence.

[0024] To enable those skilled in the art to better understand the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0025] The specific application environment architecture or specific hardware architecture on which the execution of the data hashing method depends is described here.

[0026] The embodiments of this application are applied to scenarios where input data is hashed based on the SM3 algorithm.

[0027] In related technologies, the SM3 algorithm core, with its multi-stage pipelined computing architecture, does not optimize the computation path of complex compression functions. Instead, it directly describes complex combinational logic using Register Transfer Level (RTL), resulting in a large algorithm core area. Furthermore, the complex compression function computation path leads to low throughput in the SM3 algorithm, reducing the efficiency of data hashing.

[0028] To address the aforementioned issues, this application provides a data hashing method. The core of the SM3 hashing algorithm employs a cyclic iterative computation architecture, resolving the problem of large hardware implementation area for data hashing algorithms in existing IoT devices. The compression function module of the SM3 algorithm core is recalculated to overcome its limited operating frequency, thereby increasing the data hashing throughput.

[0029] The following is based on Figure 1Taking the data hashing system shown as an example, the method provided in the embodiments of this application will be described. Figure 1 This is merely an illustrative diagram and does not constitute a limitation on the applicable scenarios of the technical solutions provided in this application.

[0030] like Figure 1 As shown, Figure 1 This is a topology diagram of a data hashing system provided in an embodiment of this application. Figure 1 In this system, 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.

[0031] Among them, the Central Processing Unit (CPU) 101 can be the core computing and control unit of the computer system, responsible for executing instructions, processing data and coordinating the work of various components.

[0032] The data hashing device 102, also known as the SM3 algorithm core, can be a key hardware infrastructure supporting the efficient operation of the SM3 algorithm. For example, the SM3 algorithm core can be a processor. The data hashing device 102 includes a preset register and a hash value register. The preset register stores the message to be hashed; the hash value register stores the hash value corresponding to the message to be hashed.

[0033] Memory 103 is a key hardware component in a computer system used for temporary storage of data and instructions. Its core function is to provide a fast-access workspace for the central processing unit 101.

[0034] A Direct Memory Access (DMA) device 104 can be a hardware component that allows external devices to transfer data directly to memory without going through the CPU. DMA can directly access memory 103 via a system bus (e.g., an Advanced High-performance Bus (AHB)).

[0035] Specifically, the CPU transmits DMA configuration information to the DMA via the AHB interface. After receiving the CPU's configuration signal and starting up, the DMA moves data from memory via the AHB interface, then writes it to the SM3 algorithm core. Finally, the SM3 algorithm core performs hash calculation on the data. After the hash calculation is complete, the SM3 algorithm core stores the hash value in the hash value register, waiting for the CPU to read it.

[0036] Figure 1The data hashing system 100 shown is for illustrative purposes only and is not intended to limit the technical solutions of this application. Those skilled in the art should understand that in specific implementations, the data hashing system 100 may also include other devices, without limitation.

[0037] This embodiment provides a data hashing method applied to the aforementioned data hashing device. Figure 2 A flowchart of the data hashing method provided in the embodiments of this application is shown below. Figure 2 As shown, the process includes the following steps:

[0038] S201: Obtain at least one set of messages corresponding to the data to be hashed.

[0039] Each message group contains multiple message words, and each message word serves as input data in different iteration rounds. Each message group occupies 512 bits. Each message group contains 16 message words, and each message word occupies 32 bits.

[0040] At least one message contains data to be hashed. The data to be hashed can be file data or message data.

[0041] In one example, after the DMA retrieves the data to be hashed from memory, it transmits the data to a data hashing device. The data hashing device receives the data to be hashed and retrieves at least one set of messages corresponding to the data.

[0042] S202: Generate new message words by expanding some of the message words in each group of messages, so that the number of message words in each group of messages is a preset number.

[0043] The preset number is the number of message words required by the SM3 algorithm. The preset number can be 64.

[0044] Understandably, since each message group contains 16 message words, each message group needs to be expanded to generate 48 new message words based on a subset of the message words within it. The rules for expanding these subsets to generate new message words are determined based on actual needs and are not restricted.

[0045] S203: When the message includes multiple groups, in the first iteration loop, an intermediate hash value corresponding to the first iteration loop is generated based on the preset number of message words included in the first group of messages corresponding to the first iteration loop and multiple pre-configured initial values.

[0046] The pre-configured initial values ​​can be multiple values ​​corresponding to the SM3 algorithm. For example, the pre-configured initial values ​​can be the status values ​​of eight registers: A, B, C, D, E, F, G, and H.

[0047] The intermediate hash value corresponding to the first iteration loop can be denoted as , , , , , , , .

[0048] 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 the preset number of message words included in the first group of messages corresponding to the first iteration loop and multiple pre-configured initial values, to generate an intermediate hash value corresponding to the first iteration loop.

[0049] S204: Based on the intermediate hash value corresponding to the first iteration loop and multiple initial values, generate the initial value of the first iteration round in the next iteration loop, and enter the next iteration loop. In the next iteration loop, based on 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, generate the intermediate hash value corresponding to the next iteration loop.

[0050] Each iteration loop corresponds to a set of messages. Each iteration loop requires 64 iterations.

[0051] In one example, the data hashing device XORs the intermediate hash value corresponding to the first iteration loop with multiple initial values ​​to generate the initial value for the first iteration in the next iteration loop.

[0052] Understandably, the initial value of the first iteration in the next iteration loop is also 8 register state values.

[0053] S205: After each iteration loop is completed, if 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.

[0054] In one example, after each iteration, if the current iteration is not the first iteration, the data hashing device performs an XOR operation on the intermediate hash value corresponding to the current iteration and the intermediate hash value corresponding to the previous iteration to generate the final hash value corresponding to the current iteration.

[0055] 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.

[0056] 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 mechanisms, and data fingerprinting, which is of great significance for information security and enhancing the independent innovation capability of cryptographic technology.

[0057] Optionally, when the message includes a set, after the data hashing device completes the first iteration loop, it determines the target hash value as the result of XORing the intermediate hash value corresponding to the first iteration loop with multiple pre-configured initial values.

[0058] Based on the above Figure 2 The method involves a data hashing device acquiring at least one set of messages corresponding to the data to be hashed, and generating new message words by expanding on a portion of the message words in each set of messages, such that the number of message words in each set of messages is a preset number. When there are multiple sets of messages, in the first iteration loop, an intermediate hash value corresponding to the first iteration loop is generated based on the preset number of message words in the first set of messages corresponding to the first iteration loop and a plurality of pre-configured initial values. Based on the intermediate hash value corresponding to the first iteration loop and the plurality of pre-configured initial values, the initial value for the first iteration round in the next iteration loop is generated, and the next iteration begins. The loop is used to generate an intermediate hash value corresponding to 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. Each iteration loop corresponds to a set of messages. After each iteration loop is executed, if the current iteration loop is not the first iteration loop, the final hash value corresponding to the current iteration loop is generated based on the intermediate hash value corresponding to the current iteration loop and the intermediate hash value corresponding to the previous iteration loop. The final hash value corresponding to the current iteration loop is determined as the target hash value when the current iteration loop is the last iteration loop.

[0059] Because the above-mentioned determination of the data to be hashed uses a cyclic iterative computation architecture, meaning that only the same set of logic function circuits is needed to process the data for 64 iterations, and the adders of the logic function circuits are repeatedly used for the modulo operation in each round; intermediate states are stored in resettable registers, eliminating the need for multiple sets of registers to store the results of all rounds. Therefore, compared to the multi-stage pipelined computation architecture used in related technologies for data hashing, this avoids the SM3 algorithm core consuming a large amount of logic resources and reduces the size of the algorithm core.

[0060] In an optional example, based on the foregoing embodiments and as described above, in the first iteration loop, the data hashing device generates an intermediate hash value corresponding to the first iteration loop based on a preset number of message words included in the first group of messages corresponding to the first iteration loop and multiple pre-configured initial values, as shown in the following method steps, see below for details. Figure 3 As shown, Figure 3 A flowchart of yet another data hashing method provided in the embodiments of this application includes:

[0061] S301: In the first iteration of the first iteration loop, the first message word corresponding to the first iteration and the pre-configured initial values ​​in the multiple message words included in the first group of messages are used to generate multiple intermediate hash values ​​corresponding to the first iteration.

[0062] Understandably, the input to the first iteration in the first iteration loop includes multiple pre-configured initial values.

[0063] S302: In the i-th iteration, all intermediate hash values ​​generated in the (i-1)-th iteration are used as the initial values ​​corresponding to the i-th iteration.

[0064] Where i is a positive integer.

[0065] Understandably, the input in the i-th iteration of the first iteration loop includes: multiple intermediate hash values ​​generated in the (i-1)-th iteration as initial values.

[0066] S303: Based on the i-th message word corresponding to the i-th iteration round, multiple initial values ​​corresponding to the i-th iteration round, and multiple pre-configured initial values, generate an intermediate hash value corresponding to the i-th iteration round.

[0067] In one example, the data hashing device selects at least one initial value from a plurality of initial values ​​corresponding to the i-th iteration round that corresponds to the q-th intermediate hash value; and 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.

[0068] There are eight compression function computation paths. Specifically, each intermediate hash value is obtained based on these eight compression function computation paths. Each compression function computation path includes at least one sub-path.

[0069] For example, with an initial value , , , , , , , The intermediate hash value is , , , , , , , For example; the following is the calculation path of the compression function corresponding to each intermediate hash value:

[0070]

[0071]

[0072]

[0073]

[0074]

[0075]

[0076]

[0077]

[0078] The above A is the first round function; B is the first 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; and E is the fifth initial value among multiple pre-configured initial values. The constant is the round constant. The j-th message word included in the message group corresponding to each iteration round; The message group corresponding to each iteration round includes the (j+4)th message word; The message group corresponding to each iteration round includes the (j+4)th message word and the jth message word; This is the second round function; Let F be the first permutation function; F is the fifth initial value among a plurality of pre-configured initial values. The sixth initial value among a plurality of pre-configured initial values; This is the seventh initial value among a plurality of pre-configured initial values.

[0079] In some optional implementations, the data hashing device obtains the number of addition logic operations for 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 based on the unit calculation delay corresponding to each addition logic operation and the number of addition logic operations.

[0080] For example, with The corresponding compression function calculation path, taking a unit calculation delay of T as an example, is obtained by the data hashing device. The number of addition logic operations in the corresponding compression function calculation path is 5; based on the unit calculation delay T corresponding to each addition logic operation and the number of addition logic operations of 5, the calculation delay 5*T of the compression function calculation path corresponding to each intermediate hash value is determined.

[0081] Understandably, the computation path of the compression function corresponding to each intermediate hash value, in addition to the addition logic, also involves delays from related Boolean functions (shift operations) or permutation functions. For example, The computation delay is the delay of 5 adders (i.e., addition logic) and the related Boolean function. The computation delay is the delay of 5 adders, some Boolean functions, and one permutation function. Since the permutation and Boolean functions mainly involve wiring delays, their relative addition delays are negligible. Therefore, the computation delay of the compression function computation path corresponding to each intermediate hash value only needs to consider the addition logic.

[0082] Optionally, when the computation path of the compressed function includes addition logic, a carry-save adder (CSA) is used to handle the addition logic.

[0083] Understandably, when using a carry-save adder (CSA) to process consecutive operations of multiple addition logics, the addition operation only needs to be performed in the last step, while the others can be implemented through bitwise operations. Therefore, the delay is approximately the same as the delay of the last adder, which can reduce the computation delay of each compression function calculation path and thus improve the efficiency of the entire data hash.

[0084] Furthermore, the data hashing device can determine the computation delay of the compression function computation path corresponding to each intermediate hash value; based on the computation delay of each compression function computation path, select a target compression function computation path whose computation delay is greater than a preset delay threshold; when there are multiple target compression function computation paths, identify whether the multiple target compression function computation paths include the same sub-path; when it is determined that at least two target compression function computation paths include the same sub-path, after the sub-path included in one of the target compression function computation paths generates a computation result, reuse the computation result in the computation process of other target compression function computation paths in the at least two target compression function computation paths.

[0085] The calculation paths for at least two target compression functions include a first target compression function calculation path and a second target compression function calculation path. The expression for the first target compression function calculation path is shown in the following formula:

[0086]

[0087] The expression for the computation path of the second objective compression function is shown in the following formula:

[0088]

[0089] Understandably, the computation path of at least two target compression functions in the intermediate hash value compression function computation path is a relatively long computation path with a large computation delay. Therefore, the computation path of at least two target compression functions severely limits the improvement of the operating frequency and throughput of the data hash accelerator.

[0090] like Figure 4 As shown, Figure 4 This is a structural diagram of the compression function calculation path corresponding to the data hashing device provided in the embodiments of this application; Figure 4 In this process, the data hashing device can be executed using carry-store adders CSA1 and CSA2. and The addition logic is used, then the result of CSA2 is circularly shifted left by 7 bits and added to the result of the CSA1 adder to obtain the value of TT2. Finally, the value is obtained by the substitution function. Finish The calculation. After the corresponding compression function computation path is reorganized and optimized, its computation delay includes three adders, some Boolean functions, and a permutation function.

[0091] because The corresponding compression function calculation path also includes Therefore, only one CSA3 is used for execution. The addition logic for the three numbers is sufficient; after CSA2 is calculated, it will be combined with... 2. Perform an XOR operation to obtain SS2, and finally add SS2 and the result of CSA3 to complete the operation. For The corresponding compressed function computation path, after reorganization and optimization, has its computation latency reduced to three adders plus the latency of some Boolean functions. Through the above path optimization, the computation latency of the compressed function computation path is reduced to three adders plus the latency of some Boolean functions. as well as The original combinational logic latency has been reduced, increasing the system's operating frequency and throughput.

[0092] S304: When the number of iteration rounds to be executed is equal to the preset number, the first iteration loop operation is determined to be completed, 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.

[0093] Understandably, when the number of iterations executed is determined to be 64, the first iteration loop operation is determined to be completed, and the intermediate hash value corresponding to the 64th iteration loop is determined to be the intermediate hash value corresponding to the first iteration loop.

[0094] Optionally, before the data hashing device acquires at least one set of messages corresponding to the data to be hashed, it may acquire 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, the data to be hashed is padded 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, the data to be hashed or the new data to be hashed is grouped to acquire at least one set of messages.

[0095] The preset condition is that the number of bytes occupied by the data to be hashed is an integer multiple of 512 bits. That is, if the number of bytes occupied by the data to be hashed is not an integer multiple of 512 bits, the data to be hashed needs to be padded so that the generated new data to be hashed meets the preset condition.

[0096] Understandably, when the data to be hashed or new data to be hashed meets the preset conditions, it is grouped into 512-bit groups to obtain at least one group of messages.

[0097] In some alternative implementations, the data hashing device inputs a portion of the 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.

[0098] Where h is a value greater than the total number of message words in each message group 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.

[0099] In some optional implementations, the data hashing device inputs a portion of the 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, represented by the following expression:

[0100]

[0101] in, The second permutation function is represented by the following expression:

[0102]

[0103] The j-th message word included in the message group corresponding to each iteration round; The message group corresponding to each iteration round includes the (j-16th)th message word; The message group corresponding to each iteration round includes the (j-9th)th message word; The message group corresponding to each iteration round includes the (j-3)th message word; The message group corresponding to each iteration round includes the (j-6th)th message word; The message group corresponding to each iteration round includes the (j-13th)th message word.

[0104] In one example, the preset number of message words in the i-th group are all stored in the preset register corresponding to the i-th group of messages. The triggering time for generating new message words based on the partial message words included in the i-th group of messages is after each iteration round and the corresponding intermediate hash value is completed. After the data hashing device generates a new message word, it deletes the message word that was first stored in the preset register 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.

[0105] Among them, the preset registers are 16 registers preset by the data hashing device.

[0106] The initial values ​​of the 16 registers are pre-configured. Subsequent message words W16~W67 are calculated by expanding the previously generated message words. Iterative compression and message word expansion are performed simultaneously; that is, W16 is calculated during the first round of iterative compression. The expansion method for W16~W67 is as follows: Figure 5 As shown, Figure 5 This is a schematic diagram of the message word expansion structure corresponding to the data hashing device provided in this application embodiment. When the expansion of the new message word is completed, the values ​​of the last 15 registers are shifted left by 32 bits and stored in the first 15 registers. The new message word is stored in the last register, thus completing one round of updating the 16 register values. The value in the register with the smallest sequence number is passed to the compression function for compression calculation.

[0107] In addition, the data hashing device also has a pre-defined register W' for storing the message word. Based on message words W0~W67, we can obtain W0'~W63'. These message words update register W' in sequence and are synchronously transmitted to the compression function calculation path.

[0108] Understandably, since the data dependency of message word expansion calculation only exists between every 16 consecutive 32-bit message words, after each round of iteration calculation, the message word in the register will be shifted left by 32 bits, and the newly calculated message word will be stored in the last register, forming a new set of 16 consecutive message words, realizing register reuse and greatly saving hardware resource consumption.

[0109] This embodiment provides another data hashing method. Figure 6 This is a schematic diagram of another data hashing method provided in an embodiment of this application. Figure 6 In this method, the data hashing process consists of three parts: padding, message expansion, and iterative compression. The message to be hashed is padded by the upper-layer software and then enters the message expansion hardware module. The expanded message word is then passed to the iterative compression module for calculation. During the hashing of the first group of messages, an initial value is assigned to eight registers (A~H). After 64 rounds of compression calculations, if there is only one group of messages to be hashed, the result of the 64 rounds of compression calculations is XORed with the initial value to obtain the hash value. If there are multiple groups, the result of the 64 rounds of compression calculations XORed with the initial value is used as a new initial value and assigned to registers A~H. This value is then combined with the message word obtained from the expansion of the new group message for 64 rounds of compression calculations until the last group of messages is compressed. Finally, this last group of messages is XORed with the initial value V(i) from the previous round to obtain the final hash value.

[0110] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method.

[0111] Embodiments of this application also provide a data hashing device, such as... Figure 7 As shown, Figure 7 This application provides a structural block diagram of a data hashing device. The data hashing device includes: an acquisition module 701, configured to acquire at least one set of messages corresponding to the data to be hashed, wherein each set of messages includes multiple message words, and each message word serves as input data in different iteration rounds; a processing module 702, configured to generate new message words by expanding a portion of the message words in each set of messages, such that the number of message words in each set of messages is a preset number; and a further configured to, when the message includes multiple sets, generate an intermediate hash value corresponding to the first iteration loop in the first iteration loop based on the preset number of message words included in the first set of messages corresponding to the first iteration loop and multiple pre-configured initial values.

[0112] Processing module 702 is further configured to generate an initial value for the first iteration round in the next iteration loop based on the intermediate hash value corresponding to the first iteration loop and multiple pre-configured initial values, and then enter the next iteration loop. In 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, an intermediate hash value corresponding to the next iteration loop is generated. Each iteration loop corresponds to a set of messages. Processing module 702 is further configured to, after each iteration loop is executed, if the current iteration loop is not the first iteration loop, generate 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. Processing module 702 is further configured to, until the current iteration loop is the last iteration loop, determine that the final hash value corresponding to the current iteration loop is the target hash value.

[0113] In some optional implementations, the processing module 702 is specifically used to, in the first iteration of the first iteration loop, generate multiple intermediate hash values ​​corresponding to the first iteration from the first message word corresponding to the first iteration and multiple pre-configured initial values ​​among the multiple message words included in the first group of messages; in the i-th iteration, use all the multiple intermediate hash values ​​generated in the (i-1)-th iteration as initial values ​​corresponding to the i-th iteration, where i is a positive integer; generate intermediate hash values ​​corresponding to the i-th iteration based on the i-th message word corresponding to the i-th iteration, the multiple initial values ​​corresponding to the i-th iteration, and the multiple pre-configured initial values; when it is determined that the number of iterations executed is equal to a preset number, the first iteration loop operation is determined to end, and the intermediate hash value corresponding to the i-th iteration is determined to be the intermediate hash value corresponding to the first iteration loop.

[0114] In some optional implementations, the intermediate hash value corresponding to the i-th iteration round includes multiple values. The processing module 702 is specifically used to select at least one initial value corresponding to the q-th intermediate hash value from the multiple initial values ​​corresponding to the i-th iteration round; and to perform data hash 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.

[0115] In some optional implementations, the processing module 702 is specifically used to determine the computation delay of the compression function computation path corresponding to each intermediate hash value; select a target compression function computation path whose computation delay is greater than a preset delay threshold based on the computation delay of each compression function computation path; when there are multiple target compression function computation paths, identify whether the multiple target compression function computation paths include the same sub-path; when it is determined that at least two target compression function computation paths include the same sub-path, after the sub-path included in one of the target compression function computation paths generates a computation result, reuse the computation result in the computation process of other target compression function computation paths in the at least two target compression function computation paths.

[0116] In some optional implementations, the processing module 702 is further specifically used to obtain the number of addition logic operations in the compression function calculation path corresponding to each intermediate hash value; and to determine the calculation delay of the compression function calculation path corresponding to each intermediate hash value based on the unit calculation delay corresponding to each addition logic operation and the number of addition logic operations.

[0117] In some alternative implementations, when the computation path of the compressed function includes addition logic, a carry-saving adder is used to process the addition logic.

[0118] In some optional implementations, at least two target compression function calculation paths include a first target compression function calculation path and a second target compression function calculation path, wherein the expression of the first target compression function calculation path is shown in the following formula:

[0119]

[0120] in, The first intermediate hash value corresponding to each iteration round; A is the first round function; B is the first 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; and E is the fifth initial value among multiple pre-configured initial values. The constant is the round constant. The j-th message word included in the message group corresponding to each iteration round; The message group corresponding to each iteration round includes the (j+4)th message word; The message group corresponding to each iteration round includes the (j+4)th message word and the jth message word.

[0121] The expression for the computation path of the second objective compression function is shown in the following formula:

[0122]

[0123] in, The fifth intermediate hash value corresponding to each iteration round; This is the second round function; Let F be the first permutation function; F is the fifth initial value among a plurality of pre-configured initial values. The sixth initial value among a plurality of pre-configured initial values; This is the seventh initial value among a plurality of pre-configured initial values.

[0124] In some optional implementations, before obtaining at least one set of messages corresponding to the data to be hashed, the acquisition module 701 is further configured to acquire 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, the data to be hashed is padded 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, the data to be hashed or the new data to be hashed is grouped to obtain at least one set of messages.

[0125] In some optional implementations, the processing module 702 is further specifically used 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 is a value that is greater than the total number of message words included in each group of messages and less than or equal to a preset number.

[0126] In some optional implementations, the partial message word matching the h-th new message word is input into a pre-configured permutation function to expand and generate the h-th new message word, represented by the following expression:

[0127]

[0128] in, The j-th message word included in the message group corresponding to each iteration round; The message group corresponding to each iteration round includes the (j-16th)th message word; The message group corresponding to each iteration round includes the (j-9th)th message word; The message group corresponding to each iteration round includes the (j-3)th message word; The message group corresponding to each iteration round includes the (j-6th)th message word; The message group corresponding to each iteration round includes the (j-13th)th message word; This is the second permutation function.

[0129] In some optional implementations, the i-th group of preset number of message words are all stored in the preset register corresponding to the i-th group of messages, and the triggering time for generating new message words based on the partial message words included in the i-th group of messages is the time after each iteration round of the intermediate hash value corresponding to it is completed; the processing module 702 is also used to delete the message word first stored in the preset register from the preset register after each new message word is generated.

[0130] In some optional implementations, after deleting the message word first stored in the preset register from the preset register, the processing module 702 is further configured to shift the remaining message word 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.

[0131] For a description of the features in the embodiments corresponding to the data hashing device, please refer to the relevant descriptions in the embodiments corresponding to the data hashing method, which will not be repeated here.

[0132] Embodiments of this application also provide an electronic device, such as... Figure 8 As shown, Figure 8 This is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of this application. The electronic device includes a processor 10 and a memory 20, in which a computer program is stored. The processor 10 is configured to run the computer program to perform the steps in any of the above-described data hashing method embodiments.

[0133] Embodiments of this application also provide a computer-readable storage medium storing a computer program configured to execute the steps in any of the above-described data hashing method embodiments at runtime.

[0134] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard disk, magnetic disk, or optical disk.

[0135] Embodiments of this application also provide a computer program product, which includes a computer program that, when executed by a processor, implements the steps in any of the above-described data hashing method embodiments.

[0136] Embodiments of this application also provide another computer program product, including a non-volatile computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps in any of the above-described data hashing method embodiments.

[0137] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software 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 beyond the scope of this application.

[0138] The data hashing method, apparatus, electronic device, and storage medium provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are merely for the purpose of helping to understand the method and its core ideas. It should be noted that those skilled in the art can make various improvements and modifications to this application without departing from its principles, 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: Obtain at least one set of messages corresponding to the data to be hashed, wherein each set of messages includes multiple message words, and each message word is used as input data in different iteration rounds; New message words are generated by expanding on a portion of the message words in each group of messages, so that the number of message words in each group of messages is a preset number. When the message includes multiple groups, in the first iteration loop, an intermediate hash value corresponding to the first iteration loop is generated based on the preset number of message words included in the first group of messages corresponding to the first iteration loop and multiple pre-configured initial values. Based on the intermediate hash value corresponding to the first iteration loop and the pre-configured multiple initial values, the initial value of the first iteration round in the next iteration loop is generated, and the next iteration loop is entered. In the next iteration loop, based on 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, an intermediate hash value corresponding to the next iteration loop is generated. Each iteration loop corresponds to a set of messages. After each iteration loop is completed, if the current iteration loop is not the first iteration loop, a final hash value corresponding to the current iteration loop is generated 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, the final hash value corresponding to the current iteration loop is determined to be the target hash value.

2. The method according to claim 1, characterized in that, In the first iteration loop, based on a preset number of message words and multiple pre-configured initial values ​​included in the first group of messages corresponding to the first iteration loop, an intermediate hash value corresponding to the first iteration loop is generated, including: In the first iteration of the first iteration loop, the first message word corresponding to the first iteration and the pre-configured initial values ​​among the multiple message words included in the first group of messages are used to generate multiple intermediate hash values ​​corresponding to the first iteration. In the i-th iteration, the intermediate hash values ​​generated in the (i-1)-th iteration are all used as the initial values ​​corresponding to the i-th iteration, where i is a positive integer; Based on the i-th message word corresponding to the i-th iteration round and multiple initial values ​​corresponding to the i-th iteration round, as well as the multiple pre-configured initial values, an intermediate hash value corresponding to the i-th iteration round is generated; When the number of iterations executed is equal to the preset number, the first iteration loop operation is determined to have ended, and the intermediate hash value corresponding to the i-th iteration is determined to be the intermediate hash value corresponding to the first iteration loop.

3. The method according to claim 2, characterized in that, The intermediate hash value corresponding to the i-th iteration round includes multiple values. The process of generating 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, multiple initial values ​​corresponding to the i-th iteration round, and the pre-configured multiple initial values ​​includes: Select at least one initial value from the multiple initial values ​​corresponding to the i-th iteration round that corresponds to the q-th intermediate hash value corresponding to the i-th iteration round; The data hashing process is performed on at least one initial value corresponding to the qth intermediate hash value based on the compression function calculation path corresponding to the qth intermediate hash value to obtain the qth 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 obtaining the qth intermediate hash value by performing data hashing processing on at least one initial value corresponding to the qth intermediate hash value according to the compression function calculation path corresponding to the qth intermediate hash value, the method further includes: Determine the computation delay of the compression function computation path corresponding to each of the intermediate hash values; Based on the calculation delay of each compression function calculation path, a target compression function calculation path with a calculation delay greater than a preset delay threshold is selected; When the target compression function calculation path includes multiple 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 calculation result is generated by the sub-path included in one of the target compression function calculation paths, the calculation result is reused in the calculation process of other target compression function calculation paths in the at least two target compression function calculation paths.

5. The method according to claim 4, characterized in that, The step of determining the computation delay of the compression function computation path corresponding to each of the intermediate hash values ​​includes: Obtain the number of addition logic operations in the compression function calculation path corresponding to each of the intermediate hash values; Based on the unit computation delay corresponding to each addition logic and the number of each addition logic, the computation delay of the compression function computation path corresponding to each intermediate hash value is determined.

6. The method according to claim 5, characterized in that, When the calculation path of the compression function includes addition logic, the addition logic is processed using a carry-saving adder.

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, wherein the expression of the first target compression function calculation path is shown in the following formula: in, The first intermediate hash value corresponding to each iteration round; A is the first round function; B is the first 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; and E is the fifth initial value among the pre-configured multiple initial values. The constant is the round constant. The j-th message word included in the message group corresponding to each iteration round; The message group corresponding to each iteration round includes the (j+4)th message word; The message group corresponding to each iteration round includes the (j+4)th message word and the jth message word; The expression for the computation path of the second objective compression function is shown in the following formula: in, The fifth intermediate hash value corresponding to each iteration round; This is the second round function; Let F be the first permutation function; F is the fifth initial value among the pre-configured plurality of initial values; The sixth initial value among the pre-configured plurality of initial values; This 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 set of messages corresponding to the data to be hashed, the method further includes: Get the data to be hashed; Identify whether the number of bytes occupied by the data to be hashed meets a preset condition; If the number of bytes occupied by the data to be hashed does not meet the preset condition, the data to be hashed is padded to generate new data to be hashed in order to meet the preset condition. When it is determined that the data to be hashed or the new data to be hashed meets the preset conditions, the data to be hashed or the new data to be hashed is grouped to obtain at least one set of the messages.

9. The method according to any one of claims 1-6, characterized in that, The step of generating new message words by expanding a portion of the message words in each group of messages, so that the number of message words in each group of messages is a preset number, includes: The partial message word that matches the h-th new message word is input 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 that is greater than the total number of message words included in each group of messages, and less than or equal to the preset number.

10. The method according to claim 9, characterized in that, The process of 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: in, The j-th message word included in the message group corresponding to each iteration round; The message group corresponding to each iteration round includes the (j-16th)th message word; The message group corresponding to each iteration round includes the (j-9th)th message word; The message group corresponding to each iteration round includes the (j-3)th message word; The message group corresponding to each iteration round includes the (j-6th)th message word; The message group corresponding to each iteration round includes the (j-13th)th message word; This is the second permutation function.

11. The method according to claim 10, characterized in that, 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 time for generating new message words based on the partial message words included in the i-th group of messages is after each iteration round of the intermediate hash value corresponding to it; the method further includes: After each new message word is generated, the message word that was first stored in the preset register is deleted from the preset register.

12. The method according to claim 11, characterized in that, After deleting the message word first stored in the preset register from the preset register, the method further includes: The remaining message word stored in the preset register is shifted left by one bit, and the generated new message word is stored in the last register bit of the preset register.

13. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the steps of the data hashing method as described in any one of claims 1 to 12.

14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the steps of the data hashing method as described in any one of claims 1 to 12.

15. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the data hashing method as described in any one of claims 1 to 12.

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