1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2019 Huawei Technologies Co., Ltd
4  */
5 #ifndef CORE_CRYPTO_SM4_H
6 #define CORE_CRYPTO_SM4_H
7 
8 #include <stddef.h>
9 #include <stdint.h>
10 
11 #define SM4_ENCRYPT	1
12 #define SM4_DECRYPT	0
13 
14 struct sm4_context {
15 	int mode;         /* SM4_ENCRYPT/SM4_DECRYPT */
16 	uint32_t sk[32];  /* SM4 subkeys */
17 };
18 
19 void sm4_setkey_enc(struct sm4_context *ctx, const uint8_t key[16]);
20 void sm4_setkey_dec(struct sm4_context *ctx, const uint8_t key[16]);
21 void sm4_crypt_ecb(struct sm4_context *ctx, size_t length, const uint8_t *input,
22 		   uint8_t *output);
23 void sm4_crypt_cbc(struct sm4_context *ctx, size_t length, uint8_t iv[16],
24 		   const uint8_t *input, uint8_t *output);
25 void sm4_crypt_ctr(struct sm4_context *ctx, size_t length, uint8_t ctr[16],
26 		   const uint8_t *input, uint8_t *output);
27 
28 #endif /* CORE_CRYPTO_SM4_H */
29