brintos

brintos / linux-shallow public Read only

0
0
Text · 1.6 KiB · 1f021ad Raw
65 lines · c
1/* SPDX-License-Identifier: GPL-2.0-only */2/*3 * Common values for SM3 algorithm4 *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_H11#define _CRYPTO_SM3_H12 13#include <linux/types.h>14 15#define SM3_DIGEST_SIZE	3216#define SM3_BLOCK_SIZE	6417 18#define SM3_T1		0x79CC451919#define SM3_T2		0x7A879D8A20 21#define SM3_IVA		0x7380166f22#define SM3_IVB		0x4914b2b923#define SM3_IVC		0x172442d724#define SM3_IVD		0xda8a060025#define SM3_IVE		0xa96f30bc26#define SM3_IVF		0x163138aa27#define SM3_IVG		0xe38dee4d28#define SM3_IVH		0xb0fb0e4e29 30extern const u8 sm3_zero_message_hash[SM3_DIGEST_SIZE];31 32struct sm3_state {33	u32 state[SM3_DIGEST_SIZE / 4];34	u64 count;35	u8 buffer[SM3_BLOCK_SIZE];36};37 38/*39 * Stand-alone implementation of the SM3 algorithm. It is designed to40 * have as little dependencies as possible so it can be used in the41 * kexec_file purgatory. In other cases you should generally use the42 * hash APIs from include/crypto/hash.h. Especially when hashing large43 * amounts of data as those APIs may be hw-accelerated.44 *45 * For details see lib/crypto/sm3.c46 */47 48static inline void sm3_init(struct sm3_state *sctx)49{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;58	sctx->count = 0;59}60 61void sm3_update(struct sm3_state *sctx, const u8 *data, unsigned int len);62void sm3_final(struct sm3_state *sctx, u8 *out);63 64#endif65