Lightweight Cryptography Primitives
 All Data Structures Files Functions Variables Typedefs Macros Pages
aead-common.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Southern Storm Software, Pty Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef LWCRYPTO_AEAD_COMMON_H
24 #define LWCRYPTO_AEAD_COMMON_H
25 
26 #include <stddef.h>
27 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
59 typedef int (*aead_cipher_encrypt_t)
60  (unsigned char *c, unsigned long long *clen,
61  const unsigned char *m, unsigned long long mlen,
62  const unsigned char *ad, unsigned long long adlen,
63  const unsigned char *nsec,
64  const unsigned char *npub,
65  const unsigned char *k);
66 
86 typedef int (*aead_cipher_decrypt_t)
87  (unsigned char *m, unsigned long long *mlen,
88  unsigned char *nsec,
89  const unsigned char *c, unsigned long long clen,
90  const unsigned char *ad, unsigned long long adlen,
91  const unsigned char *npub,
92  const unsigned char *k);
93 
104 typedef int (*aead_hash_t)
105  (unsigned char *out, const unsigned char *in, unsigned long long inlen);
106 
112 typedef void (*aead_hash_init_t)(void *state);
113 
121 typedef void (*aead_hash_update_t)
122  (void *state, const unsigned char *in, unsigned long long inlen);
123 
130 typedef void (*aead_hash_finalize_t)(void *state, unsigned char *out);
131 
141 typedef void (*aead_xof_absorb_t)
142  (void *state, const unsigned char *in, unsigned long long inlen);
143 
151 typedef void (*aead_xof_squeeze_t)
152  (void *state, unsigned char *out, unsigned long long outlen);
153 
157 #define AEAD_FLAG_NONE 0x0000
158 
169 #define AEAD_FLAG_LITTLE_ENDIAN 0x0001
170 
174 #define AEAD_FLAG_SC_PROTECT_KEY 0x0002
175 
180 #define AEAD_FLAG_SC_PROTECT_ALL 0x0004
181 
185 typedef struct
186 {
187  const char *name;
188  unsigned key_len;
189  unsigned nonce_len;
190  unsigned tag_len;
191  unsigned flags;
195 } aead_cipher_t;
196 
204 typedef struct
205 {
206  const char *name;
207  size_t state_size;
208  unsigned hash_len;
209  unsigned flags;
218 
234 int aead_check_tag
235  (unsigned char *plaintext, unsigned long long plaintext_len,
236  const unsigned char *tag1, const unsigned char *tag2,
237  unsigned tag_len);
238 
259  (unsigned char *plaintext, unsigned long long plaintext_len,
260  const unsigned char *tag1, const unsigned char *tag2,
261  unsigned tag_len, int precheck);
262 
263 #ifdef __cplusplus
264 }
265 #endif
266 
267 #endif
Meta-information about an AEAD cipher.
Definition: aead-common.h:185
Meta-information about a hash algorithm that is related to an AEAD.
Definition: aead-common.h:204
unsigned nonce_len
Definition: aead-common.h:189
void(* aead_hash_init_t)(void *state)
Initializes the state for a hashing operation.
Definition: aead-common.h:112
int(* aead_cipher_encrypt_t)(unsigned char *c, unsigned long long *clen, const unsigned char *m, unsigned long long mlen, const unsigned char *ad, unsigned long long adlen, const unsigned char *nsec, const unsigned char *npub, const unsigned char *k)
Encrypts and authenticates a packet with an AEAD scheme.
Definition: aead-common.h:60
unsigned flags
Definition: aead-common.h:191
unsigned hash_len
Definition: aead-common.h:208
int(* aead_hash_t)(unsigned char *out, const unsigned char *in, unsigned long long inlen)
Hashes a block of input data.
Definition: aead-common.h:105
size_t state_size
Definition: aead-common.h:207
aead_hash_init_t init
Definition: aead-common.h:211
const char * name
Definition: aead-common.h:206
aead_xof_squeeze_t squeeze
Definition: aead-common.h:215
aead_hash_finalize_t finalize
Definition: aead-common.h:213
void(* aead_hash_finalize_t)(void *state, unsigned char *out)
Returns the final hash value from a hashing operation.
Definition: aead-common.h:130
void(* aead_xof_squeeze_t)(void *state, unsigned char *out, unsigned long long outlen)
Squeezes output data from an XOF state.
Definition: aead-common.h:152
aead_hash_t hash
Definition: aead-common.h:210
aead_hash_update_t update
Definition: aead-common.h:212
int(* aead_cipher_decrypt_t)(unsigned char *m, unsigned long long *mlen, unsigned char *nsec, const unsigned char *c, unsigned long long clen, const unsigned char *ad, unsigned long long adlen, const unsigned char *npub, const unsigned char *k)
Decrypts and authenticates a packet with an AEAD scheme.
Definition: aead-common.h:87
unsigned tag_len
Definition: aead-common.h:190
int aead_check_tag(unsigned char *plaintext, unsigned long long plaintext_len, const unsigned char *tag1, const unsigned char *tag2, unsigned tag_len)
Check an authentication tag in constant time.
Definition: aead-common.c:26
unsigned flags
Definition: aead-common.h:209
unsigned key_len
Definition: aead-common.h:188
const char * name
Definition: aead-common.h:187
aead_cipher_encrypt_t encrypt
Definition: aead-common.h:192
void(* aead_xof_absorb_t)(void *state, const unsigned char *in, unsigned long long inlen)
Aborbs more input data into an XOF state.
Definition: aead-common.h:142
aead_cipher_decrypt_t decrypt
Definition: aead-common.h:193
int aead_check_tag_precheck(unsigned char *plaintext, unsigned long long plaintext_len, const unsigned char *tag1, const unsigned char *tag2, unsigned tag_len, int precheck)
Check an authentication tag in constant time with a previous check.
Definition: aead-common.c:49
aead_xof_absorb_t absorb
Definition: aead-common.h:214
void(* aead_hash_update_t)(void *state, const unsigned char *in, unsigned long long inlen)
Updates a hash state with more input data.
Definition: aead-common.h:122