Data processing method and electronic device
By improving the SM3 algorithm and utilizing iterative updates and SIMD register technology, the problems of low memory usage and low processing efficiency of the SM3 algorithm are solved, and more efficient message block compression processing is achieved.
Patent Information
- Application Number
- CN202210086205.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-25
- Publication Date
- 2026-01-16
- Estimated Expiration
- 2042-01-25
AI Technical Summary
The existing SM3 algorithm suffers from high memory consumption, long processing time, and low processing efficiency when processing messages.
By splitting the target message block into a reference word set and storing it in a predetermined storage unit, the digest information is updated iteratively, avoiding the generation and storage of all extended words in memory at once. This is achieved by combining window sliding and SIMD register technology.
It effectively reduces memory usage and execution time, improves algorithm execution efficiency, and meets the message block compression processing requirements of algorithms such as SM3.
Smart Images

Figure CN114428641B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of data security, and particularly relates to a data processing method and an electronic device. BACKGROUND
[0002] SM3 is an algorithm standard for generating a message digest, and the digest length is 256 Bit. The security and efficiency of SM3 are equivalent to those of SHA-256.
[0003] When SM3 is used to process a message, SM3 divides the message into message blocks each having a size of 512 Bit, that is, 16 Word, wherein 1 Word = 4 Bytes. By performing compression processing on each message block of the message, a message digest is obtained. In the compression processing of the message block, in order to disrupt data, SM3 first expands the message block from 16 Word to 132 Word, and places the 132 Word obtained by expansion in the memory in the algorithm implementation. The compression processing of the message block is implemented by performing multiple iteration processing based on the 132 Word stored in the memory.
[0004] However, the above processing mode has problems of high memory occupation amount of the algorithm, long occupation time, and low algorithm processing efficiency. Therefore, it is very important to provide an optimized solution to solve at least part of the defects of the above processing mode in the field. SUMMARY
[0005] To this end, the application discloses the following technical solutions:
[0006] A data processing method comprises:
[0007] Obtaining a target message block, splitting the target message block into a first number of original words as a reference word set, and storing the reference word set in a predetermined storage unit;
[0008] Obtaining a first digest information recorded with initial digest information, wherein the initial digest information is preset information or digest information of other message blocks;
[0009] Updating the first digest information according to the reference word set;
[0010] Iteratively updating the reference word set according to a first word set in the predetermined storage unit, performing an update operation on the first digest information according to the reference word set updated each time, and generating the first word set according to the reference word set before updating each time;
[0011] Determining that the iteration update of the reference word set satisfies an end condition, and outputting a digest of the target message block according to the first digest information updated based on the update of the reference word set.
[0012] Optionally, the storing the reference word set in the predetermined storage unit comprises:
[0013] storing the reference word set in a first register;
[0014] wherein a capacity of the first register corresponds to a data amount of the reference word set.
[0015] Optionally, the storing the reference word set in the first register comprises:
[0016] grouping the first quantity of reference words to obtain a plurality of reference word groups;
[0017] storing different reference word groups in different first registers according to corresponding orders of the different reference word groups in the target message block;
[0018] wherein a capacity of one first register corresponds to a data amount of one reference word group, and the first register can process a plurality of words through one instruction.
[0019] Optionally, the iteratively updating the reference word set in the predetermined storage unit according to the first word set comprises:
[0020] releasing a predetermined quantity of reference words at a head of the reference word set in the predetermined storage unit, adding the first word set to a tail of remaining reference words in the predetermined storage unit to obtain an updated reference word set, wherein the predetermined quantity is a word number corresponding to the first word set.
[0021] Optionally, the iteratively updating the reference word set in the predetermined storage unit according to the first word set comprises:
[0022] releasing reference words in a first first register of a plurality of first registers in which each reference word group is stored in sequence;
[0023] transferring reference words stored in each first register other than the first first register to a corresponding previous adjacent first register;
[0024] storing the first word set in a last first register of the first registers;
[0025] wherein the number of the first registers is 4, a capacity of each first register is 4 words, and a word number of reference words stored in each first register is 4, and a word number corresponding to the first word set is 4.
[0026] Optionally, the updating the first digest information according to the reference word set comprises:
[0027] generating a second word set according to the reference word set;
[0028] updating the first digest information according to the reference word set and the second word set.
[0029] the updating operation of the first digest information according to the reference word set each time, comprising:
[0030] updating the second word set according to the updated reference word set;
[0031] updating the first digest information according to the updated reference word set and the updated second word set.
[0032] Optionally, the updating of the first digest information according to the corresponding reference word set and the second word set comprises:
[0033] sequentially obtaining one reference word in the reference word set and one word in the second word set;
[0034] updating the current first digest information based on the obtained one reference word and one word in the second word set according to a preset updating rule, to obtain updated first digest information;
[0035] updating the first digest information based on the next reference word and the next word in the second word set obtained sequentially, until the words in the second word set are used up, to complete the updating of the first digest information based on the corresponding reference word set and the second word set.
[0036] Optionally, the method further comprises:
[0037] storing the first word set into a second register;
[0038] storing the second word set into a third register;
[0039] The second register and the third register can respectively process multiple words through one instruction; when the reference word set in the predetermined storage unit is updated according to the first word set, the first word set in the second register is transferred to the predetermined storage unit.
[0040] Optionally, the determining that the iterative updating of the reference word set meets the end condition, and outputting the digest of the target message block according to the first digest information updated based on the updating of the reference word set, comprises:
[0041] determining that the number of times of updating the reference word set or the first digest information reaches a corresponding number threshold, generating the digest of the target message block according to the first digest information updated based on the updating of the reference word set and the initial digest information, and outputting the generated digest.
[0042] An electronic device, comprising:
[0043] a memory for storing at least a set of instructions;
[0044] a predetermined storage unit distinguished from the memory;
[0045] a processor for invoking and executing the set of instructions in the memory, and realizing the data processing method according to any one of the above by executing the set of instructions.
[0046] From the above scheme, the data processing method and the electronic device provided by the present application can split the target message block to be processed into a first number of original words as a reference word set, store the reference word set in a predetermined storage unit, and update the first summary information recorded with initial summary information according to the reference word set; on this basis, the first summary information is synchronously and iteratively updated by performing iterative update on the reference word set in the predetermined storage unit, and finally the summary of the target message block is generated and output based on the updated first summary information when the end condition of iteration is met, so as to realize the compression processing of the target message block.
[0047] For SM3 algorithm and the like, the essence of the present application is to realize the iterative expansion of the target message block by iterative update of the reference word set in the predetermined storage unit, and the iterative expansion of the target message block follows the iteration processing progress of the summary information in the compression processing of the message block, which can effectively meet the use demand of different expansion words of the message block in the message block compression processing of SM3 algorithm and the like, and at the same time, avoids generating all expansion words of the target message block at one time and storing the target message block and all expansion words in the memory for use in the compression processing process, at least reduces the occupation amount and occupation time of the memory, so as to realize the optimization of the traditional implementation mode of SM3 algorithm and the like. BRIEF DESCRIPTION OF DRAWINGS
[0048] In order to more clearly illustrate the technical solutions of the embodiments of the present application or the prior art, the drawings needed in the embodiment or prior art description will be briefly introduced below. Obviously, the drawings in the following description are only embodiments of the present application, and those skilled in the art can obtain other drawings according to the provided drawings without creative labor.
[0049] Figure 1 is a flowchart of the data processing method provided by the present application;
[0050] Figure 2 is an implementation process flowchart of updating the reference word set provided by the present application;
[0051] Figure 3 is an implementation process flowchart of updating the first summary information provided by the present application;
[0052] Figure 4 is a schematic diagram of padding rules of the SM3 algorithm for a message block;
[0053] Figure 5 is a schematic diagram of message digest calculation principles of the SM3 algorithm;
[0054] Figure 6 is a flowchart of the SM3 algorithm;
[0055] Figure 7 is a flowchart of processing of a compression function CF of the SM3 algorithm;
[0056] Figure 8 is a schematic diagram of an implementation process of a conventional implementation of the SM3 algorithm;
[0057] Figure 9 is a schematic diagram of an implementation process of the SM3 algorithm provided by the present application;
[0058] Figure 10 is a constituent structure diagram of an electronic device provided by the present application. DETAILED DESCRIPTION
[0059] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the scope of protection of the present application.
[0060] The present application discloses a data processing method and an electronic device, which are used for an algorithm that needs to store data (such as each word of a message block and each word extended for the message block) in memory and perform related processing based on memory data, and provide an optimized solution for an algorithm implementation process, so as to reduce the memory occupation amount and occupation time of the algorithm, and / or improve the algorithm execution efficiency, and the like. The embodiments of the present application will mainly take message processing based on SM3 as an example for solution description.
[0061] The data processing method disclosed by the present application can be applied to, but is not limited to, electronic devices in a plurality of general-purpose or special-purpose computing device environments or configurations, such as personal computers, server computers, handheld devices or portable devices, tablet devices, multi-processor devices, and the like.
[0062] Referring to Figure 1 , a processing flow of the data processing method disclosed by the embodiments of the present application is shown, as shown in Figure 1 , the data processing method comprises the following steps.
[0063] Step 101: Obtain the target message block, split the target message block into a first number of original words as a reference word set, and store the reference word set in a predetermined storage unit.
[0064] The target message block can be any message block among the various message blocks obtained by segmenting the message during message processing based on the corresponding algorithm.
[0065] Taking SM3-based message processing as an example, when processing messages using SM3, SM3 divides the message into message blocks, each 512 bits (16 words) in size. Here, 1 word = 4 bytes. A message digest is obtained by compressing each message block. In this example, the target message block can be any one of the 512-bit (16-word) message blocks that SM3 divides the message into.
[0066] In practical applications, for each message block of the message to be processed, each message block can be obtained sequentially according to its corresponding order in the message, and the obtained message blocks can be processed one by one by using the method of this application to realize the message processing, such as realizing message digest calculation and processing based on SM3.
[0067] In step 101, after obtaining the message block currently to be processed as the target message block, the target message block is split into data units of Words, the target message block is split into a first number of original words as a reference word set, and the reference word set is stored in a predetermined storage unit.
[0068] Optionally, the predetermined storage unit is a first register, and the reference word set is stored in the first register accordingly. In this embodiment, the capacity of the first register corresponds to the data volume of the reference word set, that is, the difference between the capacity of the first register and the data volume of the reference word set does not exceed a preset threshold, so as to avoid wasting register storage resources during algorithm execution as much as possible.
[0069] Preferably, the capacity of the first register is the amount of data corresponding to the reference word set, thereby maximizing the conservation of register resources.
[0070] Specifically, for the case where the first register is used as the predetermined storage unit, the process of storing the reference word set in the first register can be further implemented as follows:
[0071] 11) Group the first number of reference words to obtain multiple reference word groups;
[0072] 12) Store the different reference word groups into different first registers according to the order in which they correspond in the target message block.
[0073] The capacity of the first register corresponds to the data amount of a reference word group, preferably, the capacity of the first register is the data amount of a reference word group, and preferably, the first register is a SIMD (Single Instruction Multiple Data) register, which can process multiple words through one instruction.
[0074] Taking SM3-based message processing as an example, for a message block of 16 words in size in message processing, the first number of reference words included in the reference word set corresponds to 16 original words of the message block at the initial time. When storing the reference words in the SIMD register, the 16-word message block can be grouped based on the actual capacity of the SIMD register. Assuming that the capacity of the SIMD register is 4 words (it can also be other capacities, such as 8 words, depending on the actual SIMD register used), the 16 reference words can be divided into 4 groups according to their order in the message block, each group containing 4 reference words. Different groups are stored in different SIMD registers according to the corresponding order of the different groups in the message block. Four SIMD registers are used to store the 16-word reference word set, and the reference word set occupies 16 words of storage space.
[0075] Step 102, obtaining first digest information recording initial digest information, the initial digest information being preset information or digest information of other message blocks.
[0076] Specifically, if the target message block is the first message block in the to-be-processed message, the initial digest information recorded by the first digest information is preset information. If the target message block is a message block other than the first message block in the to-be-processed message, i.e., a message block other than the first message block, the initial digest information recorded by the first digest information is the digest information of the corresponding adjacent message block before the target message block in the to-be-processed message.
[0077] Step 103, updating the first digest information according to the reference word set.
[0078] Specifically, a second word set can be generated according to the reference word set, and the first digest information can be updated according to the reference word set and the second word set.
[0079] The generation rule for generating the second word set according to the reference word set is determined by the algorithm requirement of the actual message processing algorithm used in message processing, and the update rule for updating the first digest information according to the reference word set and the second word set is also determined by the algorithm requirement of the actual message processing algorithm used in message processing. The following embodiments will take SM3 as an example of the actual message processing algorithm to describe in detail the process of generating the second word set and updating the first digest information according to the reference word set and the second word set.
[0080] Step 104, iteratively update the reference word set in the predetermined storage unit according to the first word set, and perform an update operation on the first digest information according to each updated reference word set, and the first word set is generated according to the reference word set before the update in each iteration.
[0081] On the basis of storing each original word of the target message block as the reference word set in the predetermined storage unit, and updating the first digest information recorded with the initial digest information according to the reference word set, the embodiments of the application further perform two types of iterative update processing, one is the iterative update of the reference word set in the predetermined storage unit based on the first word set, and the other is the iterative update of the first digest information based on the reference word set, and the two iterative update processes are synchronized, and one update of the reference word set triggers an update operation on the first digest information based on the latest updated reference word set.
[0082] In each iteration, the first word set is generated according to the reference word set before the update, similarly, the generation rule of the first word set according to the reference word set before the update is also determined by the algorithm requirement of the actual message processing algorithm (such as SM3) adopted in the message processing, and for the message processing based on SM3, the embodiments of the application generate the first word set with a size of 4 words for each round of iterative update in the above-mentioned two types of synchronous processing.
[0083] In each update of the reference word set in the predetermined storage unit based on the first word set, specifically, a predetermined number of reference words at the head of the reference word set in the predetermined storage unit can be released, and the first word set is added to the tail of the remaining reference words in the predetermined storage unit to obtain the updated reference word set; wherein the predetermined number is the number of words corresponding to the first word set, such as 4.
[0084] Referring to Figure 2 For the case of using the first register as the predetermined storage unit, the above-mentioned process of updating the reference word set in the predetermined storage unit based on the first word set can be further implemented as:
[0085] Step 201, release the reference words in the first first register of the plurality of first registers storing the plurality of reference words in sequence.
[0086] Taking the case of using 4 SIMD registers R1, R2, R3, R4 to store 16 words included in the reference word set in SM3 message processing (initially the reference word set includes 16 original words of the message block) in sequence as an example, the capacity of each SIMD register is 4 words and the number of words stored in each SIMD register is 4, in this example, the 4 words in R1 can be released, and the released 4 words are the 4 reference words at the head of the reference word set.
[0087] Step 202, transfer the reference words stored in the other first registers except the first one to the corresponding previous adjacent first register.
[0088] For the above example, based on the window sliding idea, specifically, the 4 words in R2 are transferred to R1, the 4 words in R3 are transferred to R2, and the 4 words in R4 are transferred to R3, through data transfer to the previous adjacent first register (SIMD register), the storage space of the last first register is reserved.
[0089] Step 203, store the first word set in the last first register of each first register.
[0090] Then, further store each word in the first word set in the last first register, for example, for SM3-based message processing, specifically, 4 words in the first word set are stored in the SIMD register R4, so as to realize the update of the reference word set in the predetermined storage unit based on the first word set in one round of iteration update processing.
[0091] Each update of the reference word set triggers an update operation on the first digest information according to the latest reference word set after each update, specifically, the second word set described above can be updated according to the updated reference word set, and the first digest information can be updated according to the updated reference word set and the updated second word set.
[0092] Among them, referring to Figure 3 , the process of updating the first digest information according to the corresponding reference word set and the second word set can be implemented as shown in the processing flow as Figure 3 .
[0093] Step 301, sequentially obtain one reference word in the reference word set to be currently used and one word in the second word set to be currently used.
[0094] Step 302, based on the preset update rule and the obtained one reference word and one word in the second word set, update the current first digest information to obtain the updated first digest information;
[0095] Among them, when updating the current first digest information based on the obtained one reference word and one word in the second word set, the update rule used is determined by the algorithm requirement of the message processing algorithm (such as SM3) actually used in the message processing.
[0096] Step 303, update the first digest information based on the next reference word and the next word in the second word set obtained in sequence until the words in the second word set are used up, and complete the update of the first digest information based on the corresponding reference word set and the second word set.
[0097] That is to say, in the update operation performed on the first digest information based on the updated reference word set and the updated second word set, each word in the second word set participates in the update of the first digest information, and each word independently participates in a round of update of the first digest information, and accordingly, in the update operation of the first digest information triggered based on one update of the reference word set, multiple (at least the number of words included in the second word set) updates of the first digest information are actually performed.
[0098] Each word in the first word set and each word in the second word set can be regarded as each expansion word obtained by expanding the target message block, such as each expansion word corresponding to the expansion of the message block from 16 words to 132 words by SM3.
[0099] That is to say, the traditional implementation manner of performing iterative update on the digest information based on the 132 words stored in the memory is different from the manner of compressing the message block of the message by the algorithm such as SM3, which first expands the message block from 16 words to 132 words, and then expands the message block from 16 words to 132 words in the initial stage of processing, and adjusts the one-time expansion of the message block to iterative expansion, and synchronizes the iterative expansion of the message block with the iterative update of the digest information (the first digest information) according to the progress of the iterative processing of the digest information, so as to effectively meet the use demand of different expansion words in the message block compression processing process of the algorithm such as SM3, and at the same time, achieve the purpose of occupying the storage space as little as possible.
[0100] Step 105, determining that the iterative update of the reference word set meets the end condition, and outputting the digest of the target message block according to the first digest information updated based on the update of the reference word set.
[0101] The end condition can be, but is not limited to, set as that the number of times of iterative update of the reference word set reaches a number threshold, or the number of times of actual update of the first digest information reaches a number threshold. The value of the number threshold can be set in combination with the algorithm requirement of the actually used message processing algorithm in the message processing. Taking the SM3 algorithm as an example, the number threshold of the update of the reference word set in the end condition can be set as 13 (i.e. the number of window sliding times), or the number threshold of the update of the first digest information in the end condition can be set as 64.
[0102] It should be noted that in the update operation of the first digest information triggered based on one update of the reference word set, multiple (at least the number of words included in the second word set) updates of the first digest information are actually performed, and the number threshold set for the first digest information here is a threshold set for the actual number of updates of the first digest information in the algorithm.
[0103] Based on the above ending condition, in the synchronous iterative updating process of the reference word set and the first digest information, it is determined whether the number of updates of the reference word set / first digest information reaches the corresponding number threshold, if yes, the updating is ended, otherwise, the corresponding updating process is continued.
[0104] And in the case of ending the updating process of the reference word set / first digest information, further based on the first digest information updated based on the updating of the reference word set and the initial digest information in the first digest information before the updating, the digest corresponding to the target message block is generated and outputted.
[0105] The digest of the target message block generated and outputted is used as intermediate data to participate in the calculation process of the digest information of the message to which the target message block belongs, so as to finally calculate the digest of the message to which the target message block belongs.
[0106] In an embodiment, in addition to storing the reference word set in the first register, the first word set and the second word set can also be stored in the second register and the third register respectively, that is, the first word set is stored in the second register and the second word set is stored in the third register. The second register and the third register can also be SIMD registers capable of processing multiple words through one instruction.
[0107] In this embodiment, when the reference word set in the predetermined storage unit is updated according to the first word set, the first word set in the second register is correspondingly transferred to the predetermined storage unit (for example, to the last first register in the plurality of first registers), and when the second word set is updated according to the updating of the reference word set, the existing second word set stored in the third register is directly replaced based on the newly generated second word set.
[0108] In the SM3-based message processing, the data amount of the first word set and the second word set can be 4 words respectively for the SIMD register with a capacity of 4 words.
[0109] From the above scheme, it can be seen that the method of the embodiment of the present application splits the target message block to be processed into a first number of original words as a reference word set, stores the reference word set in a predetermined storage unit, and updates the first digest information recording the initial digest information according to the reference word set; on this basis, the first digest information is synchronously and iteratively updated by performing iterative updating on the reference word set in the predetermined storage unit, and finally the digest of the target message block is generated and outputted based on the updated first digest information when the ending condition of iteration is met, so as to realize the compression processing of the target message block.
[0110] For algorithms such as SM3, the essence of the present application is to realize the iterative expansion of the target message block by iteratively updating the reference word set in the predetermined storage unit, and the iterative expansion of the target message block follows the iterative processing progress of the digest information in the message block compression processing process, which can effectively meet the different expansion word usage requirements of the message block compression processing process of SM3 and other algorithms, while avoiding the generation of all expansion words of the target message block at one time and the storage of the target message block and all expansion words in the memory for the compression processing process, which can reduce the memory occupation and occupation time. In addition, the embodiment of the present application provides a data storage space by using a SIMD register as a first register, which can process multiple words through one instruction, thereby reducing the number of IO times in the algorithm execution process, and accordingly further improving the execution efficiency of SM3 and other algorithms, and realizing the optimization of the traditional implementation method of SM3 and other algorithms.
[0111] The following provides an application example of the data processing method of the present application based on SM3 message processing.
[0112] When processing the message by using SM3, SM3 first divides the message into message blocks with a size of 512 Bit, that is, 16 Word, and if the last data block is less than 512 Bit, a set of padding rules is used for padding processing to make up 512 Bit.
[0113] The padding rule is shown in Figure 4 , assuming that the data length of data block x is l < 512 Bit, then a "1" bit, k "0" bits, and the data length value l of data block x are sequentially filled in the tail of data block x, wherein l + 1 + k = 448, and k is the smallest non-negative integer of (448-l-1) mod 512, based on the above value of k, l + 1 + k + 64 = 512, so as to realize the supplement of data block x to 512 Bit.
[0114] In the SM3 algorithm process, after the message is divided into message blocks with a size of 512 Bit, that is, 16 Word, each message block is read in sequence, and for each read message block, a compression function CF is used for compression processing to obtain the digest corresponding to the message block, and finally the digest of the entire message is calculated based on the digest corresponding to the message block.
[0115] Specifically as Figure 5The illustrated CF-based message digest calculation principle initializes the initial digest information (recorded in the first digest information) for the first message block B0 of the message, such as the preset initial digest information V0 = IV, and inputs the preset initial digest information V0 and the message block B0 into the compression function CF to obtain V1 output by the compression function CF, which is the digest of the message block B0. Then, V1 is input into the compression function CF together with the second message block B1 to obtain V2 as the digest of the message block B1. In fact, V2 is essentially the digest of the total block (i.e., B0 + B1) composed of the message block B1 and all the message blocks before B1. Such iteration is performed until the last message block Bn of the message is generated. n-1 The corresponding digest V n is the digest of the entire message.
[0116] The compression function mainly aims to compress the 512-bit message block into 256 bits. In the compression process, in order to disrupt the data, it is required to expand the message block from 16 words to 132 words. The 132 words are as follows:
[0117] W0 ~ W 15 : 16 original words of the message block obtained by splitting the message block;
[0118] W 16 ~ W 67 : each W 16 ~ W 67 in W j is an expansion word obtained by calculating and processing the corresponding word in the first 16 words of W j .
[0119] W'0 ~ W' 63 : each W' 63 in W'0 ~ W' j is an expansion word obtained by calculating and processing the corresponding W j and W j+4 .
[0120] Referring to the SM3 algorithm process provided in Figure 6 , the algorithm process of the compression function CF includes the following four steps:
[0121] 21) Message block expansion;
[0122] That is, the expansion processing of the message block, which expands the message block from 16 words to 132 words in the traditional technology.
[0123] 22) ABCDEFGH assignment;
[0124] The values A through H represent the individual bit blocks obtained by dividing the first digest information into blocks according to bit order. For the first message block of the message, such as... Figure 5 In message block B0, the values of A to H are the 8-bit blocks obtained by dividing digest V0 according to bit order. For non-first message blocks (such as B1), the values of A to H are the 8-bit blocks obtained by dividing the digest (such as V1) corresponding to the previous adjacent message block according to bit order.
[0125] 23) Calculate the intermediate values TT1 and TT2;
[0126] 24) Update ABCDEFGH.
[0127] For more detailed processing of the SM3 algorithm in expanding the message block from 16 words to 132 words, and for more detailed processing of the compression function CF, please refer to [link to relevant documentation]. Figure 7 The corresponding algorithm process provided by the compression function CF process.
[0128] in, Figure 7 In the provided algorithm, SS1 and SS2 are two variables, FF j GG j All of these are Boolean functions in SM3. P0 is the permutation function in the compression function, and P1 is the permutation function in the message expansion function. These are all variables / functions built into the SM3 algorithm. By using these variables or functions to iteratively update ABCDEFGH, the information of ABCDEFGH is shuffled, which means iteratively updating the first digest information. Finally, the digest of the message block is calculated by combining the iteratively updated ABCDEFGH and the initial digest information in the first digest information (i.e., the digest information corresponding to ABCDEFGH before the iterative update).
[0129] Each message block of the message to be processed is 512 bits, or 16 words. In the traditional implementation of SM3, the 16 words are first expanded to 132 words in step 21), and the 132 words are placed in memory. The subsequent steps 22)-24) require 64 rounds of processing. By executing the processing of steps 22)-24) for 64 rounds, the ABCDEFGH (i.e., the first digest information) is iteratively updated. Each round involves related I / O interactions and operations between the CPU, General Registers, and Memory. The specific implementation process is as follows: Figure 8 As shown, this implementation method has high memory consumption, long execution time, complex I / O interactions, and low algorithm execution efficiency.
[0130] This example, based on the data processing method provided in this application, improves the execution performance of SM3 by implementing message block digest calculation based on the compression function CF through window sliding and SIMD instructions.
[0131] See Figure 9 This illustration demonstrates the computational principle of message block digest computation implemented in this example using window sliding and SIMD instructions. The specific process of implementing message block digest computation includes:
[0132] 31) Split the message block into W0~W 15 There are a total of 16 Words, and W0 to W... 15 Divided into 4 groups, they are stored sequentially in 4 SIMD registers: G0, G4, G8, and G12;
[0133] 32) Store the 8 Ws in G0 and G4 j After SM3 operation, four corresponding W's are generated. j For example, W'0 to W'3, which are the second word sets of 4 words, are generated by SM3 operation based on W0 to W7 of G0 and G4 and stored in SIMD register T0;
[0134] 33) Utilize the four W' stored in the SIMD register T0 j Perform four operations in sequence, each using the corresponding W. j and W' j Calculate the intermediate values TT1 and TT2, and update ABCDEFGH based on the intermediate values TT1 and TT2;
[0135] 34) Store the 16 Ws in G0, G4, G8, and G12 j After SM3 operation, four corresponding W values are generated. j For example, W0~W in G0, G4, G8, G12 15 W is generated after SM3 operation 16 ~W 19 That is, the first character set of 4 words, and stored in SIMD register G16;
[0136] 35) Proceed to the next round of calculations, storing the 16 W values in G4, G8, G12, and G16. j , such as W4~W 19 The registers are moved forward one register at a time, to G0, G4, G8, and G12, which means a window sliding operation with a step size of 4 Words is performed. Then, step 32 is executed to achieve iterative update of ABCDEFGH.
[0137] The sliding window has a size of 16 Words.
[0138] It should be noted that for the last window, i.e., W 52 ~W 67 In addition to storing the 8 Ws in G0 and G4 j After SM3 operation, four corresponding W's are generated. j And perform 4 operations in sequence to update ABCDEFGH, and also need to store 8 Ws in G4 and G8. j After SM3 operation, four corresponding W's are generated. j And the 8 Ws stored in G8 and G12 j After SM3 operation, four corresponding W's are generated. j And for each of the four W' generated j Perform four operations in sequence to update ABCDEFGH.
[0139] 36) When the termination condition is met, such as based on 64 W's j After updating ABCDEFGH 64 times, we obtain the updated ABCDEFGH. Based on the updated ABCDEFGH and using 64 W's... j The digest corresponding to ABCDEFGH before the update is used to calculate the digest of the current message block.
[0140] When the termination condition is met, the updated information consisting of ABCDEFGH constitutes the first summary information after the update is completed, based on 64 W's. j The digest corresponding to ABCDEFGH before updating ABCDEFGH is the initial digest information recorded in the first digest information, specifically the preset information or the digest information corresponding to the previous adjacent message block of the current message block.
[0141] In SM3-based message processing, this example uses six SIMD registers (G0, G4, G8, G12, G16, and T0) with a capacity of 4 words, which is enough to meet the storage space requirements of the entire execution process of the SM3 algorithm for compressing message blocks. Compared with the traditional technology that requires 132 words of memory space, this application significantly reduces the amount of storage space occupied and the time occupied by using window sliding based on iterative update. At the same time, by using SIMD registers based on SIMD instructions, the number of I / O operations during the algorithm execution process is further reduced, thereby improving the algorithm execution efficiency.
[0142] In actual application of the method, the SM3 algorithm can be implemented by matching a window sliding algorithm and a SIMD register, designing an SM3 instruction set compatible with the technical idea of the application for the SM3 algorithm, and reconstructing an implementation process of the SM3 algorithm based on the instruction set.
[0143] The electronic device can be, but is not limited to, a device in a general or specific computing device environment or configuration, such as a personal computer, a server computer, a handheld or portable device, a tablet device, a multiprocessor system, and the like. The structure of the electronic device is shown in FIG. 1, and specifically includes: Figure 10
[0144] The memory 10 is configured to store a computer instruction set.
[0145] The computer instruction set can be implemented in the form of a computer program.
[0146] The processor 20 is configured to implement the data processing method disclosed in any of the method embodiments above by executing the computer instruction set.
[0147] The processor 20 can be a central processing unit (CPU), an application-specific integrated circuit (ASIC), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices.
[0148] In addition, the electronic device can further include a communication interface, a communication bus, and the like. The memory, the processor, and the communication interface can communicate with each other through the communication bus.
[0149] The communication interface is configured to communicate between the electronic device and other devices. The communication bus can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, and the like. The communication bus can be divided into an address bus, a data bus, a control bus, and the like.
[0150] In summary, the data processing method and the electronic device disclosed in the application have at least the following technical advantages compared with the conventional technology:
[0151] 41) In the process of compressing the message block, the data is stored in the SIMD register, and the SIMD register is updated based on the window sliding technology, only a small amount of data storage space (such as 24 Word storage space for SM3 algorithm) is required to meet the algorithm requirements, and the memory space and the occupation time are saved;
[0152] 42) For each Word (such as 24 Words) stored in the SIMD register, the SIMD instruction is used to perform IO and operation with other variables, which improves the algorithm execution rate;
[0153] 43) Based on the technical idea of the present application, the instruction set of SM3 algorithm and other algorithms is designed by using the window sliding algorithm and the SIMD instruction, and the design difficulty is low, so that the implementation complexity of the method of the present application is low, and the method is simple and easy to implement.
[0154] It should be noted that each embodiment in the specification adopts a progressive manner for description, and each embodiment focuses on the different places from other embodiments, and the same and similar parts of each embodiment can be referred to.
[0155] In order to describe conveniently, the above system or device is described as various modules or units respectively. Of course, in the implementation of the present application, the functions of each unit can be realized in the same or multiple software and / or hardware.
[0156] From the description of the above embodiments, those skilled in the art can clearly understand that the present application can be realized by means of software and necessary general hardware platform. Based on such understanding, the technical solutions of the present application can be embodied in the form of software product, which can be stored in a storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., including a plurality of instructions to make a computer device (which can be a personal computer, server, or network device, etc.) execute the method described in each embodiment or some parts of the embodiments of the present application.
[0157] Finally, it needs to be pointed out that, in this document, relational terms such as first, second, third, and fourth and the like can only be used to distinguish one entity or action from another entity or action, without necessarily requiring or implying any actual relationship or order between or among such entities or actions. Moreover, the terms "comprises", "comprising", or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but can include other elements not expressly listed or inherent to such process, method, article, or apparatus. An element proceeded by "comprises... a" does not, without more constraints, exclude the existence of additional identical elements in the process, method, article, or apparatus that comprises the element.
[0158] The above description is only the preferred embodiment of the present application, and it should be pointed out that, for those skilled in the art, some improvements and refinements can be made without departing from the principles of the present application, and these improvements and refinements should also be considered as the protection scope of the present application.
Claims
1. A data processing method, comprising: obtaining a target message block, splitting the target message block into a first number of original words as a reference word set, and storing the reference word set in a predetermined storage unit; obtaining first summary information recorded with initial summary information, the initial summary information being preset information or summary information of other message blocks; updating the first summary information according to the reference word set; iteratively updating the reference word set in the predetermined storage unit according to a first word set, performing an updating operation on the first summary information according to the reference word set updated each time, the first word set being generated according to the reference word set before updating each time; determining that the iteratively updating of the reference word set meets an ending condition, and outputting a summary of the target message block according to the first summary information updated based on the updating of the reference word set; wherein the iteratively updating the reference word set in the predetermined storage unit according to the first word set comprises: releasing a predetermined number of reference words at the head of the reference word set in the predetermined storage unit, adding the first word set to the tail of the remaining reference words in the predetermined storage unit to obtain an updated reference word set, and wherein the predetermined number is the number of words corresponding to the first word set. 2.The method of claim 1, wherein the storing the reference word set in a predetermined storage unit comprises: storing the reference word set in a first register; and wherein the capacity of the first register corresponds to the data amount of the reference word set. 3.The method of claim 2, wherein the storing the reference word set in a first register comprises: grouping the first number of reference words to obtain a plurality of reference word groups; and storing different reference word groups in different first registers according to the corresponding order of the different reference word groups in the target message block. wherein the capacity of one first register corresponds to the data amount of one reference word group, and the first register can process multiple words through one instruction. 4.The method of claim 3, wherein the iteratively updating the reference word set in the predetermined storage unit according to the first word set comprises: releasing the reference words in a first first register of a plurality of first registers in which each reference word group is stored in order; and transferring the reference words stored in each first register other than the first first register to the corresponding previous adjacent first register. storing the first word set in the last first register of the first registers. wherein the number of the first registers is 4, the capacity of each first register is 4 words, and the number of the reference words stored in each first register is 4, and the number of words corresponding to the first word set is 4. 5.The method of claim 1, wherein the updating the first summary information according to the reference word set comprises: generating a second word set according to the reference word set; and updating the first summary information according to the reference word set and the second word set. wherein the performing an updating operation on the first summary information according to the reference word set updated each time comprises: updating the second word set according to the updated reference word set. updating the first digest information according to the updated reference word set and the updated second word set.
6. The method of claim 5, wherein, updating the first digest information according to the corresponding reference word set and the second word set, comprising: sequentially obtaining a current one of the reference word set to be used and a current one of the second word set to be used; updating the current first digest information based on a preset updating rule and the obtained one of the reference word set and the second word set, to obtain updated first digest information; updating the first digest information based on sequentially obtained next ones of the reference word set and the second word set, until the second word set is used up, to complete the updating of the first digest information based on the corresponding reference word set and the second word set.
7. The method of claim 5, further comprising: storing the first word set to a second register; storing the second word set to a third register; wherein the second register and the third register can respectively handle multiple words through one instruction; when updating the reference word set in the predetermined storage unit according to the first word set, transferring the first word set in the second register to the predetermined storage unit.
8. The method of claim 1, wherein the determining that the iterative updating of the reference word set meets an ending condition comprises: determining that the number of updates to the reference word set or the first digest information reaches a corresponding number threshold, and generating a digest of the target message block according to the updated first digest information based on the updating of the reference word set and the initial digest information, and outputting the generated digest.
9. An electronic device, comprising: a memory for storing at least a set of instructions; a predetermined storage unit different from the memory; a processor for calling and executing the set of instructions in the memory, and realizing the data processing method of any one of claims 1-8 by executing the set of instructions.
Citation Information
Patent Citations
Method for achieving iterative compression in SM3 password hash algorithm
CN104092534A