CN114422110A - 一种面向长指令字的sm3哈希函数消息处理的快速实现方法 - Google Patents
一种面向长指令字的sm3哈希函数消息处理的快速实现方法 Download PDFInfo
- Publication number
- CN114422110A CN114422110A CN202210321831.3A CN202210321831A CN114422110A CN 114422110 A CN114422110 A CN 114422110A CN 202210321831 A CN202210321831 A CN 202210321831A CN 114422110 A CN114422110 A CN 114422110A
- Authority
- CN
- China
- Prior art keywords
- algorithm
- vector
- instruction set
- parallel
- variables
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 21
- 239000013598 vector Substances 0.000 claims abstract description 52
- 238000004364 calculation method Methods 0.000 claims description 21
- 229910052754 neon Inorganic materials 0.000 claims description 14
- GKAOGPIIYCISHV-UHFFFAOYSA-N neon atom Chemical compound [Ne] GKAOGPIIYCISHV-UHFFFAOYSA-N 0.000 claims description 14
- 230000008569 process Effects 0.000 claims description 5
- 238000005457 optimization Methods 0.000 abstract description 4
- 230000006870 function Effects 0.000 description 23
- 230000006835 compression Effects 0.000 description 5
- 238000007906 compression Methods 0.000 description 5
- 125000004122 cyclic group Chemical group 0.000 description 3
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000004891 communication Methods 0.000 description 1
- 238000010276 construction Methods 0.000 description 1
- 230000001419 dependent effect Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 238000012886 linear function Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 239000000126 substance Substances 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L9/00—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
- H04L9/06—Cryptographic 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/0643—Hash functions, e.g. MD5, SHA, HMAC or f9 MAC
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/30—Arrangements for executing machine instructions, e.g. instruction decode
- G06F9/30003—Arrangements for executing specific machine instructions
- G06F9/30007—Arrangements for executing specific machine instructions to perform operations on data operands
- G06F9/30036—Instructions to perform operations on packed data, e.g. vector, tile or matrix operations
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L2209/00—Additional information or applications relating to cryptographic mechanisms or cryptographic arrangements for secret or secure communication H04L9/00
- H04L2209/12—Details relating to cryptographic hardware or logic circuitry
- H04L2209/125—Parallelization or pipelining, e.g. for accelerating processing of cryptographic operations
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- Mathematical Physics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Power Engineering (AREA)
- Computer Security & Cryptography (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Storage Device Security (AREA)
- Executing Machine-Instructions (AREA)
Abstract
Description
技术领域
本发明属于安全密码应用技术领域,具体涉及一种面向长指令字的SM3哈希函数消息处理的快速实现方法。
背景技术
密码杂凑(Hash)函数是一类用途广泛的基础密码算法,除了用于计算数据杂凑值之外,还是数字签名、消息认证码等众多密码方案、安全协议的基本组成部分。常用的密码杂凑函数包括美国国家标准与技术研究所(NIST)发布的SHA-1算法、SHA-2系列算法、由欧洲研究者设计的RIPEMD-160算法、NIST评选的SHA-3算法等。密码杂凑函数的典型应用经常涉及大量数据处理和高速网络通信,这些应用场景对密码杂凑函数的实现性能有较高的要求。为了提高密码杂凑函数的处理速度,处理器厂商开始在CPU中提供了常用密码杂凑函数的硬件实现,例如Intel在其部分处理器中增加了支持SHA-1和SHA-256计算的CPU指令,这些算法的专用硬件指令实现相对于软件实现有非常大的性能提升。
SM3密码杂凑函数是由中国国家密码管理局公布的中国密码行业标准,用于在商用领域中取代SHA-1、SHA-2等国外算法。SM3也是目前中国商用密码标准体系中唯一的密码杂凑函数,是SM2公钥密码算法、SSL VPN协议等商用密码标准中的关键组成部分。由于目前使用最广泛的Intel/AMD X86处理器和ARM处理器并不提供SM3算法的硬件实现,故如何在这些通用处理器上提供SM3算法的高性能软件实现对SM3算法的实际应用具有重要的意义。
SM3密码杂凑函数采用了典型的Merkle-Damgård构造。算法的核心是一个压缩函数,压缩函数具有256位的内部状态,512位消息经过消息扩展函数变化后,通过压缩函数压入256位的内部状态,通过64轮迭代,输出256位的结果。SM3算法的基本运算单位是32位字。根据我国发布的《SM3密码杂凑算法》,该算法涉及的部分运算符号及相应的含义如下:
mod :模运算;
原始标准SM3消息扩展函数定义如下:
SM3消息扩展算法如下:
目前主流的CPU除了基本的通用指令集之外,还包括SIMD (Single Instruction,Multiple Data)指令集等扩展指令集,例如目前主流的Intel和AMD的X86处理器支持AVX/AVX2指令集,ARM Cortex-A系列架构的移动处理器支持NEON指令集。SIMD指令集又称为向量指令集,一般提供一组和通用指令集不共享的寄存器,SIMD指令集可以在向量寄存器上执行并行计算,一个指令可以对向量寄存器中的一组数据做并行计算。
Intel AVX-2支持256位的指令集,AVX2指令集包含16个256位的向量寄存器,可以执行8路32位标量的向量计算。目前Intel和AMD的主流笔记本、桌面处理器中均支持AVX2指令集。Intel已经公布了AVX-512指令集,Haswell架构的处理器中支持AVX-512指令集。AVX-512指令集包含32个512位的向量寄存器,可以执行16路的32位字向量运算。NEON是ARMCortex-A架构的SIMD指令集。NEON架构包含16个128位的SIMD寄存器,可以这些寄存器上执行4路的32位标量的向量计算。
目前主流的Intel/AMD X86处理器和ARM处理器,都可以同时支持非向量指令集和向量指令集的计算,在ARM/NEON指令集、X86/AVX2指令集的计算平台上,常规的并行算法,往往是通过向量寄存器多路并行,同时执行多个SM3算法,但是这样的算法在执行的时候不能充分利用非向量处理器的计算资源,也无法提高单个SM3密码算法的运算速度。迫切需要一种计算资源利用更加充分,单线程SM3运算速度更快的算法。
发明内容
为了在并行环境中实现更加高效的SM3算法,针对SM3的68个字长度的变量,本发明提出一种面向长指令字的SM3哈希函数消息处理的快速实现方法,本方法为一种SM3的68个字长度的变量的并行化算法,并在SIMD指令集上的实现。本发明可以同时利用处理器内的向量指令运算和非向量指令运算,加快变量运算速度,从而加快SM3密码杂凑的运算速度,更加充分地利用处理器的计算资源。
本发明提出一种面向长指令字的SM3哈希函数消息处理的快速实现方法,包括以下步骤:
上述步骤3)中的并行计算使用SIMD指令集中的向量指令执行,SM3算法的非并行部分使用SIMD指令集中的非向量指令执行。
进一步地,该并行化优化方法在可同时执行向量指令和非向量指令的计算平台上,能够得到更高的SM3计算速率。
进一步地,SIMD指令集包括ARM/NEON指令集或X86/AVX2指令集,符号/表示兼有。
具体实施方式
为使本发明的上述特征和优点能更明显易懂,下文特举实施例,作详细说明如下。
本发明实施例提供一种面向长指令字的SM3哈希函数消息处理的快速实现方法,以6轮迭代并行化为例,多路并行算法将SM3密码杂凑算法的展开与并行化过程具体包括如下步骤:
下面将描述如何将对上述6轮并行算法进行向量实现。
在具备向量指令的条件(即CPU支持向量指令集,利用向量指令集提供的向量寄存器可以执行多路并行计算)下,一批变量的相同运算可以同时执行,比如向量长度为6字的异或运算可以同时计算得到结果。因此,上述变量可以并行计算,将本来需要6次才能运算得到的结果,通过向量指令集一次计算得到。
结合具体的指令集,将上述6路并行算法的计算过程实现。
可以看到,本发明方法进行6路并行将计算同样变量的所需的运算次数降低。
以下给出对本发明方法进行具体实现的两组实施例。
实施例1:ARM/NEON指令集实现。
ARM处理器是目前手机等智能移动设备采用的主流处理器,其中部署最广泛的Cortex-A系列ARM处理器架构除了包含ARM通用指令集(ARMv7指令集),还包含NEON SIMD指令集。NEON指令集包含16个128位的SIMD寄存器,可以做4路32位字的并行计算,因此可以将本发明的SM3压缩函数4路并行算法中的向量计算以NEON指令实现,除了上述向量指令以外的其他指令以常规的ARM通用指令实现,可以使用高级语言编写并通过编译实现。
下面给出用到的NEON指令,这些指令以伪函数(Intrinsics)的方式给出,该伪函数是指下文的veorq_s32、vrshlq_s32、vaddq_s32、vld1q_s32,其中int32x4_t为128位的NEON向量寄存器:
实施例2:X86/AVX2指令集实现。
非向量指令代码可以使用高级语言编写并通过编译实现,向量指令使用AVX2指令实现。
向量左移 _mm256_sllv_epi32 (__m256i a, __m256i count);
向量右移 _mm256_srlv_epi32 (__m256i a, __m256i count);
向量或 _mm256_or_si256 (__m256i a, __m256i b)。
总的执行语句如下:
__mm256i c = mm256_or_si256 (_mm256_sllv_epi32 (a, k), _mm256_srlv_ epi32 (a, 32-k));
由于AVX2向量寄存器最大支持8个32比特字的计算,因此根据表1,需要12次 _ mm256_xor_si256指令、8次 _mm256_sllv_epi32 指令、8次 _mm256_srlv_epi32指令、8次 _mm256_or_si256指令完成1组的计算,总计36次逻辑运算。
需要注意的是,上述实施例的目的在于帮助进一步理解本发明,但是本领域的技术人员可以理解,在不脱离本发明及所附权利要求的精神和范围内,各种替换和修改都是可能的。因此,本发明不应局限于实施例所公开的内容,本发明要求保护的范围以权利要求书界定的范围为准。
Claims (6)
3.如权利要求2所述的方法,其特征在于,所述多路并行算法采用6路并行算法,在计算过程中进行6轮迭代。
6.如权利要求1所述的方法,其特征在于,SIMD指令集包括ARM/NEON指令集或X86/AVX2指令集,符号/表示兼有。
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210321831.3A CN114422110B (zh) | 2022-03-30 | 2022-03-30 | 一种面向长指令字的sm3哈希函数消息处理的快速实现方法 |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210321831.3A CN114422110B (zh) | 2022-03-30 | 2022-03-30 | 一种面向长指令字的sm3哈希函数消息处理的快速实现方法 |
Publications (2)
Publication Number | Publication Date |
---|---|
CN114422110A true CN114422110A (zh) | 2022-04-29 |
CN114422110B CN114422110B (zh) | 2022-08-23 |
Family
ID=81263552
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210321831.3A Active CN114422110B (zh) | 2022-03-30 | 2022-03-30 | 一种面向长指令字的sm3哈希函数消息处理的快速实现方法 |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114422110B (zh) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115664640A (zh) * | 2022-12-23 | 2023-01-31 | 苏州浪潮智能科技有限公司 | Sha-3算法的硬件实现方法、系统、存储介质及设备 |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106452769A (zh) * | 2016-09-13 | 2017-02-22 | 杭州华为数字技术有限公司 | 一种数据处理方法、数据处理装置以及处理器 |
EP3419213A1 (en) * | 2017-06-23 | 2018-12-26 | Vestel Elektronik Sanayi ve Ticaret A.S. | Computer implemented method, computer system and computer readable computer program product |
CN109547192A (zh) * | 2018-11-08 | 2019-03-29 | 北京大学 | Sm3密码杂凑算法的并行化优化方法 |
CN111752609A (zh) * | 2019-03-29 | 2020-10-09 | 英特尔公司 | 用于散列指令的装置、方法和系统 |
-
2022
- 2022-03-30 CN CN202210321831.3A patent/CN114422110B/zh active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106452769A (zh) * | 2016-09-13 | 2017-02-22 | 杭州华为数字技术有限公司 | 一种数据处理方法、数据处理装置以及处理器 |
EP3419213A1 (en) * | 2017-06-23 | 2018-12-26 | Vestel Elektronik Sanayi ve Ticaret A.S. | Computer implemented method, computer system and computer readable computer program product |
CN109547192A (zh) * | 2018-11-08 | 2019-03-29 | 北京大学 | Sm3密码杂凑算法的并行化优化方法 |
CN111752609A (zh) * | 2019-03-29 | 2020-10-09 | 英特尔公司 | 用于散列指令的装置、方法和系统 |
Non-Patent Citations (2)
Title |
---|
杨先伟等: "SM3杂凑算法的软件快速实现研究", 《智能系统学报》 * |
杨先伟等: "SM3杂凑算法的软件快速实现研究", 《智能系统学报》, vol. 10, no. 06, 31 December 2015 (2015-12-31) * |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115664640A (zh) * | 2022-12-23 | 2023-01-31 | 苏州浪潮智能科技有限公司 | Sha-3算法的硬件实现方法、系统、存储介质及设备 |
Also Published As
Publication number | Publication date |
---|---|
CN114422110B (zh) | 2022-08-23 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US8804951B2 (en) | Speeding up galois counter mode (GCM) computations | |
Bisheh-Niasar et al. | Cryptographic accelerators for digital signature based on Ed25519 | |
US8340280B2 (en) | Using a single instruction multiple data (SIMD) instruction to speed up galois counter mode (GCM) computations | |
CN109547192B (zh) | Sm3密码杂凑算法的并行化优化方法 | |
CN114422110B (zh) | 一种面向长指令字的sm3哈希函数消息处理的快速实现方法 | |
Jankowski et al. | Packed AES-GCM algorithm suitable for AES/PCLMULQDQ instructions | |
CN112367158A (zh) | 一种加速sm3算法的方法、处理器、芯片及电子设备 | |
US10855468B2 (en) | System and method for efficient implementation of prime field arithmetic in ARM processors | |
Gröbert | Automatic identification of cryptographic primitives in software | |
Roma et al. | Energy efficiency analysis of post-quantum cryptographic algorithms | |
Becker et al. | Hybrid scalar/vector implementations of Keccak and SPHINCS+ on AArch64 | |
CN113282947A (zh) | 一种基于sm4算法的数据加密方法、装置及计算机平台 | |
Gueron | AES-GCM for efficient authenticated encryption–ending the reign of HMAC-SHA-1 | |
Wang et al. | A hybrid CPU/GPU scheme for optimizing ChaCha20 stream cipher | |
Zhao et al. | Efficient implementation of kyber on mobile devices | |
Song et al. | High-speed fault attack resistant implementation of PIPO block cipher on ARM cortex-A | |
Drucker et al. | Fast constant time implementations of ZUC-256 on x86 CPUs | |
Henzen et al. | VLSI hardware evaluation of the stream ciphers Salsa20 and ChaCha, and the compression function Rumba | |
Aoki et al. | The security and performance of “GCM” when short multiplications are used instead | |
Goll et al. | Vectorization of Poly1305 message authentication code | |
Junod et al. | Revisiting the IDEA philosophy | |
Seo et al. | Compact GCM implementations on 32-bit ARMv7-A processors | |
Jalali et al. | Optimized supersingular isogeny key encapsulation on armv8 processors | |
Lemmen et al. | Optimizing Elephant for RISC-V | |
Seo et al. | Portable and Efficient Implementation of CRYSTALS-Kyber Based on WebAssembly. |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |