General hash function description

This allows us to make use of hash functions without depending on a specific one. This is useful in implementing, for example, HMAC.

Macros

CF_CHASH_MAXCTX

The maximum size of a cf_chash_ctx. This allows use to put a structure in automatic storage that can store working data for any supported hash function.

CF_CHASH_MAXBLK

Maximum hash function block size (in bytes).

CF_MAXHASH

Maximum hash function output (in bytes).

Types

cf_chash_init

Hashing initialisation function type.

Functions of this type should initialise the context in preparation for hashing a message with cf_chash_update functions.

Return type:

void

Parameters:
  • ctx – hash function-specific context structure.
cf_chash_update

Hashing data processing function type.

Functions of this type hash count bytes of data at data, updating the contents of ctx.

Return type:

void

Parameters:
  • ctx – hash function-specific context structure.
  • data – input data to hash.
  • count – number of bytes to hash.
cf_chash_digest

Hashing completion function type.

Functions of this type complete a hashing operation, writing cf_chash.hashsz bytes to hash.

This function does not change ctx – any padding which needs doing must be done seperately (in a copy of ctx, say).

This means you can interlave _update and _digest calls to learn H(A) and H(A || B) without hashing A twice.

Return type:

void

Parameters:
  • ctx – hash function-specific context structure.
  • hash – location to write hash result.
cf_chash

This type describes an incremental hash function in an abstract way.

cf_chash.hashsz

The hash function’s output, in bytes.

cf_chash.blocksz

The hash function’s internal block size, in bytes.

cf_chash.init

Context initialisation function.

cf_chash:update

Data processing function.

cf_chash:digest

Completion function.

cf_chash_ctx

A type usable with any cf_chash as a context.

Functions

void cf_hash(const cf_chash *h, const void *m, size_t nm, uint8_t *out)

One shot hashing: out = h(m).

Using the hash function h, nm bytes at m are hashed and h->hashsz bytes of result is written to the buffer out.

Parameters:
  • h – hash function description.
  • m – message buffer.
  • nm – message length.
  • out – hash result buffer (written).