blob: 0899943d563a0eb9f516a997fb05b53f8d4dfceb [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/* aes.h
2 *
3 * Copyright (C) 2006-2021 wolfSSL Inc.
4 *
5 * This file is part of wolfSSL.
6 *
7 * wolfSSL is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * wolfSSL is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20 */
21
22
23
24/* aes.h defines mini des openssl compatibility layer
25 *
26 */
27
28
29#ifndef WOLFSSL_AES_H_
30#define WOLFSSL_AES_H_
31
32#include <wolfssl/wolfcrypt/settings.h>
33
34#ifndef NO_AES
35#include <wolfssl/openssl/ssl.h> /* for size_t */
36
37#ifdef __cplusplus
38 extern "C" {
39#endif
40
41/* This structure wrapper is done because there is no aes_new function with
42 * OpenSSL compatibility layer. This makes code working with an AES structure
43 * to need the size of the structure. */
44typedef struct WOLFSSL_AES_KEY {
45 ALIGN16 void *buf[(sizeof(Aes) / sizeof(void *)) + 1];
46} WOLFSSL_AES_KEY;
47typedef WOLFSSL_AES_KEY AES_KEY;
48
49WOLFSSL_API int wolfSSL_AES_set_encrypt_key
50 (const unsigned char *, const int bits, AES_KEY *);
51WOLFSSL_API int wolfSSL_AES_set_decrypt_key
52 (const unsigned char *, const int bits, AES_KEY *);
53WOLFSSL_API void wolfSSL_AES_cbc_encrypt
54 (const unsigned char *in, unsigned char* out, size_t len,
55 AES_KEY *key, unsigned char* iv, const int enc);
56WOLFSSL_API void wolfSSL_AES_ecb_encrypt
57 (const unsigned char *in, unsigned char* out,
58 AES_KEY *key, const int enc);
59WOLFSSL_API void wolfSSL_AES_cfb128_encrypt
60 (const unsigned char *in, unsigned char* out, size_t len,
61 AES_KEY *key, unsigned char* iv, int* num, const int enc);
62WOLFSSL_API int wolfSSL_AES_wrap_key(AES_KEY *key, const unsigned char *iv,
63 unsigned char *out,
64 const unsigned char *in, unsigned int inlen);
65WOLFSSL_API int wolfSSL_AES_unwrap_key(AES_KEY *key, const unsigned char *iv,
66 unsigned char *out,
67 const unsigned char *in, unsigned int inlen);
68
69#define AES_cbc_encrypt wolfSSL_AES_cbc_encrypt
70#define AES_ecb_encrypt wolfSSL_AES_ecb_encrypt
71#define AES_cfb128_encrypt wolfSSL_AES_cfb128_encrypt
72#define AES_set_encrypt_key wolfSSL_AES_set_encrypt_key
73#define AES_set_decrypt_key wolfSSL_AES_set_decrypt_key
74#define AES_wrap_key wolfSSL_AES_wrap_key
75#define AES_unwrap_key wolfSSL_AES_unwrap_key
76
77#ifdef WOLFSSL_AES_DIRECT
78WOLFSSL_API void wolfSSL_AES_encrypt
79 (const unsigned char* input, unsigned char* output, AES_KEY *);
80WOLFSSL_API void wolfSSL_AES_decrypt
81 (const unsigned char* input, unsigned char* output, AES_KEY *);
82
83#define AES_encrypt wolfSSL_AES_encrypt
84#define AES_decrypt wolfSSL_AES_decrypt
85#endif /* HAVE_AES_DIRECT */
86
87#ifndef AES_ENCRYPT
88#define AES_ENCRYPT AES_ENCRYPTION
89#endif
90#ifndef AES_DECRYPT
91#define AES_DECRYPT AES_DECRYPTION
92#endif
93
94#ifdef __cplusplus
95 } /* extern "C" */
96#endif
97
98#endif /* NO_AES */
99
100#endif /* WOLFSSL_AES_H_ */