3 EAX mode, see http://www.cs.ucdavis.edu/~rogaway/papers/eax.pdf
5 Copyright (C) 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_EAX_H_INCLUDED
35 #define NETTLE_EAX_H_INCLUDED
44 #define eax_set_key nettle_eax_set_key
45 #define eax_set_nonce nettle_eax_set_nonce
46 #define eax_update nettle_eax_update
47 #define eax_encrypt nettle_eax_encrypt
48 #define eax_decrypt nettle_eax_decrypt
49 #define eax_digest nettle_eax_digest
51 #define eax_aes128_set_key nettle_eax_aes128_set_key
52 #define eax_aes128_set_nonce nettle_eax_aes128_set_nonce
53 #define eax_aes128_update nettle_eax_aes128_update
54 #define eax_aes128_encrypt nettle_eax_aes128_encrypt
55 #define eax_aes128_decrypt nettle_eax_aes128_decrypt
56 #define eax_aes128_digest nettle_eax_aes128_digest
58 /* Restricted to block ciphers with 128 bit block size. FIXME: Reflect
61 #define EAX_BLOCK_SIZE 16
62 #define EAX_DIGEST_SIZE 16
63 /* FIXME: Reasonable default? */
64 #define EAX_IV_SIZE 16
66 /* Values independent of message and nonce */
69 union nettle_block16 pad_block;
70 union nettle_block16 pad_partial;
75 union nettle_block16 omac_nonce;
76 union nettle_block16 omac_data;
77 union nettle_block16 omac_message;
78 union nettle_block16 ctr;
82 eax_set_key (struct eax_key *key, const void *cipher, nettle_cipher_func *f);
85 eax_set_nonce (struct eax_ctx *eax, const struct eax_key *key,
86 const void *cipher, nettle_cipher_func *f,
87 size_t nonce_length, const uint8_t *nonce);
90 eax_update (struct eax_ctx *eax, const struct eax_key *key,
91 const void *cipher, nettle_cipher_func *f,
92 size_t data_length, const uint8_t *data);
95 eax_encrypt (struct eax_ctx *eax, const struct eax_key *key,
96 const void *cipher, nettle_cipher_func *f,
97 size_t length, uint8_t *dst, const uint8_t *src);
100 eax_decrypt (struct eax_ctx *eax, const struct eax_key *key,
101 const void *cipher, nettle_cipher_func *f,
102 size_t length, uint8_t *dst, const uint8_t *src);
105 eax_digest (struct eax_ctx *eax, const struct eax_key *key,
106 const void *cipher, nettle_cipher_func *f,
107 size_t length, uint8_t *digest);
109 /* Put the cipher last, to get cipher-independent offsets for the EAX
111 #define EAX_CTX(type) \
112 { struct eax_key key; struct eax_ctx eax; type cipher; }
114 #define EAX_SET_KEY(ctx, set_key, encrypt, data) \
116 (set_key)(&(ctx)->cipher, (data)); \
117 if (0) (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
118 (uint8_t *) 0, (const uint8_t *) 0); \
119 eax_set_key (&(ctx)->key, &(ctx)->cipher, (nettle_cipher_func *) encrypt); \
122 #define EAX_SET_NONCE(ctx, encrypt, length, nonce) \
123 (0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
124 (uint8_t *) 0, (const uint8_t *) 0) \
125 : eax_set_nonce (&(ctx)->eax, &(ctx)->key, \
126 &(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
129 #define EAX_UPDATE(ctx, encrypt, length, data) \
130 (0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
131 (uint8_t *) 0, (const uint8_t *) 0) \
132 : eax_update (&(ctx)->eax, &(ctx)->key, \
133 &(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
136 #define EAX_ENCRYPT(ctx, encrypt, length, dst, src) \
137 (0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
138 (uint8_t *) 0, (const uint8_t *) 0) \
139 : eax_encrypt (&(ctx)->eax, &(ctx)->key, \
140 &(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
141 (length), (dst), (src)))
143 #define EAX_DECRYPT(ctx, encrypt, length, dst, src) \
144 (0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
145 (uint8_t *) 0, (const uint8_t *) 0) \
146 : eax_decrypt (&(ctx)->eax, &(ctx)->key, \
147 &(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
148 (length), (dst), (src)))
150 #define EAX_DIGEST(ctx, encrypt, length, digest) \
151 (0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
152 (uint8_t *) 0, (const uint8_t *) 0) \
153 : eax_digest (&(ctx)->eax, &(ctx)->key, \
154 &(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
157 struct eax_aes128_ctx EAX_CTX(struct aes128_ctx);
160 eax_aes128_set_key(struct eax_aes128_ctx *ctx, const uint8_t *key);
163 eax_aes128_set_nonce(struct eax_aes128_ctx *ctx,
164 size_t length, const uint8_t *iv);
167 eax_aes128_update(struct eax_aes128_ctx *ctx,
168 size_t length, const uint8_t *data);
171 eax_aes128_encrypt(struct eax_aes128_ctx *ctx,
172 size_t length, uint8_t *dst, const uint8_t *src);
175 eax_aes128_decrypt(struct eax_aes128_ctx *ctx,
176 size_t length, uint8_t *dst, const uint8_t *src);
179 eax_aes128_digest(struct eax_aes128_ctx *ctx, size_t length, uint8_t *digest);
185 #endif /* NETTLE_EAX_H_INCLUDED */