1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2019 Huawei Technologies Co., Ltd
4  */
5 /**
6  * \file sm3.h
7  * thanks to Xyssl
8  * author:goldboar
9  * email:goldboar@163.com
10  * 2011-10-26
11  */
12 #ifndef CORE_CRYPTO_SM3_H
13 #define CORE_CRYPTO_SM3_H
14 
15 #include <stddef.h>
16 #include <stdint.h>
17 
18 struct sm3_context {
19 	uint32_t total[2];   /* number of bytes processed */
20 	uint32_t state[8];   /* intermediate digest state */
21 	uint8_t buffer[64];  /* data block being processed */
22 	uint8_t ipad[64];    /* HMAC: inner padding */
23 	uint8_t opad[64];    /* HMAC: outer padding */
24 };
25 
26 void sm3_init(struct sm3_context *ctx);
27 void sm3_update(struct sm3_context *ctx, const uint8_t *input, size_t ilen);
28 void sm3_final(struct sm3_context *ctx, uint8_t output[32]);
29 void sm3(const uint8_t *input, size_t ilen, uint8_t output[32]);
30 
31 void sm3_hmac_init(struct sm3_context *ctx, const uint8_t *key, size_t keylen);
32 void sm3_hmac_update(struct sm3_context *ctx, const uint8_t *input,
33 		     size_t ilen);
34 void sm3_hmac_final(struct sm3_context *ctx, uint8_t output[32]);
35 void sm3_hmac(const uint8_t *key, size_t keylen, const uint8_t *input,
36 	      size_t ilen, uint8_t output[32]);
37 
38 #endif /* CORE_CRYPTO_SM3_H */
39