Lightweight Cryptography Primitives
 All Data Structures Files Functions Variables Typedefs Macros Pages
ascon128.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_ASCON_H
24 #define LWCRYPTO_ASCON_H
25 
26 #include "aead-common.h"
27 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
54 #define ASCON128_KEY_SIZE 16
55 
59 #define ASCON128_NONCE_SIZE 16
60 
64 #define ASCON128_TAG_SIZE 16
65 
69 #define ASCON80PQ_KEY_SIZE 20
70 
74 #define ASCON80PQ_NONCE_SIZE 16
75 
79 #define ASCON80PQ_TAG_SIZE 16
80 
84 #define ASCON_HASH_SIZE 32
85 
89 typedef union
90 {
91  struct {
92  unsigned char state[40];
93  unsigned char count;
94  unsigned char mode;
95  } s;
96  unsigned long long align;
99 
103 extern aead_cipher_t const ascon128_cipher;
104 
108 extern aead_cipher_t const ascon128a_cipher;
109 
113 extern aead_cipher_t const ascon80pq_cipher;
114 
119 
124 
147  (unsigned char *c, unsigned long long *clen,
148  const unsigned char *m, unsigned long long mlen,
149  const unsigned char *ad, unsigned long long adlen,
150  const unsigned char *nsec,
151  const unsigned char *npub,
152  const unsigned char *k);
153 
177  (unsigned char *m, unsigned long long *mlen,
178  unsigned char *nsec,
179  const unsigned char *c, unsigned long long clen,
180  const unsigned char *ad, unsigned long long adlen,
181  const unsigned char *npub,
182  const unsigned char *k);
183 
206  (unsigned char *c, unsigned long long *clen,
207  const unsigned char *m, unsigned long long mlen,
208  const unsigned char *ad, unsigned long long adlen,
209  const unsigned char *nsec,
210  const unsigned char *npub,
211  const unsigned char *k);
212 
236  (unsigned char *m, unsigned long long *mlen,
237  unsigned char *nsec,
238  const unsigned char *c, unsigned long long clen,
239  const unsigned char *ad, unsigned long long adlen,
240  const unsigned char *npub,
241  const unsigned char *k);
242 
265  (unsigned char *c, unsigned long long *clen,
266  const unsigned char *m, unsigned long long mlen,
267  const unsigned char *ad, unsigned long long adlen,
268  const unsigned char *nsec,
269  const unsigned char *npub,
270  const unsigned char *k);
271 
295  (unsigned char *m, unsigned long long *mlen,
296  unsigned char *nsec,
297  const unsigned char *c, unsigned long long clen,
298  const unsigned char *ad, unsigned long long adlen,
299  const unsigned char *npub,
300  const unsigned char *k);
301 
315 int ascon_hash
316  (unsigned char *out, const unsigned char *in, unsigned long long inlen);
317 
326 
337  (ascon_hash_state_t *state, const unsigned char *in,
338  unsigned long long inlen);
339 
349  (ascon_hash_state_t *state, unsigned char *out);
350 
367 int ascon_xof
368  (unsigned char *out, const unsigned char *in, unsigned long long inlen);
369 
378 
388 void ascon_xof_absorb
389  (ascon_hash_state_t *state, const unsigned char *in,
390  unsigned long long inlen);
391 
402  (ascon_hash_state_t *state, unsigned char *out, unsigned long long outlen);
403 
404 #ifdef __cplusplus
405 }
406 #endif
407 
408 #endif
aead_cipher_t const ascon128_cipher
Meta-information block for the ASCON-128 cipher.
Definition: ascon128.c:42
unsigned long long align
Definition: ascon128.h:96
Meta-information about an AEAD cipher.
Definition: aead-common.h:185
aead_cipher_t const ascon80pq_cipher
Meta-information block for the ASCON-80pq cipher.
Definition: ascon128.c:62
Definitions that are common across AEAD schemes.
void ascon_hash_finalize(ascon_hash_state_t *state, unsigned char *out)
Returns the final hash value from an ASCON-HASH hashing operation.
Definition: ascon-hash.c:147
Meta-information about a hash algorithm that is related to an AEAD.
Definition: aead-common.h:204
int ascon80pq_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 ASCON-80pq.
Definition: ascon128.c:602
int ascon128_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 ASCON-128.
Definition: ascon128.c:334
int ascon_hash(unsigned char *out, const unsigned char *in, unsigned long long inlen)
Hashes a block of input data with ASCON-HASH.
Definition: ascon-hash.c:51
int ascon128a_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 ASCON-128a.
Definition: ascon128.c:493
void ascon_xof_init(ascon_hash_state_t *state)
Initializes the state for an ASCON-XOF hashing operation.
Definition: ascon-xof.c:60
State information for ASCON-HASH and ASCON-XOF incremental modes.
Definition: ascon128.h:89
int ascon128_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 ASCON-128.
Definition: ascon128.c:386
aead_hash_algorithm_t const ascon_hash_algorithm
Meta-information block for the ASCON-HASH algorithm.
Definition: ascon-hash.c:37
void ascon_hash_update(ascon_hash_state_t *state, const unsigned char *in, unsigned long long inlen)
Updates an ASCON-HASH state with more input data.
Definition: ascon-hash.c:94
aead_hash_algorithm_t const ascon_xof_algorithm
Meta-information block for the ASCON-XOF algorithm.
Definition: ascon-xof.c:37
void ascon_xof_absorb(ascon_hash_state_t *state, const unsigned char *in, unsigned long long inlen)
Aborbs more input data into an ASCON-XOF state.
Definition: ascon-xof.c:76
void ascon_hash_init(ascon_hash_state_t *state)
Initializes the state for an ASCON-HASH hashing operation.
Definition: ascon-hash.c:78
int ascon_xof(unsigned char *out, const unsigned char *in, unsigned long long inlen)
Hashes a block of input data with ASCON-XOF and generates a fixed-length 32 byte output.
Definition: ascon-xof.c:51
int ascon128a_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 ASCON-128a.
Definition: ascon128.c:441
void ascon_xof_squeeze(ascon_hash_state_t *state, unsigned char *out, unsigned long long outlen)
Squeezes output data from an ASCON-XOF state.
Definition: ascon-xof.c:95
int ascon80pq_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 ASCON-80pq.
Definition: ascon128.c:548
unsigned char count
Definition: ascon128.h:93
unsigned char mode
Definition: ascon128.h:94
aead_cipher_t const ascon128a_cipher
Meta-information block for the ASCON-128a cipher.
Definition: ascon128.c:52