WO2024098613A1 - 一种hmac算法处理系统、方法、设备及非易失性可读存储介质 - Google Patents

一种hmac算法处理系统、方法、设备及非易失性可读存储介质 Download PDF

Info

Publication number
WO2024098613A1
WO2024098613A1 PCT/CN2023/082297 CN2023082297W WO2024098613A1 WO 2024098613 A1 WO2024098613 A1 WO 2024098613A1 CN 2023082297 W CN2023082297 W CN 2023082297W WO 2024098613 A1 WO2024098613 A1 WO 2024098613A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
dma
algorithm
hash
hmac
Prior art date
Application number
PCT/CN2023/082297
Other languages
English (en)
French (fr)
Inventor
孙旭
赵新宇
周玉龙
刘刚
Original Assignee
苏州元脑智能科技有限公司
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 苏州元脑智能科技有限公司 filed Critical 苏州元脑智能科技有限公司
Publication of WO2024098613A1 publication Critical patent/WO2024098613A1/zh

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/06Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols the encryption apparatus using shift registers or memories for block-wise or stream coding, e.g. DES systems or RC4; Hash functions; Pseudorandom sequence generators
    • H04L9/0643Hash functions, e.g. MD5, SHA, HMAC or f9 MAC
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L2209/00Additional information or applications relating to cryptographic mechanisms or cryptographic arrangements for secret or secure communication H04L9/00
    • H04L2209/12Details relating to cryptographic hardware or logic circuitry
    • H04L2209/125Parallelization or pipelining, e.g. for accelerating processing of cryptographic operations

