CN113342530A - Data hash processing method, device, CPU, system and electronic equipment - Google Patents

Data hash processing method, device, CPU, system and electronic equipment Download PDF

Info

Publication number
CN113342530A
CN113342530A CN202110698761.9A CN202110698761A CN113342530A CN 113342530 A CN113342530 A CN 113342530A CN 202110698761 A CN202110698761 A CN 202110698761A CN 113342530 A CN113342530 A CN 113342530A
Authority
CN
China
Prior art keywords
data
hash
hash value
storage information
data segment
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110698761.9A
Other languages
Chinese (zh)
Inventor
王小明
李亚斌
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Haiguang Information Technology Co Ltd
Original Assignee
Haiguang Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Haiguang Information Technology Co Ltd filed Critical Haiguang Information Technology Co Ltd
Priority to CN202110698761.9A priority Critical patent/CN113342530A/en
Publication of CN113342530A publication Critical patent/CN113342530A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • G06F9/5038Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the execution order of a plurality of tasks, e.g. taking priority or time dependency constraints into consideration

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the application provides a data hash processing method, a data hash processing device, a CPU, a system and electronic equipment, wherein the method executed by a user mode of the CPU comprises the following steps: obtaining the storage information of the last hash value from the kernel state; determining the storage information of the current data segment for carrying out hash operation; transmitting the storage information of the current data segment and the storage information of the previous hash value to a kernel state, so that the kernel state updates the initial value used for the hash operation to the previous hash value according to the storage information of the previous hash value, and then the current data segment is subjected to the hash operation according to the updated initial value; and acquiring the storage information of the hash value corresponding to the current data segment from the kernel mode. The embodiment of the application can realize the segmented hash operation on the data and expand the application scene of the data hash processing scheme.

Description

