Skip to content
Key Derivation & Password Hashing

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

FunctionIntended inputMemory-hardSpecification
Argon2idPasswordsYesRFC 9106
scryptPasswordsYesRFC 7914
PBKDF2PasswordsNoRFC 8018, SP 800-132
HKDFHigh-entropy secretsNoRFC 5869

See Also

References

  1. RFC 9106: Argon2 Memory-Hard Function for Password Hashing and Proof-of-Work Applications
  2. Password Hashing Competition
  3. OWASP Password Storage Cheat Sheet
  4. RFC 7914: The scrypt Password-Based Key Derivation Function
  5. Tarsnap: The scrypt key derivation function
  6. RFC 5869: HMAC-based Extract-and-Expand Key Derivation Function (HKDF)
  7. RFC 8018: PKCS #5: Password-Based Cryptography Specification Version 2.1
  8. NIST SP 800-132: Recommendation for Password-Based Key Derivation, Part 1: Storage Applications