PBKDF2 explained

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 vulnerability to 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 RFC2898. It supersedes PBKDF1, which could only produce derived keys up to 160 bits long.[1] RFC8018 (PKCS#5 v2.1), published in 2017, recommends PBKDF2 for password hashing.[2]

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.

When the standard was written in the year 2000 the recommended minimum number of iterations was 1,000, but the parameter is intended to be increased over time as CPU speeds increase. A Kerberos standard in 2005 recommended 4,096 iterations;[3] Apple reportedly used 2,000 for iOS 3, and 10,000 for iOS 4;[4] while LastPass in 2011 used 5,000 iterations for JavaScript clients and 100,000 iterations for server-side hashing.[5] In 2023, OWASP recommended to use 600,000 iterations for PBKDF2-HMAC-SHA256 and 210,000 for PBKDF2-HMAC-SHA512.[6]

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 public key cryptography standard recommends a salt length of at least 64 bits.[7] The US National Institute of Standards and Technology recommends a salt length of at least 128 bits.[8]

Key derivation process

The PBKDF2 key derivation function has five input parameters:[9]

where:

Each -bit block of derived key, is computed as follows (with marking string concatenation):

The function is the xor of c iterations of chained PRFs. The first iteration of PRF uses Password as the PRF key and Salt concatenated with 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:

where:

For example, WPA2 uses:

PBKDF1 had a simpler process: the initial U (called T in this version) is created by, and the following ones are simply . The key is extracted as the first dkLen bits of the final hash, which is why there is a size limit.[9]

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.[10] 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 using HMAC-SHA1, it is pre-hashed using SHA-1 into:

Which can be represented in ASCII as:

This means regardless of the salt or iterations, PBKDF2-HMAC-SHA1 will generate the same key bytes for the passwords:

For example, using:

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.[11]

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.[12] 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 significantly stronger against such attacks,[13] 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, the 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.[14] Another alternative is Balloon hashing, which is recommended in NIST password guidelines.[15]

To limit a brute-force attack, it is possible to make each password attempt require an online interaction, without harming the confidentiality of the password. This can be done using an oblivious pseudorandom function to perform password-hardening.[16] This can be done as alternative to, or as an additional step in, a PBKDF.

See also

External links

Notes and References

  1. PKCS#5: Password-Based Cryptography Specification, Version 2.0 . RFC2898 . tools.ietf.org . 2015-10-23. Burt. Kaliski. 2000 . 10.17487/RFC2898 . Burt Kaliski. free .
  2. RFC8018 . PKCS#5: Password-Based Cryptography Specification, Version 2.1 . Kathleen . Moriarty . K . Moriarty . etal . tools.ietf.org. 2017 . 10.17487/RFC8018 .
  3. Advanced Encryption Standard (AES) Encryption for Kerberos 5. tools.ietf.org. 2015-10-23 . Kenneth . Raeburn . 2005 . 10.17487/RFC3962 . RFC3962. free .
  4. Web site: Smartphone Forensics: Cracking BlackBerry Backup Passwords . Advanced Password Cracking – Insight . ElcomSoft . 30 September 2010 . 2015-10-23.
  5. Web site: LastPass Security Notification . The LastPass Blog. 5 May 2011. 2023-01-31.
  6. Web site: 15 August 2021 . Password Storage Cheat Sheet . live . https://web.archive.org/web/20230123232056/https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html . 23 January 2023 . 2023-01-23 . OWASP Cheat Sheet Series.
  7. RFC8018 . PKCS#5: Password-Based Cryptography Specification, Version 2.1: Section 4. Salt and Iteration Count . tools.ietf.org. 2018-01-24 . Kathleen . Moriarty . K . Moriarty . 2017 . 10.17487/RFC8018 . etal.
  8. Web site: SP800-132 . Recommendation for Password-Based Key Derivation Part 1: Storage Applications . NIST . 2018-12-20 . Meltem . Sönmez Turan . Elaine . Barker . William . Burr . Lily . Chen.
  9. Password-Based Cryptography Specification
  10. Web site: PBKDF2+HMAC hash collisions explained . Mathias . Bynens . mathiasbynens.be.
  11. Web site: Collision resistance - Why is HMAC-SHA1 still considered secure? . crypto.stackexchange.com.
  12. [Colin Percival]
  13. Web site: New 25 GPU Monster Devours Passwords In Seconds . The Security Ledger . 2012-12-04 . 2013-09-07.
  14. https://password-hashing.net "Password Hashing Competition"
  15. Web site: NIST . SP800-63B . Digital Identity Guidelines Authentication and Lifecycle Management Section 5.1.1.2 . June 18, 2021.
  16. Book: Ford . W. . Kaliski . B. S. . Server-assisted generation of a strong secret from a password . Proceedings IEEE 9th International Workshops on Enabling Technologies: Infrastructure for Collaborative Enterprises (WET ICE 2000). 2000 . 176–180 . 10.1109/ENABL.2000.883724 . 0-7695-0798-0 . 1977743 . https://ieeexplore.ieee.org/document/883724.