code wiki / (root) / nx_drbg_hmac.nx

nx_drbg_hmac.nx

buildroot/runtime/nx_drbg_hmac.nx

8232 B235 linesdepth 6pulls 6 transitivereach 50 importersview sourcekind library
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_sha256.nx nx_hmac.nx nx_drbg_hmac.nx nx_drbg_hmac_test.nx nx_ecdsa_p256_sign.nx

imports: nx_syscalls.nxnx_sha256.nxnx_hmac.nx

imported by: nx_drbg_hmac_test.nxnx_ecdsa_p256_sign.nx

structs

none

consts

82const DRBG_OUTLEN: i64 = 32 // HMAC-SHA-256 output bytes
83const DRBG_STATE_LEN: i64 = 72 // K(32) + V(32) + reseed_counter(8)
84const DRBG_K_OFF: i64 = 0
85const DRBG_V_OFF: i64 = 32
86const DRBG_RC_OFF: i64 = 64
87const DRBG_MAX_BYTES: i64 = 65536 // per SP 800-90A §10.1 table

functions

91func _drbg_k(state: *u8) -> *u8
95func _drbg_v(state: *u8) -> *u8
101func _drbg_copy(dst: *u8, src: *u8, n: i64) -> i64
107func _drbg_fill(dst: *u8, val: i64, n: i64) -> i64
called by 1: drbg_hmac_init
124func drbg_hmac_update(state: *u8, data: *u8, data_len: i64) -> i64
175func drbg_hmac_init(state: *u8, seed: *u8, seed_len: i64) -> i64
195func drbg_hmac_generate(state: *u8, out: *u8, n_bytes: i64) -> i64
232func drbg_hmac_reseed_counter(state: *u8) -> i64
called by 1: main