This article has an unclear citation style.(December 2012)
In cryptography, PBKDF1 and PBKDF2 (Password-Based Key Derivation Function 1 and 2) are key derivation functions with a sliding computational cost, used to reduce vulnerabilities of brute-force attacks.
PBKDF2 is part of RSA Laboratories' Public-Key Cryptography Standards (PKCS) series, specifically PKCS #5 v2.0, also published as Internet Engineering Task Force's RFC 2898. It supersedes PBKDF1, which could only produce derived keys up to 160 bits long. RFC 8018 (PKCS #5 v2.1), published in 2017, recommends PBKDF2 for password hashing.
Purpose and operation
PBKDF2 applies a pseudorandom function, such as hash-based message authentication code (HMAC), to the input password or passphrase along with a salt value and repeats the process many times to produce a derived key, which can then be used as a cryptographic key in subsequent operations. The added computational work makes password cracking much more difficult, and is known as key stretching.
Having a salt added to the password reduces the ability to use precomputed hashes (rainbow tables) for attacks, and means that multiple passwords have to be tested individually, not all at once. The standard recommends a salt length of at least 64 bits. The US National Institute of Standards and Technology recommends a salt length of 128 bits.
Key derivation process
The PBKDF2 key derivation function has five input parameters:
DK = PBKDF2(PRF, Password, Salt, c, dkLen)
- PRF is a pseudorandom function of two parameters with output length hLen (e.g., a keyed HMAC)
- Password is the master password from which a derived key is generated
- Salt is a sequence of bits, known as a cryptographic salt
- c is the number of iterations desired
- dkLen is the desired bit-length of the derived key
- DK is the generated derived key
Each hLen-bit block Ti of derived key DK, is computed as follows (with
+ marking string concatenation):
DK = T1 + T2 + ⋯ + Tdklen/hlen Ti = F(Password, Salt, c, i)
The function F is the xor (^) of c iterations of chained PRFs. The first iteration of PRF uses Password as the PRF key and Salt concatenated with i encoded as a big-endian 32-bit integer as the input. (Note that i is a 1-based index.) Subsequent iterations of PRF use Password as the PRF key and the output of the previous PRF computation as the input:
F(Password, Salt, c, i) = U1 ^ U2 ^ ⋯ ^ Uc
U1 = PRF(Password, Salt + INT_32_BE(i)) U2 = PRF(Password, U1) ⋮ Uc = PRF(Password, Uc−1)
For example, WPA2 uses:
DK = PBKDF2(HMAC−SHA1, passphrase, ssid, 4096, 256)
PBKDF1 had a simpler process: the initial U (called T in this version) is created by
PRF(Password + Salt), and the following ones are simply
PRF(Uprevious). The key is extracted as the first dkLen bits of the final hash, which is why there is a size limit.
PBKDF2 has an interesting property when using HMAC as its pseudo-random function. It is possible to trivially construct any number of different password pairs with collisions within each pair. If a supplied password is longer than the block size of the underlying HMAC hash function, the password is first pre-hashed into a digest, and that digest is instead used as the password. For example, the following password is too long:
therefore (when for example using HMAC-SHA1) it is pre-hashed using SHA-1 into:
- SHA1 (hex):
Which can be represented in ASCII as:
- SHA1 (ASCII):
This means regardless of the salt or iterations, PBKDF2-HMAC-SHA1 will generate the same key bytes for the passwords:
For example, using:
- PRF: HMAC-SHA1
- Salt: A009C1A485912C6AE630D3E744240B04
- Iterations: 1,000
- Derived key length: 16 bytes
the following two function calls:
PBKDF2-HMAC-SHA1("plnlrtfpijpuhqylxbgqiiyipieyxvfsavzgxbbcfusqkozwpngsyejqlmjsytrmd", ...) PBKDF2-HMAC-SHA1("eBkXQTfuBqp'cTcar&g*", ...)
will generate the same derived key bytes (
17EB4014C8C461C300E9B61518B9A18B). These derived key collisions do not represent a security vulnerability – as one still must know the original password in order to generate the hash of the password.
Alternatives to PBKDF2
One weakness of PBKDF2 is that while its number of iterations can be adjusted to make it take an arbitrarily large amount of computing time, it can be implemented with a small circuit and very little RAM, which makes brute-force attacks using application-specific integrated circuits or graphics processing units relatively cheap. The bcrypt password hashing function requires a larger amount of RAM (but still not tunable separately, i. e. fixed for a given amount of CPU time) and is slightly stronger against such attacks, while the more modern scrypt key derivation function can use arbitrarily large amounts of memory and is therefore more resistant to ASIC and GPU attacks.
In 2013, a Password Hashing Competition (PHC) was held to develop a more resistant approach. On 20 July 2015 Argon2 was selected as the final PHC winner, with special recognition given to four other password hashing schemes: Catena, Lyra2, yescrypt and Makwa. Another alternative is Balloon hashing, which is recommended in NIST password guidelines.
- Kaliski, Burt. "PKCS #5: Password-Based Cryptography Specification Version 2.0". tools.ietf.org. Retrieved 2015-10-23.
- "PKCS #5: Password-Based Cryptography Specification Version 2.1". tools.ietf.org.
- Kenneth Raeburn. "Advanced Encryption Standard (AES) Encryption for Kerberos 5". tools.ietf.org. Retrieved 2015-10-23.
- "Smartphone Forensics: Cracking BlackBerry Backup Passwords". Advanced Password Cracking – Insight (ElcomSoft). 30 September 2010. Retrieved 2015-10-23.
- "LastPass Security Notification". The LastPass Blog. 5 May 2011. Retrieved 2015-10-23.
- K. Moriarty; et al. "RFC 8018 - PKCS #5: Password-Based Cryptography Specification, Version 2.1". tools.ietf.org. Retrieved 2018-01-24.
- Meltem Sönmez Turan, Elaine Barker, William Burr, and Lily Chen. "NIST SP 800-132, Recommendation for Password-Based Key Derivation Part 1: Storage Applications" (PDF). www.nist.gov. Retrieved 2018-12-20.CS1 maint: multiple names: authors list (link)
- Password-Based Cryptography Specification RFC 2898
- Bynens, Mathias. "PBKDF2+HMAC hash collisions explained".
- "Collision resistance - Why is HMAC-SHA1 still considered secure?".
- Colin Percival. scrypt. As presented in "Stronger Key Derivation via Sequential Memory-Hard Functions". presented at BSDCan'09, May 2009.
- "New 25 GPU Monster Devours Passwords In Seconds". The Security Ledger. 2012-12-04. Retrieved 2013-09-07.
- "Password Hashing Competition"
- "NIST SP800-63B Digital Identity Guidelines Authentication and Lifecycle Management Section 22.214.171.124" (PDF). Retrieved June 18, 2021.
- RSA PKCS #5 – RSA Laboratories PKCS #5 v2.1.
- RFC 2898 – Specification of PKCS #5 v2.0.
- RFC 6070 – Test vectors for PBKDF2 with HMAC-SHA1.
- NIST Special Publication 800-132 Recommendation for Password-Based Key Derivation