1*eb90686dSTianjia Zhang /* SPDX-License-Identifier: GPL-2.0-only */ 24f0fc160SGilad Ben-Yossef /* 34f0fc160SGilad Ben-Yossef * Common values for SM3 algorithm 4*eb90686dSTianjia Zhang * 5*eb90686dSTianjia Zhang * Copyright (C) 2017 ARM Limited or its affiliates. 6*eb90686dSTianjia Zhang * Copyright (C) 2017 Gilad Ben-Yossef <gilad@benyossef.com> 7*eb90686dSTianjia Zhang * Copyright (C) 2021 Tianjia Zhang <tianjia.zhang@linux.alibaba.com> 84f0fc160SGilad Ben-Yossef */ 94f0fc160SGilad Ben-Yossef 104f0fc160SGilad Ben-Yossef #ifndef _CRYPTO_SM3_H 114f0fc160SGilad Ben-Yossef #define _CRYPTO_SM3_H 124f0fc160SGilad Ben-Yossef 134f0fc160SGilad Ben-Yossef #include <linux/types.h> 144f0fc160SGilad Ben-Yossef 154f0fc160SGilad Ben-Yossef #define SM3_DIGEST_SIZE 32 164f0fc160SGilad Ben-Yossef #define SM3_BLOCK_SIZE 64 174f0fc160SGilad Ben-Yossef 184f0fc160SGilad Ben-Yossef #define SM3_T1 0x79CC4519 194f0fc160SGilad Ben-Yossef #define SM3_T2 0x7A879D8A 204f0fc160SGilad Ben-Yossef 214f0fc160SGilad Ben-Yossef #define SM3_IVA 0x7380166f 224f0fc160SGilad Ben-Yossef #define SM3_IVB 0x4914b2b9 234f0fc160SGilad Ben-Yossef #define SM3_IVC 0x172442d7 244f0fc160SGilad Ben-Yossef #define SM3_IVD 0xda8a0600 254f0fc160SGilad Ben-Yossef #define SM3_IVE 0xa96f30bc 264f0fc160SGilad Ben-Yossef #define SM3_IVF 0x163138aa 274f0fc160SGilad Ben-Yossef #define SM3_IVG 0xe38dee4d 284f0fc160SGilad Ben-Yossef #define SM3_IVH 0xb0fb0e4e 294f0fc160SGilad Ben-Yossef 304f0fc160SGilad Ben-Yossef extern const u8 sm3_zero_message_hash[SM3_DIGEST_SIZE]; 314f0fc160SGilad Ben-Yossef 324f0fc160SGilad Ben-Yossef struct sm3_state { 334f0fc160SGilad Ben-Yossef u32 state[SM3_DIGEST_SIZE / 4]; 344f0fc160SGilad Ben-Yossef u64 count; 354f0fc160SGilad Ben-Yossef u8 buffer[SM3_BLOCK_SIZE]; 364f0fc160SGilad Ben-Yossef }; 374f0fc160SGilad Ben-Yossef 38*eb90686dSTianjia Zhang /* 39*eb90686dSTianjia Zhang * Stand-alone implementation of the SM3 algorithm. It is designed to 40*eb90686dSTianjia Zhang * have as little dependencies as possible so it can be used in the 41*eb90686dSTianjia Zhang * kexec_file purgatory. In other cases you should generally use the 42*eb90686dSTianjia Zhang * hash APIs from include/crypto/hash.h. Especially when hashing large 43*eb90686dSTianjia Zhang * amounts of data as those APIs may be hw-accelerated. 44*eb90686dSTianjia Zhang * 45*eb90686dSTianjia Zhang * For details see lib/crypto/sm3.c 46*eb90686dSTianjia Zhang */ 47*eb90686dSTianjia Zhang sm3_init(struct sm3_state * sctx)48*eb90686dSTianjia Zhangstatic inline void sm3_init(struct sm3_state *sctx) 49*eb90686dSTianjia Zhang { 50*eb90686dSTianjia Zhang sctx->state[0] = SM3_IVA; 51*eb90686dSTianjia Zhang sctx->state[1] = SM3_IVB; 52*eb90686dSTianjia Zhang sctx->state[2] = SM3_IVC; 53*eb90686dSTianjia Zhang sctx->state[3] = SM3_IVD; 54*eb90686dSTianjia Zhang sctx->state[4] = SM3_IVE; 55*eb90686dSTianjia Zhang sctx->state[5] = SM3_IVF; 56*eb90686dSTianjia Zhang sctx->state[6] = SM3_IVG; 57*eb90686dSTianjia Zhang sctx->state[7] = SM3_IVH; 58*eb90686dSTianjia Zhang sctx->count = 0; 59*eb90686dSTianjia Zhang } 60*eb90686dSTianjia Zhang 61*eb90686dSTianjia Zhang void sm3_update(struct sm3_state *sctx, const u8 *data, unsigned int len); 62*eb90686dSTianjia Zhang void sm3_final(struct sm3_state *sctx, u8 *out); 63*eb90686dSTianjia Zhang 644f0fc160SGilad Ben-Yossef #endif 65