1/* aes.h
2
3 The aes/rijndael block cipher.
4
5 Copyright (C) 2001, 2013 Niels Möller
6
7 This file is part of GNU Nettle.
8
9 GNU Nettle is free software: you can redistribute it and/or
10 modify it under the terms of either:
11
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.
15
16 or
17
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.
21
22 or both in parallel, as here.
23
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.
28
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/.
32*/
33
34#ifndef NETTLE_AES_H_INCLUDED
35#define NETTLE_AES_H_INCLUDED
36
37#include "nettle-types.h"
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/* Name mangling */
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
64
65#define AES_BLOCK_SIZE 16
66
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
73
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
78
79/* Older nettle-2.7 interface */
80
81#define AES_KEY_SIZE 32
82
83struct aes_ctx
84{
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 */
87};
88
89void
90aes_set_encrypt_key(struct aes_ctx *ctx,
91 size_t length, const uint8_t *key);
92
93void
94aes_set_decrypt_key(struct aes_ctx *ctx,
95 size_t length, const uint8_t *key);
96
97void
98aes_invert_key(struct aes_ctx *dst,
99 const struct aes_ctx *src);
100
101void
102aes_encrypt(const struct aes_ctx *ctx,
103 size_t length, uint8_t *dst,
104 const uint8_t *src);
105void
106aes_decrypt(const struct aes_ctx *ctx,
107 size_t length, uint8_t *dst,
108 const uint8_t *src);
109
110struct aes128_ctx
111{
112 uint32_t keys[4 * (_AES128_ROUNDS + 1)];
113};
114
115void
116aes128_set_encrypt_key(struct aes128_ctx *ctx, const uint8_t *key);
117void
118aes128_set_decrypt_key(struct aes128_ctx *ctx, const uint8_t *key);
119void
120aes128_invert_key(struct aes128_ctx *dst,
121 const struct aes128_ctx *src);
122void
123aes128_encrypt(const struct aes128_ctx *ctx,
124 size_t length, uint8_t *dst,
125 const uint8_t *src);
126void
127aes128_decrypt(const struct aes128_ctx *ctx,
128 size_t length, uint8_t *dst,
129 const uint8_t *src);
130
131struct aes192_ctx
132{
133 uint32_t keys[4 * (_AES192_ROUNDS + 1)];
134};
135
136void
137aes192_set_encrypt_key(struct aes192_ctx *ctx, const uint8_t *key);
138void
139aes192_set_decrypt_key(struct aes192_ctx *ctx, const uint8_t *key);
140void
141aes192_invert_key(struct aes192_ctx *dst,
142 const struct aes192_ctx *src);
143void
144aes192_encrypt(const struct aes192_ctx *ctx,
145 size_t length, uint8_t *dst,
146 const uint8_t *src);
147void
148aes192_decrypt(const struct aes192_ctx *ctx,
149 size_t length, uint8_t *dst,
150 const uint8_t *src);
151
152struct aes256_ctx
153{
154 uint32_t keys[4 * (_AES256_ROUNDS + 1)];
155};
156
157void
158aes256_set_encrypt_key(struct aes256_ctx *ctx, const uint8_t *key);
159void
160aes256_set_decrypt_key(struct aes256_ctx *ctx, const uint8_t *key);
161void
162aes256_invert_key(struct aes256_ctx *dst,
163 const struct aes256_ctx *src);
164void
165aes256_encrypt(const struct aes256_ctx *ctx,
166 size_t length, uint8_t *dst,
167 const uint8_t *src);
168void
169aes256_decrypt(const struct aes256_ctx *ctx,
170 size_t length, uint8_t *dst,
171 const uint8_t *src);
172
173#ifdef __cplusplus
174}
175#endif
176
177#endif /* NETTLE_AES_H_INCLUDED */
178