1 | /* aes.h
|
---|
2 | *
|
---|
3 | * Copyright (C) 2006-2020 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. */
|
---|
44 | typedef struct WOLFSSL_AES_KEY {
|
---|
45 | /* aligned and big enough for Aes from wolfssl/wolfcrypt/aes.h */
|
---|
46 | ALIGN16 void* holder[(376 + WC_ASYNC_DEV_SIZE)/ sizeof(void*)];
|
---|
47 | #ifdef GCM_TABLE
|
---|
48 | /* key-based fast multiplication table. */
|
---|
49 | ALIGN16 void* M0[4096 / sizeof(void*)];
|
---|
50 | #endif /* GCM_TABLE */
|
---|
51 | #if defined(WOLFSSL_DEVCRYPTO) && \
|
---|
52 | (defined(WOLFSSL_DEVCRYPTO_AES) || defined(WOLFSSL_DEVCRYPTO_CBC))
|
---|
53 | /* large enough for additional devcrypto information */
|
---|
54 | void* devKey[288 / sizeof(void*)];
|
---|
55 | #endif
|
---|
56 | #ifdef WOLFSSL_AFALG
|
---|
57 | void* afalg_holder[288 / sizeof(void*)];
|
---|
58 | #endif
|
---|
59 | #ifdef HAVE_PKCS11
|
---|
60 | void* pkcs11_holder[(AES_MAX_ID_LEN + sizeof(int)) / sizeof(void*)];
|
---|
61 | #endif
|
---|
62 | #if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_CB)
|
---|
63 | void* async_holder[128 / sizeof(void*)];
|
---|
64 | #endif
|
---|
65 | } WOLFSSL_AES_KEY;
|
---|
66 | typedef WOLFSSL_AES_KEY AES_KEY;
|
---|
67 |
|
---|
68 | WOLFSSL_API int wolfSSL_AES_set_encrypt_key
|
---|
69 | (const unsigned char *, const int bits, AES_KEY *);
|
---|
70 | WOLFSSL_API int wolfSSL_AES_set_decrypt_key
|
---|
71 | (const unsigned char *, const int bits, AES_KEY *);
|
---|
72 | WOLFSSL_API void wolfSSL_AES_cbc_encrypt
|
---|
73 | (const unsigned char *in, unsigned char* out, size_t len,
|
---|
74 | AES_KEY *key, unsigned char* iv, const int enc);
|
---|
75 | WOLFSSL_API void wolfSSL_AES_ecb_encrypt
|
---|
76 | (const unsigned char *in, unsigned char* out,
|
---|
77 | AES_KEY *key, const int enc);
|
---|
78 | WOLFSSL_API void wolfSSL_AES_cfb128_encrypt
|
---|
79 | (const unsigned char *in, unsigned char* out, size_t len,
|
---|
80 | AES_KEY *key, unsigned char* iv, int* num, const int enc);
|
---|
81 |
|
---|
82 | #define AES_cbc_encrypt wolfSSL_AES_cbc_encrypt
|
---|
83 | #define AES_ecb_encrypt wolfSSL_AES_ecb_encrypt
|
---|
84 | #define AES_cfb128_encrypt wolfSSL_AES_cfb128_encrypt
|
---|
85 | #define AES_set_encrypt_key wolfSSL_AES_set_encrypt_key
|
---|
86 | #define AES_set_decrypt_key wolfSSL_AES_set_decrypt_key
|
---|
87 |
|
---|
88 | #ifdef WOLFSSL_AES_DIRECT
|
---|
89 | WOLFSSL_API void wolfSSL_AES_encrypt
|
---|
90 | (const unsigned char* input, unsigned char* output, AES_KEY *);
|
---|
91 | WOLFSSL_API void wolfSSL_AES_decrypt
|
---|
92 | (const unsigned char* input, unsigned char* output, AES_KEY *);
|
---|
93 |
|
---|
94 | #define AES_encrypt wolfSSL_AES_encrypt
|
---|
95 | #define AES_decrypt wolfSSL_AES_decrypt
|
---|
96 | #endif /* HAVE_AES_DIRECT */
|
---|
97 |
|
---|
98 | #ifndef AES_ENCRYPT
|
---|
99 | #define AES_ENCRYPT AES_ENCRYPTION
|
---|
100 | #endif
|
---|
101 | #ifndef AES_DECRYPT
|
---|
102 | #define AES_DECRYPT AES_DECRYPTION
|
---|
103 | #endif
|
---|
104 |
|
---|
105 | #ifdef __cplusplus
|
---|
106 | } /* extern "C" */
|
---|
107 | #endif
|
---|
108 |
|
---|
109 | #endif /* NO_AES */
|
---|
110 |
|
---|
111 | #endif /* WOLFSSL_AES_H_ */
|
---|