code wiki / (root) / pbkdf2.nx

pbkdf2.nx

buildroot/runtime/pbkdf2.nx

4386 B117 linesdepth 6pulls 6 transitivereach 0 importersview sourcekind tooltopic pbkdf2
docsdependenciesstructsconstsfunctions

about

pbkdf2.nx -- PBKDF2 password-based key derivation (RFC 8018). Stretches a user password (low-entropy) into a crypto key (high-entropy) by iterating HMAC many times over (password, salt, counter). The iteration count makes brute-force attacks expensive while legitimate derivations pay only a one-time cost. Used for: user-auth password hashing, key wrapping, PKCS#5 v2 PBKDF2 (widely deployed in 1Password / KeePass / LastPass container formats, TLS-PSK). Superseded for new systems by Argon2id (memory-hard; harder to attack with GPUs). Still required for interop with many existing databases + hardware tokens. Algorithm (RFC 8018 ยง5.2 PBKDF2): For each `dkLen / hash_len` block: U_1 = HMAC(password, salt || counter_as_u32_be) U_i = HMAC(password, U_{i-1}) for i = 2..iterations T_j = U_1 XOR U_2 XOR ... XOR U_iterations Concatenate T_j for the final derived key. Invariants: P1 iterations must be >= 1. OWASP-minimum for SHA-256 is ~600_000 as of 2023. Caller chooses; we don't enforce. P2 dkLen capped at (2^32 - 1) * hash_len. In practice nothing needs more than a handful of blocks; we don't validate. P3 Counter is 1-indexed, big-endian, appended to salt for the U_1 computation. P4 XOR accumulation is in-place to avoid allocating a per- iteration scratch.

dependencies 2 imports · 0 importers

syscalls.nx nx_hmac.nx pbkdf2.nx

imports: syscalls.nxnx_hmac.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main pbkdf2_sha256 hmac_sha256 sys_mmap sha256_digest sys_mmap ↻ sha256_init sys_mmap ↻ sha256_k sha256_update sha256_compress_ni_blocks blk_set_byte sha256_compress sha256_compress_ni blk_word sha256_final blk_set_byte ↻ sha256_compress ↻ sha256_init ↻ sha256_update ↻ sha256_final ↻

structs

none

consts

38const PBKDF2_HASH_LEN: i64 = 32 // HMAC-SHA-256 output size

functions

40func pbkdf2_sha256(password: *u8, pass_len: i64,
called by 1: main calls 1: hmac_sha256
109func main() -> i64
calls 1: pbkdf2_sha256