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

Header file for the EVP Hasher abstraction. More...

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

Go to the source code of this file.

Macros

#define ha_ctx(hash)
 Context type for a specific hash algorithm.
#define ha_init_fun(hash)
 Function macros for initializing, updating, and finalizing hashing operations.
#define ha_update_fun(hash)
#define ha_final_fun(hash)
#define ha_hash_fun(hash)
#define ha_init(hash, ctx)
 Initializes the hash context for a specific algorithm.
#define ha_update(hash, ctx, buf, buflen)
 Updates the hash context with more data.
#define ha_final(hash, ctx, ...)
 Finalizes the hash context and produces the hash.
#define ha_hash(hash, buf, buflen, digest, ...)
 Computes the hash in a single operation.

Typedefs

typedef struct ha_evp_hasher ha_evp_hasher_t
 Opaque structure for the EVP hasher state.
typedef struct ha_evp_hasher * ha_evp_phasher_t

Functions

enum ha_evp_hashty ha_enum_base (uint8_t)
enum ha_enum_base (int8_t)
HA_EXTERN_C_BEG HA_PUBFUN void ha_evp_put (struct ha_evp_hasher *hasher, ha_cdigest_t digest, const char *end)
 Put hash to stdout.
HA_PUBFUN void ha_evp_fput (struct ha_evp_hasher *hasher, FILE *stream, ha_cdigest_t digest, const char *end)
 Put hash to FILE *.
HA_PUBFUN signed long ha_evp_hashty_get_digestlen (enum ha_evp_hashty hashty)
 Get fixed hash size.
HA_PUBFUN const char * ha_evp_hashty_tostr (enum ha_evp_hashty hashty)
 Returns g_ha_evp_hashty_strings[hashty] (with error handling)
HA_PUBFUN void ha_evp_hasher_set_keccak_rate (struct ha_evp_hasher *hasher, uint16_t rate)
 Setter for ha_evp_hasher krate field.
HA_PUBFUN size_t ha_evp_hasher_keccak_rate (struct ha_evp_hasher *hasher)
 Getter for ha_evp_hasher krate field.
HA_PUBFUN void ha_evp_hasher_set_keccak_custom (struct ha_evp_hasher *hasher, bool custom)
 Setter for ha_evp_hasher kustom field.
HA_PUBFUN bool ha_evp_hasher_keccak_custom (struct ha_evp_hasher *hasher)
 Getter for ha_evp_hasher kustom field.
HA_PUBFUN size_t ha_evp_hasher_ctxsize (struct ha_evp_hasher *hasher)
 Getter for ha_evp_hasher ctx_size field.
HA_PUBFUN enum ha_evp_hashty ha_evp_hasher_hashty (struct ha_evp_hasher *hasher)
 Getter for ha_evp_hasher ctx_hashty field.
HA_PUBFUN void ha_evp_hasher_set_hashty (struct ha_evp_hasher *hasher, enum ha_evp_hashty hashty)
 Setter for ha_evp_hasher ctx_hashty field.
HA_PUBFUN size_t ha_evp_hasher_digestlen (struct ha_evp_hasher *hasher)
 Getter for ha_evp_hasher ctx_digestlen field.
HA_PUBFUN void ha_evp_hasher_set_digestlen (struct ha_evp_hasher *hasher, size_t digestlen)
 Setter for ha_evp_hasher ctx_digestlen field.
HA_PUBFUN struct ha_evp_hasher * ha_evp_hasher_new (void)
 Creates a new EVP hasher. ( malloc(g_ha_evp_hasher_size) )
HA_PUBFUN void ha_evp_hasher_delete (struct ha_evp_hasher *ptr)
 Frees the memory of an EVP hasher.
HA_PUBFUN void ha_evp_hasher_init (struct ha_evp_hasher *hasher, enum ha_evp_hashty hashty, size_t digestlen)
 Initializes the EVP hasher for a specific algorithm and digest length.
HA_PUBFUN void ha_evp_hasher_cleanup (struct ha_evp_hasher *hasher)
 Cleans up the internal state of the EVP hasher.
HA_PUBFUN void ha_evp_hasher_reinit (struct ha_evp_hasher *hasher, enum ha_evp_hashty hashty, size_t digestlen)
 Reinitializes the EVP hasher with a new algorithm and digest length.
HA_PUBFUN void ha_evp_hasher_commit (struct ha_evp_hasher *hasher)
 Reinitializes the EVP hasher.
