ASCON Suite
Functions
ascon-xof.c File Reference
#include <ascon/xof.h>
#include "core/ascon-util-snp.h"
#include "hash/ascon-xof-internal.h"
#include <string.h>

Go to the source code of this file.

Functions

void ascon_xof (unsigned char *out, const unsigned char *in, size_t inlen)
 Hashes a block of input data with ASCON-XOF and generates a fixed-length 32 byte output. More...
 
void ascon_xof_init (ascon_xof_state_t *state)
 Initializes the state for an ASCON-XOF hashing operation. More...
 
void ascon_xof_init_fixed (ascon_xof_state_t *state, size_t outlen)
 Initializes the state for an incremental ASCON-XOF operation, with a fixed output length. More...
 
void ascon_xof_absorb_custom (ascon_xof_state_t *state, const unsigned char *custom, size_t customlen)
 Absorbs a customization string into an ASCON-XOF state. More...
 
void ascon_xof_init_custom (ascon_xof_state_t *state, const char *function_name, const unsigned char *custom, size_t customlen, size_t outlen)
 Initializes the state for an incremental ASCON-XOF operation, with a named function, customization string, and output length. More...
 
void ascon_xof_reinit (ascon_xof_state_t *state)
 Re-initializes the state for an ASCON-XOF hashing operation. More...
 
void ascon_xof_reinit_fixed (ascon_xof_state_t *state, size_t outlen)
 Re-initializes the state for an incremental ASCON-XOF operation, with a fixed output length. More...
 
void ascon_xof_reinit_custom (ascon_xof_state_t *state, const char *function_name, const unsigned char *custom, size_t customlen, size_t outlen)
 Re-nitializes the state for an incremental ASCON-XOF operation, with a named function, customization string, and output length. More...
 
void ascon_xof_free (ascon_xof_state_t *state)
 Frees the ASCON-XOF state and destroys any sensitive material. More...
 
void ascon_xof_absorb (ascon_xof_state_t *state, const unsigned char *in, size_t inlen)
 Absorbs more input data into an ASCON-XOF state. More...
 
void ascon_xof_squeeze (ascon_xof_state_t *state, unsigned char *out, size_t outlen)
 Squeezes output data from an ASCON-XOF state. More...
 
void ascon_xof_pad (ascon_xof_state_t *state)
 Absorbs enough zeroes into an ASCON-XOF state to pad the input to the next multiple of the block rate. More...
 
void ascon_xof_copy (ascon_xof_state_t *dest, const ascon_xof_state_t *src)
 Clones a copy of an ASCON-XOF state. More...
 

Function Documentation

◆ ascon_xof()

void ascon_xof ( unsigned char *  out,
const unsigned char *  in,
size_t  inlen 
)

Hashes a block of input data with ASCON-XOF and generates a fixed-length 32 byte output.

Parameters
outBuffer to receive the hash output which must be at least 32 bytes in length.
inPoints to the input data to be hashed.
inlenLength of the input data in bytes.

Use ascon_xof_squeeze() instead if you need variable-length XOF ouutput.

See also
ascon_xof_init(), ascon_xof_absorb(), ascon_xof_squeeze()

Definition at line 28 of file ascon-xof.c.

◆ ascon_xof_absorb()

void ascon_xof_absorb ( ascon_xof_state_t state,
const unsigned char *  in,
size_t  inlen 
)

Absorbs more input data into an ASCON-XOF state.

Parameters
stateXOF state to be updated.
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_xof_init(), ascon_xof_squeeze()

Definition at line 228 of file ascon-xof.c.

◆ ascon_xof_absorb_custom()

void ascon_xof_absorb_custom ( ascon_xof_state_t state,
const unsigned char *  custom,
size_t  customlen 
)

Absorbs a customization string into an ASCON-XOF state.

Parameters
stateXOF state to be updated.
customPoints to the customization string.
customlenNumber of bytes in the customization string.

Definition at line 131 of file ascon-xof.c.

◆ ascon_xof_copy()

void ascon_xof_copy ( ascon_xof_state_t dest,
const ascon_xof_state_t src 
)

Clones a copy of an ASCON-XOF state.

Parameters
destDestination XOF state to copy into.
srcSource XOF state to copy from.

The destination will be initialized by this operation, so it must not previously have been initialized or it has already been freed. The source must be already initialized.

Definition at line 344 of file ascon-xof.c.

◆ ascon_xof_free()

void ascon_xof_free ( ascon_xof_state_t state)

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

Parameters
stateXOF state to be freed.

