libhasha 2.2.2
Loading...
Searching...
No Matches
keccak.h File Reference

Header file for Keccak-based hash functions. More...

Include dependency graph for keccak.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ha_keccak_context
 Keccak hash state context. More...

Macros

#define HA_KECCAK_224_DIGEST_SIZE   ha_bB(224)
 The digest size for the Keccak-224 hash function.
#define HA_KECCAK_256_DIGEST_SIZE   ha_bB(256)
 The digest size for the Keccak-256 hash function.
#define HA_KECCAK_384_DIGEST_SIZE   ha_bB(384)
 The digest size for the Keccak-384 hash function.
#define HA_KECCAK_512_DIGEST_SIZE   ha_bB(512)
 The digest size for the Keccak-512 hash function.

Typedefs

typedef struct ha_keccak_context ha_keccak_context
typedef ha_keccak_context ha_keccak_224_context
typedef ha_keccak_context ha_keccak_256_context
typedef ha_keccak_context ha_keccak_384_context
typedef ha_keccak_context ha_keccak_512_context

Functions

enum ha_pb ha_enum_base (uint8_t)
HA_PUBFUN void ha_keccak_init (ha_keccak_context *ctx, size_t rate)
 Initializes the Keccak-Based context.
HA_PUBFUN void ha_keccak_update (ha_keccak_context *ctx, ha_inbuf_t buf, size_t len)
 Absorbs data into the Keccak-Based context.
HA_PUBFUN void ha_keccak_final (ha_keccak_context *ctx, enum ha_pb padbyte, ha_digest_t digest, size_t digestlen)
 Finalizes the Keccak-Based computation.
HA_PUBFUN void ha_keccak_hash (size_t rate, enum ha_pb padbyte, ha_inbuf_t buf, size_t len, ha_digest_t digest, size_t digestlen)
 Computes the Keccak-Based hash in a one-shot operation.
HA_PUBFUN void ha_keccak_224_init (ha_keccak_224_context *ctx)
 Initializes the Keccak-224 context.
HA_PUBFUN void ha_keccak_224_update (ha_keccak_224_context *ctx, ha_inbuf_t data, size_t length)
 Absorbs input data for Keccak-224.
HA_PUBFUN void ha_keccak_224_final (ha_keccak_224_context *ctx, ha_digest_t digest)
 Finalizes the Keccak-224 context.
HA_PUBFUN void ha_keccak_224_hash (ha_inbuf_t data, size_t length, ha_digest_t digest)
 Computes the Keccak-224 hash in a single operation.
HA_PUBFUN void ha_keccak_256_init (ha_keccak_256_context *ctx)
 Initializes the Keccak-256 context.
HA_PUBFUN void ha_keccak_256_update (ha_keccak_256_context *ctx, ha_inbuf_t data, size_t length)
 Absorbs input data for Keccak-256.
HA_PUBFUN void ha_keccak_256_final (ha_keccak_256_context *ctx, ha_digest_t digest)
 Finalizes the Keccak-256 context.
HA_PUBFUN void ha_keccak_256_hash (ha_inbuf_t data, size_t length, ha_digest_t digest)
 Computes the Keccak-256 hash in a single operation.
HA_PUBFUN void ha_keccak_384_init (ha_keccak_384_context *ctx)
 Initializes the Keccak-384 context.
HA_PUBFUN void ha_keccak_384_update (ha_keccak_384_context *ctx, ha_inbuf_t data, size_t length)
 Absorbs input data for Keccak-384.
HA_PUBFUN void ha_keccak_384_final (ha_keccak_384_context *ctx, ha_digest_t digest)
 Finalizes the Keccak-384 context.
HA_PUBFUN void ha_keccak_384_hash (ha_inbuf_t data, size_t length, ha_digest_t digest)
 Computes the Keccak-384 hash in a single operation.
HA_PUBFUN void ha_keccak_512_init (ha_keccak_512_context *ctx)
 Initializes the Keccak-512 context.
HA_PUBFUN void ha_keccak_512_update (ha_keccak_512_context *ctx, ha_inbuf_t data, size_t length)
 Absorbs input data for Keccak-512.
HA_PUBFUN void ha_keccak_512_final (ha_keccak_512_context *ctx, ha_digest_t digest)
 Finalizes the Keccak-512 context.
HA_PUBFUN void ha_keccak_512_hash (ha_inbuf_t data, size_t length, ha_digest_t digest)
 Computes the Keccak-512 hash in a single operation.

Detailed Description

Header file for Keccak-based hash functions.

This header file defines the interface for various Keccak hash functions, including Keccak-224, Keccak-256, Keccak-384, and Keccak-512. It provides macro definitions for the rate and digest sizes of each variant, as well as a common context structure for holding the internal state of the hash computation.

The functions declared in this file include those for initializing the context, absorbing input data, finalizing the hash computation, and squeezing out the final digest. Additionally, one-shot operations are provided for convenience.

