Leancrypto 0.12.0
Post-Quantum Cryptographic Library
Loading...
Searching...
No Matches
Key Derivation Functions

Macros

#define LC_HKDF_CTX_ON_STACK(name, hashname)
 Allocate stack memory for the HKDF context.
 

Functions

int lc_hkdf_extract (struct lc_hkdf_ctx *hkdf_ctx, const uint8_t *ikm, size_t ikmlen, const uint8_t *salt, size_t saltlen)
 HMAC-based Extract-and-Expand Key Derivation Function (HKDF) - RFC5869 Extract phase.
 
int lc_hkdf_expand (struct lc_hkdf_ctx *hkdf_ctx, const uint8_t *info, size_t infolen, uint8_t *dst, size_t dlen)
 HMAC-based Extract-and-Expand Key Derivation Function (HKDF) - RFC5869 Expand phase.
 
static void lc_hkdf_zero (struct lc_hkdf_ctx *hkdf_ctx)
 Zeroize HKDF context allocated with either LC_HKDF_CTX_ON_STACK or hkdf_alloc.
 
int lc_hkdf_alloc (const struct lc_hash *hash, struct lc_hkdf_ctx **hkdf_ctx)
 Allocate HKDF context on heap.
 
void lc_hkdf_zero_free (struct lc_hkdf_ctx *hkdf_ctx)
 Zeroize and free HKDF context.
 
static int lc_hkdf (const struct lc_hash *hash, const uint8_t *ikm, size_t ikmlen, const uint8_t *salt, size_t saltlen, const uint8_t *info, size_t infolen, uint8_t *dst, size_t dlen)
 HMAC-based Extract-and-Expand Key Derivation Function (HKDF) - RFC5869 Complete implementation.
 
int lc_kdf_ctr_init (struct lc_hmac_ctx *hmac_ctx, const uint8_t *key, size_t keylen)
 Key-based Key Derivation in Counter Mode - SP800-108 - initialization.
 
int lc_kdf_ctr_generate (struct lc_hmac_ctx *hmac_ctx, const uint8_t *label, size_t labellen, uint8_t *dst, size_t dlen)
 Key-based Key Derivation in Counter Mode - SP800-108 - data generation.
 
int lc_kdf_ctr (const struct lc_hash *hash, const uint8_t *key, size_t keylen, const uint8_t *label, size_t labellen, uint8_t *dst, size_t dlen)
 One-shot Key-based Key Derivation in Counter Mode - SP800-108.
 
int lc_kdf_dpi_init (struct lc_hmac_ctx *hmac_ctx, const uint8_t *key, size_t keylen)
 Key-based Key Derivation in Double-Pipeline Mode - SP800-108 - initialization.
 
int lc_kdf_dpi_generate (struct lc_hmac_ctx *hmac_ctx, const uint8_t *label, size_t labellen, uint8_t *dst, size_t dlen)
 Key-based Key Derivation in Double-Pipeline Mode - SP800-108 - data generation.
 
int lc_kdf_dpi (const struct lc_hash *hash, const uint8_t *key, size_t keylen, const uint8_t *label, size_t labellen, uint8_t *dst, size_t dlen)
 One-Shot Key-based Key Derivation in Double-Pipeline Mode - SP800-108.
 
int lc_kdf_fb_init (struct lc_hmac_ctx *hmac_ctx, const uint8_t *key, size_t keylen)
 Key-based Key Derivation in Feedback Mode - SP800-108 - initialization.
 
int lc_kdf_fb_generate (struct lc_hmac_ctx *hmac_ctx, const uint8_t *iv, size_t ivlen, const uint8_t *label, size_t labellen, uint8_t *dst, size_t dlen)
 Key-based Key Derivation in Feedback Mode - SP800-108 - data generation.
 
int lc_kdf_fb (const struct lc_hash *hash, const uint8_t *key, size_t keylen, const uint8_t *iv, size_t ivlen, const uint8_t *label, size_t labellen, uint8_t *dst, size_t dlen)
 One-shot Key-based Key Derivation in Feedback Mode - SP800-108.
 
