Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:16

0001 /* siv-cmac.h
0002 
0003    AES-SIV, RFC5297
0004 
0005    Copyright (C) 2017 Nikos Mavrogiannopoulos
0006 
0007    This file is part of GNU Nettle.
0008 
0009    GNU Nettle is free software: you can redistribute it and/or
0010    modify it under the terms of either:
0011 
0012      * the GNU Lesser General Public License as published by the Free
0013        Software Foundation; either version 3 of the License, or (at your
0014        option) any later version.
0015 
0016    or
0017 
0018      * the GNU General Public License as published by the Free
0019        Software Foundation; either version 2 of the License, or (at your
0020        option) any later version.
0021 
0022    or both in parallel, as here.
0023 
0024    GNU Nettle is distributed in the hope that it will be useful,
0025    but WITHOUT ANY WARRANTY; without even the implied warranty of
0026    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0027    General Public License for more details.
0028 
0029    You should have received copies of the GNU General Public License and
0030    the GNU Lesser General Public License along with this program.  If
0031    not, see http://www.gnu.org/licenses/.
0032 */
0033 
0034 #ifndef NETTLE_SIV_H_INCLUDED
0035 #define NETTLE_SIV_H_INCLUDED
0036 
0037 #include "nettle-types.h"
0038 #include "nettle-meta.h"
0039 #include "cmac.h"
0040 #include "aes.h"
0041 
0042 #ifdef __cplusplus
0043 extern "C" {
0044 #endif
0045 
0046 /* Name mangling */
0047 #define siv_cmac_set_key nettle_siv_cmac_set_key
0048 #define siv_cmac_encrypt_message nettle_siv_cmac_encrypt_message
0049 #define siv_cmac_decrypt_message nettle_siv_cmac_decrypt_message
0050 #define siv_cmac_aes128_set_key nettle_siv_cmac_aes128_set_key
0051 #define siv_cmac_aes128_encrypt_message nettle_siv_cmac_aes128_encrypt_message
0052 #define siv_cmac_aes128_decrypt_message nettle_siv_cmac_aes128_decrypt_message
0053 #define siv_cmac_aes256_set_key nettle_siv_cmac_aes256_set_key
0054 #define siv_cmac_aes256_encrypt_message nettle_siv_cmac_aes256_encrypt_message
0055 #define siv_cmac_aes256_decrypt_message nettle_siv_cmac_aes256_decrypt_message
0056 
0057 /* For SIV, the block size of the underlying cipher shall be 128 bits. */
0058 #define SIV_BLOCK_SIZE  16
0059 #define SIV_DIGEST_SIZE 16
0060 #define SIV_MIN_NONCE_SIZE 1
0061 
0062 void
0063 siv_cmac_set_key(struct cmac128_key *cmac_key, void *cmac_cipher, void *ctr_cipher,
0064          const struct nettle_cipher *nc,
0065          const uint8_t *key);
0066 
0067 void
0068 siv_cmac_encrypt_message(const struct cmac128_key *cmac_key, const void *cmac_cipher_ctx,
0069              const struct nettle_cipher *nc,
0070              const void *ctr_ctx,
0071              size_t nlength, const uint8_t *nonce,
0072              size_t alength, const uint8_t *adata,
0073              size_t clength, uint8_t *dst, const uint8_t *src);
0074 
0075 int
0076 siv_cmac_decrypt_message(const struct cmac128_key *cmac_key, const void *cmac_cipher,
0077              const struct nettle_cipher *nc,
0078              const void *ctr_cipher,
0079              size_t nlength, const uint8_t *nonce,
0080              size_t alength, const uint8_t *adata,
0081              size_t mlength, uint8_t *dst, const uint8_t *src);
0082 
0083 /*
0084  * SIV mode requires the aad and plaintext when building the IV, which
0085  * prevents streaming processing and it incompatible with the AEAD API.
0086  */
0087 
0088 #define SIV_CMAC_CTX(type) { struct cmac128_key cmac_key; type cmac_cipher; type ctr_cipher; }
0089 
0090 /* SIV_CMAC_AES128 */
0091 #define SIV_CMAC_AES128_KEY_SIZE 32
0092 
0093 struct siv_cmac_aes128_ctx SIV_CMAC_CTX(struct aes128_ctx);
0094 
0095 void
0096 siv_cmac_aes128_set_key(struct siv_cmac_aes128_ctx *ctx, const uint8_t *key);
0097 
0098 void
0099 siv_cmac_aes128_encrypt_message(const struct siv_cmac_aes128_ctx *ctx,
0100                 size_t nlength, const uint8_t *nonce,
0101                 size_t alength, const uint8_t *adata,
0102                 size_t clength, uint8_t *dst, const uint8_t *src);
0103 
0104 int
0105 siv_cmac_aes128_decrypt_message(const struct siv_cmac_aes128_ctx *ctx,
0106                 size_t nlength, const uint8_t *nonce,
0107                 size_t alength, const uint8_t *adata,
0108                 size_t mlength, uint8_t *dst, const uint8_t *src);
0109 
0110 /* SIV_CMAC_AES256 */
0111 #define SIV_CMAC_AES256_KEY_SIZE 64
0112 
0113 struct siv_cmac_aes256_ctx SIV_CMAC_CTX(struct aes256_ctx);
0114 
0115 void
0116 siv_cmac_aes256_set_key(struct siv_cmac_aes256_ctx *ctx, const uint8_t *key);
0117 
0118 void
0119 siv_cmac_aes256_encrypt_message(const struct siv_cmac_aes256_ctx *ctx,
0120                 size_t nlength, const uint8_t *nonce,
0121                 size_t alength, const uint8_t *adata,
0122                 size_t clength, uint8_t *dst, const uint8_t *src);
0123 
0124 int
0125 siv_cmac_aes256_decrypt_message(const struct siv_cmac_aes256_ctx *ctx,
0126                 size_t nlength, const uint8_t *nonce,
0127                 size_t alength, const uint8_t *adata,
0128                 size_t mlength, uint8_t *dst, const uint8_t *src);
0129 
0130 #ifdef __cplusplus
0131 }
0132 #endif
0133 
0134 #endif /* NETTLE_SIV_H_INCLUDED */