The core transformation is based on the Keccak-f[1600] permutation (see keccak1600.h) and adheres to the specifications set forth in the SHA-3 standard.

Note
The rate and digest sizes are defined in accordance with the SHA-3 standard.
See also
https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf for further details on the SHA-3 standard.

Definition in file keccak.h.

Macro Definition Documentation

◆ HA_KECCAK_224_DIGEST_SIZE

#define HA_KECCAK_224_DIGEST_SIZE   ha_bB(224)

The digest size for the Keccak-224 hash function.

This defines the size of the output hash for Keccak-224, which is 224 bits. This value is automatically calculated using the ha_bB macro.

Definition at line 40 of file keccak.h.

◆ HA_KECCAK_256_DIGEST_SIZE

#define HA_KECCAK_256_DIGEST_SIZE   ha_bB(256)

The digest size for the Keccak-256 hash function.

This defines the size of the output hash for Keccak-256, which is 256 bits. This value is automatically calculated using the ha_bB macro.

Definition at line 49 of file keccak.h.

◆ HA_KECCAK_384_DIGEST_SIZE

#define HA_KECCAK_384_DIGEST_SIZE   ha_bB(384)

The digest size for the Keccak-384 hash function.

This defines the size of the output hash for Keccak-384, which is 384 bits. This value is automatically calculated using the ha_bB macro.

Definition at line 58 of file keccak.h.

◆ HA_KECCAK_512_DIGEST_SIZE

#define HA_KECCAK_512_DIGEST_SIZE   ha_bB(512)

The digest size for the Keccak-512 hash function.

This defines the size of the output hash for Keccak-512, which is 512 bits. This value is automatically calculated using the ha_bB macro.

Definition at line 67 of file keccak.h.

Typedef Documentation

◆ ha_keccak_224_context

Definition at line 187 of file keccak.h.

◆ ha_keccak_256_context

Definition at line 187 of file keccak.h.

◆ ha_keccak_384_context

Definition at line 188 of file keccak.h.

◆ ha_keccak_512_context

Definition at line 188 of file keccak.h.

◆ ha_keccak_context

typedef struct ha_keccak_context ha_keccak_context

Function Documentation

◆ ha_enum_base()

enum ha_pb ha_enum_base ( uint8_t )

Keccak Padding Byte

Definition at line 70 of file keccak.h.

71{
72 HA_PB_KECCAK = 0x01,
73 HA_PB_SHA3 = 0x06,
74};

◆ ha_keccak_224_final()

HA_PUBFUN void ha_keccak_224_final ( ha_keccak_224_context * ctx,
ha_digest_t digest )

Finalizes the Keccak-224 context.

This function finals the Keccak-224 context after all data has been absorbed, preparing the context for squeezing the hash output.

Parameters
ctxPointer to the Keccak-224 context.

◆ ha_keccak_224_hash()

HA_PUBFUN void ha_keccak_224_hash ( ha_inbuf_t data,
size_t length,
ha_digest_t digest )

Computes the Keccak-224 hash in a single operation.

This function combines the initialization, absorption, finalization, and squeezing steps into a single operation for convenience.

Parameters
dataPointer to the input data to be hashed.
lengthThe length of the input data in bytes.
digestPointer to the buffer where the resulting hash will be stored.

◆ ha_keccak_224_init()

HA_PUBFUN void ha_keccak_224_init ( ha_keccak_224_context * ctx)

Initializes the Keccak-224 context.

This function initializes the context for the Keccak-224 hash function, setting the internal state to the default values.

Parameters
ctxPointer to the Keccak-224 context to be initialized.

◆ ha_keccak_224_update()

HA_PUBFUN void ha_keccak_224_update ( ha_keccak_224_context * ctx,
ha_inbuf_t data,
size_t length )

Absorbs input data for Keccak-224.

This function absorbs the input data into the Keccak-224 context. It processes the input in chunks and updates the internal state.

Parameters
ctxPointer to the Keccak-224 context.
dataPointer to the input data to be absorbed.
lengthThe length of the input data in bytes.

◆ ha_keccak_256_final()

HA_PUBFUN void ha_keccak_256_final ( ha_keccak_256_context * ctx,
ha_digest_t digest )

Finalizes the Keccak-256 context.

This function finals the Keccak-256 context after all data has been absorbed.

Parameters
ctxPointer to the Keccak-256 context.

◆ ha_keccak_256_hash()

HA_PUBFUN void ha_keccak_256_hash ( ha_inbuf_t data,
size_t length,
ha_digest_t digest )

Computes the Keccak-256 hash in a single operation.

This function combines the initialization, absorption, finalization, and squeezing steps into a single operation for convenience.

Parameters
dataPointer to the input data to be hashed.
lengthThe length of the input data in bytes.
digestPointer to the buffer where the resulting hash will be stored.