Definitions

  • Embodiments of the present application relate to the field of chip design, and in particular, to an HMAC algorithm processing system, method, device, and non-volatile readable storage medium.
  • Hash-based Message Authentication Code is a method of message authentication based on hash functions and keys. It is used to verify data integrity and source legitimacy and is applicable to security services of any security architecture, process or application.
  • the Federal Information Processing Standards (FIPS) of the United States defines the HMAC algorithm process as: Among them, K0 is the key shared in advance by both parties, H is the hash function, text is the data to be verified, and opad and ipad are constants defined by the algorithm.
  • FIPS Federal Information Processing Standards
  • K0 is the key shared in advance by both parties
  • H is the hash function
  • text is the data to be verified
  • opad and ipad are constants defined by the algorithm.
  • the HMAC algorithm flow chart given in the FIPS standard is shown in Figure 1.
  • Hash algorithm is also called hash algorithm or hash algorithm. Due to its application in information integrity authentication and digital signature, hash algorithm is very important in the field of information security in today's era. Different hash algorithms have different parameter performance. NIST (National Institute of Standards and Technology) has successively released three standard hash algorithms SHA-0, SHA-1 and SHA-2. As MD5 and SHA-1 have been cracked one after another, SHA-2 is gradually increasing in important security fields such as economy and military. Among them, the SHA-256 cryptographic hash algorithm is widely used. The hash algorithm SM3 independently developed and designed by China has the same message digest length as SHA-256. As a commercial cryptographic hash algorithm, it is widely used in the commercial field. With the development of information technology, the amount of data has exploded, and it also requires the safe transmission and processing of data information. Therefore, as the most commonly used HMAC algorithm in the field of data authentication, its computing performance determines the computing efficiency of the entire system to a certain extent.
  • the commonly used HMAC algorithm processing mainly adopts the following two methods: the first is to use software, that is, the central processing unit CPU (Central Processing Unit) to calculate HAMC, and use hardware to complete the HAMC calculation; the second is to use hardware to complete the calculation, generally using a dedicated computing chip.
  • the above two methods have the following defects: on the one hand, when implemented in software, it will occupy a large amount of CPU resources and block the operation of other processes; on the other hand, the existing dedicated computing chips can only perform HMAC calculations of one hash algorithm at a time during authentication calculations, and require that the authentication data be sent continuously and cannot be sent in multiple segments, so there are problems such as low computing efficiency, large resource consumption, poor scalability, and low reusability.
  • a HMAC algorithm processing system comprising:
  • the AMBA bus is configured to receive a request from a central processor to process the data to be authenticated, wherein the request includes storage information of the data to be authenticated and a target hash algorithm selected from a plurality of hash algorithms;
  • a DMA control unit wherein the DMA control unit is configured to transfer the data to be authenticated through the DMA based on the storage information of the data to be authenticated;
  • a FIFO control unit comprising a plurality of FIFOs corresponding to a plurality of hash algorithms, each FIFO being used to cache data transferred by DMA according to a target hash algorithm of the data to be authenticated;
  • a logic control unit includes a grouping subunit and a key subunit corresponding to a plurality of hash algorithms one by one, the key subunit generates and stores operation parameters of each hash algorithm, and the grouping subunit reads data from the FIFO and performs bit width conversion before sending;
  • the operation unit includes an HMAC processing core and hash processing cores that share the HMAC processing core and correspond one-to-one to multiple hash algorithms.
  • the HMAC processing core receives the data sent by the grouping sub-unit and uses the stored operation parameters corresponding to the target hash algorithm to perform operations to generate calculation results.
  • the HMAC processing core distributes the calculation results to the hash processing cores corresponding to the target hash algorithm to perform hash operations.
  • system further includes a register file
  • logic control unit further includes a scheduling subunit
  • the scheduling subunit is configured to monitor the remaining space of each FIFO to generate authentication data status values corresponding to a plurality of hash algorithms
  • the register stack is used to record the authentication data status value so that when the central processor issues a new data processing request, one of the multiple hash algorithms is selected as a target hash algorithm according to the authentication data status and business operation requirements corresponding to each hash algorithm.
  • the scheduling subunit may be optionally configured as follows:
  • the authentication data status value is calculated to be three;
  • the authentication data status value is calculated to be 2;
  • the authentication data status value is calculated to be one
  • the calculated authentication data status value is zero.
  • the CPU is configured to select a target hash algorithm according to the following rules when there is a new data processing request:
  • a hash algorithm with a larger authentication data status value has a higher priority than a hash algorithm with a smaller authentication data status value, and a target hash algorithm is preferentially selected from the hash algorithms with higher priorities.
  • the DMA control unit includes a master interface and a slave interface
  • the central processing unit configures DMA-related registers from the slave interface through an AMBA bus, including DMA data length, DMA data address, DMA first segment data flag, DMA last segment data flag, and configures a DMA start register, wherein the DMA first segment data flag and the last segment data flag are determined according to the following rules:
  • the DMA first segment data flag and the DMA last segment data flag are both 1;
  • the DMA first data flag of the first transfer process is 1, the DMA last data flag of the first transfer process is 0, the DMA first data flag of the second transfer process is 0, and the DMA last data flag of the first transfer process is 1;
  • the DMA first data flag of the first transfer process is 1, the DMA last data flag of the first transfer process is 0, the DMA first data flag and the DMA last data flag of the intermediate DMA transfer processes are both 0, the DMA first data flag of the last transfer process is 0, and the DMA last data flag of the last transfer process is 1;
  • the data at the corresponding address of the data to be authenticated is read to the DMA control unit through the above-mentioned main interface, and the data is cached in the FIFO corresponding to the target hash algorithm.
  • each key subunit performs the following operations to generate operation parameters:
  • the key is filled and the filled key is XORed with ipad and opad to generate ipadkey and opadkey, where: opad and ipad are constants defined by the U.S. Federal Information Processing Standard FIPS for the HMAC algorithm;
  • the generated ipadkey and opadkey are stored.
  • each packet subunit performs the following operations to convert and send data:
  • the HMAC processing core may be optionally configured to:
  • the multiple hash algorithms include md5 algorithm, sha1 algorithm, and sm3 algorithm.
  • the above-mentioned FIFO control unit includes three FIFOs corresponding to the md5 algorithm, sha1 algorithm, and sm3 algorithm, and the operation unit includes an md5 algorithm processing core, a sha1 algorithm processing core, and an sm3 algorithm processing core.
  • a HMAC algorithm processing method comprising:
  • AMBA bus receiving a request from a central processor to process the data to be authenticated, wherein the request includes storage information of the data to be authenticated and a target hash algorithm selected from a plurality of hash algorithms;
  • the HMAC processing core in the computing unit is used to receive the data sent by the above-mentioned grouping sub-unit and use the stored computing parameters corresponding to the target hash algorithm to perform operations to generate calculation results, and the above-mentioned calculation results are distributed to the hash processing cores corresponding to the target hash algorithm in the multiple hash processing cores sharing the above-mentioned HMAC processing core to perform hash operations.
  • the above method further comprises:
  • the scheduling subunit in the above logic control unit is used to monitor the remaining space of each FIFO to generate authentication data status values corresponding to multiple hash algorithms one by one;
  • the register stack is used to record the above authentication data status value so that when the central processor issues a new data processing request, one of the multiple hash algorithms is selected as the target hash algorithm according to the authentication data status and business operation requirements corresponding to each hash algorithm.
  • the scheduling subunit in the above logic control unit is used to monitor the remaining space of each FIFO to generate authentication data status values corresponding to multiple hash algorithms, including:
  • the authentication data status value is calculated to be three;
  • the authentication data status value is calculated to be 2;
  • the authentication data status value is calculated to be one
  • the calculated authentication data status value is zero.
  • the CPU is configured to select a target hash algorithm according to the following rules when there is a new data processing request:
  • a hash algorithm with a larger authentication data status value has a higher priority than a hash algorithm with a smaller authentication data status value, and a target hash algorithm is preferentially selected from the hash algorithms with higher priorities.
  • using a DMA control unit to transfer the data to be authenticated through DMA based on the storage information of the data to be authenticated includes:
  • the CPU configures DMA related registers from the slave interface of the DMA control unit through the AMBA bus, including DMA data length, DMA data address, DMA first segment data flag, DMA last segment data flag, and configures the DMA start register, where the DMA first segment data flag and the last segment data flag are determined according to the following rules:
  • the DMA first segment data flag and the DMA last segment data flag are both 1;
  • the DMA first data flag of the first transfer process is 1, the DMA last data flag of the first transfer process is 0, the DMA first data flag of the second transfer process is 0, and the DMA last data flag of the first transfer process is 1;
  • the DMA first data flag of the first transfer process is 1, the DMA last data flag of the first transfer process is 0, the DMA first data flag and the DMA last data flag of the intermediate DMA transfer processes are both 0, the DMA first data flag of the last transfer process is 0, and the DMA last data flag of the last transfer process is 1;
  • the data at the corresponding address of the data to be authenticated is read to the DMA control unit through the main interface of the above-mentioned DMA control unit, and the data is cached in the FIFO corresponding to the target hash algorithm.
  • the key subunits corresponding to the multiple hash algorithms in the logic control unit are used to generate and store the operation parameters of each hash algorithm, including:
  • the generated ipadkey and opadkey are stored.
  • using the grouping subunits in the logic control unit corresponding to the multiple hash algorithms to read data from the FIFO and perform bit width conversion before sending includes:
  • Each packet subunit performs the following operations to convert and send data:
  • using the HMAC processing core in the computing unit to receive the data sent by the above-mentioned grouping subunit and using the stored computing parameters corresponding to the target hash algorithm to perform computing to generate a computing result includes:
  • the multiple hash algorithms include md5 algorithm, sha1 algorithm, and sm3 algorithm.
  • the above-mentioned FIFO control unit includes three FIFOs corresponding to the md5 algorithm, sha1 algorithm, and sm3 algorithm, and the operation unit includes an md5 algorithm processing core, a sha1 algorithm processing core, and an sm3 algorithm processing core.
  • a computer device comprising:
  • the memory stores a computer program that can be run on the processor, and the processor executes the aforementioned HMAC algorithm processing method when executing the program.
  • a non-volatile readable storage medium stores a computer program, and when the computer program is executed by a processor, the aforementioned HMAC algorithm processing method is executed.
  • the operation unit includes a shared HMAC processing core, and multiple groups of operations can share one hmac processing core.
  • each group of operations needs to use one hmac processing core respectively, thus reducing hardware resources, thereby reducing hardware resource consumption. It supports multiple computing modes working in parallel, multiple groups of data are calculated in different modes at the same time, multi-segment DMA cross-sends large-flow data calculations, multiple key lightweight storage and scheduling, compatible construction and implementation of multiple hash authentication calculations, as well as low resource consumption and high reusability, which can significantly improve the computing efficiency of HMAC and reduce hardware resource consumption.
  • the embodiments of the present application also provide an HMAC algorithm processing method, a computer device and a non-volatile readable storage medium, which can also achieve the above-mentioned technical effects and will not be repeated here.
  • FIG1 is a schematic diagram of a traditional HMAC algorithm processing flow chart
  • FIG2 is a schematic diagram of the structure of an HMAC algorithm processing system provided by an embodiment of the present application.
  • FIG3 is a flow chart of an HMAC algorithm processing method provided by another embodiment of the present application.
  • FIG. 4 is a diagram showing the internal structure of a computer device in another embodiment of the present application.
  • FIFO First Input First Output
  • RAM Random Access Memory
  • Chinese Chinese
  • IP Intellectual Property
  • Double Data Rate is interpreted as double data rate synchronous dynamic random access memory in Chinese;
  • AMBA Advanced Microcontroller Bus Architecture
  • Chinese advanced microcontroller bus architecture
  • AXI Advanced eXtensible Interface
  • Chinese Chinese
  • AHB Advanced High performance Bus
  • Chinese Chinese
  • DMA Direct Memory Access
  • Chinese Chinese
  • the present application embodiment provides an HMAC algorithm processing system 100.
  • the system includes:
  • the AMBA bus 110 is configured to receive a request from a central processor to process the data to be authenticated, wherein the request includes storage information of the data to be authenticated and a target hash algorithm selected from a plurality of hash algorithms;
  • a DMA control unit (DMA Control) 120 the DMA control unit 120 is configured to move the data to be authenticated through DMA based on storage information of the data to be authenticated;
  • a FIFO control unit (FIFO Control) 130 the FIFO control unit 130 includes a plurality of FIFOs 131 corresponding to a plurality of hash algorithms, each FIFO being used to cache data transferred by DMA according to a target hash algorithm of the data to be authenticated;
  • a logic control unit (Logic Control) 140 includes a grouping subunit (MoMtor) 141 and a key subunit (KEY) 142 corresponding to a plurality of hash algorithms one by one, the key subunit 142 generates and stores operation parameters of each hash algorithm, and the grouping subunit 141 reads data from the FIFO 131 and performs bit width conversion before sending;
  • MoMtor grouping subunit
  • KY key subunit
  • the algorithm core 150 includes an HMAC processing core 151 and hash processing cores 152 that share the HMAC processing core 151 and correspond one-to-one to a plurality of hash algorithms.
  • the HMAC processing core 151 receives the data sent by the grouping subunit 141 and uses the stored operation parameters corresponding to the target hash algorithm to perform operations to generate calculation results.
  • the HMAC processing core 151 distributes the calculation results to the hash processing cores 152 corresponding to the target hash algorithm to perform hash operations.
  • the above-mentioned HMAC algorithm processing system supports parallel operation of multiple computing modes, cross-segment DMA to send large-flow data calculations, lightweight storage and scheduling of multiple keys, compatible construction and implementation of various hash authentication calculations, as well as low resource consumption and high reusability, which can significantly improve the computing efficiency of HMAC and reduce hardware resource consumption.
  • the system also includes a register file (Regs file) 160, and the logic control unit 140 also includes a dispatch subunit (dispatch) 143;
  • the register file 160 includes an instruction and logic function conversion (Command to Logic functions, referred to as Cmd2logic) unit, a register unit (Regs, referred to as registers) and a logic function and register conversion unit (Logic functions to registers, referred to as Logic2reg).
  • the scheduling subunit 143 is configured to monitor the remaining space of each FIFO 131 to generate authentication data status values corresponding to a plurality of hash algorithms one by one;
  • the register stack 160 is used to record the authentication data status value so that when the central processor issues a new data processing request, it selects one from a plurality of hash algorithms as a target hash algorithm according to the authentication data status and business operation requirements corresponding to each hash algorithm.
  • the scheduling subunit 143 may be optionally configured as follows:
  • the authentication data status value is calculated and updated in the register file 160 according to the following rules:
  • the authentication data status value is calculated to be three;
  • the authentication data status value is calculated to be 2;
  • the authentication data status value is calculated to be one
  • the calculated authentication data status value is zero.
  • the CPU configuration is configured to select a target hash algorithm according to the following rules when there is a new data processing request:
  • the certain hash algorithm In response to the authentication data state value corresponding to a certain hash algorithm being equal to zero, the certain hash algorithm is prohibited from being selected as a target hash algorithm;
  • a hash algorithm with a larger authentication data status value has a higher priority than a hash algorithm with a smaller authentication data status value, and a target hash algorithm is preferentially selected from the hash algorithms with higher priorities.
  • the DMA control unit 120 includes a master interface (Master) 121 and a slave interface (Slave) 122, and the central processor configures DMA related registers from the interface 122 through the AMBA bus, including DMA data length, DMA data address, DMA first segment data flag, DMA last segment data flag, and configures the DMA start register, wherein the DMA first segment data flag and the last segment data flag are determined according to the following rules:
  • the DMA first segment data flag and the DMA last segment data flag are both 1;
  • the DMA first data flag of the first transfer process is 1, the DMA last data flag of the first transfer process is 0, the DMA first data flag of the second transfer process is 0, and the DMA last data flag of the first transfer process is 1;
  • the DMA first data flag of the first transfer process is 1, the DMA last data flag of the first transfer process is 0, the DMA first data flag and the DMA last data flag of the intermediate DMA transfer processes are both 0, the DMA first data flag of the last transfer process is 0, and the DMA last data flag of the last transfer process is 1;
  • the data at the corresponding address of the data to be authenticated is read to the DMA control unit 120 through the main interface 121, and the data is cached in the FIFO 131 corresponding to the target hash algorithm.
  • each key subunit 142 performs the following operations to generate operation parameters:
  • the generated ipadkey and opadkey are stored.
  • each grouping subunit 141 performs the following operations to convert and send data:
  • the HMAC processing core 151 may be optionally configured as follows:
  • ipadkey and opadkey are used to represent a fixed bit sequence in the standard algorithm. It can be understood that ipadkey and opadkey are the bit sequences generated by padding the key and performing XOR processing on the padded key with ipad and opad respectively;
  • the calculation result, ipadkey and opadkey are sent to the corresponding hash processing core 152 .
  • the multiple hash algorithms include md5 algorithm, sha1 algorithm, and sm3 algorithm.
  • the FIFO control unit 130 includes three FIFOs corresponding to the md5 algorithm, sha1 algorithm, and sm3 algorithm.
  • the operation unit 150 includes an md5 algorithm processing core, a sha1 algorithm processing core, and an sm3 algorithm processing core.
  • the embodiment of the present application provides a HMAC algorithm processing method 200, the method comprising:
  • Step 201 using the AMBA bus to receive a request from a central processor to process the data to be authenticated, wherein the request includes storage information of the data to be authenticated and a target hash algorithm selected from a plurality of hash algorithms;
  • Step 202 using a DMA control unit to transfer the data to be authenticated through DMA based on the storage information of the data to be authenticated;
  • Step 203 using a plurality of FIFOs included in a FIFO control unit and corresponding to a plurality of hash algorithms one by one to cache the data transferred by DMA according to the target hash algorithm of the data to be authenticated;
  • Step 204 using the key subunits in the logic control unit corresponding to the multiple hash algorithms one by one to generate and store the operation parameters of each hash algorithm, and using the grouping subunits in the logic control unit corresponding to the multiple hash algorithms one by one to read data from the FIFO and perform bit width conversion before sending;
  • Step 205 use the HMAC processing core in the computing unit to receive the data sent by the grouping sub-unit and use the stored computing parameters corresponding to the target hash algorithm to perform operations to generate calculation results, and distribute the calculation results to the hash processing cores corresponding to the target hash algorithm in the multiple hash processing cores that share the HMAC processing core to perform hash operations.
  • the above HMAC algorithm processing method supports multiple computing modes working in parallel, multi-segment DMA cross-delivery of large-flow data calculation, and multiple keys are lightweight. It can significantly improve the computing efficiency of HMAC and reduce hardware resource consumption by optimising storage and scheduling, building and implementing a variety of hash authentication calculations in a compatible manner, and achieving lower resource consumption and high reusability.
  • the method further comprises:
  • the scheduling subunit in the logic control unit is used to monitor the remaining space of each FIFO to generate authentication data status values corresponding to multiple hash algorithms one by one;
  • the register stack is used to record the authentication data status value so that when the central processor issues a new data processing request, one of the multiple hash algorithms is selected as the target hash algorithm according to the authentication data status and business operation requirements corresponding to each hash algorithm.
  • the remaining space of each FIFO is monitored by a scheduling subunit in a logic control unit to generate authentication data status values corresponding to a plurality of hash algorithms, including:
  • the authentication data status value is calculated to be three;
  • the authentication data status value is calculated to be 2;
  • the authentication data status value is calculated to be one
  • the calculated authentication data status value is zero.
  • the CPU is configured to select a target hash algorithm according to the following rules when there is a new data processing request:
  • the certain hash algorithm In response to the authentication data state value corresponding to a certain hash algorithm being equal to zero, the certain hash algorithm is prohibited from being selected as a target hash algorithm;
  • a hash algorithm with a larger authentication data status value has a higher priority than a hash algorithm with a smaller authentication data status value, and a target hash algorithm is preferentially selected from the hash algorithms with higher priorities.
  • step 202 using a DMA control unit to transfer the data to be authenticated through DMA based on the storage information of the data to be authenticated, includes:
  • the CPU configures DMA related registers from the slave interface of the DMA control unit through the AMBA bus, including DMA data length, DMA data address, DMA first segment data flag, DMA last segment data flag, and configures the DMA start register, where the DMA first segment data flag and the last segment data flag are determined according to the following rules:
  • the DMA first segment data flag and the DMA last segment data flag are both 1;
  • the DMA first data flag of the first transfer process is 1, the DMA last data flag of the first transfer process is 0, the DMA first data flag of the second transfer process is 0, and the DMA last data flag of the first transfer process is 1;
  • the DMA first data flag of the first transfer process is 1, the DMA last data flag of the first transfer process is 0, the DMA first data flag and the DMA last data flag of the intermediate DMA transfer processes are both 0, the DMA first data flag of the last transfer process is 0, and the DMA last data flag of the last transfer process is 1;
  • the data at the corresponding address of the data to be authenticated is read to the DMA control unit through the main interface of the DMA control unit, and the data is cached in the FIFO corresponding to the target hash algorithm.
  • step 204 the key subunits corresponding to the multiple hash algorithms in the logic control unit are used to generate and store the operation parameters of each hash algorithm, including:
  • the key is filled and the filled key is XORed with ipad and opad to generate ipadkey and opadkey, where opad and ipad is a constant defined by the U.S. Federal Information Processing Standard FIPS for the HMAC algorithm;
  • the generated ipadkey and opadkey are stored.
  • step 204 the grouping subunits corresponding to the multiple hash algorithms in the logic control unit are used to read the data from the FIFO and perform bit width conversion before sending, including:
  • Each packet subunit performs the following operations to convert and send data:
  • step 205 using the HMAC processing core in the computing unit to receive the data sent by the packet subunit and using the stored computing parameters corresponding to the target hash algorithm to perform computing to generate a computing result includes:
  • the calculation result, ipadkey and opadkey are sent to the corresponding hash processing core 152 .
  • the hash processing core 152 is padded with multiple hash algorithms, including the md5 algorithm, the sha1 algorithm, and the sm3 algorithm.
  • the FIFO control unit 130 includes three FIFOs corresponding to the md5 algorithm, the sha1 algorithm, and the sm3 algorithm.
  • the operation unit 150 includes the md5 algorithm processing core, the sha1 algorithm processing core, and the sm3 algorithm processing core.
  • Each unit and sub-unit in the above-mentioned HMAC algorithm processing system can be implemented in whole or in part by software, hardware and a combination thereof.
  • the above-mentioned units and sub-units can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above-mentioned units and sub-units.
  • the first part is to read the working status; the CPU reads the corresponding authentication calculation process status register Hash_status (Hash_status_sm3, Hash_status_md5, Hash_status_sha1) through the AMBA bus slave interface. If the corresponding status register is not 0, enter the following steps, otherwise wait until the value of this register is not 0.
  • Hash_status Hash_status (Hash_status_sm3, Hash_status_md5, Hash_status_sha1)
  • the second part configures the HMAC register; the CPU determines which authentication calculation process to use first through the Hash_status of the three hash algorithms read in the first part and its own business operation requirements. After that, the CPU configures the relevant registers of the hmac algorithm through the AMBA bus slave interface, including the key key, key length key_length, algorithm mode selection, etc.
  • hmac_sm3, hmac_md5, and hmac_sha1 are supported to independently configure and use keys.
  • the key When performing authentication calculations, the key must be reconfigured when it is used for the first time and when the key changes. In the subsequent authentication calculation process, if the key of the corresponding algorithm has not changed, it can be no longer configured.
  • the third part is to configure the DMA registers; the CPU configures the DMA related registers through the AMBA bus slave interface, including the DMA data length dma_length, DMA data address, DMA first segment data flag, DMA last segment data flag, and finally configures the DMA start register.
  • the DMA first segment data flag and the DMA last segment data flag are both 1;
  • the DMA first data flag is 1 during the first transfer and the DMA last data flag is 0; the DMA first data flag is 0 during the second transfer and the DMA last data flag is 1.
  • the DMA first data flag bit is 1 during the first transfer, and the DMA last data flag bit is 0; the DMA first data flag bit is 0 during the last transfer, and the DMA last data flag bit is 1; during the intermediate DMA transfers, the DMA first data flag bit and the DMA last data flag bit are both 0;
  • the fourth part, Dma control moves data; Dma control reads the data of the corresponding address to this module through the AMBA master interface, and caches the data in the corresponding fifo.
  • three identical fifos are used to cache the data to be authenticated, including: HMAC_SM3 fifo; HMAC_MD5 fifo; HMAC_SHA1 fifo; for example, if the data moved by this dma is the data authenticated by hmac_sm3, it will be written into HMAC_SM3 fifo, and so on. After all the dma data is written into the corresponding cache fifo, it indicates that the dma process is completed, and then jump back to the first part to start the next data moving process.
  • next authentication data transfer process is completely independent of the previous one.
  • the previous one is the first DMA data of the HMAC_SM3 algorithm
  • the next one can be the second data of HMAC_SM3, or HMAC_MD5 or HMAC_SHA1 data.
  • This method guarantees the convenience and operation efficiency of the upper-layer software to the greatest extent, reduces the data cache of the upper-layer software, and also maximizes the efficiency of the hardware in calculation.
  • the upper-level software first configures the algorithm and key that need to be authenticated, and then transmits the data that needs to be authenticated to the calculation module. During this period, the data must be continuous, that is, other authentication modules are not allowed to be used for calculation before the current authentication calculation is completed.
  • the fifth part is key pre-calculation and caching. Since the three authentication calculations are processed in the same way and are calculated in parallel, they will not be introduced separately. Each authentication method uses the following operations to generate ipadkey and opadkey
  • the digest value i.e., the calculation result
  • ipad is to loop the bit series 00110110 (i.e. 0x36) until it reaches 512 bits, where the i in ipad stands for inner.
  • the value obtained after the XOR operation is also 512 bits of data, which we call ipadkey, which is the pre-calculated result.
  • opad is the bit 01011100 (i.e. 0x5C) that is repeated repeatedly until it reaches 512 bits, where the "o" in opad stands for "outer".
  • the value obtained after the XOR operation is also 512 bits of data, and we call this bit series opadkey.
  • this method can reduce the storage space of the key, because the maximum length of the key can reach 256MB, and the pre-calculated result is only 512bit, which greatly reduces the required storage space.
  • the key ipadkey is calculated in advance, so that subsequent calculations only need to start from step 5 each time, reducing the subsequent calculation time and improving efficiency.
  • the seventh part is data flow dispatch; this part completes the calculation of the cache fifo space and generates the authentication data status register Hash_status.
  • the processing methods of the three authentication calculations are the same and are calculated in parallel.
  • the scheduling method of each authentication method is as follows:
  • T_num (T_num + fifo_length - wr_en + rd_en) * 4, the initial value of T_num is the storage space of the entire fifo, each time a data is written, the remaining storage space decreases, and each time a data is read, the remaining storage space increases.
  • fifo_length is the depth of the fifo.
  • Hash_status is 3;
  • Hash_status is 2;
  • Hash_status is 1;
  • Hash_status is 0.
  • HMAC calculation in this part, the three algorithms share one HMAC.
  • the keys ipadkey and opadkey of the three algorithms have been pre-calculated. Therefore, the subsequent data needs to be sent to the corresponding hash algorithm module in the order in which the data is received; at the same time, the hash algorithm is a compression algorithm, and the data requires multiple rounds of iterative compression to complete the calculation, that is, a set of input data requires multiple clock cycles to complete the calculation, which causes the input bandwidth to be much larger than the output bandwidth. Therefore, the three hash algorithm cores sharing one HMAC will not reduce the overall computing efficiency, but will reduce the consumption of hardware resources.
  • the front-end Logic control module passes the data in the format of 512-bit width to the back-end.
  • the front-end sends a group of data to the back-end every time the hash algorithm core completes the calculation of a group of data, until the last group of data for this authentication calculation is sent.
  • the total authentication data length total_num is sent to the back-end module at the same time, and the last group of data flag is set to 1, which indicates that it is the last group of data of the hash algorithm, waiting for the final calculation result, recorded as hash1
  • step c Pass the pre-calculated opadkey to the subsequent hash algorithm module. Due to the different authentication data lengths and the complexity of hash calculations, the actual order of completion of the previous step b is different. As long as step b of the current authentication algorithm is completed, step c can be entered without waiting for the process of other authentication algorithms. The three processes are independent and parallel.
  • step d Pass hash1 to the next-level hash algorithm module, and set the last set of data flag to 1, which is the last set of data in the hash algorithm. After this calculation is completed, the output value is the final result (digest value) of this hmac calculation. Due to the different lengths of authentication data and the complexity of hash calculation, the actual order of completion of the previous step c is different. As long as step c of the current authentication algorithm is completed, step d can be entered without waiting for the process of other authentication algorithms. The three processes are independent and parallel;
  • a computer device which may be a server, and its internal structure diagram is shown in FIG4 .
  • the computer device includes a processor, a memory, a network interface, and a database connected via a system bus.
  • the processor of the computer device is configured to provide computing and control capabilities.
  • the memory of the computer device includes a non-volatile storage medium and an internal memory.
  • the non-volatile storage medium stores an operating system, a computer program, and a database.
  • the internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium.
  • the database of the computer device is configured to store data.
  • the network interface of the computer device is configured to communicate with an external terminal via a network connection.
  • AMBA bus receiving a request from a central processor to process the data to be authenticated, wherein the request includes storage information of the data to be authenticated and a target hash algorithm selected from a plurality of hash algorithms;
  • the HMAC processing core in the computing unit receives the data sent by the packet subunit and uses the stored computing parameters corresponding to the target hash algorithm to perform the computing to generate the computing result, and distributes the computing result to the hash processing cores corresponding to the target hash algorithm in the multiple hash processing cores that share the HMAC processing core.
  • the processor core performs the hash operation.
  • a non-volatile readable storage medium on which a computer program is stored.
  • the above HMAC algorithm processing method is implemented. Specifically, the method includes executing the following steps:
  • AMBA bus receiving a request from a central processor to process the data to be authenticated, wherein the request includes storage information of the data to be authenticated and a target hash algorithm selected from a plurality of hash algorithms;
  • the HMAC processing core in the computing unit is used to receive data sent by the grouping sub-unit and use the stored computing parameters corresponding to the target hash algorithm to perform operations to generate calculation results, and the calculation results are distributed to the hash processing cores corresponding to the target hash algorithm in the multiple hash processing cores that share the HMAC processing core to perform hash operations.
  • Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory.
  • Volatile memory can include random access memory (RAM) or external cache memory.
  • RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

