ASCON Suite
Classes | Macros | Functions
hmac.h File Reference

Hashed Message Authentication Code (HMAC) based on ASCON-HASH. More...

#include <ascon/hash.h>

Go to the source code of this file.

Classes

struct  ascon_hmac_state_t
 State information for the ASCON-HMAC incremental mode. More...
 
struct  ascon_hmaca_state_t
 State information for the ASCON-HMACA incremental mode. More...
 

Macros

#define ASCON_HMAC_SIZE   ASCON_HASH_SIZE
 Default size of the output for ASCON-HMAC. More...
 
#define ASCON_HMACA_SIZE   ASCON_HASHA_SIZE
 Default size of the output for ASCON-HMACA. More...
 

Functions

void ascon_hmac (unsigned char *out, const unsigned char *key, size_t keylen, const unsigned char *in, size_t inlen)
 Computes a HMAC value using ASCON-HASH. More...
 
void ascon_hmac_init (ascon_hmac_state_t *state, const unsigned char *key, size_t keylen)
 Initializes an incremental HMAC state using ASCON-HASH. More...
 
void ascon_hmac_reinit (ascon_hmac_state_t *state, const unsigned char *key, size_t keylen)
 Re-initializes an incremental HMAC state using ASCON-HASH. More...
 
void ascon_hmac_free (ascon_hmac_state_t *state)
 Frees the ASCON-HMAC state and destroys any sensitive material. More...
 
void ascon_hmac_update (ascon_hmac_state_t *state, const unsigned char *in, size_t inlen)
 Updates an incremental ASCON-HMAC state with more input data. More...
 
void ascon_hmac_finalize (ascon_hmac_state_t *state, const unsigned char *key, size_t keylen, unsigned char *out)
 Finalizes an incremental ASCON-HMAC state. More...
 
void ascon_hmaca (unsigned char *out, const unsigned char *key, size_t keylen, const unsigned char *in, size_t inlen)
 Computes a HMAC value using ASCON-HASHA. More...
 
void ascon_hmaca_init (ascon_hmaca_state_t *state, const unsigned char *key, size_t keylen)
 Initializes an incremental HMAC state using ASCON-HASHA. More...
 
void ascon_hmaca_reinit (ascon_hmaca_state_t *state, const unsigned char *key, size_t keylen)
 Re-initializes an incremental HMAC state using ASCON-HASHA. More...
 
void ascon_hmaca_free (ascon_hmaca_state_t *state)
 Frees the ASCON-HMACA state and destroys any sensitive material. More...
 
void ascon_hmaca_update (ascon_hmaca_state_t *state, const unsigned char *in, size_t inlen)
 Updates an incremental ASCON-HMACA state with more input data. More...
 
void ascon_hmaca_finalize (ascon_hmaca_state_t *state, const unsigned char *key, size_t keylen, unsigned char *out)
 Finalizes an incremental ASCON-HMACA state. More...
 

Detailed Description

Hashed Message Authentication Code (HMAC) based on ASCON-HASH.

The HMAC mode provides a method to authenticate a sequence of bytes using ASCON-HASH or ASCON-HASHA as the underlying digest algorithm.

HMAC uses an underlying block size to pad the key data. The ASCON-HASH block absorption rate of 8 bytes is too short so we use the HMAC-SHA-256 block size of 64 instead.

Note
The KMAC construction is preferable for sponge-based hash algorithms as it is simpler and more efficient. HMAC mode is provided for drop-in compatibility with existing designs.

Reference: https://tools.ietf.org/html/rfc2104

Definition in file hmac.h.

Macro Definition Documentation

◆ ASCON_HMAC_SIZE

#define ASCON_HMAC_SIZE   ASCON_HASH_SIZE

Default size of the output for ASCON-HMAC.

Definition at line 53 of file hmac.h.

◆ ASCON_HMACA_SIZE

#define ASCON_HMACA_SIZE   ASCON_HASHA_SIZE

Default size of the output for ASCON-HMACA.

Definition at line 58 of file hmac.h.

Function Documentation

◆ ascon_hmac()

void ascon_hmac ( unsigned char *  out,
const unsigned char *  key,
size_t  keylen,
const unsigned char *  in,
size_t  inlen 
)

Computes a HMAC value using ASCON-HASH.

Parameters
outBuffer to receive the output HMAC value; must be at least ASCON_HMAC_SIZE bytes in length.
keyPoints to the key.
keylenNumber of bytes in the key.
inPoints to the data to authenticate.
inlenNumber of bytes of data to authenticate.

◆ ascon_hmac_finalize()

void ascon_hmac_finalize ( ascon_hmac_state_t state,
const unsigned char *  key,
size_t  keylen,
unsigned char *  out 
)

Finalizes an incremental ASCON-HMAC state.