int lc_pbkdf2 (const struct lc_hash *hash, const uint8_t *pw, size_t pwlen, const uint8_t *salt, size_t saltlen, const uint32_t count, uint8_t *key, size_t keylen)
 Password-based Key Derivation Function - SP800-132.
 

Detailed Description

Macro Definition Documentation

◆ LC_HKDF_CTX_ON_STACK

#define LC_HKDF_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_HKDF_CTX_SIZE(hashname), \
LC_HASH_COMMON_ALIGNMENT); \
struct lc_hkdf_ctx *name = (struct lc_hkdf_ctx *)name##_ctx_buf; \
LC_HKDF_SET_CTX(name, hashname); \
lc_hkdf_zero(name); \
_Pragma("GCC diagnostic pop")
#define LC_ALIGNED_BUFFER(name, size, alignment)
Allocate aligned stack memory.

Allocate stack memory for the HKDF context.

Parameters
[in]nameName of the stack variable
[in]hashnameReference to lc_hash implementation

Definition at line 142 of file lc_hkdf.h.

Function Documentation

◆ lc_hkdf()

static int lc_hkdf ( const struct lc_hash * hash,
const uint8_t * ikm,
size_t ikmlen,
const uint8_t * salt,
size_t saltlen,
const uint8_t * info,
size_t infolen,
uint8_t * dst,
size_t dlen )
inlinestatic

HMAC-based Extract-and-Expand Key Derivation Function (HKDF) - RFC5869 Complete implementation.

Parameters
[in]hashReference to lc_hash implementation
[in]ikmInput Keying Material (see RFC5869)
[in]ikmlenLength of ikm buffer
[in]saltOptional salt value - if caller does not want to use a salt set NULL here.
[in]saltlenLength of salt value buffer.
[in]infoOptional context and application specific information. This may be NULL.
[in]infolenSize of info buffer.
[out]dstBuffer to store the derived bits in
[in]dlenSize of the destination buffer.
Returns
0 on success, < 0 on error

Definition at line 173 of file lc_hkdf.h.

◆ lc_hkdf_alloc()

int lc_hkdf_alloc ( const struct lc_hash * hash,
struct lc_hkdf_ctx ** hkdf_ctx )

Allocate HKDF context on heap.

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

◆ lc_hkdf_expand()

int lc_hkdf_expand ( struct lc_hkdf_ctx * hkdf_ctx,
const uint8_t * info,
size_t infolen,
uint8_t * dst,
size_t dlen )

HMAC-based Extract-and-Expand Key Derivation Function (HKDF) - RFC5869 Expand phase.

Parameters
[in]hkdf_ctxCipher handle for the operation. This call expects the caller to hand in a HMAC cipher handle that has been initialized with hkdf_extract.
[in]infoOptional context and application specific information. This may be NULL.
[in]infolenSize of info buffer.
[out]dstBuffer to store the derived bits in
[in]dlenSize of the destination buffer.
Returns
0 on success, < 0 on error

◆ lc_hkdf_extract()

int lc_hkdf_extract ( struct lc_hkdf_ctx * hkdf_ctx,
const uint8_t * ikm,
size_t ikmlen,
const uint8_t * salt,
size_t saltlen )

HMAC-based Extract-and-Expand Key Derivation Function (HKDF) - RFC5869 Extract phase.

Parameters
[in,out]hkdf_ctxThe caller is expected to provide an allocated HMAC cipher handle in. Yet, the caller does not need to perform any operations on the handle. The extract phase adjusts the HMAC cipher handle so that it is ready for the expand phase.
[in]ikmInput Keying Material (see RFC5869)
[in]ikmlenLength of ikm buffer
[in]saltOptional salt value - if caller does not want to use a salt set NULL here.
[in]saltlenLength of salt value buffer.
Returns
0 on success, < 0 on error

◆ lc_hkdf_zero()

static void lc_hkdf_zero ( struct lc_hkdf_ctx * hkdf_ctx)
inlinestatic