◆ ha_keccak_256_init()

HA_PUBFUN void ha_keccak_256_init ( ha_keccak_256_context * ctx)

Initializes the Keccak-256 context.

This function initializes the context for the Keccak-256 hash function.

Parameters
ctxPointer to the Keccak-256 context to be initialized.

◆ ha_keccak_256_update()

HA_PUBFUN void ha_keccak_256_update ( ha_keccak_256_context * ctx,
ha_inbuf_t data,
size_t length )

Absorbs input data for Keccak-256.

This function absorbs the input data into the Keccak-256 context.

Parameters
ctxPointer to the Keccak-256 context.
dataPointer to the input data to be absorbed.
lengthThe length of the input data in bytes.

◆ ha_keccak_384_final()

HA_PUBFUN void ha_keccak_384_final ( ha_keccak_384_context * ctx,
ha_digest_t digest )

Finalizes the Keccak-384 context.

This function finals the Keccak-384 context after all data has been absorbed.

◆ ha_keccak_384_hash()

HA_PUBFUN void ha_keccak_384_hash ( ha_inbuf_t data,
size_t length,
ha_digest_t digest )

Computes the Keccak-384 hash in a single operation.

This function combines the initialization, absorption, finalization, and squeezing steps into a single operation for convenience.

◆ ha_keccak_384_init()

HA_PUBFUN void ha_keccak_384_init ( ha_keccak_384_context * ctx)

Initializes the Keccak-384 context.

This function initializes the context for the Keccak-384 hash function.

◆ ha_keccak_384_update()

HA_PUBFUN void ha_keccak_384_update ( ha_keccak_384_context * ctx,
ha_inbuf_t data,
size_t length )

Absorbs input data for Keccak-384.

This function absorbs the input data into the Keccak-384 context.

◆ ha_keccak_512_final()

HA_PUBFUN void ha_keccak_512_final ( ha_keccak_512_context * ctx,
ha_digest_t digest )

Finalizes the Keccak-512 context.

This function finals the Keccak-512 context after all data has been absorbed.

◆ ha_keccak_512_hash()

HA_PUBFUN void ha_keccak_512_hash ( ha_inbuf_t data,
size_t length,
ha_digest_t digest )

Computes the Keccak-512 hash in a single operation.

This function combines the initialization, absorption, finalization, and squeezing steps into a single operation for convenience.

◆ ha_keccak_512_init()

HA_PUBFUN void ha_keccak_512_init ( ha_keccak_512_context * ctx)

Initializes the Keccak-512 context.

This function initializes the context for the Keccak-512 hash function.

◆ ha_keccak_512_update()

HA_PUBFUN void ha_keccak_512_update ( ha_keccak_512_context * ctx,
ha_inbuf_t data,
size_t length )

Absorbs input data for Keccak-512.

This function absorbs the input data into the Keccak-512 context.

◆ ha_keccak_final()

HA_PUBFUN void ha_keccak_final ( ha_keccak_context * ctx,
enum ha_pb padbyte,
ha_digest_t digest,
size_t digestlen )

Finalizes the Keccak-Based computation.

This function finals the Keccak-Based hash calculation.

Parameters
ctxPointer to the Keccak-Based context structure.
digestPointer to the output buffer where the final hash will be stored.
digestlenThe length of the final hash (in bytes).
Note
The digest length must match the expected size

◆ ha_keccak_hash()

HA_PUBFUN void ha_keccak_hash ( size_t rate,
enum ha_pb padbyte,
ha_inbuf_t buf,
size_t len,
ha_digest_t digest,
size_t digestlen )

Computes the Keccak-Based hash in a one-shot operation.

This function computes the SHA3 hash of the provided data in a single call. It initializes, absorbs, finals, and squeezes the result internally.

Parameters
rateThe rate of the Keccak-Based algorithm (in bytes)
padbyteThe padding byte of the Keccak-Based algorithm
dataPointer to the input data to process.
lengthLength of the input data in bytes.
digestPointer to the output buffer to store the final Keccak-Based digest.

◆ ha_keccak_init()

HA_PUBFUN void ha_keccak_init ( ha_keccak_context * ctx,
size_t rate )

Initializes the Keccak-Based context.

This function initializes the Keccak-Based context to start a new hash computation.

Parameters
ctxPointer to the Keccak-Based context structure to initialize.
rateThe rate of the Keccak-Based algorithm (in bytes)

◆ ha_keccak_update()

HA_PUBFUN void ha_keccak_update ( ha_keccak_context * ctx,
ha_inbuf_t buf,
size_t len )

Absorbs data into the Keccak-Based context.

This function processes the provided data and updates the Keccak-Based context state.

Parameters
ctxPointer to the Keccak-Based context structure.
dataPointer to the input data to process.
lengthLength of the input data in bytes.
Note
The data is absorbed into the context in blocks of size defined by the rate.