1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Common values for SM3 algorithm
5 * Copyright (C) 2017 ARM Limited or its affiliates.
6 * Copyright (C) 2017 Gilad Ben-Yossef <gilad@benyossef.com>
7 * Copyright (C) 2021 Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
13 #include <linux/types.h>
15 #define SM3_DIGEST_SIZE 32
16 #define SM3_BLOCK_SIZE 64
18 #define SM3_T1 0x79CC4519
19 #define SM3_T2 0x7A879D8A
21 #define SM3_IVA 0x7380166f
22 #define SM3_IVB 0x4914b2b9
23 #define SM3_IVC 0x172442d7
24 #define SM3_IVD 0xda8a0600
25 #define SM3_IVE 0xa96f30bc
26 #define SM3_IVF 0x163138aa
27 #define SM3_IVG 0xe38dee4d
28 #define SM3_IVH 0xb0fb0e4e
30 extern const u8 sm3_zero_message_hash[SM3_DIGEST_SIZE];
33 u32 state[SM3_DIGEST_SIZE / 4];
35 u8 buffer[SM3_BLOCK_SIZE];
39 * Stand-alone implementation of the SM3 algorithm. It is designed to
40 * have as little dependencies as possible so it can be used in the
41 * kexec_file purgatory. In other cases you should generally use the
42 * hash APIs from include/crypto/hash.h. Especially when hashing large
43 * amounts of data as those APIs may be hw-accelerated.
45 * For details see lib/crypto/sm3.c
48 static inline void sm3_init(struct sm3_state *sctx)
50 sctx->state[0] = SM3_IVA;
51 sctx->state[1] = SM3_IVB;
52 sctx->state[2] = SM3_IVC;
53 sctx->state[3] = SM3_IVD;
54 sctx->state[4] = SM3_IVE;
55 sctx->state[5] = SM3_IVF;
56 sctx->state[6] = SM3_IVG;
57 sctx->state[7] = SM3_IVH;
61 void sm3_update(struct sm3_state *sctx, const u8 *data, unsigned int len);
62 void sm3_final(struct sm3_state *sctx, u8 *out);