Leancrypto 1.7.2
Post-Quantum Cryptographic Library
Macros | Functions
HMAC Keyed Message Digest

Macros

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

Functions

int lc_hmac_init (struct lc_hmac_ctx *hmac_ctx, const uint8_t *key, size_t keylen)
 Initialize HMAC context. More...
 
void lc_hmac_reinit (struct lc_hmac_ctx *hmac_ctx)
 Re-initialize HMAC context after a hmac_final operation. More...
 
void lc_hmac_update (struct lc_hmac_ctx *hmac_ctx, const uint8_t *in, size_t inlen)
 Update HMAC. More...
 
void lc_hmac_final (struct lc_hmac_ctx *hmac_ctx, uint8_t *mac)
 Calculate HMAC mac. More...
 
int lc_hmac_alloc (const struct lc_hash *hash, struct lc_hmac_ctx **hmac_ctx)
 Allocate HMAC context on heap. More...
 
void lc_hmac_zero_free (struct lc_hmac_ctx *hmac_ctx)
 Zeroize and free HMAC context. More...
 
void lc_hmac_zero (struct lc_hmac_ctx *hmac_ctx)
 Zeroize HMAC context allocated with either HMAC_CTX_ON_STACK or hmac_alloc. More...
 
enum lc_alg_status_val lc_hmac_alg_status (const struct lc_hash *hash)
 Obtain algorithm status. More...
 
enum lc_alg_status_val lc_hmac_ctx_alg_status (const struct lc_hash_ctx *ctx)
 Obtain algorithm status. More...
 
size_t lc_hmac_macsize (struct lc_hmac_ctx *hmac_ctx)
 Return the MAC size. More...
 
int 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. More...
 

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 \"-Wdeclaration-after-statement\"") \
LC_ALIGNED_BUFFER(name##_ctx_buf, LC_HMAC_CTX_SIZE, \
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 183 of file lc_hmac.h.

Function Documentation

◆ lc_hmac()

int 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.

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.

Returns
0 on success; < 0 on error

◆ lc_hmac_alg_status()

enum lc_alg_status_val lc_hmac_alg_status ( const struct lc_hash *  hash)

Obtain algorithm status.

Parameters
[in]hashHash algorithm instance
Returns
algorithm status

◆ 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_ctx_alg_status()

enum lc_alg_status_val lc_hmac_ctx_alg_status ( const struct lc_hash_ctx *  ctx)

Obtain algorithm status.

Parameters
[in]ctxHash context handle
Returns
algorithm status

◆ 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()

int 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.

Returns
0 on success; < 0 on error

◆ lc_hmac_macsize()

size_t lc_hmac_macsize ( struct lc_hmac_ctx *  hmac_ctx)

Return the MAC size.

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

◆ 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()

void lc_hmac_zero ( struct lc_hmac_ctx *  hmac_ctx)

Zeroize HMAC context allocated with either HMAC_CTX_ON_STACK or hmac_alloc.

Parameters
[in]hmac_ctxHMAC context to be zeroized

◆ 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