Key Derivation Functions: PBKDF2, bcrypt, and Argon2
Compare password hashing algorithms by their resistance to GPU and ASIC attacks, and understand how work factors and memory hardness are tuned.
Key Derivation Functions: PBKDF2, bcrypt, and Argon2 is a free Cloud & IT Cert Prep lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cloud & IT Cert Prep learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why Password Hashing Is Different
Storing passwords requires a special class of cryptographic function called a password hashing function (PHF) or key derivation function (KDF). Regular cryptographic hashes like SHA-256 are designed to be fast — a modern GPU can compute billions of SHA-256 hashes per second. This speed is catastrophic for password storage: an attacker who steals a hash database can try billions of guesses per second. Password KDFs are intentionally slow, tunable to make brute-force attacks computationally infeasible while still allowing legitimate login within milliseconds.
Salting: Defeating Rainbow Tables
Before dedicated password KDFs existed, attackers used rainbow tables — precomputed mappings from hash values back to plaintext passwords. A salt is a random value unique per user that is prepended or appended to the password before hashing, making every hash unique even for identical passwords. Salts are stored alongside the hash in the database — they are not secret, just random. A proper salt must be: at least 16 bytes, generated by a cryptographically secure random number generator, and stored per-user (never reused across accounts).
PBKDF2: The Password Standard
PBKDF2 (Password-Based Key Derivation Function 2) is defined in RFC 8018 and is approved by NIST. It works by repeatedly applying an HMAC function (typically HMAC-SHA-256) to the password and salt, for a configurable number of iterations. The iteration count is the work factor — NIST recommends at least 600,000 iterations of PBKDF2-HMAC-SHA256 as of 2023. PBKDF2 is widely used (Django, iOS Keychain, WPA2-PSK) but has one weakness: it can be implemented efficiently on GPUs, making it less GPU-resistant than alternatives.
# PBKDF2 example (Python pseudocode concept)
# import hashlib
# dk = hashlib.pbkdf2_hmac(
# 'sha256', # hash algorithm
# b'password', # password bytes
# b'random_salt', # salt bytes
# 600000 # iterations
# )bcrypt: Memory and CPU Hardness
bcrypt was designed by Niels Provos and David Mazieres in 1999 and remains widely used. Its key innovation is a cost factor (rounds parameter), where each increment doubles the computation time. Bcrypt uses a modified Blowfish cipher with an Eksblowfish key setup that is both CPU and memory intensive, making it significantly harder to accelerate on GPUs compared to PBKDF2. Bcrypt also limits password input to 72 bytes (longer passwords are truncated), which requires hashing long passwords first with SHA-256 in some implementations.
# bcrypt cost factor
# Cost 10 = ~100ms on modern hardware
# Cost 12 = ~400ms
# Cost 14 = ~1600ms
# Each +1 doubles the work
# Recommended: cost 12-14 for web apps
# Command: htpasswd -bnBC 12 username passwordArgon2: The Modern Winner
Argon2 won the Password Hashing Competition in 2015 and is the current OWASP recommendation. It comes in three variants: Argon2d (faster, vulnerable to side-channel, best for cryptocurrency), Argon2i (constant-time, best for password hashing), and Argon2id (hybrid, recommended for most uses). Argon2id is configurable along three dimensions: time cost (iterations), memory cost (RAM required), and parallelism (threads). High memory requirements make it extremely difficult to parallelize on GPUs and completely infeasible on ASICs.
# Argon2id recommended parameters (OWASP 2023)
# Memory: 64MB (65536 KiB)
# Iterations: 3
# Parallelism: 4 threads
# Output length: 32 bytes
# argon2 -id -t 3 -m 16 -p 4 -l 32Memory-Hardness: Why It Defeats GPU Attacks
GPUs have thousands of cores but limited memory per core — they excel at parallelizing simple, memory-light computations. Memory-hard functions like Argon2 and scrypt require large amounts of RAM for each hash computation. If an attacker wants to run 10,000 parallel Argon2id computations each requiring 64MB of memory, they need 640GB of GPU RAM — far exceeding what any GPU cluster has available. This property, called memory hardness, forces attackers to either use slow, sequential computations or invest in extraordinary hardware costs that make attacks uneconomical.
Work Factor Tuning in Practice
The right work factor depends on your hardware and acceptable latency. The general target is 100-300ms on the server's production hardware for each authentication. As hardware improves, you should increase the work factor — this is why bcrypt and Argon2 store the parameters alongside the hash, allowing transparent upgrades: on next login, verify the password, then re-hash with the new higher parameters. OWASP maintains current recommended minimum parameters for PBKDF2, bcrypt, and Argon2id that should be reviewed annually.
scrypt: The Other Memory-Hard KDF
scrypt, designed by Colin Percival in 2009, was the first widely adopted memory-hard KDF and is used by Litecoin and many password managers. scrypt is parameterized by N (CPU/memory cost), r (block size), and p (parallelization factor). Like Argon2, high N values require large amounts of RAM per computation. scrypt is considered secure but Argon2id is generally preferred for new applications because it won the PHC and has received more cryptographic analysis. Both are acceptable choices.
What NOT to Use: MD5, SHA-1, and Unsalted SHA
Several hashing approaches must never be used for passwords: MD5 (broken, billions of hashes/second on consumer hardware), SHA-1 (same problem), unsalted SHA-256 (fast, rainbow tables trivial), and simple encryption (reversible, key theft equals all passwords). Historical breaches like LinkedIn (2012) used unsalted SHA-1, exposing 117 million passwords that were cracked within days. Adobe (2013) encrypted (not hashed) passwords — a fundamental misunderstanding that exposed 153 million accounts. These incidents are in the Security+ exam body of knowledge.
Key Derivation for Encryption Keys
KDFs are also used to derive encryption keys from passwords (as opposed to storing password hashes). When a user sets a master password for an encrypted vault, the application uses a KDF to derive the actual AES-256 encryption key from that password. This is why password managers can decrypt your vault locally — they run the KDF on your master password to reconstruct the encryption key, which never leaves your device. HKDF (HMAC-based Key Derivation Function) is the standard for deriving multiple keys from a single high-entropy secret, used in TLS 1.3 to derive handshake and application keys.
Credential Stuffing and KDF Protection
Credential stuffing attacks replay username/password pairs stolen from one breach against other services. Strong KDFs reduce the window for offline cracking after a breach — if the attacker must spend 300ms per guess instead of microseconds, cracking a 10-character random password becomes computationally infeasible. However, KDFs do not protect against password reuse across sites — that requires users to use unique passwords. The combination of unique passwords + Argon2id storage + MFA makes credential-based attacks practically ineffective.
Quick Check
Test your understanding of CompTIA Security+ (SY0-701) concepts from this lesson.
Lesson Recap
In this lesson you learned: password KDFs are intentionally slow with tunable work factors to make offline brute-force attacks computationally infeasible, memory-hard functions like Argon2id and scrypt defeat GPU parallelization by requiring large RAM per computation, and MD5, SHA-1, and unsalted hashes are completely inadequate for password storage as demonstrated by multiple high-profile breaches. Next up we explore post-quantum cryptography and the algorithms selected by NIST to replace RSA and ECC.
Frequently asked questions
Is the “Key Derivation Functions: PBKDF2, bcrypt, and Argon2” lesson free?
Yes — the full text of “Key Derivation Functions: PBKDF2, bcrypt, and Argon2” is free to read here on the web, and the Cloud & IT Cert Prep course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cloud & IT Cert Prep course, upgrade to CoddyKit PRO.
What will I learn in “Key Derivation Functions: PBKDF2, bcrypt, and Argon2”?
Compare password hashing algorithms by their resistance to GPU and ASIC attacks, and understand how work factors and memory hardness are tuned. You practise Cloud & IT Cert Prep with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Cloud & IT Cert Prep?
No prior experience is required. Cloud & IT Cert Prep on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Key Derivation Functions: PBKDF2, bcrypt, and Argon2” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Cloud & IT Cert Prep lesson?
Yes. Every Cloud & IT Cert Prep lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- TLS 1.3 Handshake and 0-RTT Resumption
- Authenticated Encryption: AES-GCM and ChaCha20-Poly1305
- Key Derivation Functions: PBKDF2, bcrypt, and Argon2
- Post-Quantum Cryptography: CRYSTALS-Kyber and Dilithium