Data hash processing method, device, CPU, system and electronic equipment
Technical Field
The embodiment of the application relates to the technical field of data processing, in particular to a data hash processing method, a data hash processing device, a CPU, a system and electronic equipment.
Background
The data hashing processing means that data is subjected to hashing operation so as to convert the data into a hash value with a fixed length. The Hash Algorithm used in the Hash operation may be, for example, SM3 Algorithm, SHA (Secure Hash Algorithm) Algorithm, or the like.
The data hash processing is widely applied to business scenes such as digital signature and verification, authentication code generation and verification, random number generation and the like. However, the current data hash processing scheme is not suitable for a service scenario that requires a segmented hash operation on data, which results in a limited application scenario of the data hash processing scheme.
Disclosure of Invention
In view of this, embodiments of the present application provide a data hash processing method, an apparatus, a CPU, a system, and an electronic device, so as to perform a segment hash operation on data and expand an application scenario of a data hash processing scheme.
In order to achieve the above object, the embodiments of the present application provide the following technical solutions.
In a first aspect, an embodiment of the present application provides a data hash processing method, where the method is executed by a user mode of a CPU, where the CPU has the user mode and a kernel mode, and the data includes multiple data segments that are sequentially subjected to a hash operation; the method comprises the following steps:
obtaining storage information of a last hash value from a kernel state, wherein the last hash value is a hash value corresponding to a last data segment which is subjected to hash operation;
determining the storage information of the current data segment for carrying out hash operation;
transmitting the storage information of the current data segment and the storage information of the previous hash value to a kernel state, so that the kernel state updates the initial value used for the hash operation to the previous hash value according to the storage information of the previous hash value, and then the current data segment is subjected to the hash operation according to the updated initial value;
acquiring storage information of a hash value corresponding to the current data segment from a kernel mode; if the current data segment is the data segment in the last order, the hash value corresponding to the current data segment is used as the hash value of the data, and if the current data segment is not the data segment in the last order, the hash value corresponding to the current data segment is used as the new last hash value.
In a second aspect, an embodiment of the present application provides a data hash processing method, where the method is executed by a kernel mode of a CPU, where the CPU has a user mode and a kernel mode, and the data includes multiple data segments that are sequentially subjected to a hash operation; the method comprises the following steps:
acquiring storage information of a current data segment for carrying out hash operation and storage information of a previous hash value from a user state; wherein, the previous hash value is a hash value corresponding to a previous data segment which has completed the hash operation, and the storage information of the previous hash value is transmitted to the user state after the previous data segment completes the hash operation by the kernel state;
updating the initial value for the hash operation to the previous hash value according to the storage information of the previous hash value;
driving the hash operation of the current data segment according to the updated initial value and the storage information of the current data segment;
obtaining storage information of a hash value corresponding to the current data segment, and transmitting the storage information of the hash value corresponding to the current data segment to a user state; if the current data segment is the data segment in the last order, the hash value corresponding to the current data segment is used as the hash value of the data, and if the current data segment is not the data segment in the last order, the hash value corresponding to the current data segment is used as the new last hash value.
In a third aspect, an embodiment of the present application provides a data hash processing apparatus, where the apparatus is applied to a user mode of a CPU, the CPU has the user mode and a kernel mode, and the data includes a plurality of data segments that are sequentially subjected to a hash operation; the device comprises:
a last hash value information obtaining module, configured to obtain storage information of a last hash value from a kernel mode, where the last hash value is a hash value corresponding to a last data segment that has completed a hash operation;
the current data segment information determining module is used for determining the storage information of the current data segment for carrying out hash operation;
a first transmission module, configured to transmit the storage information of the current data segment and the storage information of the previous hash value to a kernel state, so that the kernel state updates an initial value used for hash operation to a previous hash value according to the storage information of the previous hash value, and then performs hash operation on the current data segment according to the updated initial value;
the first acquisition module is used for acquiring the storage information of the hash value corresponding to the current data segment from the kernel mode; if the current data segment is the data segment in the last order, the hash value corresponding to the current data segment is used as the hash value of the data, and if the current data segment is not the data segment in the last order, the hash value corresponding to the current data segment is used as the new last hash value.
In a fourth aspect, an embodiment of the present application provides a data hash processing apparatus, where the apparatus is applied to a kernel mode of a CPU, where the CPU has a user mode and a kernel mode, and the data includes a plurality of data segments that are sequentially subjected to a hash operation; the device comprises:
the current operation information acquisition module is used for acquiring the storage information of the current data segment for carrying out the hash operation and the storage information of the previous hash value from a user mode; wherein, the previous hash value is a hash value corresponding to a previous data segment which has completed the hash operation, and the storage information of the previous hash value is transmitted to the user state after the previous data segment completes the hash operation by the kernel state;
the updating module is used for updating the initial value used for the hash operation into the previous hash value according to the storage information of the previous hash value;
the driving operation module is used for driving the hash operation of the current data segment according to the updated initial value and the storage information of the current data segment;
the hash value information transmission module is used for acquiring the storage information of the hash value corresponding to the current data segment and transmitting the storage information of the hash value corresponding to the current data segment to the user state; if the current data segment is the data segment in the last order, the hash value corresponding to the current data segment is used as the hash value of the data, and if the current data segment is not the data segment in the last order, the hash value corresponding to the current data segment is used as the new last hash value.
In a fifth aspect, an embodiment of the present application provides a CPU, where the CPU has a user mode and a kernel mode; said CPU executing computer executable instructions in a user mode to implement the data hash processing method as described above in the first aspect; the CPU executes the computer-executable instructions in the kernel state to implement the data hash processing method according to the second aspect.
In a sixth aspect, an embodiment of the present application provides a data hash processing system, including the CPU as described in the fifth aspect, and a hardware unit for implementing hash operation, where the hardware unit is driven by a kernel state of the CPU to implement hash operation.
In a seventh aspect, an embodiment of the present application provides an electronic device, including the data hash processing system of the sixth aspect.
The data hash processing method provided in the embodiment of the present application is applicable to hash operations on data segments, where the data includes a plurality of data segments that are sequentially subjected to hash operations. After the hash operation is completed on the previous data segment, the kernel mode may transmit the storage information of the previous hash value of the previous data segment to the user mode. When the user mode needs to continue to perform the hash operation on the current data segment, the user mode can transmit the storage information of the current data segment and the storage information of the previous hash value to the kernel mode, so that the kernel mode can update the initial value used for the hash operation to the previous hash value according to the storage information of the previous hash value, and the current data segment can realize the hash operation according to the updated initial value.
Therefore, the data hash processing method provided by the embodiment of the application can interact the storage information of the hash value between the kernel mode and the user mode. Therefore, when the hash operation of the current data segment is carried out, the kernel mode can update the initial value used for the hash operation based on the storage information of the last hash value returned by the user mode, so that the updated initial value can be associated with the hash operation result of the last data segment. That is to say, the hash operation of the current data segment can be associated with the hash operation result of the previous data segment, and the correlation between the data segments can be considered in the process of performing the hash operation on the data segments, so that the accuracy of the hash operation is guaranteed. The data hash processing method provided by the embodiment of the application can realize the segmented hash operation on the data and obtain an accurate hash value, and the application scene of the data hash processing scheme is expanded.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, it is obvious that the drawings in the following description are only embodiments of the present application, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
Fig. 1a is a schematic diagram of an implementation process of the SM3 algorithm.
Fig. 1b is a data packet schematic of the SM3 algorithm.
Fig. 1c is a schematic diagram of an iterative compression process of the SM3 algorithm.
Fig. 2 is a schematic diagram of the implementation of the SM3 algorithm under data segmentation.
Fig. 3a is an architecture diagram of a data hash processing system according to an embodiment of the present application.
FIG. 3b is another architecture diagram of a data hash processing system according to an embodiment of the present application.
Fig. 4 is a flowchart of a data hash processing method according to an embodiment of the present application.
Fig. 5 is a diagram illustrating an implementation example of a data processing method according to an embodiment of the present application.
Fig. 6 is a diagram of another implementation example of the data processing method according to the embodiment of the present application.
Fig. 7a is a schematic diagram of a data structure provided in an embodiment of the present application.
Fig. 7b is another schematic diagram of a data structure provided in the present application.
Fig. 7c is a further schematic diagram of a data structure provided in the embodiment of the present application.
Fig. 8a is a block diagram of a data hash processing apparatus according to an embodiment of the present application.
Fig. 8b is another block diagram of a data hash processing apparatus according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The data hashing processing scheme is described below by taking the SM3 algorithm as an example. Data hash processing schemes based on other types of hash algorithms (e.g., SHA, etc.) may be referred to in a similar manner.
Fig. 1a shows a schematic diagram of the implementation process of the SM3 algorithm. The implementation of fig. 1a can be regarded as a process of hashing data by using the SM3 algorithm. As shown in fig. 1a, the SM3 algorithm is implemented mainly by data stuffing, data grouping, and iterative compression. In fig. 1a, data 110 to be hashed is data-padded to form data 120. The padded data 120 is processed by data grouping, iterative compression, and the like, and a hash value 130 is output. A hash value is understood to be a message digest (e.g. a bit string) output by a hash algorithm on a piece of data. In one example, the hash value 130 is, for example, 256 bits in length.
In some embodiments implementing data population, assume that data 110 is of length l (l < 2)64) Bits, then first add a bit "1" to the end of the data 110, then add s "0" s, s being the smallest non-negative integer satisfying l +1+ s ≡ 448(mod 512); a 64-bit string (which is a binary representation of length l) is then added to form padded data 120. The bit length of the padded data 120 is, for example, a multiple of 512.
Fig. 1b shows a data packet schematic of the SM3 algorithm. As shown in fig. 1b, the padded data 120 may be grouped into N + 1-group data (e.g., first group data through N + 1-group data). In some embodiments, the padded data 120 may be grouped by 512 bits, resulting in a first group of packet data through an N +1 group of packet data.
Fig. 1c shows a schematic diagram of an iterative compression process of the SM3 algorithm. The iterative compression process may include initialization, multiple rounds of iterative operations, and operation result output. In the initialization phase, the initial value IV (0) for the SM3 algorithm may be initialized to a default value, resulting in a default initial value. In the multi-round iterative operation stage, the SM3 algorithm starts from a default initial value, and iteratively operates each grouped data to obtain a hash value. The operation result output stage is mainly used for outputting the hash value obtained by operation.
In the multi-round iterative operation stage, the number of rounds of the multi-round iterative operation may correspond to the group number (i.e. N +1) of the grouped data, and the operation of the current round depends on the operation result of the previous round (i.e. the operation result of the previous round is used as the input of the current round), and the operation result of the last round is output as the hash value. As shown in fig. 1c, in the first round of operation, the first group of packet data is combined with the default initial value to perform operation, and an operation result IV (1) of the first round of operation is obtained. And in the intermediate operation process which is not the first round of operation, the operation result of the previous round of operation is combined with the grouped data corresponding to the current round of operation to carry out operation, and the operation result of the current round of operation is obtained and is used as the input of the next round of operation. For example, in the second round of operation, the operation result IV (1) of the first round of operation is combined with the second group of packet data corresponding to the second round of operation to obtain the operation result IV (2) of the second round of operation, and the operation result IV (2) is used as the input of the third round of operation. And repeating the operation steps until the operation is performed in the (N +1) th round, so as to obtain an operation result IV (N +1) of the (N +1) th round operation, wherein the IV (N +1) is used as a hash value output by the SM3 algorithm.
In the multi-iteration process shown in fig. 1c, IV (0) may be regarded as an initial value, for example, IV (0) is a 256-bit initial value, and is used to determine the initial state of the word register in the multi-iteration process. The value of IV (0) is set to a default value during initialization. The intermediate operation process of the multiple rounds of iterative operations uses IV (1) to IV (n) which can be regarded as intermediate values, and the values of the intermediate values IV (1) to IV (n) can be determined by iterative calculation. The IV (N +1) output by the last round of iterative operation is the hash value output by the SM3 algorithm.
It can be seen that, in the process of implementing the hash algorithms such as the SM3 algorithm, the initial value IV (0) needs to be initialized to the default value every time the hash algorithm is performed, so as to obtain the default initialization value (the default initial value is a fixed value); and obtaining a hash value corresponding to the data according to the default initial value. That is to say, the data hash processing scheme is to perform hash operation on data according to the initialized default initial value to obtain a hash value corresponding to the data. For example, after the data 110 is padded and grouped, the operation is performed on each grouped data iteratively from the initialized default initial value (see fig. 1c for details) to obtain the hash value.
The above-mentioned method needs to set the initial value IV (0) as a default initial value every time the hash operation is performed, which results in that the above-mentioned data hash processing scheme is not suitable for the case where the data has segments. This will be specifically explained below.
Fig. 2 shows a schematic diagram of an implementation of the SM3 algorithm under data segmentation. As shown in fig. 2, the data 210 has 3 pieces of data, including a data piece 211, a data piece 212, and a data piece 213. It should be noted that the number of segments into which the data is divided may be determined according to actual situations, and fig. 2 is only exemplified by dividing the data into 3 segments.
If the data 210 is processed by using the data hash processing scheme described above, the data segment 211, the data segment 212, and the data segment 213 are respectively hashed according to default initial values to obtain corresponding hash values. For example, after the data segment 211 is subjected to data padding and data grouping, each group of packet data is iteratively operated from the initialized default initial value, so as to obtain a hash value corresponding to the data segment 211. Similarly, after the data segment 212 is subjected to data padding and data grouping, each group of grouped data is iteratively operated from the initialized default initial value, so as to obtain a hash value corresponding to the data segment 212. After data padding and data grouping, the data segment 213 iteratively operates on each group of packet data from the initialized default initial value to obtain a hash value corresponding to the data segment 213.
The data segments in the data 210 are associated with each other, and if the hash values are obtained from the initialized default initial values, the association between the data segments is lost, so that the finally obtained hash values are incorrect. The data hash processing scheme that gets the hash value with the default initial value is not applicable to the case where there is segmentation of the data.
The data hash processing scheme provided by the embodiment of the application can realize the segmented hash operation on the data, and expand the application scene of the data hash processing scheme.
Fig. 3a shows an architecture diagram of a data hash processing system 300 provided by an embodiment of the present application. In some embodiments, the system 300 may be a system-on-a-chip, such as where the devices in the system 300 are integrated into a chip. In other embodiments, some of the devices in the system 300 may be integrated into a chip, and some of the devices may be connected to the chip in the form of peripheral devices. As shown in fig. 3a, the system 300 may include: a CPU (Central Processing Unit) 310, a hardware Unit 320, and a memory 330. Optionally, the CPU310 and the hardware unit 320 may interact with the memory 330 through a memory controller, respectively, to implement data reading and writing in the memory 330.
In some embodiments, the hardware unit 320 is a device that implements data processing based on hardware circuits. For example, the hardware unit 320 is a CCP (crypto CoProcessor).
The hashing algorithm may be implemented by CPU310 (i.e., the CPU may perform a hashing operation on data using the hashing algorithm), for example, CPU310 may implement the hashing algorithm by executing program instructions, processor instructions, or other computer-executable instructions. The hash algorithm may also be implemented by the hardware unit 320 (i.e. the hardware unit may perform a hash operation on data by using the hash algorithm), for example, the hardware unit 320 may have the hash algorithm built therein, and the CPU310 drives the hardware unit 320 to execute the hash algorithm through a hardware driver (e.g. a hardware driver). It should be noted that, since the CPU is good at the processing of logical operation and process scheduling, but not good at the computation of pure data, the hardware unit 320 is a better choice to implement the hash algorithm. The hardware unit 320 implements a hash algorithm, which not only improves the efficiency of data hash operation, but also reduces the burden of the CPU. Of course, the embodiment of the present application also supports the implementation of the hash algorithm by the CPU.
FIG. 3b is a diagram illustrating another architecture of a data hash processing system according to an embodiment of the present application. As shown in FIG. 3b, CPU310 may have a User Mode (User Mode) and a Kernel Mode (Kernel Mode). CPU310 may run user programs in a user mode and hardware drivers in a kernel mode (operating system programs may also be run in the kernel mode). A hardware driver may be used to drive the hardware unit 320 that implements the hash algorithm.
In the process of implementing data hash processing, a user mode (for example, a user program in the user mode) may put forward a hash operation requirement, and transmit data that needs to be subjected to a hash operation to a kernel mode (for example, a hardware driver in the kernel mode). The kernel state may drive the hardware unit 320 to perform a hash operation on the data according to the initialized default initial value, so as to obtain a hash value; the kernel mode can transmit the hash value to the user mode so as to realize that the user mode obtains the hash value corresponding to the data. The user mode transmits data to the kernel mode, and the kernel mode transmits the hash value to the user mode, which can be implemented by transmitting the storage information of the data in the memory (for example, the initial address and length of the data in the memory). The data hash processing scheme described in this paragraph is applicable to the case of data non-segmentation, and in the case of data segmentation, the embodiments of the present application provide an adaptive data processing flow, which will be described below.
In the case where the data is segmented into a plurality of data segments, the data may include a plurality of data segments that are sequentially subjected to a hash operation. Namely, each data segment is subjected to hash operation in sequence, and one data segment in the data is subjected to hash operation once. In some embodiments, the user mode transfers the data segment to the kernel mode for hashing a plurality of times in sequence. For example, in fig. 2, the data segment 211 is first transmitted from the user mode to the kernel mode for performing the hash operation, then after the data segment 211 completes the hash operation, the user mode transmits the data segment 212 to the kernel mode for performing the hash operation, and after the data segment 212 completes the hash operation, the user mode transmits the data segment 213 to the kernel mode for performing the hash operation.
In the data processing scheme provided in this embodiment of the present application, except that the data segments in the first order (for example, the data segment 211 shown in fig. 2) may perform the hash operation based on the initialized default initial value, if the hash operation is performed on the other data segments (for example, the data segments 212 and 213 shown in fig. 2) based on the initialized default initial value, the mutual association between the data segments may be lost, so that the finally obtained hash value has an error. Based on this, in the embodiment of the present application, when performing hash operation on data segments in a non-first order, the hash value corresponding to the previous data segment is considered to update the initial value currently used for the hash operation; therefore, based on the updated initial value, the hash operation is carried out on the data segments in the non-first sequence, so that the hash operation result of the previous data segment can be combined when the hash operation is carried out on the data segments in the non-first sequence. That is, in the case of data segmentation, the segment hash operation is performed on data in consideration of the correlation between data segments. It should be noted that the first-order data segment may be a data segment that is first in the data to perform a hash operation, the non-first-order data segment may be a data segment that is not first in the data to perform a hash operation, and the non-first-order data segment may be one or more data segments.
In the above-mentioned idea, since the hash operation requirement is provided by the user mode, the user mode not only transmits the data segment (specifically, for example, the storage information of the data segment) for performing the hash operation to the kernel mode when the hash operation requirement is provided each time, but also transmits the hash value corresponding to the previous data segment (specifically, for example, the storage information of the hash value corresponding to the previous data segment) to the kernel mode, so that the kernel mode updates the initial value currently used for the hash operation. Based on this, the kernel state needs to transfer the hash value (specifically, the storage information of the hash value) obtained by the hash operation to the user state after the hardware unit completes the hash operation of the data segment each time, and the user state needs to further return the hash value of the previous data segment to the kernel state when the hash operation requirement of the data segment is raised.
Fig. 4 shows a flowchart of a data hash processing method provided in an embodiment of the present application. The process shown in fig. 4 may implement hash operations on data segments in a non-first order in the data under the condition that hash values corresponding to a previous data segment are interacted between the user mode and the kernel mode, so that after hash operations are performed on data segments in an end order, hash values corresponding to data segments in the end order may be used as hash values corresponding to the data.
It should be noted that, the process of performing hash operation on the first sequence of data segments in the data can be referred to the foregoing fig. 1a, fig. 1b and fig. 1c, and is not expanded here. I.e. the first order data segments in the data, are hashed according to the default initial value, whereas the flow shown in fig. 4 focuses on how to hash the non-first order data segments when updating the initial value.
In some embodiments, the flow shown in FIG. 4 may be implemented based on the architecture shown in FIG. 3 b. In the flow shown in fig. 4, the hardware unit may be separated from the CPU or may be located in the CPU (for example, the hardware unit is a part of a device in the CPU). Regardless of how the hardware units are set up, the hardware units are driven by the kernel state of the CPU. As shown in fig. 4, the process may include the following steps.
In step S411, after the hash operation is completed on the previous data segment, the user state obtains the storage information of the previous hash value transmitted in the kernel state, where the previous hash value is the hash value corresponding to the previous data segment after the hash operation is completed.
In the process of performing the segmented hash operation on the data, after the hardware unit completes the hash operation on the previous data segment, the kernel state (specifically, for example, a hardware driver in the kernel state) may obtain the storage information of the hash value corresponding to the previous data segment and transmit the storage information to the user state. For convenience, the hash value corresponding to the previous segment of data may be referred to as the previous hash value. The storage information of the last hash value is, for example, the starting address and length of the last hash value in the memory.
In step S412, the user mode determines the storage information of the current data segment for performing the hash operation.
In step S413, the user state transmits the storage information of the current data segment and the storage information of the last hash value to the kernel state.
In the process of carrying out segmented hash operation on the data, carrying out hash operation on data segments in the data in sequence; therefore, when the hash operation needs to be performed on the current data segment, the user mode may transmit the storage information of the current data segment to the kernel mode, so that the kernel mode drives the hardware unit to perform the hash operation on the current data segment. In some embodiments, the previous data segment may be a first-order data segment, and at this time, the current data segment subjected to the hash operation may be a second-order data segment. In some embodiments, the previous data segment may be a data segment in a non-first order, in which case a plurality of data segments in the data have been subjected to the hash operation at least twice in order.
In this embodiment, the user mode further needs to transmit the storage information of the previous hash value to the kernel mode, so that the kernel mode updates the initial value for performing the hash operation. It should be explained that the CPU generally controls the hardware unit to complete the hash operation of a data segment by starting a process, and when the hash operation of the previous data segment is completed, the CPU continuously controls the hardware unit to perform the hash operation of the current data segment by restarting a process; therefore, when the process is restarted and the initial value needs to be updated, the user state needs to inform the kernel state of the storage information of the last hash value used for updating the initial value in addition to the storage information of the current data segment in the kernel state, which involves interacting the storage information of the last hash value between the kernel state and the user state.
In step S414, the kernel state updates the initial value for the hash operation to the previous hash value according to the storage information of the previous hash value.
After the kernel state obtains the storage information of the current data segment transmitted by the user state and the storage information of the previous hash value, the kernel state can obtain the previous hash value from the memory based on the storage information of the previous hash value. The kernel mode may then update the initial value for the hash operation stored in the hardware unit to the previous hash value. In some embodiments, the bit length of the initial value after updating may be kept consistent with the initial value before updating, but the specific value is adjusted to correspond to the last hash value.
In step S415, the kernel state drives the hardware unit to perform hash operation on the current data segment according to the storage information of the current data segment and the updated initial value.
In step S416, the hardware unit obtains the current data segment from the memory according to the storage information of the current data segment; and performing hash operation on the current data segment according to the updated initial value to obtain a hash value corresponding to the current data segment.
After the kernel state completes the update of the initial value, the hardware unit can be driven to perform hash operation on the current data segment according to the storage information of the current data segment and the updated initial value. Therefore, the hardware unit can acquire the current data segment from the memory based on the storage information of the current data segment. Furthermore, the hardware unit may perform a hash operation on the current data segment according to the updated initial value to obtain a hash value corresponding to the current data segment. For example, after the current data segment is subjected to data padding and data grouping, the hardware unit may iteratively operate on each grouped data starting from the updated initial value to obtain a hash value corresponding to the current data segment.
Because the updated initial value can be associated with the hash operation result of the previous data segment, the hash operation is performed on the current data segment based on the updated initial value, so that the hash operation of the current data segment can be associated with the hash operation result of the previous data segment, and the mutual association among the data segments can be considered in the process of performing the hash operation on the data segments, thereby ensuring the accuracy of the hash operation.
In step S417, the hardware unit transmits storage information of the hash value corresponding to the current data segment to the kernel state.
In step S418, the kernel mode transmits the storage information of the hash value corresponding to the current data segment to the user mode.
The hardware unit may store the hash value corresponding to the current data segment in the memory, and transmit storage information of the hash value corresponding to the current data segment to the kernel state. Furthermore, the kernel mode may transmit storage information of the hash value corresponding to the current data segment to the user mode, so that the user mode may obtain the hash value corresponding to the current data segment based on the storage information.
In some embodiments, if the current data segment is not the last sequential data segment in the data, the hash value corresponding to the current data segment is used as the new previous hash value, and the process shown in fig. 4 is executed again to perform the hash operation on the next current data segment; and repeating the steps until the hash value corresponding to the data segment in the last sequence in the data is obtained. In some embodiments, if the current data segment is a data segment in the last order of the data, the hash value corresponding to the current data segment is used as the hash value corresponding to the data, and the hash operation of the data segment is completed.
In an alternative implementation, embodiments of the present application may also perform hash operations by the CPU. In this alternative implementation, after the kernel state updates the initial value used for the hash operation to the previous hash value in step S414, the CPU may perform the hash operation on the current data segment according to the storage information of the current data segment and the updated initial value, so as to obtain the hash value corresponding to the current data segment. Further, the kernel mode can obtain the storage information of the hash value corresponding to the current data segment and transmit the storage information to the user mode.
The data hash processing method provided in the embodiment of the present application is applicable to hash operations on data segments, where the data includes a plurality of data segments that are sequentially subjected to hash operations. After the hash operation is completed on the previous data segment, the kernel mode may transmit the storage information of the previous hash value of the previous data segment to the user mode. When the user mode needs to continue to perform the hash operation on the current data segment, the user mode can transmit the storage information of the current data segment and the storage information of the previous hash value to the kernel mode, so that the kernel mode can update the initial value used for the hash operation to the previous hash value according to the storage information of the previous hash value, and the current data segment can realize the hash operation according to the updated initial value.
Therefore, the data hash processing method provided by the embodiment of the application can interact the storage information of the hash value between the kernel mode and the user mode. Therefore, when the hash operation of the current data segment is carried out, the kernel mode can update the initial value used for the hash operation based on the storage information of the last hash value returned by the user mode, so that the updated initial value can be associated with the hash operation result of the last data segment. That is to say, the hash operation of the current data segment can be associated with the hash operation result of the previous data segment, and the correlation between the data segments can be considered in the process of performing the hash operation on the data segments, so that the accuracy of the hash operation is guaranteed. The data hash processing method provided by the embodiment of the application can realize the segmented hash operation on the data and obtain an accurate hash value, and the application scene of the data hash processing scheme is expanded. For example, the data hash processing scheme provided in the embodiment of the present application can be applied to a service scenario that requires segment hash verification on data.
In one example, taking the data existence data segments 211, 212, and 213 shown in fig. 2 as an example, an implementation example of the data processing method provided in the embodiment of the present application is described. It should be noted that the number of data segments in the data may be determined according to actual situations, and the embodiment of the present application does not set a limit to this.
Fig. 5 is a diagram illustrating an implementation example of a data processing method provided in an embodiment of the present application. The implementation of fig. 5 may be used to hash the data segment 211. Since the data segment 211 is the first sequential data segment in the data, the data segment 211 can perform a hash operation based on the initialized default initial value. As shown in fig. 5, the user mode may transfer the storage information of the data segment 211 to the kernel mode. After the kernel state obtains the storage information of the data segment 211, the hardware unit may be driven to perform hash operation on the data segment 211 according to the storage information of the data segment 211 and a default initial value. After the hardware unit obtains the hash value 510 of the data segment 211, the hardware unit may store the hash value 510 in the memory, and transmit the storage information of the hash value 510 in the memory to the kernel mode. The kernel state then transmits the storage information of the hash value 510 to the user state, so that the user state can obtain the storage information of the hash value 510 of the data segment 211 after the data segment 211 completes the hash operation. That is, the user mode may obtain the hash value of each data segment after the hash operation is completed on each data segment.
Fig. 6 is a diagram illustrating another implementation example of the data processing method provided in the embodiment of the present application. The implementation of fig. 6 may be used to hash the data segment 212. Since the data segment 212 is the second-order data segment in the data, the initial value needs to be updated based on the hash value of the previous data segment 211, and then the hash operation is performed on the data segment 212. As shown in fig. 6, the user mode may transmit the storage information of the data segment 212 and the storage information of the hash value 510 (i.e., the hash value of the previous data segment 211) to the kernel mode. The kernel mode may obtain the hash value 510 from the memory according to the storage information of the hash value 510, and update the initial value in the hardware unit according to the hash value 510. Furthermore, the kernel mode may drive the hardware unit to perform hash operation on the data segment 212 according to the storage information of the data segment 212 and the updated initial value. After the hardware unit obtains the hash value 610 of the data segment 212, the hardware unit may store the hash value 610 in the memory, and transmit the storage information of the hash value 610 in the memory to the kernel mode. The kernel state transfers the stored information of the hash value 610 to the user state.
The process of hashing the data segment 213 is as follows with reference to fig. 6. Since the data segment 213 is the last sequential data segment in the data, the hash value of the data segment 213 is considered as the corresponding hash value of the data.
When the hash operation is performed on the data segments in the data, which are not in the first sequence, in the embodiment of the application, the hash value of the previous data segment can be used for updating the initial value currently used for the hash operation; therefore, based on the updated initial value, the hash operation is carried out on the data segments in the non-first sequence, so that the hash operation result of the previous data segment can be combined when the hash operation is carried out on the data segments in the non-first sequence. The embodiment of the application can realize the segmented hash operation on the data by considering the correlation among the data segments under the condition of data segmentation, and can be suitable for the service scene needing the segmented hash operation on the data. In an application example, the embodiment of the present application is applicable to a service scenario in which data is subjected to segment hash verification, and a data segment subjected to segment hash verification may be regarded as a data segment that needs to be subjected to hash operation in the embodiment of the present application.
In some embodiments, in order to interact the storage information of the previous hash value between the kernel state and the user state (for example, after the previous data segment completes the hash operation, the user state may obtain the storage information of the previous hash value from the kernel state, and when the current data segment performs the hash operation, the user state may transmit the storage information of the previous hash value to the kernel state), the embodiment of the present application may further provide a data structure and a data interface function for data interaction between the user state and the kernel state, which will be described below. It should be emphasized that the data structure and the data interface function described below are optional, and any data structure and data interface function capable of implementing the storage information of the hash value in the interaction between the kernel mode and the user mode may be applicable to the embodiment of the present application based on the data hash processing flow provided in the embodiment of the present application.
The embodiment of the application can provide the data acquisition interface function and the data transmission interface function in a user mode. The data fetch interface function may be used at least to fetch the stored information of the last hash value from the kernel state. The data transfer interface function may be at least configured to transfer storage information of a last hash value to the kernel state when a hash operation needs to be performed on a current data segment. Taking the hash algorithm as the SM3 algorithm, and the hardware unit implemented by the CCP as an example, the data fetch interface function may be defined as CCP _ SM3_ md _ update, and the data transfer interface function may be defined as CCP _ SM3_ md _ meta _ update.
The embodiment of the application also provides a data structure for data interaction between the user mode and the kernel mode. Fig. 7a is a schematic diagram illustrating a data structure provided in an embodiment of the present application. As shown in fig. 7a, the data structure may include: the data structure 710 includes a first structure unit 711 and a second structure unit 712 in the data structure 710. The first structure unit 711 may be configured to store information of a current data segment currently performing a hash operation, such as a starting address and a length of the current data segment in a memory. The second structure unit 712 can be used to store the storage information of the target structure in the memory, such as the starting address and size of the target structure in the memory. The target structure may be a structure in the memory for storing a hash value corresponding to the current data segment. For example, after the hash operation of the current data segment is completed, the hash value corresponding to the current data segment may be stored in the target structure indicated by the second structure unit 712, so that after each hash operation of the data segment is completed, the hash value of the data segment may be stored in the target structure. The target structure can be applied by a user.
Since the user mode does not need to transmit the storage information of the last hash value to the kernel mode when performing the hash operation on the data segment in the first order in the data, the process of performing data interaction between the user mode and the kernel mode based on the data structure shown in fig. 7a when performing the hash operation on the data segment in the first order in the data may be as follows. In some embodiments, the user mode may fill the storage information of the data segments in the first order into the first structure unit 711 and fill the storage information of the target structure storing the hash value in the memory into the second structure unit 712 according to a communication protocol with the kernel mode. The user mode can thus transmit the data structure 710 carrying the first structure unit 711 and the second structure unit 712 to the kernel mode.
After the kernel state obtains the data structure 710, the kernel state may drive the hardware unit to perform hash operation on the data segments in the first order based on the storage information in the first structure unit 711. After the hash operation is completed on the first-order data segments, the hardware unit may store the hash values corresponding to the first-order data segments in the target structure of the memory based on the storage information of the target structure in the second structure unit 712, and the kernel state may obtain the storage information of the hash values in the memory from the hardware unit. The kernel mode may thus fill the second structure unit 712 with the storage information of the hash values corresponding to the data segments in the first order. Furthermore, the user mode may copy the second structure unit from the kernel mode (the second structure unit is filled with the storage information of the hash values corresponding to the data segments in the first order) by using a function of copying data from the kernel mode to the user mode, so that the user mode may obtain the storage information of the hash values from the kernel mode.
In one implementation example, the user mode and the kernel mode may communicate based on a socket, and before data interaction between the user mode and the kernel mode, socket connection between the user mode and the kernel mode may be established. Of course, the embodiment of the application also supports the user mode and the kernel mode to use other types of communication protocols. Under the socket communication protocol, the data structure 710 shown in fig. 7a may be an msghdr (message header) structure, and the msghdr structure may be a variable based on socket communication and used for recording a message linked list. The first structure unit 711 may be an original linked list in the msghdr structure, and the second structure unit 712 may be a newly added linked list additionally arranged in the msghdr structure. In one example, fig. 7b shows another schematic diagram of a data structure provided by an embodiment of the present application. As shown in FIG. 7b, the msg _ iter of the msghdr structure has an original linked list iovec [0] and a newly added linked list iovec [1 ]. The original linked list iovec [0] can record the initial address and length of the data segment for hash operation, and the newly added linked list iovec [1] can record the initial address and size of the target structure. For example, when performing a hash operation on a first-order data segment in data, a starting address and a length of the first-order data segment in the memory may be recorded in the original linked list iovec [0 ]. The method is different from the method that an original linked list iovec [0] is simply arranged in an msghdr structure body, the msghdr structure body is also provided with a newly increased linked list iovec [1], the newly increased linked list iovec [1] can record the initial address and the size of a target structure body in a memory, and the target structure body can store a hash value obtained by each hash operation.
Based on the data structure shown in fig. 7b, when performing hash operation on the data segments in the first order in the data, the user state may fill the initial address and the length of the data segments in the first order in the memory to the original linked list iovec [0] according to the socket protocol, and fill the initial address and the size of the target structure in the memory to the newly added linked list iovec [1 ]. Therefore, the user state can transmit the msghdr structure body carrying the original linked list iovec [0] and the newly added linked list iovec [1] to the kernel state. For example, the msghdr structure can be transferred to the kernel mode by the sendmsg (send message) method of socket. The sendmsg method is a method for sending a message from a socket.
In some embodiments, the kernel state may set a crypto driver framework and the user state may transfer the msghdr construct to the crypto driver framework of the kernel state. The crypto driver framework in kernel state may send the original linked list iovec [0] to the hardware driver. When hash operation is performed on the data segments in the first sequence in the data, the hardware driver may drive the hardware unit to perform hash operation on the data segments in the first sequence according to the initialized default initial value based on the storage information of the data segments in the first sequence in the original linked list iovec [0 ]. After the hash operation is completed on the data segments in the first order, the hardware unit may store the hash values of the data segments in the first order in the target structure of the memory based on the indication of the newly added linked list iovec [1 ]. The hardware unit may further transmit storage information of the hash values of the first order data segments to the kernel state. Furthermore, the kernel state may fill the storage information of the hash values of the data segments in the first order into the newly added linked list iovec [1 ]. The user mode may copy the newly added linked list iovec [1] filled with the storage information of the hash values of the data segments of the first order from the kernel mode using a memcpy _ to _ msg function (a function that implements copying of data from the kernel mode to the user mode) so that the user mode obtains the storage information of the hash values of the data segments of the first order.
After the hash operation of the data segments in the first sequence is completed, if the hash operation needs to be performed on the current data segment, the user mode needs to transmit the storage information of the current data segment currently performing the hash operation and the storage information of the target structure to the kernel mode, and also needs to transmit the storage information of the last hash value to the kernel mode. Based on this, fig. 7c shows a further schematic diagram of the data structure provided by the embodiment of the present application. As shown in fig. 7a and 7c, the data structure 710 shown in fig. 7c further has auxiliary data 713 associated with a message control method (msg _ control), and the auxiliary data 713 may be used to record storage information of a previous hash value, such as a starting address and a length of the previous hash value in a memory.
In some embodiments, the first structure element 711 and the second structure element 712 may be carried in the data structure 710 in a linked list (e.g., the first structure element 711 is the original linked list iovec [0] shown in fig. 7b, the second structure element 712 is the new added linked list iovec [1] shown in fig. 7 b), and the data structure 710 is sent to the kernel state in sendmsg. The auxiliary data 713 may be associated with the data structure 710 by an msg _ control method and transmitted to the kernel mode by the msg _ control method. msg _ control can be used to set auxiliary data, also called control information, in the socket communication.
After the hash operation of the previous data segment (the previous data segment may be the data segment in the first order, or may be the data segment in the non-first order) is completed, the user mode may obtain the storage information of the previous hash value of the previous data segment transferred by the kernel mode, and the CPU may restart a process to continue the hash operation of the current data segment. At this time, the user mode may fill the storage information of the current data segment into the first structure unit 711 in the data structure 710 according to the communication protocol with the kernel mode; filling the second structure unit 712 with the storage information of the target structure for storing the hash value in the memory; the storage information of the last hash value is filled into the auxiliary data 713, and the auxiliary data 713 is associated with the data structure 710 in the msg _ control method. The user mode may transfer the data structure 710 (e.g., msghdr structure) carrying the first structure unit 711 and the second structure unit 712 to the kernel mode (e.g., the user mode transfers the data structure 710 to the kernel mode in sendmsg method); and the data structure 710 transferred to the kernel state may be associated with the auxiliary data 713 by the msg _ control method.
After the kernel mode acquires the data structure 710, the kernel mode may determine the auxiliary data 713 associated with the data structure 710 by the msg _ control method, and acquire a previous hash value from the memory based on the storage information of the previous hash value in the auxiliary data 713. Further, the kernel mode may update the initial value for the current hash operation in the hardware unit according to the last hash value. In some embodiments, the kernel mode may set a crypto driver framework, and the kernel mode may determine, in the crypto driver framework, the auxiliary data 713 associated with the data structure 710 in the msg _ control method, for example, determine whether a length of a last hash value in the auxiliary data 713 is not 0; if the length of the previous hash value is not 0, it indicates that the initial value needs to be updated for performing the hash operation on the current data segment, and at this time, the kernel mode may obtain the auxiliary data 713 associated with the data structure 710 in the msg _ control method through a memcpy _ from _ msg function (a function for implementing data replication from the user mode to the kernel mode), so as to obtain the previous hash value from the memory based on the storage information of the previous hash value in the auxiliary data 713.
After the kernel state updates the initial value used for the current hash operation in the hardware unit, the driving hardware unit may perform the hash operation on the current data segment according to the updated initial value based on the storage information of the current data segment in the first structure unit 711 (e.g., the original linked list iovec [0 ]). After the hash operation of the current data segment is completed, the kernel mode can obtain the storage information of the hash value of the current data segment in the memory. Further, the kernel state may fill the second structural unit 712 (e.g., newly added linked list iovec [1]) with the storage information of the hash value of the current data segment. And the user mode can copy the second structural body unit filled with the storage information of the hash value of the current data segment from the kernel mode by using a memcpy _ to _ msg function so as to complete the hash processing of the current data segment.
If the current data segment is the data segment in the last sequence in the data, the user mode may obtain the hash value corresponding to the data based on the storage information of the hash value of the current data segment in the copied second structure unit. If the current data segment is not the last sequential data segment in the data, the hash value of the current data segment can be used as a new previous hash value, and the hash operation is performed on the next current data segment by using the described data structure until the hash value of the last sequential data segment is obtained.
In an implementation example, the first structure unit recording the storage information of the current data segment and the second structure unit recording the storage information of the target structure may be used as a linked list of the data structure, and by the feature of msg _ control, the data structure may be enabled to associate the auxiliary data recording the storage information of the last hash value. Through such a configuration, the embodiment of the present application can implement a process hash value (i.e., a hash value of a previous data segment that completes a hash operation) in a user-mode and kernel-mode interactive data segment hash operation process on the premise of not changing a user-mode and kernel-mode communication architecture (e.g., a socket communication architecture), so that the data segment hash operation can consider the correlation between the data segments, and ensure the accuracy of a finally obtained hash value. According to the embodiment of the application, the storage information of the hash value can be interacted between the user mode and the kernel mode, the hardware drive realization function of the kernel mode is enriched, the corresponding data acquisition interface function and the data transmission interface function are realized in the user mode, the data can be subjected to segmented hash operation, the accurate hash value is obtained, and the application scene of the data hash processing scheme is expanded.
While various embodiments have been described above in connection with what are presently considered to be the embodiments of the disclosure, the various alternatives described in the various embodiments can be readily combined and cross-referenced without conflict to extend the variety of possible embodiments that can be considered to be the disclosed and disclosed embodiments of the disclosure.
The following describes the data hash processing apparatus provided in the embodiment of the present application from the perspective of the user mode of the CPU. The device content described below can be considered as a user mode of the CPU, and is a functional module that is required to implement the data hash processing method provided in the embodiment of the present application. The device content described below may be referred to in correspondence with the above description.
Fig. 8a shows a block diagram of a data hash processing apparatus according to an embodiment of the present application. The apparatus is applicable to a user mode of a CPU, and the CPU has a user mode and a kernel mode. Referring to fig. 8a, the apparatus may include:
a last hash value information obtaining module 811, configured to obtain storage information of a last hash value from a kernel state of the CPU, where the last hash value is a hash value corresponding to a last data segment that has completed a hash operation;
a current data segment information determining module 812, configured to determine storage information of a current data segment for performing hash operation;
a first transmission module 813, configured to transmit the storage information of the current data segment and the storage information of the previous hash value to a kernel state, so that the kernel state updates an initial value used for hash operation to a previous hash value according to the storage information of the previous hash value, and then performs hash operation on the current data segment according to the updated initial value;
a first obtaining module 814, configured to obtain, from the kernel state, storage information of a hash value corresponding to the current data segment; if the current data segment is the data segment in the last order, the hash value corresponding to the current data segment is used as the hash value of the data, and if the current data segment is not the data segment in the last order, the hash value corresponding to the current data segment is used as the new last hash value.
In some embodiments, the first transmitting module 813 configured to transmit the storage information of the current data segment and the storage information of the last hash value to the kernel state includes:
determining a data structure body and auxiliary data related to the data structure body; the data structure comprises a first structure unit and a second structure unit, the first structure unit is filled with storage information of a current data segment, the second structure unit is filled with storage information of a target structure, the target structure is used for storing a hash value obtained by each hash operation, and the auxiliary data records storage information of a previous hash value;
and transmitting the data structure body and the auxiliary data to a kernel state.
In some embodiments, the first obtaining module 814, configured to obtain, from the kernel mode, storage information of a hash value corresponding to the current data segment, includes:
and copying the second structure unit filled with the storage information of the hash value corresponding to the current data segment from the kernel state by using a function of copying data from the kernel state to the user state.
In some embodiments, the user mode and the kernel mode communicate based on a socket, and the first structural body unit and the second structural body unit are linked lists in the data structural body; the data structure body is associated with the auxiliary data through a message control method; a first transmission module 813, configured to transmit the data structure to the kernel mode, including:
transmitting the data structure body to a kernel state by a message sending method;
a first transfer module 813 configured to transfer the auxiliary data to the kernel mode includes:
and transmitting the auxiliary data to a kernel mode through a message control method.
In some embodiments, the previous data segment is a first order data segment, or a non-first order data segment.
When the last data segment is the data segment of the first sequence, the device can be further provided with a functional module to realize the following functions:
determining storage information of data segments in a first sequence;
and at least transmitting the storage information of the data segments in the first sequence to a kernel mode, so that the kernel mode drives the hash operation of the data segments in the first sequence according to the storage information of the data segments in the first sequence and an initialized default initial value.
In some embodiments, the transmitting, to the kernel state, at least the storage information of the first order data segments includes:
determining a data structure body, wherein a first structure body unit of the data structure body is filled with storage information of a first sequence of data segments, a second structure body unit of the data structure body is filled with storage information of a target structure body, and the target structure body is used for storing a hash value obtained by each hash operation;
and transmitting the data structure body to a kernel state.
When the previous data segment is the first-order data segment, correspondingly, the previous hash value information obtaining module 811 is configured to obtain the storage information of the previous hash value from the kernel state of the CPU, where the storage information includes:
and copying the second structure unit filled with the storage information of the hash values corresponding to the data segments in the first sequence from the kernel mode by using a function of copying data from the kernel mode to the user mode.
The embodiment of the present application further provides a CPU, where the CPU can execute the computer-executable instruction in the user mode to implement the data hash processing method executed in the user mode of the CPU provided in the embodiment of the present application.
The following describes the data hash processing apparatus provided in the embodiment of the present application from the perspective of the kernel mode of the CPU. The device content described below can be considered as a kernel mode of the CPU, and is a functional module that is required to implement the data hash processing method provided in the embodiment of the present application. The device content described below may be referred to in correspondence with the above description.
Fig. 8b shows another block diagram of a data hash processing apparatus according to an embodiment of the present application. The apparatus is applicable to a kernel mode of a CPU, and the CPU has a user mode and a kernel mode. Referring to fig. 8b, the apparatus may include:
a current operation information obtaining module 821, configured to obtain, from the user mode, storage information of a current data segment for performing hash operation and storage information of a previous hash value; wherein, the previous hash value is a hash value corresponding to a previous data segment which has completed the hash operation, and the storage information of the previous hash value is transmitted to the user state after the previous data segment completes the hash operation by the kernel state;
an updating module 822, configured to update the initial value used for the hash operation to the previous hash value according to the storage information of the previous hash value;
a driving operation module 823, configured to drive a hash operation of the current data segment according to the updated initial value and the storage information of the current data segment;
a hash value information transmission module 824, configured to obtain storage information of a hash value corresponding to the current data segment, and transmit the storage information of the hash value corresponding to the current data segment to the user state; if the current data segment is the data segment in the last order, the hash value corresponding to the current data segment is used as the hash value of the data, and if the current data segment is not the data segment in the last order, the hash value corresponding to the current data segment is used as the new last hash value.
In some embodiments, the current operation information obtaining module 821 is configured to obtain, from the user mode, storage information of the current data segment for performing the hash operation, and the storage information of the previous hash value includes:
acquiring a data structure body and auxiliary data related to the data structure body from a user mode;
the data structure comprises a first structure unit and a second structure unit, the first structure unit is filled with storage information of a current data segment, the second structure unit is filled with storage information of a target structure, the target structure is used for storing a hash value obtained by each hash operation, and the auxiliary data is used for transmitting storage information of a last hash value to the kernel state.
In some embodiments, the user mode and the kernel mode communicate based on a socket, and the first structural body unit and the second structural body unit are linked lists in the data structural body; the data structure body is associated with the auxiliary data through a message control method; the current operation information obtaining module 821, configured to obtain the data structure from the user mode, includes:
acquiring the data structure body transmitted by the user mode through a message sending method;
the current operation information obtaining module 821, configured to obtain the auxiliary data associated with the data structure from the user mode, includes:
and acquiring the auxiliary data transmitted by the user mode through a message control method.
In some embodiments, the updating module 822, configured to update the initial value for the hash operation to the previous hash value according to the storage information of the previous hash value, includes:
judging whether the length of the last hash value in the storage information of the last hash value is not 0, if so, acquiring the last hash value from the memory according to the storage information of the last hash value;
updating the initial value for the hash operation according to the last obtained hash value.
In some embodiments, the current operation information obtaining module 821, configured to obtain the auxiliary data transmitted by the user mode through the message control method, includes:
and copying the auxiliary data related to the data structure body in a message control method by using a data copying function from a user mode to a kernel mode.
In some embodiments, the hash value information transmitting module 824, configured to transmit the storage information of the hash value corresponding to the current data segment to the user mode includes:
and based on the storage information of the target structure body filled by the second structure body unit, storing the hash value corresponding to the current data segment into the target structure body in the memory, and then filling the storage information of the hash value corresponding to the current data segment into the second structure body unit, so that the user mode obtains the second structure body unit by using a function of copying data from the kernel mode to the user mode.
In some embodiments, the previous data segment is a first order data segment, or a non-first order data segment.
In some embodiments, if the previous data segment is a data segment in the first order, the apparatus may further include a function module to implement the following functions:
at least obtaining the storage information of the data segments in the first sequence from the user mode;
and driving the hash operation of the data segments of the first sequence according to the storage information of the data segments of the first sequence and the initialized default initial value.
The embodiment of the present application further provides a CPU, where the CPU can execute a computer executable instruction in a kernel mode, so as to implement the data hash processing method executed in the kernel mode of the CPU provided in the embodiment of the present application.
The embodiment of the present application further provides a data hash processing system, the architecture of which can be shown in fig. 3a and 3b, and includes a CPU and a hardware unit for implementing hash operation; the CPU has a user mode and a kernel mode, the CPU realizes the data hash processing method executed by the user mode angle of the CPU provided by the embodiment of the application in the user mode, and the CPU realizes the data hash processing method executed by the kernel mode angle of the CPU provided by the embodiment of the application in the kernel mode; the hardware unit can be driven by the kernel state of the CPU to realize the hash operation.
An embodiment of the present application further provides an electronic device, which may include the data hash processing system provided in the embodiment of the present application.
Although the embodiments of the present application are disclosed above, the present application is not limited thereto. Various changes and modifications may be effected therein by one of ordinary skill in the pertinent art without departing from the scope or spirit of the present disclosure, and it is intended that the scope of the present disclosure be defined by the appended claims.

