nx_drbg_hmac.nx
buildroot/runtime/nx_drbg_hmac.nx
about
nx_drbg_hmac.nx -- NIST SP 800-90A HMAC-DRBG with SHA-256.
license_tier: INDEPENDENT_REDERIVE
genealogy_id: international-research-sources/nist/sp_800_90a
Deterministic Random Bit Generator. Given a seed (entropy +
optional personalization), produces an arbitrary-length pseudorandom
stream that any party with the same seed can reproduce. Built on
HMAC-SHA-256 per SP 800-90A §10.1.2.
Why this exists alongside nx_csprng:
- nx_csprng reads /dev/urandom (getrandom syscall). Online-only,
no determinism, useless on MCU/sensor targets without an OS
entropy source.
- nx_drbg_hmac takes a seed and produces a deterministic stream.
Replayable for testing; usable in air-gapped + embedded contexts;
foundation for NIST post-quantum signing (ML-DSA, SLH-DSA).
State layout (72 bytes, caller-allocated):
bytes 0..31 : K (HMAC key, output_len = 32 bytes)
bytes 32..63 : V (current value, output_len = 32 bytes)
bytes 64..71 : reseed_counter (i64)
SP 800-90A §10.1.2.2 Update operation:
K = HMAC(K, V || 0x00 || data)
V = HMAC(K, V)
if len(data) > 0:
K = HMAC(K, V || 0x01 || data)
V = HMAC(K, V)
§10.1.2.3 Instantiate:
K = 0x00 * 32 ; V = 0x01 * 32
Update(seed_material)
reseed_counter = 1
§10.1.2.5 Generate:
temp = empty
while len(temp) < requested_bytes:
V = HMAC(K, V)
temp ||= V
dependencies 3 imports · 2 importers
imports: nx_syscalls.nxnx_sha256.nxnx_hmac.nx
imported by: nx_drbg_hmac_test.nxnx_ecdsa_p256_sign.nx
structs
| none |
consts
| 82 | const DRBG_OUTLEN: i64 = 32 // HMAC-SHA-256 output bytes |
| 83 | const DRBG_STATE_LEN: i64 = 72 // K(32) + V(32) + reseed_counter(8) |
| 84 | const DRBG_K_OFF: i64 = 0 |
| 85 | const DRBG_V_OFF: i64 = 32 |
| 86 | const DRBG_RC_OFF: i64 = 64 |
| 87 | const DRBG_MAX_BYTES: i64 = 65536 // per SP 800-90A §10.1 table |
functions
| 91 | func _drbg_k(state: *u8) -> *u8 |
| 95 | func _drbg_v(state: *u8) -> *u8 |
| 101 | func _drbg_copy(dst: *u8, src: *u8, n: i64) -> i64 |
| 107 | func _drbg_fill(dst: *u8, val: i64, n: i64) -> i64 called by 1: drbg_hmac_init |
| 124 | func drbg_hmac_update(state: *u8, data: *u8, data_len: i64) -> i64 |
| 175 | func drbg_hmac_init(state: *u8, seed: *u8, seed_len: i64) -> i64 |
| 195 | func drbg_hmac_generate(state: *u8, out: *u8, n_bytes: i64) -> i64 called by 2: main_ecdsa_sign_derive_k calls 6: _drbg_k_drbg_vsys_mmaphmac_sha256_drbg_copydrbg_hmac_update |
| 232 | func drbg_hmac_reseed_counter(state: *u8) -> i64 called by 1: main |