Landscapes

  • Engineering & Computer Science (AREA)
  • Power Engineering (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Storage Device Security (AREA)

Abstract

本申请实施例涉及集成电路技术领域,尤其涉及一种HMAC算法处理系统、方法、设备及非易失性可读存储介质。所述系统包括:AMBA总线接收中央处理器发出的对待认证数据进行处理的请求;DMA控制单元基于待认证数据的存储信息通过DMA对待认证数据进行搬运;FIFO控制单元用多个FIFO对应缓存DMA搬运的数据;逻辑控制单元用密钥子单元生成每种哈希算法的运算参数并存储并用分组子单元从FIFO中读取数据并进行位宽转换后发送;运算单元用HMAC处理核接收数据执行运算生成计算结果并分发给对应的哈希处理核以执行哈希运算。本申请实施例的方案支持多种哈希计算模式并行,实现较低的资源消耗和高复用性,显著提高HMAC的计算效率、降低硬件资源消耗。

Description

一种HMAC算法处理系统、方法、设备及非易失性可读存储介质
相关申请的交叉引用
本申请要求于2022年11月7日提交中国专利局,申请号为202211383706.1,申请名称为“一种HMAC算法处理系统、方法、设备及介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请实施例涉及芯片设计领域,尤其涉及一种HMAC算法处理系统、方法、设备及非易失性可读存储介质。
背景技术
密钥相关的哈希运算消息认证码(Hash-based Message Authentication Code,简称HMAC算法),是一种基于Hash(哈希)函数和密钥进行消息认证的方法,用于校验数据完整性和来源合法性,适用于任何安全体系结构、进程或应用的安全服务。美国联邦信息处理标准FIPS(Federal Information Processing Standards)对HMAC算法过程的定义为:其中,K0为通信双方提前共享的密钥,H为hash函数,text为待验证数据,opad和ipad为算法定义的常数。FIPS标准中给出的HMAC算法流程图1所示。
哈希算法(Hash Algorithm)又称为散列算法、杂凑算法。由于在信息完整性认证和数字签名等方面的应用,哈希算法在当今时代的信息安全领域非常重要。不同哈希算法的参数性能不同,NIST(National Institute of Standards and Technology,美国国家标准与技术研究院)先后发布三种标准的杂凑算法SHA-0、SHA-1和SHA-2,由于MD5和SHA-1相继被攻破,SHA-2在目前例如经济和军事等重要安全领域中应用逐渐增加,其中应用较为广泛的是SHA-256密码杂凑算法。中国自主研发设计的杂凑算法SM3与SHA-256具有相同的消息摘要长度,作为商用密码杂凑算法在商业领域应用非常广泛。随着信息技术的发展,数据量呈现爆炸增长,同时也要求数据信息安全传递和处理,因此作为数据认证领域最常用的HMAC算法,其计算性能在一定程度上决定着整个系统的运算效率。
目前,常用的HMAC算法处理主要采用以下两种方式处理:第一种是使用软件的方式即中央处理器CPU(Central Processing Unit)计算完成HAMC,使用硬件的方式完成HAMC计算;第二种是使用硬件的方式完成计算,一般使用专用的计算芯片完成。然而以上两种方式存在以下缺陷:一方面使用软件的方式实现时,会大量占用CPU的资源,阻塞其他进程的运行;另一方面现有的专用计算芯片在进行认证计算时每次只能进行一种哈希算法的HMAC的计算,且要求认证数据连续不断地发送,不可分为多段发送,因而存在着运算效率低、资源消耗大、扩展性差、复用性低的问题。
发明内容
有鉴于此,有必要针对以上技术问题,提供一种HMAC算法处理系统、方法、设备及非易失性可读存储介质。
根据本申请实施例的第一方面,提供了一种HMAC算法处理系统,上述系统包括:
AMBA总线,上述AMBA总线被配置为接收中央处理器发出的对待认证数据进行处理的请求,其中,上述请求包括对待认证数据的存储信息及从多种哈希算法中选择的目标哈希算法;
DMA控制单元,上述DMA控制单元被配置为基于待认证数据的存储信息通过DMA对待认证数据进行搬运;
FIFO控制单元,上述FIFO控制单元包括与多种哈希算法一一对应的多个FIFO,每个FIFO用于根据待认证数据的目标哈希算法对应缓存DMA搬运的数据;
逻辑控制单元,上述逻辑控制单元包括与多种哈希算法一一对应的分组子单元和密钥子单元,由上述密钥子单元生成每种哈希算法的运算参数并存储,由上述分组子单元从FIFO中读取数据并进行位宽转换后发送;
运算单元,上述运算单元包括一个HMAC处理核和共用上述HMAC处理核且与多种哈希算法一一对应的哈希处理核,由上述HMAC处理核接收上述分组子单元发送的数据并利用存储的与目标哈希算法对应的运算参数执行运算生成计算结果,并由上述HMAC处理核将上述计算结果分发给目标哈希算法对应的哈希处理核以执行哈希运算。
在一些实施例中,上述系统还包括寄存器堆,上述逻辑控制单元还包括调度子单元;
上述调度子单元被配置为对每个FIFO的剩余空间进行监控以生成与多种哈希算法一一对应的认证数据状态值;以及
利用上述寄存器堆记录上述认证数据状态值以使中央处理器下发新数据处理请求时根据每个哈希算法对应的认证数据状态和业务操作需求从多种哈希算法中选择一个作为目标哈希算法。
在一些实施例中,上述调度子单元可选的被配置为:
计算每个FIFO的当前剩余存储空间,其中,剩余存储空间的初始值为整个FIFO的存储空间,每写入一个数据当前剩余的存储空间减少本次写入所占空间大小,每读一个数据当前剩余存储空间增加本次读取所占空间大小;
根据如下规则计算认证数据状态值并更新寄存器堆中记录:
若当前剩余存储空间大于FIFO深度的百分之七十,则计算认证数据状态值为三;
若当前剩余存储空间大于FIFO深度的百分之三十且小于等于FIFO深度的百分之七十,则计算认证数据状态值为二;
若当前剩余存储空间大于零且小于等于FIFO深度的百分之三十,则计算认证数据状态值为一;
若当前剩余存储空间等于零,则计算认证数据状态值为零。
在一些实施例中,中央处理器配置被配置为当存在新数据处理请求时根据以下规则选择目标哈希算法:
响应于某一哈希算法对应的认证数据状态值等于零,则禁止将上述某一哈希算法选取为目标哈希算法;
响应于存在多个哈希算法对应的认证数据状态值不等于零,则认证数据状态值大的哈希算法优先级高于认证数据状态值小的哈希算法,并优先从优先级高的哈希算法中选择目标哈希算法。
在一些实施例中,上述DMA控制单元包括主接口和从接口,中央处理器通过AMBA总线从上述从接口配置DMA相关寄存器,包括DMA数据长度、DMA数据地址、DMA首段数据标志位、DMA末段数据标志位,以及配置DMA启动寄存器,其中,DMA首段数据标志位和末段数据标志位根据如下规则确定:
若待认证数据只需要一段DMA搬运,则DMA首段数据标志位和DMA末段数据标志位均为1;
若待认证数据需要两段DMA搬运,则第一次搬运过程DMA首段数据标志位为1,第一次搬运过程DMA末段数据标志位为0,第二次搬运过程DMA首段数据标志位为0,第一次搬运过程DMA末段数据标志位为1;
若待认证数据需要三段及以上DMA搬运,则第一次搬运过程DMA首段数据标志位为1,第一次搬运过程DMA末段数据标志位为0,中间几段DMA搬运过程DMA首段数据标志位和DMA末段数据标志位均为0,最后一次搬运过程DMA首段数据标志位为0,最后一次搬运过程DMA末段数据标志位为1;
在接收到配置DMA寄存器的同时采用如下规则统计总认证数据长度:
在第一段DMA认证数据配置时,将第一段数据长度的值赋给总的认证数据长度,在后续段DMA认证数据配置时将DMA数据长度累加;
根据DMA首段数据标志位和DMA末段数据标志位通过上述主接口读取待认证数据相应地址的数据至DMA控制单元,并将数据缓存至目标哈希算法对应的FIFO中。
在一些实施例中,每个密钥子单元执行以下操作生成运算参数:
对密钥进行填充并将填充后的密钥分别与ipad和opad进行异或处理生成ipadkey和opadkey,其中, opad和ipad为美国联邦信息处理标准FIPS对HMAC算法定义的常数;
对所生成的ipadkey和opadkey进行存储。
在一些实施例中,每个分组子单元执行以下操作进行数据转换和发送:
获取哈希算法需求的输入数据位宽;
将从对应FIFO中连续读出数据打包成等于需求的输入数据位宽;
等待哈希算法对应哈希处理核可接收数据时发送打包后的数据。
在一些实施例中,上述HMAC处理核可选的被配置为:
获取所有哈希算法对应的ipadkey和opadkey;
从上述分组子单元接收数据并使用与数据的目标哈希算法对应的ipadkey和opadkey进行运算生成计算结果;
将上述计算结果、ipadkey和opadkey发送给对应的哈希处理核。
在一些实施例中,多种哈希算法包括md5算法、sha1算法、sm3算法,上述FIFO控制单元包括三个与md5算法、sha1算法、sm3算法对应的FIFO,运算单元包括md5算法处理核、sha1算法处理核、sm3算法处理核。
根据本申请实施例的第二方面,提供了一种HMAC算法处理方法,上述方法包括:
利用AMBA总线接收中央处理器发出的对待认证数据进行处理的请求,其中,上述请求包括对待认证数据的存储信息及从多种哈希算法中选择的目标哈希算法;
利用DMA控制单元基于待认证数据的存储信息通过DMA对待认证数据进行搬运;
利用包括在FIFO控制单元中与多种哈希算法一一对应的多个FIFO根据待认证数据的目标哈希算法对应缓存DMA搬运的数据;
利用逻辑控制单元中与多种哈希算法一一对应的密钥子单元生成每种哈希算法的运算参数并存储,以及利用逻辑控制单元中与多种哈希算法一一对应的分组子单元从FIFO中读取数据并进行位宽转换后发送;
利用运算单元中的HMAC处理核接收上述分组子单元发送的数据并利用存储的与目标哈希算法对应的运算参数执行运算生成计算结果,并将上述计算结果分发给共用上述HMAC处理核的多个哈希处理核中的目标哈希算法对应的哈希处理核以执行哈希运算。
在一些实施例中,上述方法还包括:
利用上述逻辑控制单中的调度子单元对每个FIFO的剩余空间进行监控以生成与多种哈希算法一一对应的认证数据状态值;
利用寄存器堆记录上述认证数据状态值以使中央处理器下发新数据处理请求时根据每个哈希算法对应的认证数据状态和业务操作需求从多种哈希算法中选择一个作为目标哈希算法。
在一些实施例中,利用上述逻辑控制单中的调度子单元对每个FIFO的剩余空间进行监控以生成与多种哈希算法一一对应的认证数据状态值,包括:
计算每个FIFO的当前剩余存储空间,其中,剩余存储空间的初始值为整个FIFO的存储空间,每写入一个数据当前剩余的存储空间减少本次写入所占空间大小,每读一个数据当前剩余存储空间增加本次读取所占空间大小;
根据如下规则计算认证数据状态值并更新寄存器堆中记录:
若当前剩余存储空间大于FIFO深度的百分之七十,则计算认证数据状态值为三;
若当前剩余存储空间大于FIFO深度的百分之三十且小于等于FIFO深度的百分之七十,则计算认证数据状态值为二;
若当前剩余存储空间大于零且小于等于FIFO深度的百分之三十,则计算认证数据状态值为一;
若当前剩余存储空间等于零,则计算认证数据状态值为零。
在一些实施例中,中央处理器配置被配置为当存在新数据处理请求时根据以下规则选择目标哈希算法:
响应于某一哈希算法对应的认证数据状态值等于零,则禁止将上述某一哈希算法选取为目标哈希算法;
响应于存在多个哈希算法对应的认证数据状态值不等于零,则认证数据状态值大的哈希算法优先级高于认证数据状态值小的哈希算法,并优先从优先级高的哈希算法中选择目标哈希算法。
在一些实施例中,利用DMA控制单元基于待认证数据的存储信息通过DMA对待认证数据进行搬运,包括:
中央处理器通过AMBA总线从DMA控制单元的从接口配置DMA相关寄存器,包括DMA数据长度、DMA数据地址、DMA首段数据标志位、DMA末段数据标志位,以及配置DMA启动寄存器,其中,DMA首段数据标志位和末段数据标志位根据如下规则确定:
若待认证数据只需要一段DMA搬运,则DMA首段数据标志位和DMA末段数据标志位均为1;
若待认证数据需要两段DMA搬运,则第一次搬运过程DMA首段数据标志位为1,第一次搬运过程DMA末段数据标志位为0,第二次搬运过程DMA首段数据标志位为0,第一次搬运过程DMA末段数据标志位为1;
若待认证数据需要三段及以上DMA搬运,则第一次搬运过程DMA首段数据标志位为1,第一次搬运过程DMA末段数据标志位为0,中间几段DMA搬运过程DMA首段数据标志位和DMA末段数据标志位均为0,最后一次搬运过程DMA首段数据标志位为0,最后一次搬运过程DMA末段数据标志位为1;
在接收到配置DMA寄存器的同时采用如下规则统计总认证数据长度:
在第一段DMA认证数据配置时,将第一段数据长度的值赋给总的认证数据长度,在后续段DMA认证数据配置时将DMA数据长度累加;
根据DMA首段数据标志位和DMA末段数据标志位通过上述DMA控制单元的主接口读取待认证数据相应地址的数据至DMA控制单元,并将数据缓存至目标哈希算法对应的FIFO中。
在一些实施例中,利用逻辑控制单元中与多种哈希算法一一对应的密钥子单元生成每种哈希算法的运算参数并存储,包括:
对密钥进行填充并将填充后的密钥分别与ipad和opad进行异或处理生成ipadkey和opadkey,其中,opad和ipad为美国联邦信息处理标准FIPS对HMAC算法定义的常数;
对所生成的ipadkey和opadkey进行存储。
在一些实施例中,利用逻辑控制单元中与多种哈希算法一一对应的分组子单元从FIFO中读取数据并进行位宽转换后发送,包括:
每个分组子单元执行以下操作进行数据转换和发送:
获取哈希算法需求的输入数据位宽;
将从对应FIFO中连续读出数据打包成等于需求的输入数据位宽;
等待哈希算法对应哈希处理核可接收数据时发送打包后的数据。
在一些实施例中,利用运算单元中的HMAC处理核接收上述分组子单元发送的数据并利用存储的与目标哈希算法对应的运算参数执行运算生成计算结果,包括:
获取所有哈希算法对应的ipadkey和opadkey;
从上述分组子单元接收数据并使用与数据的目标哈希算法对应的ipadkey和opadkey进行运算生成计算结果;
将上述计算结果、ipadkey和opadkey发送给对应的哈希处理核。
在一些实施例中,多种哈希算法包括md5算法、sha1算法、sm3算法,上述FIFO控制单元包括三个与md5算法、sha1算法、sm3算法对应的FIFO,运算单元包括md5算法处理核、sha1算法处理核、sm3算法处理核。
根据本申请实施例的第三方面,还提供了一种计算机设备,该计算机设备包括:
至少一个处理器;以及
存储器,存储器存储有可在处理器上运行的计算机程序,处理器执行程序时执行前述的HMAC算法处理方法。
根据本申请实施例的第四方面,还提供了一种非易失性可读存储介质,非易失性可读存储介质存储有计算机程序,计算机程序被处理器执行时执行前述的HMAC算法处理方法。
上述一种HMAC算法处理系统至少具备以下有益效果:运算单元包括一个共用的HMAC处理核,多组运算可以共用一个hmac处理核,相关技术中每组运算需要分别使用一个hmac处理核,因此降低了硬件资源,进而降低了硬件资源消耗。支持多计算模式并行工作、多组数据同时进行不同模式的计算时、多段DMA交叉下发大流量数据计算,多个密钥轻量化存储及调度,兼容构建并实现多种哈希认证计算,以及实现较低的资源消耗和高复用性,可以显著提高HMAC的计算效率、降低硬件资源消耗。
此外,本申请实施例还提供了一种HMAC算法处理方法、一种计算机设备和一种非易失性可读存储介质,同样能实现上述技术效果,这里不再赘述。
附图说明
为了更清楚地说明本申请实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的实施例。
图1为传统HMAC算法处理流程图示意图;
图2为本申请一个实施例提供的一种HMAC算法处理系统的结构示意图;
图3为本申请另一个实施例提供的一种HMAC算法处理方法的流程图;
图4为本申请另一个实施例中计算机设备的内部结构图。
具体实施方式
为使本申请实施例的目的、技术方案和优点更加清楚明白,以下结合可选的实施例,并参照附图,对本申请实施例进行详细说明。
需要说明的是,本申请实施例中所有使用“第一”和“第二”的表述均是为了区分两个相同名称非相同的实体或者非相同的参量,可见“第一”“第二”仅为了表述的方便,不应理解为对本申请实施例的限定,后续实施例对此不再一一说明。
为了便于理解首先对以下出现的部分技术名词进行解释说明:
FIFO,First Input First Output,中文解释为先进先出;
SOC,System on Chip中文解释为片上系统;
RAM,Random Access Memory中文解释为随机存取存储器;
IC,Integrated Circuit中文解释为集成电路;
IP,Intellectual Property中文解释为知识产权;
DDR,Double DataRate中文解释为双倍速率同步动态随机存储器;
AMBA,Advanced Microcontroller Bus Architecture中文解释为高级微控制器总线架构;
AXI,Advanced eXtensible Interface中文解释为先进可扩展接口;
AHB,Advanced High performance Bus中文解释为高级高性能总线;
DMA,Direct Memory Access中文解释为直接存储器访问。
在一个实施例中,请参照图2所示,本申请实施例提供了一种HMAC算法处理系统100,可选的,系统包括:
AMBA总线110,AMBA总线110被配置为接收中央处理器发出的对待认证数据进行处理的请求,其中,请求包括对待认证数据的存储信息及从多种哈希算法中选择的目标哈希算法;
DMA控制单元(DMA Control)120,DMA控制单元120被配置为基于待认证数据的存储信息通过DMA对待认证数据进行搬运;
FIFO控制单元(FIFO Control)130,FIFO控制单元130包括与多种哈希算法一一对应的多个FIFO131,每个FIFO用于根据待认证数据的目标哈希算法对应缓存DMA搬运的数据;
逻辑控制单元(Logic Control)140,逻辑控制单元140包括与多种哈希算法一一对应的分组子单元(MoMtor)141和密钥子单元(KEY)142,由密钥子单元142生成每种哈希算法的运算参数并存储,由分组子单元141从FIFO131中读取数据并进行位宽转换后发送;
运算单元(Algorithm core)150,运算单元150包括一个HMAC处理核151和共用HMAC处理核151且与多种哈希算法一一对应的哈希处理核152,由HMAC处理核151接收分组子单元141发送的数据并利用存储的与目标哈希算法对应的运算参数执行运算生成计算结果,并由HMAC处理核151将计算结果分发给目标哈希算法对应的哈希处理核152以执行哈希运算。
上述一种HMAC算法处理系统支持多计算模式并行工作、多段DMA交叉下发大流量数据计算,多个密钥轻量化存储及调度,兼容构建并实现多种哈希认证计算,以及实现较低的资源消耗和高复用性,可以显著提高HMAC的计算效率、降低硬件资源消耗。
在一些实施例中,请继续结合图2所示,系统还包括寄存器堆(Regs file)160,逻辑控制单元140还包括调度子单元(dispatch)143;寄存器堆160中包括指令与逻辑功能转换(Command to Logic functions,简称Cmd2logic)单元、寄存器单元(Regs,简称registers)以及逻辑功能与寄存器转换单元(Logic functions to registers,简称Logic2reg)。
调度子单元143被配置为对每个FIFO131的剩余空间进行监控以生成与多种哈希算法一一对应的认证数据状态值;以及
利用寄存器堆160记录认证数据状态值以使中央处理器下发新数据处理请求时根据每个哈希算法对应的认证数据状态和业务操作需求从多种哈希算法中选择一个作为目标哈希算法。
在一些实施例中,请继续结合图2所示,调度子单元143可选的被配置为:
计算每个FIFO131的当前剩余存储空间,其中,剩余存储空间的初始值为整个FIFO的存储空间,每写入一个数据当前剩余的存储空间减少本次写入所占空间大小,每读一个数据当前剩余存储空间增加本次读取所占空间大小;
根据如下规则计算认证数据状态值并更新寄存器堆160中记录:
若当前剩余存储空间大于FIFO深度的百分之七十,则计算认证数据状态值为三;
若当前剩余存储空间大于FIFO深度的百分之三十且小于等于FIFO深度的百分之七十,则计算认证数据状态值为二;
若当前剩余存储空间大于零且小于等于FIFO深度的百分之三十,则计算认证数据状态值为一;
若当前剩余存储空间等于零,则计算认证数据状态值为零。
在一些实施例中,请继续结合图2所示,中央处理器配置被配置为当存在新数据处理请求时根据以下规则选择目标哈希算法:
响应于某一哈希算法对应的认证数据状态值等于零,则禁止将某一哈希算法选取为目标哈希算法;
响应于存在多个哈希算法对应的认证数据状态值不等于零,则认证数据状态值大的哈希算法优先级高于认证数据状态值小的哈希算法,并优先从优先级高的哈希算法中选择目标哈希算法。
在一些实施例中,请继续结合图2所示,DMA控制单元120包括主接口(Master)121和从接口(Slave)122,中央处理器通过AMBA总线从接口122配置DMA相关寄存器,包括DMA数据长度、DMA数据地址、DMA首段数据标志位、DMA末段数据标志位,以及配置DMA启动寄存器,其中,DMA首段数据标志位和末段数据标志位根据如下规则确定:
若待认证数据只需要一段DMA搬运,则DMA首段数据标志位和DMA末段数据标志位均为1;
若待认证数据需要两段DMA搬运,则第一次搬运过程DMA首段数据标志位为1,第一次搬运过程DMA末段数据标志位为0,第二次搬运过程DMA首段数据标志位为0,第一次搬运过程DMA末段数据标志位为1;
若待认证数据需要三段及以上DMA搬运,则第一次搬运过程DMA首段数据标志位为1,第一次搬运过程DMA末段数据标志位为0,中间几段DMA搬运过程DMA首段数据标志位和DMA末段数据标志位均为0,最后一次搬运过程DMA首段数据标志位为0,最后一次搬运过程DMA末段数据标志位为1;
在接收到配置DMA寄存器的同时采用如下规则统计总认证数据长度:
在第一段DMA认证数据配置时,将第一段数据长度的值赋给总的认证数据长度,在后续段DMA认证数据配置时将DMA数据长度累加;
根据DMA首段数据标志位和DMA末段数据标志位通过主接口121读取待认证数据相应地址的数据至DMA控制单元120,并将数据缓存至目标哈希算法对应的FIFO131中。
在一些实施例中,请继续结合图2所示,每个密钥子单元142执行以下操作生成运算参数:
对密钥进行填充并将填充后的密钥分别与ipad和opad进行异或处理生成ipadkey和opadkey,其中,opad和ipad为美国联邦信息处理标准FIPS对HMAC算法定义的常数;
对所生成的ipadkey和opadkey进行存储。
在一些实施例中,请继续结合图2所示,每个分组子单元141执行以下操作进行数据转换和发送:
获取哈希算法需求的输入数据位宽;
将从对应FIFO131中连续读出数据打包成等于需求的输入数据位宽;
等待哈希算法对应哈希处理核152可接收数据时发送打包后的数据。
在一些实施例中,请继续结合图2所示,HMAC处理核151可选的被配置为:
获取所有哈希算法对应的ipadkey和opadkey;
从分组子单元141接收数据并使用与数据的目标哈希算法对应的ipadkey和opadkey进行运算生成计算结果,Ipadkey和opadkey用于表示标准算法中的对固定比特序列。可以理解的是,ipadkey和opadkey是对密钥进行填充并将填充后的密钥分别与ipad和opad进行异或处理生成的比特序列;
将计算结果、ipadkey和opadkey发送给对应的哈希处理核152。
在一些实施例中,请继续结合图2所示,多种哈希算法包括md5算法、sha1算法、sm3算法,FIFO控制单元130包括三个与md5算法、sha1算法、sm3算法对应的FIFO,运算单元150包括md5算法处理核、sha1算法处理核、sm3算法处理核。
在又一个实施例中,请参照图3所示,本申请实施例提供了一种HMAC算法处理方法200,方法包括:
步骤201,利用AMBA总线接收中央处理器发出的对待认证数据进行处理的请求,其中,请求包括对待认证数据的存储信息及从多种哈希算法中选择的目标哈希算法;
步骤202,利用DMA控制单元基于待认证数据的存储信息通过DMA对待认证数据进行搬运;
步骤203,利用包括在FIFO控制单元中与多种哈希算法一一对应的多个FIFO根据待认证数据的目标哈希算法对应缓存DMA搬运的数据;
步骤204,利用逻辑控制单元中与多种哈希算法一一对应的密钥子单元生成每种哈希算法的运算参数并存储,以及利用逻辑控制单元中与多种哈希算法一一对应的分组子单元从FIFO中读取数据并进行位宽转换后发送;
步骤205,利用运算单元中的HMAC处理核接收分组子单元发送的数据并利用存储的与目标哈希算法对应的运算参数执行运算生成计算结果,并将计算结果分发给共用HMAC处理核的多个哈希处理核中的目标哈希算法对应的哈希处理核以执行哈希运算。
上述一种HMAC算法处理方法支持多计算模式并行工作、多段DMA交叉下发大流量数据计算,多个密钥轻量 化存储及调度,兼容构建并实现多种哈希认证计算,以及实现较低的资源消耗和高复用性,可以显著提高HMAC的计算效率、降低硬件资源消耗。
在一些实施例中,方法还包括:
利用逻辑控制单中的调度子单元对每个FIFO的剩余空间进行监控以生成与多种哈希算法一一对应的认证数据状态值;
利用寄存器堆记录认证数据状态值以使中央处理器下发新数据处理请求时根据每个哈希算法对应的认证数据状态和业务操作需求从多种哈希算法中选择一个作为目标哈希算法。
在一些实施例中,利用逻辑控制单中的调度子单元对每个FIFO的剩余空间进行监控以生成与多种哈希算法一一对应的认证数据状态值,包括:
计算每个FIFO的当前剩余存储空间,其中,剩余存储空间的初始值为整个FIFO的存储空间,每写入一个数据当前剩余的存储空间减少本次写入所占空间大小,每读一个数据当前剩余存储空间增加本次读取所占空间大小;
根据如下规则计算认证数据状态值并更新寄存器堆中记录:
若当前剩余存储空间大于FIFO深度的百分之七十,则计算认证数据状态值为三;
若当前剩余存储空间大于FIFO深度的百分之三十且小于等于FIFO深度的百分之七十,则计算认证数据状态值为二;
若当前剩余存储空间大于零且小于等于FIFO深度的百分之三十,则计算认证数据状态值为一;
若当前剩余存储空间等于零,则计算认证数据状态值为零。
在一些实施例中,中央处理器配置被配置为当存在新数据处理请求时根据以下规则选择目标哈希算法:
响应于某一哈希算法对应的认证数据状态值等于零,则禁止将某一哈希算法选取为目标哈希算法;
响应于存在多个哈希算法对应的认证数据状态值不等于零,则认证数据状态值大的哈希算法优先级高于认证数据状态值小的哈希算法,并优先从优先级高的哈希算法中选择目标哈希算法。
在一些实施例中,步骤202,利用DMA控制单元基于待认证数据的存储信息通过DMA对待认证数据进行搬运,包括:
中央处理器通过AMBA总线从DMA控制单元的从接口配置DMA相关寄存器,包括DMA数据长度、DMA数据地址、DMA首段数据标志位、DMA末段数据标志位,以及配置DMA启动寄存器,其中,DMA首段数据标志位和末段数据标志位根据如下规则确定:
若待认证数据只需要一段DMA搬运,则DMA首段数据标志位和DMA末段数据标志位均为1;
若待认证数据需要两段DMA搬运,则第一次搬运过程DMA首段数据标志位为1,第一次搬运过程DMA末段数据标志位为0,第二次搬运过程DMA首段数据标志位为0,第一次搬运过程DMA末段数据标志位为1;
若待认证数据需要三段及以上DMA搬运,则第一次搬运过程DMA首段数据标志位为1,第一次搬运过程DMA末段数据标志位为0,中间几段DMA搬运过程DMA首段数据标志位和DMA末段数据标志位均为0,最后一次搬运过程DMA首段数据标志位为0,最后一次搬运过程DMA末段数据标志位为1;
在接收到配置DMA寄存器的同时采用如下规则统计总认证数据长度:
在第一段DMA认证数据配置时,将第一段数据长度的值赋给总的认证数据长度,在后续段DMA认证数据配置时将DMA数据长度累加;
根据DMA首段数据标志位和DMA末段数据标志位通过DMA控制单元的主接口读取待认证数据相应地址的数据至DMA控制单元,并将数据缓存至目标哈希算法对应的FIFO中。
在一些实施例中,步骤204中利用逻辑控制单元中与多种哈希算法一一对应的密钥子单元生成每种哈希算法的运算参数并存储包括:
对密钥进行填充并将填充后的密钥分别与ipad和opad进行异或处理生成ipadkey和opadkey,其中,opad和 ipad为美国联邦信息处理标准FIPS对HMAC算法定义的常数;
对所生成的ipadkey和opadkey进行存储。
在一些实施例中,步骤204中利用逻辑控制单元中与多种哈希算法一一对应的分组子单元从FIFO中读取数据并进行位宽转换后发送,包括:
每个分组子单元执行以下操作进行数据转换和发送:
获取哈希算法需求的输入数据位宽;
将从对应FIFO中连续读出数据打包成等于需求的输入数据位宽;
等待哈希算法对应哈希处理核可接收数据时发送打包后的数据。
在一些实例中,步骤205中利用运算单元中的HMAC处理核接收分组子单元发送的数据并利用存储的与目标哈希算法对应的运算参数执行运算生成计算结果,包括:
获取所有哈希算法对应的ipadkey和opadkey;
从分组子单元接收数据并使用与数据的目标哈希算法对应的ipadkey和opadkey进行运算生成计算结果;
将计算结果、ipadkey和opadkey发送给对应的哈希处理核152。
在一些实例中,哈希处理核152中填充(padding)有多种哈希算法,多种哈希算法包括md5算法、sha1算法、sm3算法,FIFO控制单元130包括三个与md5算法、sha1算法、sm3算法对应的FIFO,运算单元150包括md5算法处理核、sha1算法处理核、sm3算法处理核。
需要说明的是,关于HMAC算法处理方法的限定可以参见上文中对HMAC算法处理系统的限定,在此不再赘述。上述HMAC算法处理系统中的各个单元、子单元可全部或部分通过软件、硬件及其组合来实现。上述各单元、子单元可以硬件形式内嵌于或独立于计算机设备中的处理器中,也可以以软件形式存储于计算机设备中的存储器中,以便于处理器调用执行以上各个单元、子单元对应的操作。
在又一个实施例中,下面再次结合图2所示的HMAC算法处理系统,本实施例以支持md5、sha1、sm3三种哈希算法为例详细说明该系统各部分的交互过程,并比对传统的HMAC处理流程说明本方案的优势,可选的分为以下八个部分:
第一部分,读取工作状态;CPU通过AMBA总线slave接口读取相应的认证计算过程状态寄存器Hash_status(Hash_status_sm3、Hash_status_md5、Hash_status_sha1),若对应的状态寄存器不为0,则进入下面步骤,否则等待直到此寄存器的值不为0。
第二部分,配置HMAC寄存器;CPU通过第一部分读取到的3个hash算法的Hash_status和本身的业务操作要求判断优先使用哪一种认证计算过程。之后CPU通过AMBA总线slave接口配置hmac算法的相关寄存器,包括密钥key,密钥长度key_length、算法模式选择等。在实施例中,支持hmac_sm3、hmac_md5、hmac_sha1分别独立配置和使用密钥,在进行认证计算时,首次使用及密钥发生改变时必须重新配置密钥,在后续的认证计算过程中,若对应算法的密钥并未改变,可以不再配置。
第三部分,配置DMA寄存器;CPU通过AMBA总线slave接口配置dma相关寄存器,包括dma数据长度dma_length、dma数据地址、dma首段数据标志位、dma末段数据标志位,最后配置dma启动寄存器。
若一次认证的数据只需要一段dma搬运,则dma首段数据标志位和dma末段数据标志位均为1;
若一次认证的数据需要2段dma搬运,则第一次搬运过程dma首段数据标志位为1,dma末段数据标志位为0;第二次搬运过程dma首段数据标志位为0,dma末段数据标志位为1;
若一次认证的数据需要3段及以上dma搬运,则第一次搬运过程dma首段数据标志位为1,dma末段数据标志位为0;最后一次搬运过程dma首段数据标志位为0,dma末段数据标志位为1;中间几段的dma搬运过程,dma首段数据标志位和dma末段数据标志位均为0;
在接收到配置dma寄存器的同时,计算总的认证数据长度total_num。可以为:在第一段dma认证数据配置时,将第一段数据长度的值赋给总的认证数据长度,total_num=dma_length;
在后续段数据时,将dma数据长度累加,total_num=total_num+dma_length。
第四部分,Dma control搬运数据;Dma control通过AMBA master接口读取相应地址的数据至本模块,并将数据缓存至对应的fifo中,在本提案中使用3个相同的fifo缓存待认证的数据,包括:HMAC_SM3 fifo;HMAC_MD5 fifo;HMAC_SHA1 fifo;例如,本次dma搬运的数据为hmac_sm3认证的数据,则将其写入HMAC_SM3 fifo中,以此类推。在将本次dma数据全部写入对应的缓存fifo中后,标志着此次dma过程完成,此时跳转回第一部分开始下一次数据搬运过程。
需要特别注意的是,下一次认证数据的搬运过程与前一次是完全独立的,例如前一次是HMAC_SM3算法的第一段dma数据,下一次可以是HMAC_SM3的第二段数据,也可以HMAC_MD5或HMAC_SHA1的数据。这种方式最大程度的保证了上层软件操作的便利性和运算效率,减少了上层软件的数据缓存,同时也最大程度的提高了硬件在计算时的效率。
传统处理方案中,上层软件首先配置需要认证的算法和密钥,然后传输需要认证的数据至计算模块,在这期间数据必须是连续的,即在此次认证计算完成前,不允许使用其他的认证模块进行计算。
第五部分,密钥key预计算及缓存;由于3种认证计算的处理方式是一样的,是并行计算的,因此不再分开介绍,每种认证方式采用以下操作生成ipadkey和opadkey
a.密钥填充;
首先判断密钥的长度,若超过512bit,则首先将其送入对应的hash运算核心中,计算出摘要值(即计算结果),然后在摘要值后填充0,直到总长度达到512bit;若密钥长度小于512bit,则在密钥后直接填充0,直到总长度达到512bit;若密钥长度刚好512bit,则不需做处理。
b.填充后的密钥与ipad进行“异或”处理;
ipad是将比特系列00110110(即0x36)不断循环直到达到512bit,其中ipad中的i是inner(内部)的意思。异或运算之后得到的值也是512bit数据,我们将其称为ipadkey,也就是预计算结果。
c.填充后的密钥与opad进行“异或”处理;
opad是将比特01011100(即0x5C)不断循环反复直到达到512bit,其中opad中的o是outer(外部)的意思。异或运算之后得到的值也是512bit数据,我们将这一比特系列称为opadkey。
d.将预计算的结果进行缓存;
需要特别注意的是,使用这样的方式可以减少密钥的存储空间,这是因为密钥的长度最大可以达到256MB,而预计算结果仅为512bit,这极大的降低了所需的存储空间。与此同时,提前将密钥ipadkey计算出来,使得后续的计算每次只需要从step5开始计算,减少了后续的计算时间,提高了效率。
传统处理方案中,首先将密钥key全部存储下来,在进行认证计算时从存储空间中将其读出来,依次进行图1中的step1-9过程。
第六部分,分组数据转换monitor;3种认证计算的处理方式也是一样的,是并行计算的,因此不再分开介绍。md5、sm3、sha1算法核心要求输入数据格式为512bit位宽的数据,而dma通过AMBA总线搬运数据时的数据位宽一般远小于512bit,常用的为32bit和64Bit。因此需要将其重新打包成512bit数据,即从前级fifo中连续读出16个数据(以32bit位宽为例),并进行大小端转换,然后生成valid有效信号,等待后级算法模块表明可以接收数据的ready信号也为1时,表明此数据已经被后级模块接收,之后继续读取数据直到对应的前级fifo为空。
第七部分,数据流调度dispatch;此部分完成缓存fifo空间的计算、生成认证数据状态寄存器Hash_status。3种认证计算的处理方式也是一样的,是并行计算的。每种认证方式的调度方式参考如下:
首先计算缓存fifo的剩余存储空间,T_num=(T_num+fifo_length-wr_en+rd_en)*4,T_num初始值为整个fifo的存储空间,每写入一个数据剩余的存储空间减少,每读一个,剩余的存储空间增加。fifo_length为fifo的深度。其次生成认证数据状态Hash_status;
若当前T_num>0.7*fifo_length,则Hash_status为3;
若当前0.7*fifo_length>=T_num>0.3*fifo_length,则Hash_status为2;
若当前0.3*fifo_length>=T_num>0,则Hash_status为1;
若当前T_num=0,则Hash_status为0。
第八部分,HMAC计算;在这个部分3个算法共用一个HMAC,这是因为在前面的过程中,已经预计算出了3个算法的密钥ipadkey和opadkey,因此后续只需要按照数据接收顺序发送数据至相应的hash算法模块;同时,hash算法是一种压缩算法,数据需要多轮迭代压缩才可计算完成,即一组输入数据需要多个时钟周期才能计算完成,这就导致输入带宽远大于输出带宽,因此3个hash算法核心共用一个HMAC并不会降低整体的运算效率,反而会降低硬件资源的消耗。
详细过程如下:
a.依次将3个预计算ipadkey传递给后级的hash算法模块;
b.前级Logic control模块将格式为512bit位宽的数据传递给后级,hash算法核心每计算完成一组数据的计算,前级发送一组数据至后级,直到发送完成本次认证计算的最后一组数据。在发送最后一组数据时,同时发送总的认证数据长度total_num给后级模块,同时将最后一组数据标志位置为1,标志是hash算法的最后一组数据,等待最后的计算结果,记为hash1
c.将预计算opadkey传递给后级的hash算法模块。由于认证数据长度和hash计算的复杂度不同,因此上一个步骤b的实际完成的先后顺序不同,只要当前认证算法的步骤b完成即可进入c步骤,不必等待其他认证算法的过程,3个过程独立并行。
d.将hash1传递给后级的hash算法模块,同时将最后一组数据标志位置为1,标志是hash算法的最后一组数据。在此次计算完成后,输出值即为本次hmac计算的最终结果(摘要值)。由于认证数据长度和hash计算的复杂度不同,因此上一个步骤c的实际完成的先后顺序不同,只要当前认证算法的步骤c完成即可进入d步骤,不必等待其他认证算法的过程,3个过程独立并行;
e.将对应的认证计算过程状态寄存器修改为空闲;
需要特别注意的是,3个认证算法共用一个HMAC并不会降低整体的运算效率,反而会降低硬件资源的消耗。
根据本申请实施例的另一方面,提供了一种计算机设备,该计算机设备可以是服务器,其内部结构图请参照图4所示。该计算机设备包括通过系统总线连接的处理器、存储器、网络接口和数据库。其中,该计算机设备的处理器被配置为提供计算和控制能力。该计算机设备的存储器包括非易失性存储介质、内存储器。该非易失性存储介质存储有操作系统、计算机程序和数据库。该内存储器为非易失性存储介质中的操作系统和计算机程序的运行提供环境。该计算机设备的数据库被配置为存储数据。该计算机设备的网络接口被配置为与外部的终端通过网络连接通信。该计算机程序被处理器执行时实现以上的HMAC算法处理方法,详细来说,方法包括以下步骤:
利用AMBA总线接收中央处理器发出的对待认证数据进行处理的请求,其中,请求包括对待认证数据的存储信息及从多种哈希算法中选择的目标哈希算法;
利用DMA控制单元基于待认证数据的存储信息通过DMA对待认证数据进行搬运;
利用包括在FIFO控制单元中与多种哈希算法一一对应的多个FIFO根据待认证数据的目标哈希算法对应缓存DMA搬运的数据;
利用逻辑控制单元中与多种哈希算法一一对应的密钥子单元生成每种哈希算法的运算参数并存储,以及利用逻辑控制单元中与多种哈希算法一一对应的分组子单元从FIFO中读取数据并进行位宽转换后发送;
利用运算单元中的HMAC处理核接收分组子单元发送的数据并利用存储的与目标哈希算法对应的运算参数执行运算生成计算结果,并将计算结果分发给共用HMAC处理核的多个哈希处理核中的目标哈希算法对应的哈希处 理核以执行哈希运算。
根据本申请实施例的又一方面,提供了一种非易失性可读存储介质,其上存储有计算机程序,计算机程序被处理器执行时实现以上的HMAC算法处理方法,详细来说,包括执行以下步骤:
利用AMBA总线接收中央处理器发出的对待认证数据进行处理的请求,其中,请求包括对待认证数据的存储信息及从多种哈希算法中选择的目标哈希算法;
利用DMA控制单元基于待认证数据的存储信息通过DMA对待认证数据进行搬运;
利用包括在FIFO控制单元中与多种哈希算法一一对应的多个FIFO根据待认证数据的目标哈希算法对应缓存DMA搬运的数据;
利用逻辑控制单元中与多种哈希算法一一对应的密钥子单元生成每种哈希算法的运算参数并存储,以及利用逻辑控制单元中与多种哈希算法一一对应的分组子单元从FIFO中读取数据并进行位宽转换后发送;
利用运算单元中的HMAC处理核接收分组子单元发送的数据并利用存储的与目标哈希算法对应的运算参数执行运算生成计算结果,并将计算结果分发给共用HMAC处理核的多个哈希处理核中的目标哈希算法对应的哈希处理核以执行哈希运算。
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,上述的计算机程序可存储于一非易失性计算机可读取存储介质中,该计算机程序在执行时,可包括如上述各方法的实施例的流程。其中,本申请所提供的各实施例中所使用的对存储器、存储、数据库或其它介质的任何引用,均可包括非易失性和/或易失性存储器。非易失性存储器可包括只读存储器(ROM)、可编程ROM(PROM)、电可编程ROM(EPROM)、电可擦除可编程ROM(EEPROM)或闪存。易失性存储器可包括随机存取存储器(RAM)或者外部高速缓冲存储器。作为说明而非局限,RAM以多种形式可得,诸如静态RAM(SRAM)、动态RAM(DRAM)、同步DRAM(SDRAM)、双数据率SDRAM(DDRSDRAM)、增强型SDRAM(ESDRAM)、同步链路(Synchlink)DRAM(SLDRAM)、存储器总线(Rambus)直接RAM(RDRAM)、直接存储器总线动态RAM(DRDRAM)、以及存储器总线动态RAM(RDRAM)等。
以上实施例的各技术特征可以进行任意的组合,为使描述简洁,未对上述实施例中的各个技术特征所有可能的组合都进行描述,然而,只要这些技术特征的组合不存在矛盾,都应当认为是本说明书记载的范围。
以上上述实施例仅表达了本申请实施例的几种实施方式,其描述较为详细,但并不能因此而理解为对发明专利范围的限制。应当指出的是,对于本领域的普通技术人员来说,在不脱离本申请实施例构思的前提下,还可以做出若干变形和改进,这些都属于本申请实施例的保护范围。因此,本申请实施例专利的保护范围应以所附权利要求为准。

Claims (20)

  1. 一种HMAC算法处理系统,其特征在于,所述系统包括:
    AMBA总线,所述AMBA总线被配置为接收中央处理器发出的对待认证数据进行处理的请求,其中,所述请求包括对待认证数据的存储信息及从多种哈希算法中选择的目标哈希算法;
    DMA控制单元,所述DMA控制单元被配置为基于待认证数据的存储信息通过DMA对待认证数据进行搬运;
    FIFO控制单元,所述FIFO控制单元包括与多种哈希算法一一对应的多个FIFO,每个FIFO用于根据待认证数据的目标哈希算法对应缓存DMA搬运的数据;
    逻辑控制单元,所述逻辑控制单元包括与多种哈希算法一一对应的分组子单元和密钥子单元,由所述密钥子单元生成每种哈希算法的运算参数并存储,由所述分组子单元从FIFO中读取数据并进行位宽转换后发送;
    运算单元,所述运算单元包括一个HMAC处理核和共用所述HMAC处理核且与多种哈希算法一一对应的哈希处理核,由所述HMAC处理核接收所述分组子单元发送的数据并利用存储的与目标哈希算法对应的运算参数执行运算生成计算结果,并由所述HMAC处理核将所述计算结果分发给目标哈希算法对应的哈希处理核以执行哈希运算。
  2. 根据权利要求1所述的HMAC算法处理系统,其特征在于,所述系统还包括寄存器堆,所述逻辑控制单元还包括调度子单元;
    所述调度子单元被配置为对每个FIFO的剩余空间进行监控以生成与多种哈希算法一一对应的认证数据状态值;以及
    利用所述寄存器堆记录所述认证数据状态值以使中央处理器下发新数据处理请求时根据每个哈希算法对应的认证数据状态和业务操作需求从多种哈希算法中选择一个作为目标哈希算法。
  3. 根据权利要求2所述的HMAC算法处理系统,其特征在于,所述调度子单元被配置为:
    计算每个FIFO的当前剩余存储空间,其中,剩余存储空间的初始值为整个FIFO的存储空间,每写入一个数据当前剩余的存储空间减少本次写入所占空间大小,每读一个数据当前剩余存储空间增加本次读取所占空间大小;
    根据如下规则计算认证数据状态值并更新寄存器堆中记录:
    若当前剩余存储空间大于FIFO深度的百分之七十,则计算认证数据状态值为三;
    若当前剩余存储空间大于FIFO深度的百分之三十且小于等于FIFO深度的百分之七十,则计算认证数据状态值为二;
    若当前剩余存储空间大于零且小于等于FIFO深度的百分之三十,则计算认证数据状态值为一;
    若当前剩余存储空间等于零,则计算认证数据状态值为零。
  4. 根据权利要求3所述的HMAC算法处理系统,其特征在于,中央处理器被配置为当存在新数据处理请求时根据以下规则选择目标哈希算法:
    响应于某一哈希算法对应的认证数据状态值等于零,则禁止将所述某一哈希算法选取为目标哈希算法;
    响应于存在多个哈希算法对应的认证数据状态值不等于零,则认证数据状态值大的哈希算法优先级高于认证数据状态值小的哈希算法,并优先从优先级高的哈希算法中选择目标哈希算法。
  5. 根据权利要求1所述的HMAC算法处理系统,其特征在于,所述DMA控制单元包括主接口和从接口,中央处理器通过AMBA总线从所述从接口配置DMA相关寄存器,包括DMA数据长度、DMA数据地址、DMA首段数据标志位、DMA末段数据标志位,以及配置DMA启动寄存器,其中,DMA首段数据标志位和末段数据标志位根据如下规则确定:
    若待认证数据只需要一段DMA搬运,则DMA首段数据标志位和DMA末段数据标志位均为1;
    若待认证数据需要两段DMA搬运,则第一次搬运过程DMA首段数据标志位为1,第一次搬运过程DMA末段数据标志位为0,第二次搬运过程DMA首段数据标志位为0,第一次搬运过程DMA末段数据标志位为1;
    若待认证数据需要三段及以上DMA搬运,则第一次搬运过程DMA首段数据标志位为1,第一次搬运过程DMA末段数据标志位为0,中间几段DMA搬运过程DMA首段数据标志位和DMA末段数据标志位均为0,最后一次搬运过程DMA首段数据标志位为0,最后一次搬运过程DMA末段数据标志位为1;
    在接收到配置DMA寄存器的同时采用如下规则统计总认证数据长度:
    在第一段DMA认证数据配置时,将第一段数据长度的值赋给总的认证数据长度,在后续段DMA认证数据配置时将DMA数据长度累加;
    根据DMA首段数据标志位和DMA末段数据标志位通过所述主接口读取待认证数据相应地址的数据至DMA控制单元,并将数据缓存至目标哈希算法对应的FIFO中。
  6. 根据权利要求1所述的HMAC算法处理系统,其特征在于,每个密钥子单元执行以下操作生成运算参数:
    对密钥进行填充并将填充后的密钥分别与ipad和opad进行异或处理生成ipadkey和opadkey,其中,opad和ipad为美国联邦信息处理标准FIPS对HMAC算法定义的常数;
    对所生成的ipadkey和opadkey进行存储。
  7. 根据权利要求1所述的HMAC算法处理系统,其特征在于,每个分组子单元执行以下操作进行数据转换和发送:
    获取哈希算法需求的输入数据位宽;
    将从对应FIFO中连续读出数据打包成等于需求的输入数据位宽;
    等待哈希算法对应哈希处理核可接收数据时发送打包后的数据。
  8. 根据权利要求6所述的HMAC算法处理系统,其特征在于,所述HMAC处理核被配置为:
    获取所有哈希算法对应的ipadkey和opadkey;
    从所述分组子单元接收数据并使用与数据的目标哈希算法对应的ipadkey和opadkey进行运算生成计算结果;
    将所述计算结果、ipadkey和opadkey发送给对应的哈希处理核。
  9. 根据权利要求1所述的HMAC算法处理系统,其特征在于,多种哈希算法包括md5算法、sha1算法、sm3算法,所述FIFO控制单元包括三个与md5算法、sha1算法、sm3算法对应的FIFO,运算单元包括md5算法处理核、sha1算法处理核、sm3算法处理核。
  10. 一种HMAC算法处理方法,其特征在于,所述方法包括:
    利用AMBA总线接收中央处理器发出的对待认证数据进行处理的请求,其中,所述请求包括对待认证数据的存储信息及从多种哈希算法中选择的目标哈希算法;
    利用DMA控制单元基于待认证数据的存储信息通过DMA对待认证数据进行搬运;
    利用包括在FIFO控制单元中与多种哈希算法一一对应的多个FIFO根据待认证数据的目标哈希算法对应缓存DMA搬运的数据;
    利用逻辑控制单元中与多种哈希算法一一对应的密钥子单元生成每种哈希算法的运算参数并存储,以及利用逻辑控制单元中与多种哈希算法一一对应的分组子单元从FIFO中读取数据并进行位宽转换后发送;
    利用运算单元中的HMAC处理核接收所述分组子单元发送的数据并利用存储的与目标哈希算法对应的运算参数执行运算生成计算结果,并将所述计算结果分发给共用所述HMAC处理核的多个哈希处理核中的目标哈希算法对应的哈希处理核以执行哈希运算。
  11. 根据权利要求10所述的HMAC算法处理方法,其特征在于,所述方法还包括:
    利用所述逻辑控制单中的调度子单元对每个FIFO的剩余空间进行监控以生成与多种哈希算法一一对应的认证数据状态值;
    利用寄存器堆记录所述认证数据状态值以使中央处理器下发新数据处理请求时根据每个哈希算法对应的认证数据状态和业务操作需求从多种哈希算法中选择一个作为目标哈希算法。
  12. 根据权利要求11所述的HMAC算法处理方法,其特征在于,利用所述逻辑控制单中的调度子单元对每个FIFO的剩余空间进行监控以生成与多种哈希算法一一对应的认证数据状态值,包括:
    计算每个FIFO的当前剩余存储空间,其中,剩余存储空间的初始值为整个FIFO的存储空间,每写入一个数据当前剩余的存储空间减少本次写入所占空间大小,每读一个数据当前剩余存储空间增加本次读取所占空间大小;
    根据如下规则计算认证数据状态值并更新寄存器堆中记录:
    若当前剩余存储空间大于FIFO深度的百分之七十,则计算认证数据状态值为三;
    若当前剩余存储空间大于FIFO深度的百分之三十且小于等于FIFO深度的百分之七十,则计算认证数据状态值为二;
    若当前剩余存储空间大于零且小于等于FIFO深度的百分之三十,则计算认证数据状态值为一;
    若当前剩余存储空间等于零,则计算认证数据状态值为零。
  13. 根据权利要求12所述的HMAC算法处理方法,其特征在于,中央处理器被配置为当存在新数据处理请求时根据以下规则选择目标哈希算法:
    响应于某一哈希算法对应的认证数据状态值等于零,则禁止将所述某一哈希算法选取为目标哈希算法;
    响应于存在多个哈希算法对应的认证数据状态值不等于零,则认证数据状态值大的哈希算法优先级高于认证数据状态值小的哈希算法,并优先从优先级高的哈希算法中选择目标哈希算法。
  14. 根据权利要求10所述的HMAC算法处理方法,其特征在于,利用DMA控制单元基于待认证数据的存储信息通过DMA对待认证数据进行搬运,包括:
    中央处理器通过AMBA总线从DMA控制单元的从接口配置DMA相关寄存器,包括DMA数据长度、DMA数据地址、DMA首段数据标志位、DMA末段数据标志位,以及配置DMA启动寄存器,其中,DMA首段数据标志位和末段数据标志位根据如下规则确定:
    若待认证数据只需要一段DMA搬运,则DMA首段数据标志位和DMA末段数据标志位均为1;
    若待认证数据需要两段DMA搬运,则第一次搬运过程DMA首段数据标志位为1,第一次搬运过程DMA末段数据标志位为0,第二次搬运过程DMA首段数据标志位为0,第一次搬运过程DMA末段数据标志位为1;
    若待认证数据需要三段及以上DMA搬运,则第一次搬运过程DMA首段数据标志位为1,第一次搬运过程DMA末段数据标志位为0,中间几段DMA搬运过程DMA首段数据标志位和DMA末段数据标志位均为0,最后一次搬运过程DMA首段数据标志位为0,最后一次搬运过程DMA末段数据标志位为1;
    在接收到配置DMA寄存器的同时采用如下规则统计总认证数据长度:
    在第一段DMA认证数据配置时,将第一段数据长度的值赋给总的认证数据长度,在后续段DMA认证数据配置时将DMA数据长度累加;
    根据DMA首段数据标志位和DMA末段数据标志位通过所述DMA控制单元的主接口读取待认证数据相应地址的数据至DMA控制单元,并将数据缓存至目标哈希算法对应的FIFO中。
  15. 根据权利要求10所述的HMAC算法处理方法,其特征在于,利用逻辑控制单元中与多种哈希算法一一对应的密钥子单元生成每种哈希算法的运算参数并存储,包括:
    对密钥进行填充并将填充后的密钥分别与ipad和opad进行异或处理生成ipadkey和opadkey,其中,opad和ipad为美国联邦信息处理标准FIPS对HMAC算法定义的常数;
    对所生成的ipadkey和opadkey进行存储。
  16. 根据权利要求10所述的HMAC算法处理方法,其特征在于,利用逻辑控制单元中与多种哈希算法一一对应的分组子单元从FIFO中读取数据并进行位宽转换后发送,包括:
    每个分组子单元执行以下操作进行数据转换和发送:
    获取哈希算法需求的输入数据位宽;
    将从对应FIFO中连续读出数据打包成等于需求的输入数据位宽;
    等待哈希算法对应哈希处理核可接收数据时发送打包后的数据。
  17. 根据权利要求15所述的HMAC算法处理方法,其特征在于,利用运算单元中的HMAC处理核接收所述分组子单元发送的数据并利用存储的与目标哈希算法对应的运算参数执行运算生成计算结果,包括:
    获取所有哈希算法对应的ipadkey和opadkey;
    从所述分组子单元接收数据并使用与数据的目标哈希算法对应的ipadkey和opadkey进行运算生成计算结果;
    将所述计算结果、ipadkey和opadkey发送给对应的哈希处理核。
  18. 根据权利要求10所述的HMAC算法处理方法,其特征在于,多种哈希算法包括md5算法、sha1算法、sm3算法,所述FIFO控制单元包括三个与md5算法、sha1算法、sm3算法对应的FIFO,运算单元包括md5算法处理核、sha1算法处理核、sm3算法处理核。
  19. 一种计算机设备,其特征在于,包括:
    至少一个处理器;以及
    存储器,所述存储器存储有可在所述处理器中运行的计算机程序,所述处理器执行所述程序时执行权利要求10-18任意一项所述的方法。
  20. 一种非易失性可读存储介质,所述非易失性可读存储介质存储有计算机程序,其特征在于,所述计算机程序被处理器执行时执行权利要求10-18任意一项所述的方法。
PCT/CN2023/082297 2022-11-07 2023-03-17 一种hmac算法处理系统、方法、设备及非易失性可读存储介质 WO2024098613A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202211383706.1 2022-11-07
CN202211383706.1A CN115442026B (zh) 2022-11-07 2022-11-07 一种hmac算法处理系统、方法、设备及介质

Publications (1)

Publication Number Publication Date
WO2024098613A1 true WO2024098613A1 (zh) 2024-05-16

Family

ID=84252134

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/082297 WO2024098613A1 (zh) 2022-11-07 2023-03-17 一种hmac算法处理系统、方法、设备及非易失性可读存储介质

Country Status (2)

Country Link
CN (1) CN115442026B (zh)
WO (1) WO2024098613A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115442026B (zh) * 2022-11-07 2023-03-24 苏州浪潮智能科技有限公司 一种hmac算法处理系统、方法、设备及介质

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140064483A1 (en) * 2010-06-04 2014-03-06 Kabushiki Kaisha Toshiba Computer program product and method for processing information to obtain an hmac
CN111953497A (zh) * 2020-08-06 2020-11-17 山东云海国创云计算装备产业创新中心有限公司 一种基于hmac算法的消息认证码生成装置及方法
CN114362920A (zh) * 2021-12-21 2022-04-15 浪潮金融信息技术有限公司 一种基于hmac控件的消息认证方法、系统及介质
CN115442026A (zh) * 2022-11-07 2022-12-06 苏州浪潮智能科技有限公司 一种hmac算法处理系统、方法、设备及介质

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2007164589A (ja) * 2005-12-15 2007-06-28 Seiko Epson Corp Hmac演算回路
KR100901697B1 (ko) * 2007-07-09 2009-06-08 한국전자통신연구원 저전력 sha-1 해쉬 연산 장치 및 이를 이용한 저전력hmac 암호 장치
CN103166931A (zh) * 2011-12-15 2013-06-19 华为技术有限公司 一种安全传输数据方法,装置和系统
CN111464308B (zh) * 2020-03-12 2022-07-01 烽火通信科技股份有限公司 一种实现多种哈希算法可重构的方法和系统
CN114584291B (zh) * 2022-02-18 2023-12-29 杭州代码狗科技有限公司 基于hmac算法的密钥保护方法、装置、设备和存储介质

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140064483A1 (en) * 2010-06-04 2014-03-06 Kabushiki Kaisha Toshiba Computer program product and method for processing information to obtain an hmac
CN111953497A (zh) * 2020-08-06 2020-11-17 山东云海国创云计算装备产业创新中心有限公司 一种基于hmac算法的消息认证码生成装置及方法
CN114362920A (zh) * 2021-12-21 2022-04-15 浪潮金融信息技术有限公司 一种基于hmac控件的消息认证方法、系统及介质
CN115442026A (zh) * 2022-11-07 2022-12-06 苏州浪潮智能科技有限公司 一种hmac算法处理系统、方法、设备及介质

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
KRISHNAMOORTHY R.; ARUN S.; SUJITHA N.; VIJAYALAKSHMI K.M; KARTHIGA S.; THIAGARAJAN R.: "Proposal of HMAC based Protocol for Message Authenication in Kerberos Authentication Protocol", 2022 SECOND INTERNATIONAL CONFERENCE ON ARTIFICIAL INTELLIGENCE AND SMART ENERGY (ICAIS), IEEE, 23 February 2022 (2022-02-23), pages 1443 - 1447, XP034107670, DOI: 10.1109/ICAIS53314.2022.9742992 *
LI DANFENG, WANG FEI; ZHAO GUO-HONG: "A Real-time HMAC-SM3 Acceleration Engine for Large Network Traffic", COMPUTER ENGINEERING AND SCIENCE, GUOFANG KEJI DAXUE JISUANJI XUEYUAN, CN, vol. 43, no. 1, 31 October 2021 (2021-10-31), CN , pages 82 - 88, XP093171859, ISSN: 1007-130X, DOI: 10.3969/j.issn.1007-130X.2021.01.010 *

Also Published As

Publication number Publication date
CN115442026B (zh) 2023-03-24
CN115442026A (zh) 2022-12-06

Similar Documents

Publication Publication Date Title
US20200349866A1 (en) Lightweight cryptographic engine
US20200241915A1 (en) Work conserving, load balancing, and scheduling
US10455063B2 (en) Packet flow classification
US8918646B2 (en) Data processing apparatus
US9158810B2 (en) Hardware message queues for intra-cluster communication
US8856198B2 (en) Random value production methods and systems
CN105531713A (zh) 从单个数据缓冲器生成多个安全散列
US20060023877A1 (en) Encryption apparatus and encryption method
US20100293312A1 (en) Network Communications Processor Architecture
WO2024098613A1 (zh) 一种hmac算法处理系统、方法、设备及非易失性可读存储介质
US20230102617A1 (en) Repeat transaction verification method, apparatus, and device, and medium
WO2023070924A1 (zh) 区块链交易的处理方法和系统
WO2022143536A1 (zh) 基于APSoC的国密计算方法、系统、设备及介质
US20230102374A1 (en) Data Encryption Or Decryption Method, Apparatus, And System
US20190362082A1 (en) Data processing device and operating method therefor
WO2017157006A1 (zh) 一种密钥处理方法及装置
WO2023070925A1 (zh) 区块链交易池的分片方法、系统、存储介质和计算机系统
US9092283B2 (en) Systems with multiple port random number generators and methods of their operation
CN112035866A (zh) 一种数据加解密方法、装置、设备和计算机可读存储介质
US20130179675A1 (en) Composite system, method, and storage medium
US20230350676A1 (en) Tensor Processing Method, Apparatus, and Device, and Computer-Readable Storage Medium
WO2021136014A1 (zh) 一种安全计算控制方法、数据包处理方法、装置及其系统
CN115525887A (zh) 基于hmac-sha的消息摘要生成装置、方法及计算机设备
CN117290897A (zh) 加解密电路、处理系统及电子设备
CN114140114A (zh) X个标准交易池的调用方法、系统、介质和计算机系统

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 23887321

Country of ref document: EP

Kind code of ref document: A1