API参考
载入中...
搜索中...
未找到
crypt_aes.h
1/*
2 * This file is part of the openHiTLS project.
3 *
4 * openHiTLS is licensed under the Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:
7 *
8 * http://license.coscl.org.cn/MulanPSL2
9 *
10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13 * See the Mulan PSL v2 for more details.
14 */
15
16#ifndef CRYPT_AES_H
17#define CRYPT_AES_H
18
19#include "hitls_build.h"
20#ifdef HITLS_CRYPTO_AES
21
22#include <stdint.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif // __cplusplus
27
28#define CRYPT_AES_128 128
29#define CRYPT_AES_192 192
30#define CRYPT_AES_256 256
31
32#define CRYPT_AES_MAX_ROUNDS 14
33#define CRYPT_AES_MAX_KEYLEN (4 * (CRYPT_AES_MAX_ROUNDS + 1))
34
40typedef struct {
41 uint32_t key[CRYPT_AES_MAX_KEYLEN];
42 uint32_t rounds;
43} CRYPT_AES_Key;
44
53int32_t CRYPT_AES_SetEncryptKey128(CRYPT_AES_Key *ctx, const uint8_t *key, uint32_t len);
54
63int32_t CRYPT_AES_SetEncryptKey192(CRYPT_AES_Key *ctx, const uint8_t *key, uint32_t len);
64
73int32_t CRYPT_AES_SetEncryptKey256(CRYPT_AES_Key *ctx, const uint8_t *key, uint32_t len);
74
83int32_t CRYPT_AES_SetDecryptKey128(CRYPT_AES_Key *ctx, const uint8_t *key, uint32_t len);
84
93int32_t CRYPT_AES_SetDecryptKey192(CRYPT_AES_Key *ctx, const uint8_t *key, uint32_t len);
94
103int32_t CRYPT_AES_SetDecryptKey256(CRYPT_AES_Key *ctx, const uint8_t *key, uint32_t len);
104
114int32_t CRYPT_AES_Encrypt(const CRYPT_AES_Key *ctx, const uint8_t *in, uint8_t *out, uint32_t len);
115
125int32_t CRYPT_AES_Decrypt(const CRYPT_AES_Key *ctx, const uint8_t *in, uint8_t *out, uint32_t len);
126
127#ifdef HITLS_CRYPTO_CBC
138int32_t CRYPT_AES_CBC_Encrypt(const CRYPT_AES_Key *ctx, const uint8_t *in, uint8_t *out, uint32_t len, uint8_t *iv);
139
150int32_t CRYPT_AES_CBC_Decrypt(const CRYPT_AES_Key *ctx, const uint8_t *in, uint8_t *out, uint32_t len, uint8_t *iv);
151#endif /* HITLS_CRYPTO_CBC */
152
153#if defined(HITLS_CRYPTO_CTR) || defined(HITLS_CRYPTO_GCM)
164int32_t CRYPT_AES_CTR_Encrypt(const CRYPT_AES_Key *ctx, const uint8_t *in, uint8_t *out, uint32_t len, uint8_t *iv);
165#endif
166
167#ifdef HITLS_CRYPTO_ECB
177int32_t CRYPT_AES_ECB_Encrypt(const CRYPT_AES_Key *ctx, const uint8_t *in, uint8_t *out, uint32_t len);
178
188int32_t CRYPT_AES_ECB_Decrypt(const CRYPT_AES_Key *ctx, const uint8_t *in, uint8_t *out, uint32_t len);
189#endif
190
191#ifdef HITLS_CRYPTO_CFB
203int32_t CRYPT_AES_CFB_Decrypt(const CRYPT_AES_Key *ctx, const uint8_t *in, uint8_t *out, uint32_t len, uint8_t *iv);
204#endif
205
206#ifdef HITLS_CRYPTO_XTS
217int32_t CRYPT_AES_XTS_Encrypt(const CRYPT_AES_Key *ctx, const uint8_t *in,
218 uint8_t *out, uint32_t len, const uint8_t *tweak);
219
230int32_t CRYPT_AES_XTS_Decrypt(const CRYPT_AES_Key *ctx, const uint8_t *in,
231 uint8_t *out, uint32_t len, const uint8_t *t);
232#endif
233
241void CRYPT_AES_Clean(CRYPT_AES_Key *ctx);
242
243#ifdef __cplusplus
244}
245#endif // __cplusplus
246
247#endif // HITLS_CRYPTO_AES
248
249#endif // CRYPT_AES_H