This standard is developed in accordance with the rules given in GB/T 1.1-2009.
This part was proposed by the State Cryptography Administration of the People’s Republic of China.
This part is under the jurisdiction of SAC/TC 260 National Technical Committee on Information Technology Security of Standardization Administration of China.
Drafting organizations of this part: Tsinghua University, State Commercial Cryptography Testing Center, Information Engineering University, DCS Center of Chinese Academy of Sciences.
Chief drafting staff of this part: Wang Xiaoyun, Li Zheng, Wang Yongchuan, Yu Hongbo, Xie Yongquan, Zhang Chao, Luo Peng, Lv Shuwang
Information security techniques - SM3 cryptographic hash algorithm
1 Scope
This standard specifies computing methods and steps of SM3 cryptographic hash algorithm and corresponding operation examples.
It is applicable to digital signature and verification, generation and verification of message authentication code and random number generation in commercial cypher application, which can meet the security requirements of various cryptography applications.
2 Terms and definitions
For the purposes of this document, the following terms and definitions apply.
2.1
bit string
binary digit sequence composed of 0 and 1
2.2
big-endian
a representation format of data in memory, specifying the high significant bit at left and the low significant bit at right, i.e. high order byte of digit is placed at the low address of reservoir and low order byte of digit at the high address of reservoir
2.3
message
a bit string with any finite length, used as input data for the hash algorithm in this standard
2.4
hash value
output message digest (bit string) when hash algorithm works on a message
2.5
word
set (string) with length of 32-bit
3 Symbols
For the purposes of this document, the following symbol applies.
ABCDEFGH: registers of 8 words or concatenation of their values
B(i): the ith message grouping
CF: the compression function
FFj: the Boolean function, different equations are taken depending on j
GGj: the Boolean function, different equations are taken depending on j
IV: the initial value, used to determine the initial state of the compression function register
P0: the permutation function in compression function
P1: the permutation function in message extension
Tj: the constant, different values are taken depending on j
m: the message
m': the message after filling
mod: the modulo operation
n: the number of message grouping
∧: 32 bits and operation
∨: 32 bits or operation
⊕: 32 bits exclusive-or operation
¬: 32 bits non-operation
+: mod 232 addition arithmetic operation
<<
Foreword i
1 Scope
2 Terms and definitions
3 Symbols
4 Constant and functions
4.1 Initial value
4.2 Constant
4.3 Boolean function
4.4 Permutation function
5 Algorithm description
5.1 General
5.2 Filling
5.3 Iterative compression
5.4 Outputting hash value
Annex A (Informative) Operation examples
ICS 35.040
L 80
GB/T 32905-2016
信息安全技术 SM3密码杂凑算法
Information security techniques—SM3 cryptographic hash algorithm
2016-08-29发布 2017-03-01实施
中华人民共和国国家质量监督检验检疫总局 中国国家标准化管理委员会 发布
前言
本部分按照GB/T 1.1—2009给出的规则起草。
本部分由国家密码管理局提出。
本部分由全国信息安全标准化技术委员会(SAC/TC 260)归口。
本标准起草单位:清华大学、国家密码管理局商用密码检测中心、解放军信息工程大学、中国科学院数据与通信保护研究教育中心
本标准起草人:Wang Xiaoyun, Li Zheng, Wang Yongchuan, Yu Hongbo, Xie Yongquan, Zhang Chao, Luo Peng, Lv Xuwang.
信息安全技术 SM3密码杂凑算法
1. 范围
本标准规定了SM3密码杂凑算法的计算方法和计算步骤,并给出了运算示例。
本标准适用于商用密码应用中的数字签名和验证、消息认证码的生成与验证以及随机数的生成,可满足多种密码应用的安全需求。
2术语和定义
下列属于和定义适用于本文件
2.1
比特串 bit string
由0和1组成的二进制数字序列。
2.2
大端 big-endian
数据在内存中的一种表示格式,规定左边为高有效位,右边为低有效位。即数的高阶字节放在存储器的低地址,数的低阶字节放在存储器的高地址。
2.3
消息 message
任意有限长度的比特串。本标准中消息作为杂凑算法的输入数据。
2.4
杂凑值 hash value
杂凑算法作用于一条消息时输出的消息摘要(比特串)。
2.5
字 word
长度为 32的比特的组(串)。
3 符号
下列符号适用于本文本。
ABCDEFGH: 8个字寄存器或它们的值的串连
B(i) :第 i 个消息分组
CF :压缩函数
FFj :布尔函数,随j的变化取不同的表达式
GGj :布尔函数,随j的变化取不同的表达式
IV :初始值,用于确定压缩函数寄存器的初态
P0:压缩函数中的置换函数
P1:消息扩展中的置换函数
Tj :常量,随j的变化取不同的值
m :消息
m′:填充后的消息
mod :模运算
n: 消息分组个数
∧ :32比特与运算
∨ :32比特或运算
⊕ :32比特异或运算
¬:32比特非运算
+:mod 232算术加运算
<<< k :32比特循环左移k比特运算
←:左向赋值运算符
4常数与函数
4.1初始值
4.2 常量
4.3 布尔函数
其中,X,Y,Z为字。
4.4 置换函数
其中,X为字。
5算法描述
5.1概述
SM3密码杂凑算法的输入为长度为l(l<264)比特的消息m,经过填充、迭代压缩,生成杂凑值,杂凑值输出长度为256比特。运算示例参见附录A。
5.2填充
假设消息m的长度为l比特。首先将比特“1”添加到消息的末尾,再添加k个“0”,k是满足l+1+k=448(mod 512)的最小的非负整数。然后再添加一个64位比特串,该比特串是长度l的二进制表示。填充后的消息m′的比特长度为512的倍数。
例如:对消息 01100001 01100010 01100011,其长度l =24,经填充得到比特串:
423比特
64比特
l的二进制表示
5.3 迭代压缩
5.3.1 迭代过程
将填充后的信息m’按512比特进行分组:m’= B(0)B(1)…B(n-1),其中n=(l+k+65)/512.
对m’按下列方法迭代:
FOR i=0 TO n-1
V(i+1)=CF(V(i),B(i))
ENDFOR
其中CF是压缩函数,V(0)为256比特初始值IV, B(i)为填充后的消息分组,迭代压缩结果为V(n)。
5.3.2 消息扩展
将消息分组B(i)按以下方法扩展生成132个消息字W0, W1,… W67, W’0,W’1,…W’63,用于压缩函数CF:
第一步,将消息分组B(i)划分为16个字W0, W1,… W15.
第二步,
第三步,
5.3.3 压缩函数
令A,B,C,D,E,F,G,G为字寄存器,SS1,SS2,TT1,TT2为中间变量,压缩函数Vi+=CF(V(i),B(i)), 0≤i≤n-1。 计算过程描述如下:
其中,字的存储为大端 (big-endian), 左边为高有效位,右边为低有效位。
5.4 输出杂凑值
ABCDEF GH ← V(n)
输出 256比特的杂凑值 y =ABCDEFGH。
附录A
(资料性附录)
运算示例
A.1 示例1
A1.1 输入十六进制数据
61263
A.1.2 填充后的消息
A.1.3 扩展后的消息
A.1.4 迭代压缩中间值
A.1.5 杂凑值
A.2 示例2
A.2.1 512比特消息
A.2.2 填充后的消息
A.2.3 第一个消息分组
A.2.3.1 扩展后的消息
A.2.3.2 迭代压缩中间值
A.2.4 第二个消息分组
A.2.4.1 扩展后的消息
W0W1...W67
A.2.4.2 迭代压缩的中间值
A.2.4.3 杂凑值