ASCON Suite
Macros | Functions
ascon-prf.c File Reference
#include <ascon/prf.h>
#include <ascon/utility.h>
#include "core/ascon-util-snp.h"
#include "aead/ascon-aead-common.h"

Go to the source code of this file.

Macros

#define ASCON_PRF_RATE_IN   32
 Rate of absorption for input blocks. More...
 
#define ASCON_PRF_RATE_OUT   16
 Rate of squeezing for output blocks. More...
 

Functions

void ascon_prf (unsigned char *out, size_t outlen, const unsigned char *in, size_t inlen, const unsigned char *key)
 Processes a key and input data with ASCON-Prf to produce a tag. More...
 
void ascon_prf_fixed (unsigned char *out, size_t outlen, const unsigned char *in, size_t inlen, const unsigned char *key)
 Processes a key and input data with ASCON-Prf to produce a fixed-length output tag. More...
 
int ascon_prf_short (unsigned char *out, size_t outlen, const unsigned char *in, size_t inlen, const unsigned char *key)
 Processes a key and input data with ASCON-PrfShort to produce a tag. More...
 
void ascon_mac (unsigned char *tag, const unsigned char *in, size_t inlen, const unsigned char *key)
 Processes a key and input data with ASCON-Mac to produce a tag. More...
 
int ascon_mac_verify (const unsigned char *tag, const unsigned char *in, size_t inlen, const unsigned char *key)
 Verifies an ASCON-Mac tag value. More...
 
void ascon_prf_init (ascon_prf_state_t *state, const unsigned char *key)
 Initializes the state for an incremental ASCON-Prf operation. More...
 
void ascon_prf_fixed_init (ascon_prf_state_t *state, const unsigned char *key, size_t outlen)
 Initializes the state for an incremental ASCON-Prf operation with fixed-length output. More...
 
void ascon_prf_reinit (ascon_prf_state_t *state, const unsigned char *key)
 Re-initializes the state for an incremental ASCON-Prf operation. More...
 
void ascon_prf_fixed_reinit (ascon_prf_state_t *state, const unsigned char *key, size_t outlen)
 Re-initializes the state for an incremental ASCON-Prf operation with fixed-length output. More...
 
void ascon_prf_free (ascon_prf_state_t *state)
 Frees the ASCON-Prf state and destroys any sensitive material. More...
 
void ascon_prf_absorb (ascon_prf_state_t *state, const unsigned char *in, size_t inlen)
 Absorbs input data into an incremental ASCON-Prf state. More...
 
void ascon_prf_squeeze (ascon_prf_state_t *state, unsigned char *out, size_t outlen)
 Squeezes output from an incremental ASCON-Prf operation. More...
 

Macro Definition Documentation

◆ ASCON_PRF_RATE_IN

#define ASCON_PRF_RATE_IN   32

Rate of absorption for input blocks.

Definition at line 31 of file ascon-prf.c.

◆ ASCON_PRF_RATE_OUT

#define ASCON_PRF_RATE_OUT   16

Rate of squeezing for output blocks.

Definition at line 36 of file ascon-prf.c.

Function Documentation

◆ ascon_mac()

void ascon_mac ( unsigned char *  tag,
const unsigned char *  in,
size_t  inlen,
const unsigned char *  key 
)

Processes a key and input data with ASCON-Mac to produce a tag.

Parameters
tagBuffer to receive the ASCON_PRF_TAG_SIZE bytes of the tag.
inPoints to the input data to be processed.
inlenLength of the input data in bytes.
keyPoints to the ASCON_PRF_KEY_SIZE bytes of the key.

This function operates ASCON-Prf in fixed-length output mode with the output length set to ASCON_PRF_TAG_SIZE.

See also
ascon_mac_verify(), ascon_prf()

Definition at line 85 of file ascon-prf.c.

◆ ascon_mac_verify()

int ascon_mac_verify ( const unsigned char *  tag,
const unsigned char *  in,
size_t  inlen,
const unsigned char *  key 
)

Verifies an ASCON-Mac tag value.

Parameters
tagBuffer that contains the ASCON_PRF_TAG_SIZE bytes of the tag.
inPoints to the input data to be processed.
inlenLength of the input data in bytes.
keyPoints to the ASCON_PRF_KEY_SIZE bytes of the key.
Returns
0 if the tag is correct or -1 if incorrect.
See also
ascon_mac(), ascon_prf()

Definition at line 97 of file ascon-prf.c.

◆ ascon_prf()

void ascon_prf ( unsigned char *  out,
size_t  outlen,
const unsigned char *  in,
size_t  inlen,
const unsigned char *  key 
)

Processes a key and input data with ASCON-Prf to produce a tag.

Parameters
outBuffer to receive the PRF tag which must be at least outlen bytes in length.
outlenLength of the output buffer in bytes. Recommended to be ASCON_PRF_TAG_SIZE.
inPoints to the input data to be processed.
inlenLength of the input data in bytes.
keyPoints to the ASCON_PRF_KEY_SIZE bytes of the key.

This function operates ASCON-Prf in unlimited output mode, with the output truncated at outlen bytes.

See also
ascon_prf_fixed(), ascon_prf_short(), ascon_mac()

Definition at line 38 of file ascon-prf.c.

◆ ascon_prf_absorb()