Claims (19)

1. A data hash processing method is characterized in that the method is executed by a user mode of a CPU (Central processing Unit), the CPU has a user mode and a kernel mode, and the data comprises a plurality of data segments which are subjected to hash operation in sequence; the method comprises the following steps:
obtaining storage information of a last hash value from a kernel state, wherein the last hash value is a hash value corresponding to a last data segment which is subjected to hash operation;
determining the storage information of the current data segment for carrying out hash operation;
transmitting the storage information of the current data segment and the storage information of the previous hash value to a kernel state, so that the kernel state updates the initial value used for the hash operation to the previous hash value according to the storage information of the previous hash value, and then the current data segment is subjected to the hash operation according to the updated initial value;
acquiring storage information of a hash value corresponding to the current data segment from a kernel mode; if the current data segment is the data segment in the last order, the hash value corresponding to the current data segment is used as the hash value of the data, and if the current data segment is not the data segment in the last order, the hash value corresponding to the current data segment is used as the new last hash value.
2. The method of claim 1, wherein the transmitting the storage information of the current data segment and the storage information of the last hash value to a kernel state comprises:
determining a data structure body and auxiliary data related to the data structure body; the data structure comprises a first structure unit and a second structure unit, the first structure unit is filled with storage information of a current data segment, the second structure unit is filled with storage information of a target structure, the target structure is used for storing a hash value obtained by each hash operation, and the auxiliary data records storage information of a previous hash value;
and transmitting the data structure body and the auxiliary data to a kernel state.
3. The method according to claim 2, wherein the obtaining the storage information of the hash value corresponding to the current data segment from the kernel mode comprises:
and copying the second structure unit filled with the storage information of the hash value corresponding to the current data segment from the kernel state by using a function of copying data from the kernel state to the user state.
4. The method of claim 2 or 3, wherein the user state and the kernel state are based on socket communication, and the first structure unit and the second structure unit are linked lists in the data structure; the data structure body is associated with the auxiliary data through a message control method;
the transmitting the data structure to the kernel state comprises:
transmitting the data structure body to a kernel state by a message sending method;
the transmitting the auxiliary data to the kernel mode includes:
and transmitting the auxiliary data to a kernel mode through a message control method.
5. The method of claim 1, wherein if the previous data segment is a first sequential data segment, the method further comprises:
determining storage information of data segments in a first sequence;
and at least transmitting the storage information of the data segments in the first sequence to a kernel mode, so that the kernel mode drives the hash operation of the data segments in the first sequence according to the storage information of the data segments in the first sequence and an initialized default initial value.
6. The method of claim 5, wherein transmitting at least the storage information of the first sequential data segment to a kernel state comprises:
determining a data structure body, wherein a first structure body unit of the data structure body is filled with storage information of a first sequence of data segments, a second structure body unit of the data structure body is filled with storage information of a target structure body, and the target structure body is used for storing a hash value obtained by each hash operation;
and transmitting the data structure body to a kernel state.
7. The method of claim 6, wherein obtaining the storage information of the last hash value from the kernel mode comprises:
and copying the second structure unit filled with the storage information of the hash values corresponding to the data segments in the first sequence from the kernel mode by using a function of copying data from the kernel mode to the user mode.
8. A data hash processing method is characterized in that the method is executed by a kernel mode of a CPU (Central processing Unit), the CPU has a user mode and a kernel mode, and the data comprises a plurality of data segments which are subjected to hash operation in sequence; the method comprises the following steps:
acquiring storage information of a current data segment for carrying out hash operation and storage information of a previous hash value from a user state; wherein, the previous hash value is a hash value corresponding to a previous data segment which has completed the hash operation, and the storage information of the previous hash value is transmitted to the user state after the previous data segment completes the hash operation by the kernel state;
updating the initial value for the hash operation to the previous hash value according to the storage information of the previous hash value;
driving the hash operation of the current data segment according to the updated initial value and the storage information of the current data segment;
obtaining storage information of a hash value corresponding to the current data segment, and transmitting the storage information of the hash value corresponding to the current data segment to a user state; if the current data segment is the data segment in the last order, the hash value corresponding to the current data segment is used as the hash value of the data, and if the current data segment is not the data segment in the last order, the hash value corresponding to the current data segment is used as the new last hash value.
9. The method of claim 8, wherein the obtaining the storage information of the current data segment for performing the hash operation from the user mode and the storage information of the previous hash value comprises:
acquiring a data structure body and auxiliary data related to the data structure body from a user mode;
the data structure comprises a first structure unit and a second structure unit, the first structure unit is filled with storage information of a current data segment, the second structure unit is filled with storage information of a target structure, the target structure is used for storing a hash value obtained by each hash operation, and the auxiliary data records storage information of a previous hash value.
10. The method of claim 9, wherein the user state and the kernel state are based on socket communication, and the first and second structure units are linked lists in the data structure; the data structure body is associated with the auxiliary data through a message control method;
the obtaining the data structure from the user mode comprises:
acquiring the data structure body transmitted by the user mode through a message sending method;
the acquiring auxiliary data associated with the data structure from the user mode comprises:
and acquiring the auxiliary data transmitted by the user mode through a message control method.
11. The method of claim 10, wherein the obtaining the assistance data transmitted by the user mode through a message control method comprises:
and copying the auxiliary data related to the data structure body in a message control method by using a data copying function from a user mode to a kernel mode.
12. The method according to claim 9, wherein said updating the initial value for the hash operation to the previous hash value according to the stored information of the previous hash value comprises:
judging whether the length of the last hash value in the storage information of the last hash value is not 0, if so, acquiring the last hash value from the memory according to the storage information of the last hash value;
updating the initial value for the hash operation according to the last obtained hash value.
13. The method of claim 9, wherein the transmitting the storage information of the hash value corresponding to the current data segment to the user state comprises:
and based on the storage information of the target structure in the second structure unit, storing the hash value corresponding to the current data segment in the target structure in the memory, and filling the storage information of the hash value corresponding to the current data segment in the second structure unit, so that the user mode obtains the second structure unit by using a function of copying data from the kernel mode to the user mode.
14. The method of claim 8, wherein if the previous segment is a first sequential segment, the method further comprises:
at least obtaining the storage information of the data segments in the first sequence from the user mode;
and driving the hash operation of the data segments of the first sequence according to the storage information of the data segments of the first sequence and the initialized default initial value.
15. A data hash processing device is applied to a user mode of a CPU (Central processing Unit), the CPU has a user mode and a kernel mode, and the data comprises a plurality of data segments which are subjected to hash operation in sequence; the device comprises:
a last hash value information obtaining module, configured to obtain storage information of a last hash value from a kernel mode, where the last hash value is a hash value corresponding to a last data segment that has completed a hash operation;
the current data segment information determining module is used for determining the storage information of the current data segment for carrying out hash operation;
a first transmission module, configured to transmit the storage information of the current data segment and the storage information of the previous hash value to a kernel state, so that the kernel state updates an initial value used for hash operation to a previous hash value according to the storage information of the previous hash value, and then performs hash operation on the current data segment according to the updated initial value;
the first acquisition module is used for acquiring the storage information of the hash value corresponding to the current data segment from the kernel mode; if the current data segment is the data segment in the last order, the hash value corresponding to the current data segment is used as the hash value of the data, and if the current data segment is not the data segment in the last order, the hash value corresponding to the current data segment is used as the new last hash value.
16. A data hash processing device is applied to a kernel state of a CPU (Central processing Unit), the CPU has a user state and a kernel state, and data comprises a plurality of data segments which are subjected to hash operation in sequence; the device comprises:
the current operation information acquisition module is used for acquiring the storage information of the current data segment for carrying out the hash operation and the storage information of the previous hash value from a user mode; wherein, the previous hash value is a hash value corresponding to a previous data segment which has completed the hash operation, and the storage information of the previous hash value is transmitted to the user state after the previous data segment completes the hash operation by the kernel state;
the updating module is used for updating the initial value used for the hash operation into the previous hash value according to the storage information of the previous hash value;
the driving operation module is used for driving the hash operation of the current data segment according to the updated initial value and the storage information of the current data segment;
the hash value information transmission module is used for acquiring the storage information of the hash value corresponding to the current data segment and transmitting the storage information of the hash value corresponding to the current data segment to the user state; if the current data segment is the data segment in the last order, the hash value corresponding to the current data segment is used as the hash value of the data, and if the current data segment is not the data segment in the last order, the hash value corresponding to the current data segment is used as the new last hash value.
17. A CPU, said CPU having a user state and a kernel state; the CPU executing computer-executable instructions in user mode to implement the data hash processing method of any one of claims 1-7; the CPU executes computer-executable instructions in a kernel state to implement the data hash processing method of any one of claims 8-14.
18. A data hash processing system comprising a CPU as claimed in claim 17, and a hardware unit for performing hash operations, said hardware unit being driven by a kernel state of the CPU for performing hash operations.
19. An electronic device comprising the data hash processing system of claim 18.
CN202110698761.9A 2021-06-23 2021-06-23 Data hash processing method, device, CPU, system and electronic equipment Pending CN113342530A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110698761.9A CN113342530A (en) 2021-06-23 2021-06-23 Data hash processing method, device, CPU, system and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110698761.9A CN113342530A (en) 2021-06-23 2021-06-23 Data hash processing method, device, CPU, system and electronic equipment

