1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
2 | /* |
3 | * Common values for SM3 algorithm |
4 | * |
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> |
8 | */ |
9 | |
10 | #ifndef _CRYPTO_SM3_H |
11 | #define _CRYPTO_SM3_H |
12 | |
13 | #include <linux/types.h> |
14 | |
15 | #define SM3_DIGEST_SIZE 32 |
16 | #define SM3_BLOCK_SIZE 64 |
17 | #define SM3_STATE_SIZE 40 |
18 | |
19 | #define SM3_T1 0x79CC4519 |
20 | #define SM3_T2 0x7A879D8A |
21 | |
22 | #define SM3_IVA 0x7380166f |
23 | #define SM3_IVB 0x4914b2b9 |
24 | #define SM3_IVC 0x172442d7 |
25 | #define SM3_IVD 0xda8a0600 |
26 | #define SM3_IVE 0xa96f30bc |
27 | #define SM3_IVF 0x163138aa |
28 | #define SM3_IVG 0xe38dee4d |
29 | #define SM3_IVH 0xb0fb0e4e |
30 | |
31 | extern const u8 sm3_zero_message_hash[SM3_DIGEST_SIZE]; |
32 | |
33 | struct sm3_state { |
34 | u32 state[SM3_DIGEST_SIZE / 4]; |
35 | u64 count; |
36 | u8 buffer[SM3_BLOCK_SIZE]; |
37 | }; |
38 | |
39 | /* |
40 | * Stand-alone implementation of the SM3 algorithm. It is designed to |
41 | * have as little dependencies as possible so it can be used in the |
42 | * kexec_file purgatory. In other cases you should generally use the |
43 | * hash APIs from include/crypto/hash.h. Especially when hashing large |
44 | * amounts of data as those APIs may be hw-accelerated. |
45 | * |
46 | * For details see lib/crypto/sm3.c |
47 | */ |
48 | |
49 | static inline void sm3_init(struct sm3_state *sctx) |
50 | { |
51 | sctx->state[0] = SM3_IVA; |
52 | sctx->state[1] = SM3_IVB; |
53 | sctx->state[2] = SM3_IVC; |
54 | sctx->state[3] = SM3_IVD; |
55 | sctx->state[4] = SM3_IVE; |
56 | sctx->state[5] = SM3_IVF; |
57 | sctx->state[6] = SM3_IVG; |
58 | sctx->state[7] = SM3_IVH; |
59 | sctx->count = 0; |
60 | } |
61 | |
62 | void sm3_block_generic(struct sm3_state *sctx, u8 const *data, int blocks); |
63 | |
64 | #endif |
65 | |