Zeroize HKDF context allocated with either LC_HKDF_CTX_ON_STACK or hkdf_alloc.

Parameters
[in]hkdf_ctxHMAC context to be zeroized

Definition at line 102 of file lc_hkdf.h.

◆ lc_hkdf_zero_free()

void lc_hkdf_zero_free ( struct lc_hkdf_ctx * hkdf_ctx)

Zeroize and free HKDF context.

Parameters
[in]hkdf_ctxHKDF context to be zeroized and freed

◆ lc_kdf_ctr()

int lc_kdf_ctr ( const struct lc_hash * hash,
const uint8_t * key,
size_t keylen,
const uint8_t * label,
size_t labellen,
uint8_t * dst,
size_t dlen )

One-shot Key-based Key Derivation in Counter Mode - SP800-108.

Parameters
[in]hashHash implementation to use for the KDF operation - this hash implementation is used for the HMAC calls.
[in]keyKey from which the new key is to be derived from
[in]keylenLength of the key buffer.
[in]labelOptional label string that is used to diversify the key
[in]labellenLength of the label buffer
[out]dstBuffer that is filled with the derived key. This buffer with the size of keylen must be allocated by the caller.
[in]dlenLength of the key that shall be derived.
Returns
0 on success, < 0 on error

◆ lc_kdf_ctr_generate()

int lc_kdf_ctr_generate ( struct lc_hmac_ctx * hmac_ctx,
const uint8_t * label,
size_t labellen,
uint8_t * dst,
size_t dlen )

Key-based Key Derivation in Counter Mode - SP800-108 - data generation.

Parameters
[in]hmac_ctxCipher handle for the operation. This call expects the caller to hand in a HMAC cipher handle that has been initialized with hkdf_extract.
[in]labelOptional context and application specific information. This may be NULL.
[in]labellenSize of label buffer.
[out]dstBuffer to store the derived bits in
[in]dlenSize of the destination buffer.
Returns
0 on success, < 0 on error

◆ lc_kdf_ctr_init()

int lc_kdf_ctr_init ( struct lc_hmac_ctx * hmac_ctx,
const uint8_t * key,
size_t keylen )

Key-based Key Derivation in Counter Mode - SP800-108 - initialization.

Parameters
[in,out]hmac_ctxThe caller is expected to provide an allocated HMAC cipher handle in. Yet, the caller does not need to perform any operations on the handle. The extract phase adjusts the HMAC cipher handle so that it is ready for the expand phase.
[in]keyInput Keying Material (see RFC5869)
[in]keylenLength of ikm buffer
Returns
0 on success, < 0 on error

◆ lc_kdf_dpi()

int lc_kdf_dpi ( const struct lc_hash * hash,
const uint8_t * key,
size_t keylen,
const uint8_t * label,
size_t labellen,
uint8_t * dst,
size_t dlen )

One-Shot Key-based Key Derivation in Double-Pipeline Mode - SP800-108.

Parameters
[in]hashHash implementation to use for the KDF operation - this hash implementation is used for the HMAC calls.
[in]keyKey from which the new key is to be derived from
[in]keylenLength of the key buffer.
[in]labelOptional label string that is used to diversify the key
[in]labellenLength of the label buffer
[out]dstBuffer that is filled with the derived key. This buffer with the size of keylen must be allocated by the caller.
[in]dlenLength of the key that shall be derived.
Returns
0 on success, < 0 on error

◆ lc_kdf_dpi_generate()

int lc_kdf_dpi_generate ( struct lc_hmac_ctx * hmac_ctx,
const uint8_t * label,
size_t labellen,
uint8_t * dst,
size_t dlen )

Key-based Key Derivation in Double-Pipeline Mode - SP800-108 - data generation.

Parameters
[in]hmac_ctxCipher handle for the operation. This call expects the caller to hand in a HMAC cipher handle that has been initialized with hkdf_extract.
[in]labelOptional context and application specific information. This may be NULL.
[in]labellenSize of label buffer.
[out]dstBuffer to store the derived bits in
[in]dlenSize of the destination buffer.
Returns
0 on success, < 0 on error

