libhasha 2.2.2
|
Header file for the EVP Hasher abstraction. More...
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. |
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.
#define ha_ctx | ( | hash | ) |
#define ha_final | ( | hash, | |
ctx, | |||
... ) |
#define ha_hash | ( | hash, | |
buf, | |||
buflen, | |||
digest, | |||
... ) |
#define ha_init | ( | hash, | |
ctx ) |
#define ha_init_fun | ( | hash | ) |
#define ha_update | ( | hash, | |
ctx, | |||
buf, | |||
buflen ) |
typedef struct ha_evp_hasher ha_evp_hasher_t |
typedef struct ha_evp_hasher * ha_evp_phasher_t |
enum ha_enum_base | ( | int8_t | ) |
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.
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.
hasher | Pointer to the EVP hasher. |
buf | Pointer to the input data buffer. |
len | Length of the input data in bytes. |
digest | Pointer to the buffer where the resulting digest will be stored. |
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.
hasher | Pointer to the EVP hasher. |
digest | Pointer to the buffer where the resulting digest will be stored. |
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 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.
hasher | Pointer to the EVP hasher. |
buf | Pointer to the input data buffer. |
len | Length of the input data in bytes. |
digest | Pointer to the buffer where the resulting digest will be stored. |
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.
hasher | Pointer to the EVP hasher to clean up. |
HA_PUBFUN void ha_evp_hasher_commit | ( | struct ha_evp_hasher * | hasher | ) |
Reinitializes the EVP hasher.
hasher | Pointer to the EVP hasher to reinitialize without changes. |
HA_PUBFUN size_t ha_evp_hasher_ctxsize | ( | struct ha_evp_hasher * | hasher | ) |
Getter for ha_evp_hasher ctx_size field.
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.
ptr | Pointer to the EVP hasher to be deleted. |
HA_PUBFUN size_t ha_evp_hasher_digestlen | ( | struct ha_evp_hasher * | hasher | ) |
Getter for ha_evp_hasher ctx_digestlen 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_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.
hasher | Pointer to the EVP hasher to initialize. |
hashty | The hash algorithm type. |
digestlen | The desired digest length, or 0 for the default. |
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_keccak_rate | ( | struct ha_evp_hasher * | hasher | ) |
Getter for ha_evp_hasher krate field.
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.
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.
hasher | Pointer to the EVP hasher to reinitialize. |
hashty | The new hash algorithm type. |
digestlen | The desired digest length, or 0 for the default. |
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 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 void ha_evp_hasher_set_keccak_custom | ( | struct ha_evp_hasher * | hasher, |
bool | custom ) |
Setter for ha_evp_hasher kustom field.
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 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_init | ( | struct ha_evp_hasher * | hasher | ) |
Initializes the EVP hash. ( like ha_init(hash, ctx) )
This function prepares the EVP hasher for data hashing.
hasher | Pointer to the EVP hasher. |
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_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.
hasher | Pointer to the EVP hasher. |
buf | Pointer to the input data buffer. |
len | Length of the input data in bytes. |
|
extern |
Size of the EVP hasher structure.