38 #if defined(ISAP_ALG_NAME)
40 #define ISAP_CONCAT_INNER(name,suffix) name##suffix
41 #define ISAP_CONCAT(name,suffix) ISAP_CONCAT_INNER(name,suffix)
43 #if defined(ASCON_BACKEND_DIRECT_XOR)
45 #define ISAP_ADD_BIT(state, value, bit) \
47 (state)->B[0] ^= ((value) << (bit)) & 0x80; \
50 #elif defined(ASCON_BACKEND_SLICED32)
52 #define ISAP_ADD_BIT(state, value, bit) \
54 (state)->W[1] ^= (((uint32_t)(value)) << (24 + (bit))) & 0x80000000U; \
57 #elif defined(ASCON_BACKEND_SLICED64)
59 #define ISAP_ADD_BIT(state, value, bit) \
61 (state)->S[0] ^= (((uint64_t)(value)) << (56 + (bit))) & 0x8000000000000000ULL; \
66 #define ISAP_ADD_BIT(state, value, bit) \
68 uint8_t absorb = (uint8_t)(((value) << (bit)) & 0x80); \
69 ascon_add_bytes((state), &absorb, 0, 1); \
107 const unsigned char *
data,
unsigned data_len)
109 unsigned bit, num_bits;
115 num_bits = data_len * 8 - 1;
116 for (bit = 0; bit < num_bits; ++bit) {
117 ISAP_ADD_BIT(
state,
data[bit / 8], bit % 8);
120 ISAP_ADD_BIT(
state,
data[bit / 8], bit % 8);
136 unsigned char *c,
const unsigned char *m,
size_t mlen)
171 const unsigned char *npub,
172 const unsigned char *ad,
size_t adlen,
173 const unsigned char *c,
size_t clen,
177 #if ISAP_KEY_SIZE != ISAP_TAG_SIZE
194 temp = (unsigned)adlen;
208 temp = (unsigned)clen;
215 #if ISAP_KEY_SIZE == ISAP_TAG_SIZE
230 #if ISAP_KEY_SIZE != ISAP_TAG_SIZE
294 (
unsigned char *c,
size_t *clen,
295 const unsigned char *m,
size_t mlen,
296 const unsigned char *ad,
size_t adlen,
297 const unsigned char *npub,
311 (&
state, pk, npub, ad, adlen, c, mlen, c + mlen);
316 (
unsigned char *m,
size_t *mlen,
317 const unsigned char *c,
size_t clen,
318 const unsigned char *ad,
size_t adlen,
319 const unsigned char *npub,
334 (&
state, pk, npub, ad, adlen, c, *mlen, tag);
351 #undef ISAP_KEY_STATE
353 #undef ISAP_NONCE_SIZE
360 #undef ISAP_STATE_SIZE
361 #undef ISAP_CONCAT_INNER
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.
#define ascon_pad(state, offset)
#define ascon_separator(state)
#define ASCON_ISAP_SAVED_KEY_SIZE
Size of a pre-computed key in its save format.
void ascon_free(ascon_state_t *state)
Frees an ASCON permutation state and attempts to destroy any sensitive material.
void ascon_release(ascon_state_t *state)
Temporarily releases access to any shared hardware resources that a permutation state was using.
void ascon_overwrite_bytes(ascon_state_t *state, const uint8_t *data, unsigned offset, unsigned size)
Overwrites existing bytes in the ASCON state.
void ascon_copy(ascon_state_t *dest, const ascon_state_t *src)
Copies the entire ASCON permutation state from a source to a destination.
void ascon_extract_bytes(const ascon_state_t *state, uint8_t *data, unsigned offset, unsigned size)
Extracts bytes from the ASCON state.
void ascon_add_bytes(ascon_state_t *state, const uint8_t *data, unsigned offset, unsigned size)
Adds bytes to the ASCON state by XOR'ing them with existing bytes.
void ascon_extract_and_add_bytes(const ascon_state_t *state, const uint8_t *input, uint8_t *output, unsigned offset, unsigned size)
Extracts bytes from the ASCON state and XOR's them with input bytes to produce output bytes.
void ascon_permute(ascon_state_t *state, uint8_t first_round)
Permutes the ASCON state with a specified number of rounds.
void ascon_acquire(ascon_state_t *state)
Re-acquires access to any shared hardware resources that a permutation state was using.
void ascon_init(ascon_state_t *state)
Initializes the words of the ASCON permutation state to zero.
ascon_state_t state
[snippet_key]
unsigned char data[8]
[snippet_key]
Structure of the internal state of the ASCON permutation.
void ascon_clean(void *buf, unsigned size)
Cleans a buffer that contains sensitive material.