◆ lc_kdf_dpi_init()

int lc_kdf_dpi_init ( struct lc_hmac_ctx * hmac_ctx,
const uint8_t * key,
size_t keylen )

Key-based Key Derivation in Double-Pipeline Mode - SP800-108 - initialization.

Parameters
[in,out]hmac_ctxThe caller is expected to provide an allocated HMAC cipher handle in. Yet, the caller does not need to perform any operations on the handle. The extract phase adjusts the HMAC cipher handle so that it is ready for the expand phase.
[in]keyInput Keying Material (see RFC5869)
[in]keylenLength of ikm buffer
Returns
0 on success, < 0 on error

◆ lc_kdf_fb()

int lc_kdf_fb ( const struct lc_hash * hash,
const uint8_t * key,
size_t keylen,
const uint8_t * iv,
size_t ivlen,
const uint8_t * label,
size_t labellen,
uint8_t * dst,
size_t dlen )

One-shot Key-based Key Derivation in Feedback Mode - SP800-108.

Parameters
[in]hashHash implementation to use for the KDF operation - this hash implementation is used for the HMAC calls.
[in]keyKey from which the new key is to be derived from
[in]keylenLength of the key buffer.
[in]ivInitialization vector which must be exactly as large as the message digest of the selected hash.
[in]ivlenSize of the IV buffer.
[in]labelOptional label string that is used to diversify the key
[in]labellenLength of the label buffer
[out]dstBuffer that is filled with the derived key. This buffer with the size of keylen must be allocated by the caller.
[in]dlenLength of the key that shall be derived.
Returns
0 on success, < 0 on error

◆ lc_kdf_fb_generate()

int lc_kdf_fb_generate ( struct lc_hmac_ctx * hmac_ctx,
const uint8_t * iv,
size_t ivlen,
const uint8_t * label,
size_t labellen,
uint8_t * dst,
size_t dlen )

Key-based Key Derivation in Feedback Mode - SP800-108 - data generation.

Parameters
[in]hmac_ctxCipher handle for the operation. This call expects the caller to hand in a HMAC cipher handle that has been initialized with hkdf_extract.
[in]ivInitialization vector which must be exactly as large as the message digest of the selected hash.
[in]ivlenSize of the IV buffer.
[in]labelOptional context and application specific information. This may be NULL.
[in]labellenSize of label buffer.
[out]dstBuffer to store the derived bits in
[in]dlenSize of the destination buffer.
Returns
0 on success, < 0 on error

◆ lc_kdf_fb_init()

int lc_kdf_fb_init ( struct lc_hmac_ctx * hmac_ctx,
const uint8_t * key,
size_t keylen )

Key-based Key Derivation in Feedback Mode - SP800-108 - initialization.

Parameters
[in,out]hmac_ctxThe caller is expected to provide an allocated HMAC cipher handle in. Yet, the caller does not need to perform any operations on the handle. The extract phase adjusts the HMAC cipher handle so that it is ready for the expand phase.
[in]keyInput Keying Material (see RFC5869)
[in]keylenLength of ikm buffer
Returns
0 on success, < 0 on error

◆ lc_pbkdf2()

int lc_pbkdf2 ( const struct lc_hash * hash,
const uint8_t * pw,
size_t pwlen,
const uint8_t * salt,
size_t saltlen,
const uint32_t count,
uint8_t * key,
size_t keylen )

Password-based Key Derivation Function - SP800-132.

Parameters
[in]hashHash implementation to use for the PBKDF2 operation - this hash implementation is used for the HMAC calls.
[in]pwPassword from which to derive the key
[in]pwlenLength of the password buffer
[in]saltOptional salt value, may be NULL
[in]saltlenLength of the salt value
[in]countNumber of iterations that shall be performed to derive the key.
[out]keyBuffer that is filled with the derived key. This buffer with the size of keylen must be allocated by the caller.
[in]keylenLength of the key that shall be derived.
Returns
0 on success, < 0 on error