In cryptography, PBKDF1 and PBKDF2 are key derivation functions with a sliding computational cost, used to reduce vulnerabilities to brute force attacks. PBKDF2 is part of RSA Laboratories' Public-Key Cryptography Standards 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, published in 2017, recommends PBKDF2 for password hashing.
Purpose and operation
PBKDF2 applies a pseudorandom function, such as hash-based message authentication code, 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. When the standard was written in the year 2000 the recommended minimum number of iterations was 1000, but the parameter is intended to be increased over time as CPU speeds increase. A Kerberos standard in 2005 recommended 4096 iterations; Apple reportedly used 2000 for iOS 3, and for iOS 4; while LastPass in 2011 used 5000 iterations for JavaScript clients and iterations for server-side hashing. Having a salt added to the password reduces the ability to use precomputed hashes 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.
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 : DK = T1 + T2 +... + Tdklen/hlen Ti = F 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. Subsequent iterations of PRF use Password as the PRF key and the output of the previous PRF computation as the input: F = U1 ^ U2 ^... ^ Uc where: U1 = PRF U2 = PRF ... Uc = PRF For example, WPA2 uses: DK = PBKDF2 PBKDF1 had a simpler process: the initial U is created by PRF, and the following ones are simply PRF. The key is extracted as the first dkLen bits of the final hash, which is why there is a size limit.
HMAC collisions
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:
Password:
therefore it is pre-hashed using SHA-1 into:
SHA1 : 65426b585154667542717027635463617226672a
Which can be represented in ASCII as:
SHA1 : eBkXQTfuBqp'cTcar&g*
This means regardless of the salt or iterations, PBKDF2-HMAC-SHA1 will generate the same key bytes for the passwords:
the following two function calls: PBKDF2-HMAC-SHA1 PBKDF2-HMAC-SHA1 will generate the same derived key bytes. 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 bcryptpassword hashing function requires a larger amount of RAM 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 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.