HMAC

This is a one-shot and incremental interface to computing HMAC with any hash function.

(Note: HMAC with SHA3 is possible, but is probably not a sensible thing to want.)

Types

cf_hmac_ctx

HMAC incremental interface context.

cf_hmac_ctx.hash

Hash function description.

cf_hmac_ctx.inner

Inner hash computation.

cf_hmac_ctx.outer

Outer hash computation.

Functions

void cf_hmac_init(cf_hmac_ctx *ctx, const cf_chash *hash, const uint8_t *key, size_t nkey)

Set up ctx for computing a HMAC using the given hash and key.

void cf_hmac_update(cf_hmac_ctx *ctx, const void *data, size_t ndata)

Input data.

void cf_hmac_finish(cf_hmac_ctx *ctx, uint8_t *out)

Finish and compute HMAC. ctx->hash->hashsz bytes are written to out.

void cf_hmac(const uint8_t *key, size_t nkey, const uint8_t *msg, size_t nmsg, uint8_t *out, const cf_chash *hash)

One shot interface: compute HMAC_hash(key, msg), writing the answer (which is hash->hashsz long) to out.

This function does not fail.