void ascon_prf_absorb ( ascon_prf_state_t state,
const unsigned char *  in,
size_t  inlen 
)

Absorbs input data into an incremental ASCON-Prf state.

Parameters
statePRF state to be absorb.
inPoints to the input data to be absorbed into the state.
inlenLength of the input data to be absorbed into the state.
See also
ascon_prf_init(), ascon_prf_squeeze()

Definition at line 156 of file ascon-prf.c.

◆ ascon_prf_fixed()

void ascon_prf_fixed ( unsigned char *  out,
size_t  outlen,
const unsigned char *  in,
size_t  inlen,
const unsigned char *  key 
)

Processes a key and input data with ASCON-Prf to produce a fixed-length output tag.

Parameters
outBuffer to receive the PRF tag which must be at least outlen bytes in length.
outlenLength of the output buffer in bytes. Recommended to be ASCON_PRF_TAG_SIZE.
inPoints to the input data to be processed.
inlenLength of the input data in bytes.
keyPoints to the ASCON_PRF_KEY_SIZE bytes of the key.

This function operates ASCON-Prf in fixed-length output mode, with the output length set at exactly outlen bytes.

See also
ascon_prf(), ascon_prf_short(), ascon_mac()

Definition at line 50 of file ascon-prf.c.

◆ ascon_prf_fixed_init()

void ascon_prf_fixed_init ( ascon_prf_state_t state,
const unsigned char *  key,
size_t  outlen 
)

Initializes the state for an incremental ASCON-Prf operation with fixed-length output.

Parameters
statePRF state to be initialized.
keyPoints to the ASCON_PRF_KEY_SIZE bytes of the key.
outlenNumber of bytes of output that is desired, or 0 for unlimited.

This function will set ASCON-Prf into unlimited output mode.

See also
ascon_prf_init(), ascon_prf_absorb(), ascon_prf_squeeze()

Definition at line 115 of file ascon-prf.c.

◆ ascon_prf_fixed_reinit()

void ascon_prf_fixed_reinit ( ascon_prf_state_t state,
const unsigned char *  key,
size_t  outlen 
)

Re-initializes the state for an incremental ASCON-Prf operation with fixed-length output.

Parameters
statePRF state to be re-initialized.
keyPoints to the ASCON_PRF_KEY_SIZE bytes of the key.
outlenNumber of bytes of output that is desired, or 0 for unlimited.

This function is equivalent to calling ascon_prf_free() and then ascon_prf_init() to restart the hashing process.

See also
ascon_prf_reinit(), ascon_prf_fixed_init()

Definition at line 139 of file ascon-prf.c.

◆ ascon_prf_free()

void ascon_prf_free ( ascon_prf_state_t state)

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

Parameters
statePRF state to be freed.

Definition at line 146 of file ascon-prf.c.

◆ ascon_prf_init()

void ascon_prf_init ( ascon_prf_state_t state,
const unsigned char *  key 
)

Initializes the state for an incremental ASCON-Prf operation.

Parameters
statePRF state to be initialized.
keyPoints to the ASCON_PRF_KEY_SIZE bytes of the key.

This function will set ASCON-Prf into unlimited output mode.

See also
ascon_prf_fixed_init(), ascon_prf_absorb(), ascon_prf_squeeze()

Definition at line 110 of file ascon-prf.c.

◆ ascon_prf_reinit()

void ascon_prf_reinit ( ascon_prf_state_t state,
const unsigned char *  key 
)

Re-initializes the state for an incremental ASCON-Prf operation.

Parameters
statePRF state to be re-initialized.
keyPoints to the ASCON_PRF_KEY_SIZE bytes of the key.

This function is equivalent to calling ascon_prf_free() and then ascon_prf_init() to restart the hashing process.

See also
ascon_prf_fixed_reinit(), ascon_prf_init()

Definition at line 133 of file ascon-prf.c.

◆ ascon_prf_short()

int ascon_prf_short ( unsigned char *  out,
size_t  outlen,
const unsigned char *  in,
size_t  inlen,
const unsigned char *  key 
)

Processes a key and input data with ASCON-PrfShort to produce a tag.

Parameters
outBuffer to receive the PRF tag which must be at least outlen bytes in length.
outlenLength of the output buffer in bytes between 0 and ASCON_PRF_SHORT_MAX_OUTPUT_SIZE.
inPoints to the input data to be processed.
inlenLength of the input data in bytes between 0 and ASCON_PRF_SHORT_MAX_INPUT_SIZE.
keyPoints to the ASCON_PRF_KEY_SIZE bytes of the key.
Returns
0 if the output was generated, or -1 if either outlen or inlen are out of range.
See also
ascon_prf(), ascon_prf_fixed(), ascon_mac()

Definition at line 62 of file ascon-prf.c.

◆ ascon_prf_squeeze()

void ascon_prf_squeeze ( ascon_prf_state_t state,
unsigned char *  out,
size_t  outlen 
)

Squeezes output from an incremental ASCON-Prf operation.

Parameters
statePRF state to squeeze output from.
outPoints to the output buffer to receive the output.
outlenNumber of bytes of output that are required for this call.

This function can be called any number of times until all desired output has been retrieved.

See also
ascon_prf_init(), ascon_prf_absorb()

Definition at line 207 of file ascon-prf.c.