Choosing the wrong derivation function is one of the quietest ways to lose every password or key in a breach, because the mistake only shows when an attacker starts guessing offline. Password hashing is the deliberately slow, salted transformation of a password into a verifier that can be stored, and key derivation is the process of turning a password or an existing secret into one or more cryptographic keys. The two overlap in algorithms such as PBKDF2 and Argon2 but serve different jobs, and confusing them (HKDF on passwords, a password hash where a fast KDF is needed) is a common design error. This guide explains how Argon2id, scrypt, bcrypt, PBKDF2 and HKDF work inside, which NIST and OWASP rules apply, how to tune and migrate, and how the choice changes for machine credentials. It is written for developers, security architects and reviewers. For the wider hashing topic, see the Hashing Guide.
Key takeaways
- Two families, two jobs. Password-based functions (Argon2id, scrypt, bcrypt, PBKDF2) add cost to make each guess expensive; key-based KDFs (HKDF, SP 800-108) are fast and assume the input already has full entropy.
- Argon2id is the default for new password storage. RFC 9106 makes Argon2id the mandatory variant, and OWASP lists equivalent settings from m=46 MiB, t=1 to m=7 MiB, t=5.
- PBKDF2 remains the FIPS route. NIST SP 800-132 specifies PBKDF2 with HMAC, and OWASP recommends 600,000 iterations for HMAC-SHA256.
- NIST 800-63B-4 sets the floor. At least a 32-bit salt, an approved scheme, a cost factor as high as practical, the scheme stored per password, and a separately stored secret key (pepper), ideally in an HSM or TPM.
- High-entropy machine secrets do not need slow hashing. API keys and tokens generated with 128 bits or more of randomness can be stored as an HMAC; the slow functions exist to compensate for low-entropy human choices.
What it is
A password hashing function takes a password, a unique salt and cost parameters, and outputs a fixed-length value. Verification repeats the computation and compares results. The function must be one-way, salted so identical passwords give different outputs, and expensive enough that an attacker with the stored values can test only a limited number of guesses per second.
A key derivation function (KDF) outputs keying material. There are two kinds:
- Password-based KDFs (PBKDFs): derive an encryption key from a password, for example to encrypt a vault or a backup. NIST SP 800-132 covers this for storage applications: the derived master key protects data directly or wraps a data protection key, and passwords must never be used directly as keys.
- Key-based KDFs: derive many keys from one strong secret, such as a Diffie-Hellman shared secret or a master key. HKDF (RFC 5869) and NIST SP 800-108 Rev. 1 (HMAC, CMAC or KMAC as the pseudorandom function) are the main examples. They are fast by design.
| Function | Family | Hardness | Specification | Typical use |
|---|---|---|---|---|
| Argon2id | Password hash and PBKDF | Memory-hard, tunable time and parallelism | RFC 9106 (Informational, CFRG, 2021) | New password storage, vault key derivation |
| scrypt | Password hash and PBKDF | Memory-hard | RFC 7914 | Where Argon2id is unavailable |
| bcrypt | Password hash | CPU-hard, small fixed memory | No IETF or NIST standard | Existing systems; 72-byte input limit |
| PBKDF2 | Password hash and PBKDF | CPU-hard only (iterations) | NIST SP 800-132, PKCS #5 | FIPS 140 environments |
| HKDF | Key-based KDF | None (fast) | RFC 5869 | TLS 1.3 key schedule, deriving session and sub-keys |
| SP 800-108 KDFs | Key-based KDF | None (fast) | NIST SP 800-108 Rev. 1 Update 1 | Deriving keys from a master key in FIPS modules |
How it works
Argon2id
Argon2 fills a block of memory of m kibibytes, organised into p lanes, over t passes. Argon2i uses data-independent memory access, which resists side-channel timing attacks; Argon2d uses data-dependent access, which resists GPU and ASIC trade-offs. Argon2id uses Argon2i-style access for the first half of the first pass and Argon2d-style afterwards, and RFC 9106 states it must be supported by every implementation. Inputs include the password, a salt (16 bytes recommended), an optional secret key K and associated data X, and the version 0x13.
RFC 9106 suggests t=1, p=4, m=2 GiB where memory allows, or t=3, p=4, m=64 MiB when memory is constrained, both with a 128-bit salt and 256-bit tag. Those are aimed at key derivation and dedicated hardware. Login servers handling many requests usually follow OWASP's lower-memory equivalents: m=47104 (46 MiB), t=1; m=19456 (19 MiB), t=2; m=12288 (12 MiB), t=3; m=9216 (9 MiB), t=4; or m=7168 (7 MiB), t=5, all with p=1. OWASP describes these as equal defence, trading CPU against RAM. RFC 9106 also advises enabling the library's memory-wiping option where side channels are a concern.
scrypt
scrypt uses PBKDF2 to expand the input, runs a memory-hard mixing step whose memory is set by the cost N and block size r, and compresses the result with PBKDF2 again. OWASP's equivalent settings run from N=2^17 (128 MiB), r=8, p=1 to N=2^13 (8 MiB), r=8, p=10. Its weakness in practice is parameter confusion: N, r and p interact, and many libraries default to values far below these.
bcrypt
bcrypt runs an expensive Blowfish key setup 2^cost times. OWASP recommends a work factor of at least 10, and as high as server performance allows. Most implementations accept at most 72 bytes of input, so longer passphrases are silently truncated. Pre-hashing with a fast hash to get around the limit is dangerous (null bytes in raw output, and "password shucking" where leaked unsalted hashes from other breaches can be tested against the inner value). If pre-hashing is unavoidable, OWASP suggests HMAC keyed with a pepper and base64-encoded.
PBKDF2
PBKDF2 iterates a pseudorandom function, normally HMAC with SHA-256 or SHA-512, c times over the password and salt. SP 800-132 requires a salt of at least 128 bits from an approved random bit generator, a derived key of at least 112 bits, and recommends an iteration count of at least 1,000 (about 10,000,000 for especially critical keys). That 2010 minimum is far below current practice: OWASP recommends 600,000 iterations for HMAC-SHA256, 220,000 for HMAC-SHA512, and 1,400,000 for HMAC-SHA1 in legacy use only. NIST noted in May 2023 that it plans to revise SP 800-132. Requesting more output than the hash length multiplies the defender's work without increasing the attacker's, so request no more than one hash length per derivation.
HKDF and SP 800-108
HKDF has two steps. Extract computes PRK = HMAC-Hash(salt, IKM) to concentrate entropy from uneven input; Expand chains HMAC over PRK, an info string and a counter to produce up to 255 times the hash length of output. The info field binds each derived key to its purpose (for example "db-encryption-v2"), so one master secret can safely yield many independent keys. RFC 5869 is explicit that extract cannot amplify low entropy and HKDF has no slow-down mechanism, pointing to PKCS #5 for passwords. SP 800-108 Rev. 1 Update 1 (February 2024) specifies equivalent key-based KDFs using HMAC, CMAC or KMAC for FIPS environments.
Why it matters
Stored password verifiers are stolen far more often than they are guessed online. Once an attacker has them, ATT&CK T1110.002 Password Cracking happens offline, with no rate limiting and on rented GPUs. The only defences left are the cost of each guess and the entropy of the password.
- Plaintext or fast hashes fail completely: the Firebase misconfiguration exposure included about 19.87 million passwords stored in plaintext, which no cost parameter can rescue.
- Password-derived encryption keys face the same attack: in the LastPass breach, stolen vault backups were protected by each customer's master password, and the company warned that attackers may try to brute force master passwords offline. The strength of the PBKDF and its iteration count decide how long that takes.
NIST SP 800-63B-4 requirements
| Requirement (section 3.1.1.2) | Level | Implementation note |
|---|---|---|
| Salt of at least 32 bits, chosen to minimise collisions; salt and hash stored | SHALL | Use 128 bits from a CSPRNG to also satisfy SP 800-132 |
| Suitable password hashing scheme, such as one approved in the latest SP 800-132 or updated NIST guidance | SHOULD | PBKDF2 for FIPS; Argon2id elsewhere, documented as a risk decision |
| Cost factor as high as practical, increased over time | SHOULD | Benchmark on production hardware, review yearly |
| Scheme and cost factor stored per password | SHOULD | PHC string format, for example $argon2id$v=19$m=19456,t=2,p=1$... |
| Additional keyed hash or encryption with a secret key known only to the verifier, from an approved RBG, stored separately | SHOULD (key storage SHALL be separate) | Pepper in an HSM, TPM or vault; HMAC the hash output |
| Minimum length 15 for single-factor, 8 within MFA; maximum at least 64; blocklist; no composition rules or periodic changes | SHALL / SHOULD | Policy side: see the NIST SP 800-63B-4 Authenticator Assurance Levels Guide |
Choosing a function
| Situation | Choose | Why |
|---|---|---|
| New application, no FIPS constraint | Argon2id, OWASP settings, plus pepper | Memory-hard, standardised, tunable |
| FIPS 140 validated modules required | PBKDF2-HMAC-SHA256 at 600,000 iterations or more | Specified in SP 800-132 |
| Existing bcrypt estate | Keep bcrypt at cost 10 or more, plan Argon2id at next login | No urgent weakness, but 72-byte limit |
| Legacy MD5 or SHA-1 hashes | Wrap immediately (Argon2id over the old hash), then replace at login | Protects all accounts at once |
| Encrypting a vault or file from a passphrase | Argon2id with higher memory, or PBKDF2 for FIPS | Offline attack is the whole threat model |
| Deriving keys from a shared secret or master key | HKDF or SP 800-108 | Input already strong; speed matters |
| Storing randomly generated API keys or tokens | HMAC-SHA256 with a server key, or SHA-256 | 128-bit random secrets cannot be brute forced |
Common misconceptions
- "A salted SHA-256 is fine." Salts stop precomputation, not guessing speed. A single fast hash per guess leaves human passwords open to GPU cracking.
- "HKDF is a password hash." HKDF is fast and has no cost parameter. Feeding a password into HKDF gives a key no stronger than one quick hash.
- "More iterations is always better." Above roughly one second per hash (OWASP's ceiling), login endpoints become a denial-of-service target. Tune under realistic peak load.
- "A pepper can be rotated like any key." OWASP notes a compromised pepper forces password resets, because existing hashes cannot be re-keyed without the passwords. An HMAC over the stored hash, with a key version identifier, at least makes rotation planned rather than chaotic.
- "bcrypt handles any length." Most implementations stop at 72 bytes; passphrases beyond that share hashes with their prefix.
- "Upgrading the algorithm upgrades existing hashes." Old hashes stay weak until rehashed at login or wrapped. Accounts that never log in keep the old hash indefinitely.
Migrating safely
- Inventory every store of password verifiers and password-derived keys, including admin consoles, appliances and old databases.
- Pick the target scheme and benchmark parameters on production hardware at peak login rate, keeping verification under one second.
- Store scheme and parameters with every hash using the PHC string format so old and new can coexist.
- Wrap legacy fast hashes immediately (Argon2id or PBKDF2 over the old value), then rehash with the plain target scheme at next successful login.
- Add a pepper by HMAC with a vaulted key, recording the key version.
- After a defined period, expire remaining legacy hashes and require reset for those accounts.
- Roll back by keeping verification code for previous schemes until the migration metric reaches its target; never delete old verification paths first.
Related concepts
- Machine credentials: service account passwords, client secrets and API keys should be generated, not chosen, with at least 128 bits of randomness; then fast HMAC storage is safe and slow hashing only wastes CPU. Where a service stores a human-style password for a machine, replace it. See the API Key Management Guide and the Secrets Management Guide.
- Windows hashes: NTLM hashes are unsalted and fast, which is why credential dumping (T1003 OS Credential Dumping) is so damaging. See the Local Administrator Password Solution (LAPS) Guide.
- Passwordless: passkeys remove the stored password verifier entirely. See the Passwordless and Passkeys Guide.
- Framework mapping:
| Framework | Reference | Relevance |
|---|---|---|
| NIST SP 800-53 Rev. 5 | IA-5(1) Password-based Authentication | Requires salted, keyed hashing of stored passwords |
| NIST SP 800-53 Rev. 5 | SC-12 Key Establishment and Management; SC-13 Cryptographic Protection; SC-28 Protection of Information at Rest | Peppers and derived keys, approved algorithms, protected verifier stores |
| NIST CSF 2.0 | PR.AA-01; PR.DS-01 | Credential management, data at rest |
| OWASP ASVS 5.0 | Password storage and cryptography chapters | Verification requirements for applications |
| MITRE ATT&CK | T1110.002 Password Cracking; T1003 OS Credential Dumping | Offline attack on stolen verifiers |
Metrics to track: percentage of verifiers on the target scheme; median and 99th percentile verification time at peak; number of stores still holding fast or unsalted hashes (target zero); percentage of verifiers covered by a vaulted pepper; and the date parameters were last benchmarked.
Practitioner checklist
- Use Argon2id with an OWASP-equivalent setting for new password storage, or PBKDF2-HMAC-SHA256 at 600,000 iterations or more where FIPS applies.
- Generate a unique salt of at least 128 bits per password with a CSPRNG.
- Store algorithm and parameters with each hash in PHC string format.
- Apply a pepper by HMAC with a key held in an HSM, TPM or vault, with a version identifier.
- Benchmark cost parameters at peak load and keep verification under one second; review yearly.
- Wrap legacy fast hashes now and rehash at login; expire unmigrated accounts after a set period.
- Never use HKDF or a bare hash on passwords; use HKDF or SP 800-108 only on high-entropy secrets.
- Enforce bcrypt's 72-byte limit explicitly if bcrypt stays in use.
- Generate machine secrets with 128 bits or more of randomness and store them as HMACs.
Standards and references
- NIST: SP 800-63B-4, Authentication and Authenticator Management
- NIST: SP 800-132, Recommendation for Password-Based Key Derivation
- NIST: SP 800-108 Rev. 1, Recommendation for Key Derivation Using Pseudorandom Functions
- IETF: RFC 9106, Argon2 Memory-Hard Function for Password Hashing and Proof-of-Work Applications
- IETF: RFC 5869, HMAC-based Extract-and-Expand Key Derivation Function (HKDF)
- OWASP: Password Storage Cheat Sheet
- OWASP: Application Security Verification Standard 5.0
Related NHI Mgmt Group resources: Hashing Guide · Password Security Guide · NIST SP 800-63B-4 Authenticator Assurance Levels Guide · Cryptographic Key Management Guide