3 The aes/rijndael block cipher.
5 Copyright (C) 2001, 2013 Niels Möller
7 This file is part of GNU Nettle.
9 GNU Nettle is free software: you can redistribute it and/or
10 modify it under the terms of either:
12 * the GNU Lesser General Public License as published by the Free
13 Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
18 * the GNU General Public License as published by the Free
19 Software Foundation; either version 2 of the License, or (at your
20 option) any later version.
22 or both in parallel, as here.
24 GNU Nettle is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 General Public License for more details.
29 You should have received copies of the GNU General Public License and
30 the GNU Lesser General Public License along with this program. If
31 not, see http://www.gnu.org/licenses/.
34 #ifndef NETTLE_AES_H_INCLUDED
35 #define NETTLE_AES_H_INCLUDED
37 #include "nettle-types.h"
44 #define aes_set_encrypt_key nettle_aes_set_encrypt_key
45 #define aes_set_decrypt_key nettle_aes_set_decrypt_key
46 #define aes_invert_key nettle_aes_invert_key
47 #define aes_encrypt nettle_aes_encrypt
48 #define aes_decrypt nettle_aes_decrypt
49 #define aes128_set_encrypt_key nettle_aes128_set_encrypt_key
50 #define aes128_set_decrypt_key nettle_aes128_set_decrypt_key
51 #define aes128_invert_key nettle_aes128_invert_key
52 #define aes128_encrypt nettle_aes128_encrypt
53 #define aes128_decrypt nettle_aes128_decrypt
54 #define aes192_set_encrypt_key nettle_aes192_set_encrypt_key
55 #define aes192_set_decrypt_key nettle_aes192_set_decrypt_key
56 #define aes192_invert_key nettle_aes192_invert_key
57 #define aes192_encrypt nettle_aes192_encrypt
58 #define aes192_decrypt nettle_aes192_decrypt
59 #define aes256_set_encrypt_key nettle_aes256_set_encrypt_key
60 #define aes256_set_decrypt_key nettle_aes256_set_decrypt_key
61 #define aes256_invert_key nettle_aes256_invert_key
62 #define aes256_encrypt nettle_aes256_encrypt
63 #define aes256_decrypt nettle_aes256_decrypt
65 #define AES_BLOCK_SIZE 16
67 #define AES128_KEY_SIZE 16
68 #define AES192_KEY_SIZE 24
69 #define AES256_KEY_SIZE 32
70 #define _AES128_ROUNDS 10
71 #define _AES192_ROUNDS 12
72 #define _AES256_ROUNDS 14
74 /* Variable key size between 128 and 256 bits. But the only valid
75 * values are 16 (128 bits), 24 (192 bits) and 32 (256 bits). */
76 #define AES_MIN_KEY_SIZE AES128_KEY_SIZE
77 #define AES_MAX_KEY_SIZE AES256_KEY_SIZE
79 /* Older nettle-2.7 interface */
81 #define AES_KEY_SIZE 32
85 unsigned rounds; /* number of rounds to use for our key size */
86 uint32_t keys[4*(_AES256_ROUNDS + 1)]; /* maximum size of key schedule */
90 aes_set_encrypt_key(struct aes_ctx *ctx,
91 size_t length, const uint8_t *key);
94 aes_set_decrypt_key(struct aes_ctx *ctx,
95 size_t length, const uint8_t *key);
98 aes_invert_key(struct aes_ctx *dst,
99 const struct aes_ctx *src);
102 aes_encrypt(const struct aes_ctx *ctx,
103 size_t length, uint8_t *dst,
106 aes_decrypt(const struct aes_ctx *ctx,
107 size_t length, uint8_t *dst,
112 uint32_t keys[4 * (_AES128_ROUNDS + 1)];
116 aes128_set_encrypt_key(struct aes128_ctx *ctx, const uint8_t *key);
118 aes128_set_decrypt_key(struct aes128_ctx *ctx, const uint8_t *key);
120 aes128_invert_key(struct aes128_ctx *dst,
121 const struct aes128_ctx *src);
123 aes128_encrypt(const struct aes128_ctx *ctx,
124 size_t length, uint8_t *dst,
127 aes128_decrypt(const struct aes128_ctx *ctx,
128 size_t length, uint8_t *dst,
133 uint32_t keys[4 * (_AES192_ROUNDS + 1)];
137 aes192_set_encrypt_key(struct aes192_ctx *ctx, const uint8_t *key);
139 aes192_set_decrypt_key(struct aes192_ctx *ctx, const uint8_t *key);
141 aes192_invert_key(struct aes192_ctx *dst,
142 const struct aes192_ctx *src);
144 aes192_encrypt(const struct aes192_ctx *ctx,
145 size_t length, uint8_t *dst,
148 aes192_decrypt(const struct aes192_ctx *ctx,
149 size_t length, uint8_t *dst,
154 uint32_t keys[4 * (_AES256_ROUNDS + 1)];
158 aes256_set_encrypt_key(struct aes256_ctx *ctx, const uint8_t *key);
160 aes256_set_decrypt_key(struct aes256_ctx *ctx, const uint8_t *key);
162 aes256_invert_key(struct aes256_ctx *dst,
163 const struct aes256_ctx *src);
165 aes256_encrypt(const struct aes256_ctx *ctx,
166 size_t length, uint8_t *dst,
169 aes256_decrypt(const struct aes256_ctx *ctx,
170 size_t length, uint8_t *dst,
177 #endif /* NETTLE_AES_H_INCLUDED */