HA_PUBFUN void ha_evp_init (struct ha_evp_hasher *hasher)
 Initializes the EVP hash. ( like ha_init(hash, ctx) )
HA_PUBFUN void ha_evp_update (struct ha_evp_hasher *hasher, ha_inbuf_t buf, size_t len)
 Updates the EVP hash with input data. ( like ha_update(hash, ctx, buf, len) )
HA_PUBFUN void ha_evp_final (struct ha_evp_hasher *hasher, ha_digest_t digest)
 Finalizes the EVP hash and produces the output digest. ( like ha_final(hash, ctx, digest, opt digestlen) )
HA_PUBFUN void ha_evp_hash (struct ha_evp_hasher *hasher, ha_inbuf_t buf, size_t len, ha_digest_t digest)
 Computes the EVP hash in a single (hash) operation. ( like ha_hash(hash, buf, len, digest, opt digestlen) )
HA_PUBFUN void ha_evp_digest (struct ha_evp_hasher *hasher, ha_inbuf_t buf, size_t len, ha_digest_t digest)
 Computes the EVP hash in a init, update, final operation. ( like ha_ada_hash(hash, buf, len, digest, opt digestlen) )

Variables

const size_t g_ha_evp_hasher_size
 Size of the EVP hasher structure.

Detailed Description

Header file for the EVP Hasher abstraction.

This file defines the API for the EVP (Envelope) hasher abstraction, which supports various cryptographic hash algorithms, including BLAKE2b, SHA-3, and others. The API includes function declarations for initialization, update, finalization, and a one-shot hashing operation.

The EVP abstraction allows for easy integration with multiple hash algorithms and provides flexibility for extending the library with additional algorithms in the future.

Definition in file evp.h.

Macro Definition Documentation

◆ ha_ctx

#define ha_ctx ( hash)
Value:
ha_##hash##_context

Context type for a specific hash algorithm.

Definition at line 26 of file evp.h.

◆ ha_final

#define ha_final ( hash,
ctx,
... )
Value:
ha_##hash##_final(ctx, ##__VA_ARGS__)

Finalizes the hash context and produces the hash.

Definition at line 51 of file evp.h.

◆ ha_final_fun

#define ha_final_fun ( hash)
Value:
ha_##hash##_final

Definition at line 34 of file evp.h.

◆ ha_hash

#define ha_hash ( hash,
buf,
buflen,
digest,
... )
Value:
ha_##hash##_hash(buf, buflen, digest, ##__VA_ARGS__)

Computes the hash in a single operation.

Definition at line 56 of file evp.h.

56#define ha_hash(hash, buf, buflen, digest, ...) \
57 ha_##hash##_hash(buf, buflen, digest, ##__VA_ARGS__)

◆ ha_hash_fun

#define ha_hash_fun ( hash)
Value:
ha_##hash##_hash

Definition at line 35 of file evp.h.

◆ ha_init

#define ha_init ( hash,
ctx )
Value:
ha_##hash##_init(ctx)

Initializes the hash context for a specific algorithm.

Definition at line 40 of file evp.h.

◆ ha_init_fun

#define ha_init_fun ( hash)
Value:
ha_##hash##_init

Function macros for initializing, updating, and finalizing hashing operations.

Definition at line 32 of file evp.h.

◆ ha_update

#define ha_update ( hash,
ctx,
buf,
buflen )
Value:
ha_##hash##_update(ctx, buf, buflen)

Updates the hash context with more data.

Definition at line 45 of file evp.h.

45#define ha_update(hash, ctx, buf, buflen) \
46 ha_##hash##_update(ctx, buf, buflen)

◆ ha_update_fun

#define ha_update_fun ( hash)
Value:
ha_##hash##_update

Definition at line 33 of file evp.h.

Typedef Documentation

◆ ha_evp_hasher_t

typedef struct ha_evp_hasher ha_evp_hasher_t

Opaque structure for the EVP hasher state.

Definition at line 133 of file evp.h.

◆ ha_evp_phasher_t

typedef struct ha_evp_hasher * ha_evp_phasher_t

Definition at line 133 of file evp.h.

Function Documentation

◆ ha_enum_base() [1/2]

enum ha_enum_base ( int8_t )

Definition at line 106 of file evp.h.

120{
121 /* constant: i8 */
122 HA_EVPTY_SIZE_DYNAMIC = -1,
123};

◆ ha_enum_base() [2/2]