Publications (1)

Publication Number Publication Date
CN113342530A true CN113342530A (en) 2021-09-03

Family

ID=77478376

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110698761.9A Pending CN113342530A (en) 2021-06-23 2021-06-23 Data hash processing method, device, CPU, system and electronic equipment

Country Status (1)

Country Link
CN (1) CN113342530A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109918925A (en) * 2019-02-19 2019-06-21 上海泉坤信息科技有限公司 Date storage method, back end and storage medium
US20190253436A1 (en) * 2016-09-21 2019-08-15 Institute Of Information Engineering, Chinese Academy Of Sciences Method, system, and apparatus for monitoring network traffic and generating summary
CN111464308A (en) * 2020-03-12 2020-07-28 烽火通信科技股份有限公司 Method and system for realizing reconstruction of multiple Hash algorithms
CN112084534A (en) * 2020-08-20 2020-12-15 郑州信大捷安信息技术股份有限公司 Method and device for realizing Hash algorithm
CN112631772A (en) * 2020-12-21 2021-04-09 海光信息技术股份有限公司 Cryptographic operation method, processor, device and storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20190253436A1 (en) * 2016-09-21 2019-08-15 Institute Of Information Engineering, Chinese Academy Of Sciences Method, system, and apparatus for monitoring network traffic and generating summary
CN109918925A (en) * 2019-02-19 2019-06-21 上海泉坤信息科技有限公司 Date storage method, back end and storage medium
CN111464308A (en) * 2020-03-12 2020-07-28 烽火通信科技股份有限公司 Method and system for realizing reconstruction of multiple Hash algorithms
CN112084534A (en) * 2020-08-20 2020-12-15 郑州信大捷安信息技术股份有限公司 Method and device for realizing Hash algorithm
CN112631772A (en) * 2020-12-21 2021-04-09 海光信息技术股份有限公司 Cryptographic operation method, processor, device and storage medium