Definition at line 218 of file ascon-xof.c.

◆ ascon_xof_init()

void ascon_xof_init ( ascon_xof_state_t state)

Initializes the state for an ASCON-XOF hashing operation.

Parameters
stateXOF state to be initialized.
See also
ascon_xof_absorb(), ascon_xof_squeeze(), ascon_xof()

Definition at line 37 of file ascon-xof.c.

◆ ascon_xof_init_custom()

void ascon_xof_init_custom ( ascon_xof_state_t state,
const char *  function_name,
const unsigned char *  custom,
size_t  customlen,
size_t  outlen 
)

Initializes the state for an incremental ASCON-XOF operation, with a named function, customization string, and output length.

Parameters
stateXOF state to be initialized.
function_nameName of the function; e.g. "KMAC". May be NULL or empty for no function name.
customPoints to the customization string.
customlenNumber of bytes in the customization string.
outlenThe desired output length in bytes, or 0 for arbitrary-length.

In the ASCON standard, the output length is encoded as a bit counter in a 32-bit word. If outlen is greater than 536870911, it will be replaced with zero to indicate arbitary-length output instead.

This version of initialization is intended for building higher-level functions like KMAC on top of ASCON-XOF. The function name provides domain separation between different functions. The customization string provides domain separation between different users of the same function.

See also
ascon_xof_init()

Definition at line 145 of file ascon-xof.c.

◆ ascon_xof_init_fixed()

void ascon_xof_init_fixed ( ascon_xof_state_t state,
size_t  outlen 
)

Initializes the state for an incremental ASCON-XOF operation, with a fixed output length.

Parameters
stateXOF state to be initialized.
outlenThe desired output length in bytes, or 0 for arbitrary-length.

In the ASCON standard, the output length is encoded as a bit counter in a 32-bit word. If outlen is greater than 536870911, it will be replaced with zero to indicate arbitary-length output instead.

See also
ascon_xof_init()

Definition at line 74 of file ascon-xof.c.

◆ ascon_xof_pad()

void ascon_xof_pad ( ascon_xof_state_t state)

Absorbs enough zeroes into an ASCON-XOF state to pad the input to the next multiple of the block rate.

Parameters
stateXOF state to pad. Does nothing if the state is already aligned on a multiple of the block rate.

This function can avoid unnecessary XOR-with-zero operations to save some time when padding is required.

Definition at line 329 of file ascon-xof.c.

◆ ascon_xof_reinit()

void ascon_xof_reinit ( ascon_xof_state_t state)

Re-initializes the state for an ASCON-XOF hashing operation.

Parameters
stateXOF state to be re-initialized.

This function is equivalent to calling ascon_xof_free() and then ascon_xof_init() to restart the hashing process.

See also
ascon_xof_init()

Definition at line 183 of file ascon-xof.c.

◆ ascon_xof_reinit_custom()

void ascon_xof_reinit_custom ( ascon_xof_state_t state,
const char *  function_name,
const unsigned char *  custom,
size_t  customlen,
size_t  outlen 
)

Re-nitializes the state for an incremental ASCON-XOF operation, with a named function, customization string, and output length.

Parameters
stateXOF state to be initialized.
function_nameName of the function; e.g. "KMAC". May be NULL or empty for no function name.
customPoints to the customization string.
customlenNumber of bytes in the customization string.
outlenThe desired output length in bytes, or 0 for arbitrary-length.
See also
ascon_xof_init_custom()

Definition at line 205 of file ascon-xof.c.

◆ ascon_xof_reinit_fixed()

void ascon_xof_reinit_fixed ( ascon_xof_state_t state,
size_t  outlen 
)

Re-initializes the state for an incremental ASCON-XOF operation, with a fixed output length.

Parameters
stateXOF state to be re-initialized.
outlenThe desired output length in bytes, or 0 for arbitrary-length.

This function is equivalent to calling ascon_xof_free() and then ascon_xof_init_fixed() to restart the hashing process.

See also
ascon_xof_init_fixed()

Definition at line 194 of file ascon-xof.c.

◆ ascon_xof_squeeze()

void ascon_xof_squeeze ( ascon_xof_state_t state,
unsigned char *  out,
size_t  outlen 
)

Squeezes output data from an ASCON-XOF state.

Parameters
stateXOF state to squeeze the output data from.
outPoints to the output buffer to receive the squeezed data.
outlenNumber of bytes of data to squeeze out of the state.
See also
ascon_xof_init(), ascon_xof_update()

Definition at line 278 of file ascon-xof.c.