Parameters
stateHMAC state to squeeze the output data from.
keyPoints to the key.
keylenNumber of bytes in the key.
outPoints to the output buffer to receive the HMAC value; must be at least ASCON_HMAC_SIZE bytes in length.
See also
ascon_hmac_init(), ascon_hmac_update()

◆ ascon_hmac_free()

void ascon_hmac_free ( ascon_hmac_state_t state)

Frees the ASCON-HMAC state and destroys any sensitive material.

Parameters
stateHMAC state to be freed.

◆ ascon_hmac_init()

void ascon_hmac_init ( ascon_hmac_state_t state,
const unsigned char *  key,
size_t  keylen 
)

Initializes an incremental HMAC state using ASCON-HASH.

Parameters
statePoints to the state to be initialized.
keyPoints to the key.
keylenNumber of bytes in the key.

The key needs to be preserved until the ascon_hmac_finalize() call to provide the outer HMAC hashing key.

See also
ascon_hmac_update(), ascon_hmac_finalize()

◆ ascon_hmac_reinit()

void ascon_hmac_reinit ( ascon_hmac_state_t state,
const unsigned char *  key,
size_t  keylen 
)

Re-initializes an incremental HMAC state using ASCON-HASH.

Parameters
statePoints to the state to be re-initialized.
keyPoints to the key.
keylenNumber of bytes in the key.

The key needs to be preserved until the ascon_hmac_finalize() call to provide the outer HMAC hashing key.

This function is equivalent to calling ascon_hmac_free() followed by ascon_hmac_init().

See also
ascon_hmac_init()

◆ ascon_hmac_update()

void ascon_hmac_update ( ascon_hmac_state_t state,
const unsigned char *  in,
size_t  inlen 
)

Updates an incremental ASCON-HMAC state with more input data.

Parameters
stateHMAC state to be updated.
inPoints to the input data to be incorporated into the state.
inlenLength of the input data to be incorporated into the state.
See also
ascon_hmac_init(), ascon_hmac_finalize()

◆ ascon_hmaca()

void ascon_hmaca ( unsigned char *  out,
const unsigned char *  key,
size_t  keylen,
const unsigned char *  in,
size_t  inlen 
)

Computes a HMAC value using ASCON-HASHA.

Parameters
outBuffer to receive the output HMAC value; must be at least ASCON_HMACA_SIZE bytes in length.
keyPoints to the key.
keylenNumber of bytes in the key.
inPoints to the data to authenticate.
inlenNumber of bytes of data to authenticate.

◆ ascon_hmaca_finalize()

void ascon_hmaca_finalize ( ascon_hmaca_state_t state,
const unsigned char *  key,
size_t  keylen,
unsigned char *  out 
)

Finalizes an incremental ASCON-HMACA state.

Parameters
stateHMAC state to squeeze the output data from.
keyPoints to the key.
keylenNumber of bytes in the key.
outPoints to the output buffer to receive the HMAC value; must be at least ASCON_HMACA_SIZE bytes in length.
See also
ascon_hmaca_init(), ascon_hmaca_update()

◆ ascon_hmaca_free()

void ascon_hmaca_free ( ascon_hmaca_state_t state)

Frees the ASCON-HMACA state and destroys any sensitive material.

Parameters
stateHMAC state to be freed.

◆ ascon_hmaca_init()

void ascon_hmaca_init ( ascon_hmaca_state_t state,
const unsigned char *  key,
size_t  keylen 
)

Initializes an incremental HMAC state using ASCON-HASHA.

Parameters
statePoints to the state to be initialized.
keyPoints to the key.
keylenNumber of bytes in the key.

The key needs to be preserved until the ascon_hmaca_finalize() call to provide the outer HMAC hashing key.

See also
ascon_hmaca_update(), ascon_hmaca_finalize()

◆ ascon_hmaca_reinit()

void ascon_hmaca_reinit ( ascon_hmaca_state_t state,
const unsigned char *  key,
size_t  keylen 
)

Re-initializes an incremental HMAC state using ASCON-HASHA.

Parameters
statePoints to the state to be re-initialized.
keyPoints to the key.
keylenNumber of bytes in the key.

The key needs to be preserved until the ascon_hmaca_finalize() call to provide the outer HMAC hashing key.

This function is equivalent to calling ascon_hmaca_free() followed by ascon_hmaca_init().

See also
ascon_hmac_init()

◆ ascon_hmaca_update()

void ascon_hmaca_update ( ascon_hmaca_state_t state,
const unsigned char *  in,
size_t  inlen 
)

Updates an incremental ASCON-HMACA state with more input data.

Parameters
stateHMAC state to be updated.
inPoints to the input data to be incorporated into the state.
inlenLength of the input data to be incorporated into the state.
See also
ascon_hmaca_init(), ascon_hmaca_finalize()