code wiki / (root) / pbkdf2.nx

pbkdf2.nx

buildroot/runtime/pbkdf2.nx

4386 B117 linesdepth 6pulls 6 transitivereach 0 importersview sourcekind orphan librarytopic 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)

structs

none

consts

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

functions

40func pbkdf2_sha256(password: *u8, pass_len: i64,
109func main() -> i64