Key Derivation & Password Hashing
Functions for deriving keys from passwords and other secrets.
Password Hashing
Argon2 (recommended)
Memory-hard password hashing function
- Three variants: Argon2d, Argon2i, Argon2id
- Winner of the Password Hashing Competition, announced July 2015
- Specified in RFC 9106, an Informational RFC
- OWASP recommends Argon2id first for password storage
Use Argon2 for:
- User password authentication
- Deriving encryption keys from passwords
scrypt
Memory-hard password-based key derivation, specified in RFC 7914
- OWASP recommends it when Argon2id is not available
- Originally developed for the Tarsnap online backup system
Key Derivation Functions
HKDF
HMAC-based extract-and-expand key derivation, specified in RFC 5869
- For deriving keys from shared secrets and other key material
- Not for passwords: HKDF has no slowing-down mechanism and cannot amplify entropy
PBKDF2
Password-Based Key Derivation Function 2
- Specified in RFC 8018, which obsoletes RFC 2898
- Approved by NIST SP 800-132 with HMAC and an approved hash function
- OWASP prefers it where FIPS-140 compliance is required
- Use Argon2 for new applications
Quick Comparison
| Function | Intended input | Memory-hard | Specification |
|---|---|---|---|
| Argon2id | Passwords | Yes | RFC 9106 |
| scrypt | Passwords | Yes | RFC 7914 |
| PBKDF2 | Passwords | No | RFC 8018, SP 800-132 |
| HKDF | High-entropy secrets | No | RFC 5869 |
See Also
- Password Hashing Guide - Best practices
- Security Concepts - Understanding cryptography
- Algorithm Selection Guide - Choosing between the commonly used algorithms
References
- RFC 9106: Argon2 Memory-Hard Function for Password Hashing and Proof-of-Work Applications
- Password Hashing Competition
- OWASP Password Storage Cheat Sheet
- RFC 7914: The scrypt Password-Based Key Derivation Function
- Tarsnap: The scrypt key derivation function
- RFC 5869: HMAC-based Extract-and-Expand Key Derivation Function (HKDF)
- RFC 8018: PKCS #5: Password-Based Cryptography Specification Version 2.1
- NIST SP 800-132: Recommendation for Password-Based Key Derivation, Part 1: Storage Applications