27 static uint8_t
const ASCON80PQ_IV[8] =
28 {0xa0, 0x40, 0x0c, 0x06, 0x00, 0x00, 0x00, 0x00};
32 static void ascon80pq_masked_aead_init
38 uint64_t *preserve,
const unsigned char *npub,
42 #if ASCON_MASKED_KEY_SHARES == 2
44 #elif ASCON_MASKED_KEY_SHARES == 3
55 ascon_masked_key_randomize(
state, trng);
56 ascon_masked_key_load(word, ASCON80PQ_IV, trng);
57 ascon_masked_key_xor(&(
state->M[0]), word);
58 ascon_masked_key_xor(&(
state->M[0]), &(k->
k[3]));
59 ascon_masked_key_xor(&(
state->M[1]), &(k->
k[4]));
60 ascon_masked_key_xor(&(
state->M[2]), &(k->
k[5]));
61 ascon_masked_key_load(word, npub, trng);
62 ascon_masked_key_xor(&(
state->M[3]), word);
63 ascon_masked_key_load(word, npub + 8, trng);
64 ascon_masked_key_xor(&(
state->M[4]), word);
65 ascon_masked_key_permute(
state, 0, preserve);
66 ascon_masked_key_xor(&(
state->M[2]), &(k->
k[3]));
67 ascon_masked_key_xor(&(
state->M[3]), &(k->
k[4]));
68 ascon_masked_key_xor(&(
state->M[4]), &(k->
k[5]));
71 #if ASCON_MASKED_DATA_SHARES == 1
72 ascon_copy_key_to_x1(state_x1,
state);
73 #elif ASCON_MASKED_DATA_SHARES == 2
74 ascon_copy_key_to_x2(
state, trng);
75 #elif ASCON_MASKED_DATA_SHARES == 3
76 ascon_copy_key_to_x3(
state, trng);
78 ascon_copy_key_to_x4(
state, trng);
83 static void ascon80pq_masked_aead_finalize
92 #if ASCON_MASKED_KEY_SHARES == 2
94 #elif ASCON_MASKED_KEY_SHARES == 3
104 #if ASCON_MASKED_DATA_SHARES == 1
105 ascon_copy_key_from_x1(
state, state_x1, trng);
106 #elif ASCON_MASKED_DATA_SHARES == 2
107 ascon_copy_key_from_x2(
state, trng);
108 #elif ASCON_MASKED_DATA_SHARES == 3
109 ascon_copy_key_from_x3(
state, trng);
111 ascon_copy_key_from_x4(
state, trng);
115 ascon_masked_key_xor(&(
state->M[1]), &(k->
k[0]));
116 ascon_masked_key_xor(&(
state->M[2]), &(k->
k[1]));
117 ascon_masked_key_xor(&(
state->M[3]), &(k->
k[2]));
118 ascon_masked_key_permute(
state, 0, preserve);
119 ascon_masked_key_xor(&(
state->M[3]), &(k->
k[4]));
120 ascon_masked_key_xor(&(
state->M[4]), &(k->
k[5]));
121 ascon_masked_key_store(tag, &(
state->M[3]));
122 ascon_masked_key_store(tag + 8, &(
state->M[4]));
126 (
unsigned char *c,
size_t *clen,
127 const unsigned char *m,
size_t mlen,
128 const unsigned char *ad,
size_t adlen,
129 const unsigned char *npub,
133 #if ASCON_MASKED_DATA_SHARES == 1
135 unsigned char partial;
147 #if ASCON_MASKED_DATA_SHARES == 1
149 ascon80pq_masked_aead_init
150 (&
state, &state_x1, &trng, &word, preserve, npub, k);
164 ascon80pq_masked_aead_finalize
165 (&
state, &state_x1, &trng, preserve, k, c + mlen);
168 ascon80pq_masked_aead_init(&
state, &trng, &word, preserve, npub, k);
173 (&
state, ad, adlen, 6, &word, preserve, &trng);
181 (&
state, c, m, mlen, 6, &word, preserve, &trng);
184 ascon80pq_masked_aead_finalize(&
state, &trng, preserve, k, c + mlen);
188 #if ASCON_MASKED_DATA_SHARES == 1
198 (
unsigned char *m,
size_t *mlen,
199 const unsigned char *c,
size_t clen,
200 const unsigned char *ad,
size_t adlen,
201 const unsigned char *npub,
205 #if ASCON_MASKED_DATA_SHARES == 1
207 unsigned char partial;
223 #if ASCON_MASKED_DATA_SHARES == 1
225 ascon80pq_masked_aead_init
226 (&
state, &state_x1, &trng, &word, preserve, npub, k);
240 ascon80pq_masked_aead_finalize(&
state, &state_x1, &trng, preserve, k, tag);
243 ascon80pq_masked_aead_init(&
state, &trng, &word, preserve, npub, k);
248 (&
state, ad, adlen, 6, &word, preserve, &trng);
256 (&
state, m, c, *mlen, 6, &word, preserve, &trng);
259 ascon80pq_masked_aead_finalize(&
state, &trng, preserve, k, tag);
266 #if ASCON_MASKED_DATA_SHARES == 1
#define ASCON80PQ_TAG_SIZE
Size of the authentication tag for ASCON-80pq.
unsigned char ascon_aead_encrypt_8(ascon_state_t *state, unsigned char *dest, const unsigned char *src, size_t len, uint8_t first_round, unsigned char partial)
Encrypts a block of data with an ASCON state and an 8-byte rate.
int ascon_aead_check_tag(unsigned char *plaintext, size_t plaintext_len, const unsigned char *tag1, const unsigned char *tag2, size_t size)
Check an authentication tag in constant time.
unsigned char ascon_aead_decrypt_8(ascon_state_t *state, unsigned char *dest, const unsigned char *src, size_t len, uint8_t first_round, unsigned char partial)
Decrypts a block of data with an ASCON state and an 8-byte rate.
void ascon_aead_absorb_8(ascon_state_t *state, const unsigned char *data, size_t len, uint8_t first_round, int last_permute)
Absorbs data into an ASCON state with an 8-byte rate.
void ascon80pq_masked_aead_encrypt(unsigned char *c, size_t *clen, const unsigned char *m, size_t mlen, const unsigned char *ad, size_t adlen, const unsigned char *npub, const ascon_masked_key_160_t *k)
Encrypts and authenticates a packet with masked ASCON-80pq.
int ascon80pq_masked_aead_decrypt(unsigned char *m, size_t *mlen, const unsigned char *c, size_t clen, const unsigned char *ad, size_t adlen, const unsigned char *npub, const ascon_masked_key_160_t *k)
Decrypts and authenticates a packet with masked ASCON-80pq.
void ascon_masked_aead_absorb_8(ascon_masked_state_t *state, const unsigned char *data, size_t len, uint8_t first_round, ascon_masked_word_t *word, uint64_t *preserve, ascon_trng_state_t *trng)
Absorbs data into a masked ASCON state with an 8-byte rate.
void ascon_masked_aead_decrypt_8(ascon_masked_state_t *state, unsigned char *dest, const unsigned char *src, size_t len, uint8_t first_round, ascon_masked_word_t *word, uint64_t *preserve, ascon_trng_state_t *trng)
Decrypts a block of data with a masked ASCON state and an 8-byte rate.
void ascon_masked_aead_encrypt_8(ascon_masked_state_t *state, unsigned char *dest, const unsigned char *src, size_t len, uint8_t first_round, ascon_masked_word_t *word, uint64_t *preserve, ascon_trng_state_t *trng)
Encrypts a block of data with a masked ASCON state and an 8-byte rate.
#define ASCON_MASKED_DATA_SHARES
Number of shares to use for plaintext data and associated data, between 1 and ASCON_MASKED_KEY_SHARES...
#define ASCON_MASKED_KEY_SHARES
Number of shares to use for key material, between 2 and 4 with the default being 4.
void ascon_masked_state_free(ascon_masked_state_t *state)
Frees an ASCON-x2 permutation state and attempts to destroy any sensitive material.
void ascon_masked_state_init(ascon_masked_state_t *state)
Initializes the words of a masked ASCON permutation state.
void ascon_masked_word_separator(ascon_masked_word_t *word)
Adds a separator marker to a masked word.
uint64_t ascon_trng_generate_64(ascon_trng_state_t *state)
Generates a 64-bit random value for masking operations.
int ascon_trng_init(ascon_trng_state_t *state)
Initializes the random number source for generating a sequence of masking material at high speed.
void ascon_trng_free(ascon_trng_state_t *state)
Frees the random number source and destroys any sensitive material.
#define ascon_pad(state, offset)
#define ascon_separator(state)
void ascon_free(ascon_state_t *state)
Frees an ASCON permutation state and attempts to destroy any sensitive material.
ascon_state_t state
[snippet_key]
160-bit key that has been masked to hide its value when the code is operating on it.
ascon_masked_key_word_t k[6]
State of the ASCON permutation which has been masked with up to 4 shares.
State of the random number source.
Masked 64-bit word with up to ASCON_MASKED_MAX_SHARES shares.
Structure of the internal state of the ASCON permutation.
void ascon_clean(void *buf, unsigned size)
Cleans a buffer that contains sensitive material.