enum ha_evp_hashty ha_enum_base ( uint8_t )

< Undefined (not handled)

< BLAKE2b hash

< BLAKE2s hash

< BLAKE3 hash

< Keccak (pre-standard SHA-3)

< MD5 hash

< SHA-1 hash

< SHA-2 (SHA-224/256/384/512)

< SHA-3 (standardized version)

Definition at line 106 of file evp.h.

107{
108 HA_EVPTY_UNDEFINED,
109 HA_EVPTY_BLAKE2B,
110 HA_EVPTY_BLAKE2S,
111 HA_EVPTY_BLAKE3,
112 HA_EVPTY_KECCAK,
113 HA_EVPTY_MD5,
114 HA_EVPTY_SHA1,
115 HA_EVPTY_SHA2,
116 HA_EVPTY_SHA3,
117};

◆ ha_evp_digest()

HA_PUBFUN void ha_evp_digest ( struct ha_evp_hasher * hasher,
ha_inbuf_t buf,
size_t len,
ha_digest_t digest )

Computes the EVP hash in a init, update, final operation. ( like ha_ada_hash(hash, buf, len, digest, opt digestlen) )

This function combines initialization, updating, and finalization steps into a single call.

Parameters
hasherPointer to the EVP hasher.
bufPointer to the input data buffer.
lenLength of the input data in bytes.
digestPointer to the buffer where the resulting digest will be stored.

◆ ha_evp_final()

HA_PUBFUN void ha_evp_final ( struct ha_evp_hasher * hasher,
ha_digest_t digest )

Finalizes the EVP hash and produces the output digest. ( like ha_final(hash, ctx, digest, opt digestlen) )

This function completes the hashing process and stores the resulting digest in the specified buffer.

Parameters
hasherPointer to the EVP hasher.
digestPointer to the buffer where the resulting digest will be stored.

◆ ha_evp_fput()

HA_PUBFUN void ha_evp_fput ( struct ha_evp_hasher * hasher,
FILE * stream,
ha_cdigest_t digest,
const char * end )

Put hash to FILE *.

◆ ha_evp_hash()

HA_PUBFUN void ha_evp_hash ( struct ha_evp_hasher * hasher,
ha_inbuf_t buf,
size_t len,
ha_digest_t digest )

Computes the EVP hash in a single (hash) operation. ( like ha_hash(hash, buf, len, digest, opt digestlen) )

This function combines initialization, updating, and finalization steps into a single call.

Parameters
hasherPointer to the EVP hasher.
bufPointer to the input data buffer.
lenLength of the input data in bytes.
digestPointer to the buffer where the resulting digest will be stored.

◆ ha_evp_hasher_cleanup()

HA_PUBFUN void ha_evp_hasher_cleanup ( struct ha_evp_hasher * hasher)

Cleans up the internal state of the EVP hasher.

This function clears any buffers and prepares the EVP hasher for reuse.

Parameters
hasherPointer to the EVP hasher to clean up.

◆ ha_evp_hasher_commit()

HA_PUBFUN void ha_evp_hasher_commit ( struct ha_evp_hasher * hasher)

Reinitializes the EVP hasher.

Parameters
hasherPointer to the EVP hasher to reinitialize without changes.

◆ ha_evp_hasher_ctxsize()

HA_PUBFUN size_t ha_evp_hasher_ctxsize ( struct ha_evp_hasher * hasher)

Getter for ha_evp_hasher ctx_size field.

Returns
Returns ha_evp_hasher->ctx_size

◆ ha_evp_hasher_delete()

HA_PUBFUN void ha_evp_hasher_delete ( struct ha_evp_hasher * ptr)

Frees the memory of an EVP hasher.

This function frees the memory allocated for the EVP hasher and its internal state.

Parameters
ptrPointer to the EVP hasher to be deleted.

◆ ha_evp_hasher_digestlen()

HA_PUBFUN size_t ha_evp_hasher_digestlen ( struct ha_evp_hasher * hasher)

Getter for ha_evp_hasher ctx_digestlen field.

Returns
Returns ha_evp_hasher->digestlen

◆ ha_evp_hasher_hashty()

HA_PUBFUN enum ha_evp_hashty ha_evp_hasher_hashty ( struct ha_evp_hasher * hasher)

Getter for ha_evp_hasher ctx_hashty field.

Returns
Returns ha_evp_hasher->hashty

◆ ha_evp_hasher_init()

