Lightweight Cryptography Primitives
 All Data Structures Files Functions Variables Typedefs Macros Pages
sparkle.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_SPARKLE_H
24 #define LWCRYPTO_SPARKLE_H
25 
26 #include "aead-common.h"
27 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
56 #define SCHWAEMM_256_128_KEY_SIZE 16
57 
61 #define SCHWAEMM_256_128_TAG_SIZE 16
62 
66 #define SCHWAEMM_256_128_NONCE_SIZE 32
67 
71 #define SCHWAEMM_192_192_KEY_SIZE 24
72 
76 #define SCHWAEMM_192_192_TAG_SIZE 24
77 
81 #define SCHWAEMM_192_192_NONCE_SIZE 24
82 
86 #define SCHWAEMM_128_128_KEY_SIZE 16
87 
91 #define SCHWAEMM_128_128_TAG_SIZE 16
92 
96 #define SCHWAEMM_128_128_NONCE_SIZE 16
97 
101 #define SCHWAEMM_256_256_KEY_SIZE 32
102 
106 #define SCHWAEMM_256_256_TAG_SIZE 32
107 
111 #define SCHWAEMM_256_256_NONCE_SIZE 32
112 
116 #define ESCH_256_HASH_SIZE 32
117 
121 #define ESCH_384_HASH_SIZE 48
122 
127 
132 
137 
142 
147 
152 
156 typedef union
157 {
158  struct {
159  unsigned char state[48];
160  unsigned char block[16];
161  unsigned char count;
162  } s;
163  unsigned long long align;
166 
170 typedef union
171 {
172  struct {
173  unsigned char state[64];
174  unsigned char block[16];
175  unsigned char count;
176  } s;
177  unsigned long long align;
180 
203  (unsigned char *c, unsigned long long *clen,
204  const unsigned char *m, unsigned long long mlen,
205  const unsigned char *ad, unsigned long long adlen,
206  const unsigned char *nsec,
207  const unsigned char *npub,
208  const unsigned char *k);
209 
233  (unsigned char *m, unsigned long long *mlen,
234  unsigned char *nsec,
235  const unsigned char *c, unsigned long long clen,
236  const unsigned char *ad, unsigned long long adlen,
237  const unsigned char *npub,
238  const unsigned char *k);
239 
262  (unsigned char *c, unsigned long long *clen,
263  const unsigned char *m, unsigned long long mlen,
264  const unsigned char *ad, unsigned long long adlen,
265  const unsigned char *nsec,
266  const unsigned char *npub,
267  const unsigned char *k);
268 
292  (unsigned char *m, unsigned long long *mlen,
293  unsigned char *nsec,
294  const unsigned char *c, unsigned long long clen,
295  const unsigned char *ad, unsigned long long adlen,
296  const unsigned char *npub,
297  const unsigned char *k);
298 
321  (unsigned char *c, unsigned long long *clen,
322  const unsigned char *m, unsigned long long mlen,
323  const unsigned char *ad, unsigned long long adlen,
324  const unsigned char *nsec,
325  const unsigned char *npub,
326  const unsigned char *k);
327 
351  (unsigned char *m, unsigned long long *mlen,
352  unsigned char *nsec,
353  const unsigned char *c, unsigned long long clen,
354  const unsigned char *ad, unsigned long long adlen,
355  const unsigned char *npub,
356  const unsigned char *k);
357 
380  (unsigned char *c, unsigned long long *clen,
381  const unsigned char *m, unsigned long long mlen,
382  const unsigned char *ad, unsigned long long adlen,
383  const unsigned char *nsec,
384  const unsigned char *npub,
385  const unsigned char *k);
386 
410  (unsigned char *m, unsigned long long *mlen,
411  unsigned char *nsec,
412  const unsigned char *c, unsigned long long clen,
413  const unsigned char *ad, unsigned long long adlen,
414  const unsigned char *npub,
415  const unsigned char *k);
416 
428 int esch_256_hash
429  (unsigned char *out, const unsigned char *in, unsigned long long inlen);
430 
439 
450  (esch_256_hash_state_t *state, const unsigned char *in,
451  unsigned long long inlen);
452 
462  (esch_256_hash_state_t *state, unsigned char *out);
463 
475 int esch_384_hash
476  (unsigned char *out, const unsigned char *in, unsigned long long inlen);
477 
486 
497  (esch_384_hash_state_t *state, const unsigned char *in,
498  unsigned long long inlen);
499 
509  (esch_384_hash_state_t *state, unsigned char *out);
510 
511 #ifdef __cplusplus
512 }
513 #endif
514 
515 #endif
void esch_384_hash_finalize(esch_384_hash_state_t *state, unsigned char *out)
Returns the final hash value from an Esch384 hashing operation.
Definition: sparkle.c:1113
Meta-information about an AEAD cipher.
Definition: aead-common.h:185
Definitions that are common across AEAD schemes.
void esch_384_hash_update(esch_384_hash_state_t *state, const unsigned char *in, unsigned long long inlen)
Updates an Esch384 state with more input data.
Definition: sparkle.c:1091
int schwaemm_192_192_aead_encrypt(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 Schwaemm192-192.
Definition: sparkle.c:368
int schwaemm_256_256_aead_encrypt(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 Schwaemm256-256.
Definition: sparkle.c:752
void esch_256_hash_init(esch_256_hash_state_t *state)
Initializes the state for an Esch256 hashing operation.
Definition: sparkle.c:954
int schwaemm_128_128_aead_encrypt(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 Schwaemm128-128.
Definition: sparkle.c:557
Meta-information about a hash algorithm that is related to an AEAD.
Definition: aead-common.h:204
unsigned char count
Definition: sparkle.h:175
int schwaemm_192_192_aead_decrypt(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 Schwaemm192-192.
Definition: sparkle.c:431
int schwaemm_256_256_aead_decrypt(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 Schwaemm256-256.
Definition: sparkle.c:815
void esch_256_hash_update(esch_256_hash_state_t *state, const unsigned char *in, unsigned long long inlen)
Updates an Esch256 state with more input data.
Definition: sparkle.c:960
State information for the Esch384 incremental hash mode.
Definition: sparkle.h:170
int esch_256_hash(unsigned char *out, const unsigned char *in, unsigned long long inlen)
Hashes a block of input data with Esch256 to generate a hash value.
Definition: sparkle.c:924
void esch_384_hash_init(esch_384_hash_state_t *state)
Initializes the state for an Esch384 hashing operation.
Definition: sparkle.c:1085
aead_hash_algorithm_t const esch_256_hash_algorithm
Meta-information block for the Esch256 hash algorithm.
Definition: sparkle.c:67
unsigned char count
Definition: sparkle.h:161
int esch_384_hash(unsigned char *out, const unsigned char *in, unsigned long long inlen)
Hashes a block of input data with Esch384 to generate a hash value.
Definition: sparkle.c:1053
int schwaemm_256_128_aead_encrypt(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 Schwaemm256-128.
Definition: sparkle.c:176
int schwaemm_256_128_aead_decrypt(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 Schwaemm256-128.
Definition: sparkle.c:239
State information for the Esch256 incremental hash mode.
Definition: sparkle.h:156
unsigned long long align
Definition: sparkle.h:177
unsigned long long align
Definition: sparkle.h:163
aead_cipher_t const schwaemm_128_128_cipher
Meta-information block for the Schwaemm128-128 cipher.
Definition: sparkle.c:47
aead_cipher_t const schwaemm_192_192_cipher
Meta-information block for the Schwaemm192-192 cipher.
Definition: sparkle.c:37
aead_cipher_t const schwaemm_256_256_cipher
Meta-information block for the Schwaemm256-256 cipher.
Definition: sparkle.c:57
aead_cipher_t const schwaemm_256_128_cipher
Meta-information block for the Schwaemm256-128 cipher.
Definition: sparkle.c:27
int schwaemm_128_128_aead_decrypt(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 Schwaemm128-128.
Definition: sparkle.c:620
void esch_256_hash_finalize(esch_256_hash_state_t *state, unsigned char *out)
Returns the final hash value from an Esch256 hashing operation.
Definition: sparkle.c:982
aead_hash_algorithm_t const esch_384_hash_algorithm
Meta-information block for the Esch384 hash algorithm.
Definition: sparkle.c:80