5 Copyright (C) 2017 Nikos Mavrogiannopoulos
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_SIV_H_INCLUDED
35 #define NETTLE_SIV_H_INCLUDED
37 #include "nettle-types.h"
38 #include "nettle-meta.h"
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
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
63 siv_cmac_set_key(struct cmac128_key *cmac_key, void *cmac_cipher, void *ctr_cipher,
64 const struct nettle_cipher *nc,
68 siv_cmac_encrypt_message(const struct cmac128_key *cmac_key, const void *cmac_cipher_ctx,
69 const struct nettle_cipher *nc,
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);
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);
84 * SIV mode requires the aad and plaintext when building the IV, which
85 * prevents streaming processing and it incompatible with the AEAD API.
88 #define SIV_CMAC_CTX(type) { struct cmac128_key cmac_key; type cmac_cipher; type ctr_cipher; }
91 #define SIV_CMAC_AES128_KEY_SIZE 32
93 struct siv_cmac_aes128_ctx SIV_CMAC_CTX(struct aes128_ctx);
96 siv_cmac_aes128_set_key(struct siv_cmac_aes128_ctx *ctx, const uint8_t *key);
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);
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);
110 /* SIV_CMAC_AES256 */
111 #define SIV_CMAC_AES256_KEY_SIZE 64
113 struct siv_cmac_aes256_ctx SIV_CMAC_CTX(struct aes256_ctx);
116 siv_cmac_aes256_set_key(struct siv_cmac_aes256_ctx *ctx, const uint8_t *key);
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);
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);
134 #endif /* NETTLE_SIV_H_INCLUDED */