HA_PUBFUN void ha_evp_hasher_init ( struct ha_evp_hasher * hasher,
enum ha_evp_hashty hashty,
size_t digestlen )

Initializes the EVP hasher for a specific algorithm and digest length.

This function sets the hash algorithm and digest length for the EVP hasher.

Parameters
hasherPointer to the EVP hasher to initialize.
hashtyThe hash algorithm type.
digestlenThe desired digest length, or 0 for the default.

◆ ha_evp_hasher_keccak_custom()

HA_PUBFUN bool ha_evp_hasher_keccak_custom ( struct ha_evp_hasher * hasher)

Getter for ha_evp_hasher kustom field.

◆ ha_evp_hasher_keccak_rate()

HA_PUBFUN size_t ha_evp_hasher_keccak_rate ( struct ha_evp_hasher * hasher)

Getter for ha_evp_hasher krate field.

◆ ha_evp_hasher_new()

HA_PUBFUN struct ha_evp_hasher * ha_evp_hasher_new ( void )

Creates a new EVP hasher. ( malloc(g_ha_evp_hasher_size) )

This function allocates. The user must call ha_evp_hasher_delete() to free the allocated memory.

Returns
Pointer to the new EVP hasher, or NULL on failure.

◆ ha_evp_hasher_reinit()

HA_PUBFUN void ha_evp_hasher_reinit ( struct ha_evp_hasher * hasher,
enum ha_evp_hashty hashty,
size_t digestlen )

Reinitializes the EVP hasher with a new algorithm and digest length.

This function resets the EVP hasher to use a new hash algorithm and digest length.

Parameters
hasherPointer to the EVP hasher to reinitialize.
hashtyThe new hash algorithm type.
digestlenThe desired digest length, or 0 for the default.

◆ ha_evp_hasher_set_digestlen()

HA_PUBFUN void ha_evp_hasher_set_digestlen ( struct ha_evp_hasher * hasher,
size_t digestlen )

Setter for ha_evp_hasher ctx_digestlen field.

◆ ha_evp_hasher_set_hashty()

HA_PUBFUN void ha_evp_hasher_set_hashty ( struct ha_evp_hasher * hasher,
enum ha_evp_hashty hashty )

Setter for ha_evp_hasher ctx_hashty field.

◆ ha_evp_hasher_set_keccak_custom()

HA_PUBFUN void ha_evp_hasher_set_keccak_custom ( struct ha_evp_hasher * hasher,
bool custom )

Setter for ha_evp_hasher kustom field.

◆ ha_evp_hasher_set_keccak_rate()

HA_PUBFUN void ha_evp_hasher_set_keccak_rate ( struct ha_evp_hasher * hasher,
uint16_t rate )

Setter for ha_evp_hasher krate field.

◆ ha_evp_hashty_get_digestlen()

HA_PUBFUN signed long ha_evp_hashty_get_digestlen ( enum ha_evp_hashty hashty)

Get fixed hash size.

Returns
If hashty has a fixed hash size (e.g. sha1, md5) - returns fixed hash size, otherwise returns HA_EVPTY_SIZE_DYNAMIC (-1)

◆ ha_evp_hashty_tostr()

HA_PUBFUN const char * ha_evp_hashty_tostr ( enum ha_evp_hashty hashty)

Returns g_ha_evp_hashty_strings[hashty] (with error handling)

◆ ha_evp_init()

HA_PUBFUN void ha_evp_init ( struct ha_evp_hasher * hasher)

Initializes the EVP hash. ( like ha_init(hash, ctx) )

This function prepares the EVP hasher for data hashing.

Parameters
hasherPointer to the EVP hasher.

◆ ha_evp_put()

HA_EXTERN_C_BEG HA_PUBFUN void ha_evp_put ( struct ha_evp_hasher * hasher,
ha_cdigest_t digest,
const char * end )

Put hash to stdout.

◆ ha_evp_update()

HA_PUBFUN void ha_evp_update ( struct ha_evp_hasher * hasher,
ha_inbuf_t buf,
size_t len )

Updates the EVP hash with input data. ( like ha_update(hash, ctx, buf, len) )

This function adds data to the ongoing hash computation.

Parameters
hasherPointer to the EVP hasher.
bufPointer to the input data buffer.
lenLength of the input data in bytes.

Variable Documentation

◆ g_ha_evp_hasher_size

const size_t g_ha_evp_hasher_size
extern

Size of the EVP hasher structure.