PBKDF2
The iterated-HMAC password-based key derivation function from PKCS #5 and NIST SP 800-132
Overview
PBKDF2 is a password-based key derivation function defined in PKCS #5 (now RFC 8018). It applies a pseudo-random function, usually HMAC, many times to slow down brute-force guessing, and is approved by NIST in SP 800-132 and widely required in FIPS environments.
For each output block i, PBKDF2 computes U1 = PRF(password, salt ‖ i), then U2 = PRF(password, U1), and so on for c iterations, XORing all Uj together to form the block. Blocks are concatenated to the requested key length. The iteration count c is the only cost parameter; memory use is negligible.
NextSSL includes a generic PBKDF2 and PBKDF2-HMAC-SHA1, PBKDF2-HMAC-SHA256 and PBKDF2-HMAC-SHA512 instances, matching test vectors from RFC 6070 and RFC 7914. PBKDF2 is used in WPA2 Wi-Fi keys, many disk-encryption formats, password managers and Django's default password hasher. Its simplicity has made it the most portable choice. Salts should be at least 16 bytes.
History
2000–2017PBKDF2 published in PKCS #5 v2.0 (RFC 2898)
Recommended in NIST SP 800-132
Specified in RFC 7914 section 11
RFC 8018 updates PKCS #5
How it works
- Compute U1 = HMAC(password, salt ‖ block index)
- Iterate Uj = HMAC(password, Uj−1) c times
- XOR all Uj into the output block
- Concatenate blocks to the requested length
Security notes
PBKDF2 is not broken, but because it needs almost no memory it is far cheaper to attack with GPUs and ASICs than memory-hard functions. Iteration counts must be high: OWASP currently suggests hundreds of thousands of iterations for HMAC-SHA256. Requesting more output than the PRF's length multiplies the defender's cost but not the attacker's.
Typical uses
Variants in NextSSL
4| Algorithm | Tier | Sizes (bytes) | Standards | API |
|---|---|---|---|---|
| PBKDF2 pbkdf2 |
standard FIPS | out 16–1024 · salt 4–64 | RFC 8018, NIST SP 800-132, RFC 7914 section 11 | safe |
| PBKDF2-HMAC-SHA-256 pbkdf2-hmac-sha256 |
standard FIPS | out 16–1024 · salt 4–64 | RFC 8018, NIST SP 800-132, RFC 7914 section 11 | safe |
| PBKDF2-HMAC-SHA-512 pbkdf2-hmac-sha512 |
standard FIPS | out 16–1024 · salt 4–64 | RFC 8018, NIST SP 800-132 | safe |
| PBKDF2-HMAC-SHA-1 pbkdf2-hmac-sha1 |
legacy FIPS | out 16–1024 · salt 4–64 | RFC 8018, RFC 6070, NIST SP 800-132 | root |
Frequently asked questions
Which PBKDF2 variants does NextSSL include?
NextSSL registers 4 PBKDF2 variants: pbkdf2, pbkdf2-hmac-sha256, pbkdf2-hmac-sha512, pbkdf2-hmac-sha1.
Other password hashing
All 30Related
NIST SP 800-90A deterministic random bit generator built on HMAC
HKDFHMAC-based extract-and-expand key derivation function (RFC 5869)
HMACThe standard way to build a MAC from a cryptographic hash (RFC 2104, FIPS 198-1)
Argon2The Password Hashing Competition winner: memory-hard hashing standardised in RFC 9106
scryptColin Percival's memory-hard key derivation function, standardised in RFC 7914