ProtoCore v0.0.2
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
kdf.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file kdf.h
6 * @brief SP800-108 counter-mode key derivation (HMAC-SHA256 PRF).
7 *
8 * The shared NIST SP800-108 §5.1 counter-mode KDF. SMB 3.x uses it to derive its signing and
9 * encryption keys (MS-SMB2 §3.1.4.2); the caller assembles the fixed input, keeping this independent
10 * of any protocol's label/context choices. Verified against the NIST CAVP KBKDF (KDFCTR) vectors.
11 *
12 * @author Douglas Quigg (dstroy0)
13 * @date 2026
14 */
15
16#ifndef PROTOCORE_KDF_H
17#define PROTOCORE_KDF_H
18
19#include <stddef.h>
20#include <stdint.h>
21
22/**
23 * @brief SP800-108 KDF in counter mode with HMAC-SHA256 as the PRF (NIST SP800-108 §5.1; r = 32-bit
24 * counter placed before the fixed input).
25 *
26 * K(i) = HMAC-SHA256(Ki, [i]_32be || fixed); the blocks are concatenated for i = 1, 2, ... and the
27 * result truncated to @p out_len bytes. The caller assembles @p fixed as `Label || 0x00 || Context ||
28 * [L]` (L = the output length in bits, 32-bit big-endian) and passes it whole.
29 *
30 * @param ki the key-derivation key (e.g. the SMB 3.x session key).
31 * @param ki_len length of @p ki in bytes.
32 * @param fixed the fixed input (`Label || 0x00 || Context || [L]`).
33 * @param fixed_len length of @p fixed in bytes.
34 * @param out receives @p out_len derived bytes.
35 * @param out_len number of output bytes (>= 1); the caller must encode L = out_len * 8 into @p fixed.
36 * @return true on success; false on a null pointer or @p out_len == 0.
37 */
38bool pc_kdf_ctr_hmac_sha256(const uint8_t *ki, size_t ki_len, const uint8_t *fixed, size_t fixed_len, uint8_t *out,
39 size_t out_len);
40
41#endif // PROTOCORE_KDF_H
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 pl...
Definition kdf.cpp:20