Leancrypto 0.12.0
Post-Quantum Cryptographic Library
Loading...
Searching...
No Matches
HMAC Keyed Message Digest

Macros

#define LC_HMAC_CTX_ON_STACK(name, hashname)
 Allocate stack memory for the HMAC context.
 

Functions

void lc_hmac_init (struct lc_hmac_ctx *hmac_ctx, const uint8_t *key, size_t keylen)
 Initialize HMAC context.
 
void lc_hmac_reinit (struct lc_hmac_ctx *hmac_ctx)
 Re-initialize HMAC context after a hmac_final operation.
 
void lc_hmac_update (struct lc_hmac_ctx *hmac_ctx, const uint8_t *in, size_t inlen)
 Update HMAC.
 
void lc_hmac_final (struct lc_hmac_ctx *hmac_ctx, uint8_t *mac)
 Calculate HMAC mac.
 
int lc_hmac_alloc (const struct lc_hash *hash, struct lc_hmac_ctx **hmac_ctx)
 Allocate HMAC context on heap.
 
void lc_hmac_zero_free (struct lc_hmac_ctx *hmac_ctx)
 Zeroize and free HMAC context.
 
static void lc_hmac_zero (struct lc_hmac_ctx *hmac_ctx)
 Zeroize HMAC context allocated with either HMAC_CTX_ON_STACK or hmac_alloc.
 
static size_t lc_hmac_macsize (struct lc_hmac_ctx *hmac_ctx)
 Return the MAC size.
 
static void lc_hmac (const struct lc_hash *hash, const uint8_t *key, size_t keylen, const uint8_t *in, size_t inlen, uint8_t *mac)
 Calculate HMAC - one-shot.
 

Detailed Description

Macro Definition Documentation

◆ LC_HMAC_CTX_ON_STACK

#define LC_HMAC_CTX_ON_STACK ( name,
hashname )
Value:
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wvla\"") _Pragma( \
"GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
LC_ALIGNED_BUFFER(name##_ctx_buf, \
LC_HMAC_CTX_SIZE(hashname), \
LC_HASH_COMMON_ALIGNMENT); \
struct lc_hmac_ctx *name = (struct lc_hmac_ctx *)name##_ctx_buf; \
LC_HMAC_SET_CTX(name, hashname); \
lc_hmac_zero(name); \
_Pragma("GCC diagnostic pop")
#define LC_ALIGNED_BUFFER(name, size, alignment)
Allocate aligned stack memory.

Allocate stack memory for the HMAC context.

Parameters
[in]nameName of the stack variable
[in]hashnamePointer of type struct hash referencing the hash implementation to be used

Definition at line 165 of file lc_hmac.h.

Function Documentation

◆ lc_hmac()

static void lc_hmac ( const struct lc_hash * hash,
const uint8_t * key,
size_t keylen,
const uint8_t * in,
size_t inlen,
uint8_t * mac )
inlinestatic

Calculate HMAC - one-shot.

Parameters
[in]hashReference to hash implementation to be used to perform HMAC calculation with.
[in]keyMAC key of arbitrary size
[in]keylenSize of the MAC key
[in]inBuffer holding the data whose MAC shall be calculated
[in]inlenLength of the input buffer
[out]macBuffer with at least the size of the message digest.

The HMAC calculation operates entirely on the stack.

Definition at line 206 of file lc_hmac.h.

◆ lc_hmac_alloc()

int lc_hmac_alloc ( const struct lc_hash * hash,
struct lc_hmac_ctx ** hmac_ctx )

Allocate HMAC context on heap.

Parameters
[in]hashReference to hash implementation to be used to perform HMAC calculation with.
[out]hmac_ctxAllocated HMAC context
Returns
0 on success, < 0 on error

◆ lc_hmac_final()

void lc_hmac_final ( struct lc_hmac_ctx * hmac_ctx,
uint8_t * mac )

Calculate HMAC mac.

If the cipher handle shall be used for a new HMAC operation with the same key after this call, you MUST re-initialize the handle with hmac_reinit.

Parameters
[in]hmac_ctxReference to hmac context implementation to be used to perform HMAC calculation with.
[out]macBuffer with at least the size of the message digest that is returned by hmac_macsize.

◆ lc_hmac_init()

void lc_hmac_init ( struct lc_hmac_ctx * hmac_ctx,
const uint8_t * key,
size_t keylen )

Initialize HMAC context.

Parameters
[in]hmac_ctxReference to hmac context implementation to be used to perform HMAC calculation with.
[in]keyMAC key of arbitrary size
[in]keylenSize of the MAC key

The caller must provide an allocated hmac_ctx. This can be achieved by using HMAC_CTX_ON_STACK or by using hmac_alloc.

◆ lc_hmac_macsize()

static size_t lc_hmac_macsize ( struct lc_hmac_ctx * hmac_ctx)
inlinestatic

Return the MAC size.

Parameters
[in]hmac_ctxHMAC context to be zeroized
Returns
MAC size

Definition at line 185 of file lc_hmac.h.

◆ lc_hmac_reinit()

void lc_hmac_reinit ( struct lc_hmac_ctx * hmac_ctx)

Re-initialize HMAC context after a hmac_final operation.

This operation allows the HMAC context to be used again with the same key set during hmac_init.

Parameters
[in]hmac_ctxReference to hmac context implementation to be used to perform HMAC calculation with.

◆ lc_hmac_update()

void lc_hmac_update ( struct lc_hmac_ctx * hmac_ctx,
const uint8_t * in,
size_t inlen )

Update HMAC.

Parameters
[in]hmac_ctxReference to hmac context implementation to be used to perform HMAC calculation with.
[in]inBuffer holding the data whose MAC shall be calculated
[in]inlenLength of the input buffer

◆ lc_hmac_zero()

static void lc_hmac_zero ( struct lc_hmac_ctx * hmac_ctx)
inlinestatic

Zeroize HMAC context allocated with either HMAC_CTX_ON_STACK or hmac_alloc.

Parameters
[in]hmac_ctxHMAC context to be zeroized

Definition at line 148 of file lc_hmac.h.

◆ lc_hmac_zero_free()

void lc_hmac_zero_free ( struct lc_hmac_ctx * hmac_ctx)

Zeroize and free HMAC context.

Parameters
[in]hmac_ctxHMAC context to be zeroized and freed