Mention dependencies on GNU make and GNU GMP in the README file.
[gd/nettle] / siv-cmac.h
1 /* siv-cmac.h
2
3    AES-SIV, RFC5297
4
5    Copyright (C) 2017 Nikos Mavrogiannopoulos
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_SIV_H_INCLUDED
35 #define NETTLE_SIV_H_INCLUDED
36
37 #include "nettle-types.h"
38 #include "nettle-meta.h"
39 #include "cmac.h"
40 #include "aes.h"
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 /* Name mangling */
47 #define siv_cmac_set_key nettle_siv_cmac_set_key
48 #define siv_cmac_encrypt_message nettle_siv_cmac_encrypt_message
49 #define siv_cmac_decrypt_message nettle_siv_cmac_decrypt_message
50 #define siv_cmac_aes128_set_key nettle_siv_cmac_aes128_set_key
51 #define siv_cmac_aes128_encrypt_message nettle_siv_cmac_aes128_encrypt_message
52 #define siv_cmac_aes128_decrypt_message nettle_siv_cmac_aes128_decrypt_message
53 #define siv_cmac_aes256_set_key nettle_siv_cmac_aes256_set_key
54 #define siv_cmac_aes256_encrypt_message nettle_siv_cmac_aes256_encrypt_message
55 #define siv_cmac_aes256_decrypt_message nettle_siv_cmac_aes256_decrypt_message
56
57 /* For SIV, the block size of the underlying cipher shall be 128 bits. */
58 #define SIV_BLOCK_SIZE  16
59 #define SIV_DIGEST_SIZE 16
60 #define SIV_MIN_NONCE_SIZE 1
61
62 void
63 siv_cmac_set_key(struct cmac128_key *cmac_key, void *cmac_cipher, void *ctr_cipher,
64                  const struct nettle_cipher *nc,
65                  const uint8_t *key);
66
67 void
68 siv_cmac_encrypt_message(const struct cmac128_key *cmac_key, const void *cmac_cipher_ctx,
69                          const struct nettle_cipher *nc,
70                          const void *ctr_ctx,
71                          size_t nlength, const uint8_t *nonce,
72                          size_t alength, const uint8_t *adata,
73                          size_t clength, uint8_t *dst, const uint8_t *src);
74
75 int
76 siv_cmac_decrypt_message(const struct cmac128_key *cmac_key, const void *cmac_cipher,
77                          const struct nettle_cipher *nc,
78                          const void *ctr_cipher,
79                          size_t nlength, const uint8_t *nonce,
80                          size_t alength, const uint8_t *adata,
81                          size_t mlength, uint8_t *dst, const uint8_t *src);
82
83 /*
84  * SIV mode requires the aad and plaintext when building the IV, which
85  * prevents streaming processing and it incompatible with the AEAD API.
86  */
87
88 #define SIV_CMAC_CTX(type) { struct cmac128_key cmac_key; type cmac_cipher; type ctr_cipher; }
89
90 /* SIV_CMAC_AES128 */
91 #define SIV_CMAC_AES128_KEY_SIZE 32
92
93 struct siv_cmac_aes128_ctx SIV_CMAC_CTX(struct aes128_ctx);
94
95 void
96 siv_cmac_aes128_set_key(struct siv_cmac_aes128_ctx *ctx, const uint8_t *key);
97
98 void
99 siv_cmac_aes128_encrypt_message(const struct siv_cmac_aes128_ctx *ctx,
100                                 size_t nlength, const uint8_t *nonce,
101                                 size_t alength, const uint8_t *adata,
102                                 size_t clength, uint8_t *dst, const uint8_t *src);
103
104 int
105 siv_cmac_aes128_decrypt_message(const struct siv_cmac_aes128_ctx *ctx,
106                                 size_t nlength, const uint8_t *nonce,
107                                 size_t alength, const uint8_t *adata,
108                                 size_t mlength, uint8_t *dst, const uint8_t *src);
109
110 /* SIV_CMAC_AES256 */
111 #define SIV_CMAC_AES256_KEY_SIZE 64
112
113 struct siv_cmac_aes256_ctx SIV_CMAC_CTX(struct aes256_ctx);
114
115 void
116 siv_cmac_aes256_set_key(struct siv_cmac_aes256_ctx *ctx, const uint8_t *key);
117
118 void
119 siv_cmac_aes256_encrypt_message(const struct siv_cmac_aes256_ctx *ctx,
120                                 size_t nlength, const uint8_t *nonce,
121                                 size_t alength, const uint8_t *adata,
122                                 size_t clength, uint8_t *dst, const uint8_t *src);
123
124 int
125 siv_cmac_aes256_decrypt_message(const struct siv_cmac_aes256_ctx *ctx,
126                                 size_t nlength, const uint8_t *nonce,
127                                 size_t alength, const uint8_t *adata,
128                                 size_t mlength, uint8_t *dst, const uint8_t *src);
129
130 #ifdef __cplusplus
131 }
132 #endif
133
134 #endif /* NETTLE_SIV_H_INCLUDED */