ProtoCore v0.0.2
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
kdf.cpp File Reference

SP800-108 counter-mode KDF with HMAC-SHA256 PRF (see kdf.h). More...

#include "crypto/kdf/kdf.h"
#include "crypto/crypto_opt.h"
#include "crypto/hash/sha256.h"
#include "shared_primitives/endian.h"
#include <string.h>

Go to the source code of this file.

Functions

PC_CRYPTO_HOT bool pc_kdf_ctr_hmac_sha256 (const uint8_t *ki, size_t ki_len, const uint8_t *fixed, size_t fixed_len, uint8_t *out, size_t out_len)
 SP800-108 KDF in counter mode with HMAC-SHA256 as the PRF (NIST SP800-108 §5.1; r = 32-bit counter placed before the fixed input).
 

Detailed Description

SP800-108 counter-mode KDF with HMAC-SHA256 PRF (see kdf.h).

The HMAC key is constant across counter iterations, so the ipad/opad key blocks are derived once and reused for every block; only the (counter || fixed) message changes. Streaming SHA-256 (pc_sha256_*) inherits hardware acceleration on ESP32 transparently.

Definition in file kdf.cpp.

Function Documentation

◆ pc_kdf_ctr_hmac_sha256()

PC_CRYPTO_HOT bool pc_kdf_ctr_hmac_sha256 ( const uint8_t *  ki,
size_t  ki_len,
const uint8_t *  fixed,
size_t  fixed_len,
uint8_t *  out,
size_t  out_len 
)

SP800-108 KDF in counter mode with HMAC-SHA256 as the PRF (NIST SP800-108 §5.1; r = 32-bit counter placed before the fixed input).

K(i) = HMAC-SHA256(Ki, [i]_32be || fixed); the blocks are concatenated for i = 1, 2, ... and the result truncated to out_len bytes. The caller assembles fixed as Label || 0x00 || Context || [L] (L = the output length in bits, 32-bit big-endian) and passes it whole.

Parameters
kithe key-derivation key (e.g. the SMB 3.x session key).
ki_lenlength of ki in bytes.
fixedthe fixed input (Label || 0x00 || Context || [L]).
fixed_lenlength of fixed in bytes.
outreceives out_len derived bytes.
out_lennumber of output bytes (>= 1); the caller must encode L = out_len * 8 into fixed.
Returns
true on success; false on a null pointer or out_len == 0.

Definition at line 20 of file kdf.cpp.

References pc_sha256(), pc_sha256_final(), pc_sha256_init(), pc_sha256_update(), and pc_wr32be().