Similar Documents

Publication Publication Date Title
US6624762B1 (en) Hardware-based, LZW data compression co-processor
US20130156183A1 (en) Encryption key generating apparatus and computer program product
JP2008519360A (en) Compressed read-only memory file system (CRMFS) image update
JP2007521555A (en) Method and system for updating a version of content stored in a storage device
US20090164783A1 (en) Methods, apparatuses, and computer program products for authentication of fragments using hash trees
WO2000022540A1 (en) Apparatus and method for efficiently updating files in computer networks
US20180260126A1 (en) System and method for synchronizing history data for compression and decompression
WO2023221735A1 (en) Embedded device firmware updating method, embedded device, and development end device
WO2023216845A1 (en) Firmware update method for embedded device, embedded device, and development end device
JP4876051B2 (en) Image processing apparatus and control method thereof
US20080301537A1 (en) Packet transmission device and packet transmission method
CN113342530A (en) Data hash processing method, device, CPU, system and electronic equipment
JP4285679B2 (en) Differential transfer method, program and system
CN116318660B (en) Message expansion and compression method and related device
CN105162747B (en) System and method for compression device and decompression device discovery and handshake
WO2019174191A1 (en) Report data initialization method and apparatus, and computer device and storage medium
WO2019095952A1 (en) Synchronization method and apparatus
US10901952B2 (en) Method for transferring a difference file
JP2023552774A (en) Method and system for streaming block templates using cross-references
KR100720274B1 (en) Method for firmware updating of a embedded system
JP4727478B2 (en) Device control apparatus and device control program
EP4035288A1 (en) Packet payload mapping for robust transmission of data
Priyanga et al. A fixed length payload encoding for can
KR100743253B1 (en) Method and apparatus for correcting code data error
JP2008203959A (en) Serialization method in data transfer, data format and data transfer device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination