Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Common values for SM3 algorithm
0004  *
0005  * Copyright (C) 2017 ARM Limited or its affiliates.
0006  * Copyright (C) 2017 Gilad Ben-Yossef <gilad@benyossef.com>
0007  * Copyright (C) 2021 Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
0008  */
0009 
0010 #ifndef _CRYPTO_SM3_H
0011 #define _CRYPTO_SM3_H
0012 
0013 #include <linux/types.h>
0014 
0015 #define SM3_DIGEST_SIZE 32
0016 #define SM3_BLOCK_SIZE  64
0017 
0018 #define SM3_T1      0x79CC4519
0019 #define SM3_T2      0x7A879D8A
0020 
0021 #define SM3_IVA     0x7380166f
0022 #define SM3_IVB     0x4914b2b9
0023 #define SM3_IVC     0x172442d7
0024 #define SM3_IVD     0xda8a0600
0025 #define SM3_IVE     0xa96f30bc
0026 #define SM3_IVF     0x163138aa
0027 #define SM3_IVG     0xe38dee4d
0028 #define SM3_IVH     0xb0fb0e4e
0029 
0030 extern const u8 sm3_zero_message_hash[SM3_DIGEST_SIZE];
0031 
0032 struct sm3_state {
0033     u32 state[SM3_DIGEST_SIZE / 4];
0034     u64 count;
0035     u8 buffer[SM3_BLOCK_SIZE];
0036 };
0037 
0038 /*
0039  * Stand-alone implementation of the SM3 algorithm. It is designed to
0040  * have as little dependencies as possible so it can be used in the
0041  * kexec_file purgatory. In other cases you should generally use the
0042  * hash APIs from include/crypto/hash.h. Especially when hashing large
0043  * amounts of data as those APIs may be hw-accelerated.
0044  *
0045  * For details see lib/crypto/sm3.c
0046  */
0047 
0048 static inline void sm3_init(struct sm3_state *sctx)
0049 {
0050     sctx->state[0] = SM3_IVA;
0051     sctx->state[1] = SM3_IVB;
0052     sctx->state[2] = SM3_IVC;
0053     sctx->state[3] = SM3_IVD;
0054     sctx->state[4] = SM3_IVE;
0055     sctx->state[5] = SM3_IVF;
0056     sctx->state[6] = SM3_IVG;
0057     sctx->state[7] = SM3_IVH;
0058     sctx->count = 0;
0059 }
0060 
0061 void sm3_update(struct sm3_state *sctx, const u8 *data, unsigned int len);
0062 void sm3_final(struct sm3_state *sctx, u8 *out);
0063 
0064 #endif