PBKDF2: Password Based Key Derivation (2024)

PBKDF2: Password Based Key Derivation (1)

PBKDF2, defined in RFC 2898, is a specific Key Derivation Function (KDF). A KDF is simply any mechanism for taking a password (something a user remembers or stores in a password manager) and turning it into a symmetric key suitable for cryptographic operations (i.e., AES). It turns out that this approach is extremely handy for a variety of use cases. However, it is also not without its flaws.

  • How PBKDF2 works
  • PBKDF2 as a hash
  • PBKDF2 as a symmetric key
  • PBKDF2 to decrypt a symmetric key
  • Conclusion

How PBKDF2 works

PBKDF2 takes as input a password, a salt, an integer defining how many “iterations” of the hash function to undergo, and an integer describing the desired key length for the output.

Password: IL0veCrypt0!!!Salt: D04A77B765E5CA3A84AA27C4C1908A72Iterations: 10,000Hash Function: SHA256Desired Key Length: 32 bytes (256 bits)Output: D122D2A917B3EC896214F87CAEC0FBF914D0092423EBFCEBED72ABF82C945AE1 

The byte array corresponding to the output string above is suitable for use as an AES key. Note that by increasing the number of iterations (times we run through the HMAC), we intentionally make the resulting output more computationally expensive. This property is desirable as it slows down the ability for an attacker to brute force through the key space of the original password (though it does nothing to prevent the attacker from brute forcing the key output itself). This is useful because 256 bits with a high entropy is much more useful for security purposes than a short passphrase!

PBKDF2 as a hash

One popular use case of PBKDF2 is as a means of hashing a password in order to avoid storing a plaintext password in a database. By iterating through the hashing procedure many times, it becomes slower for an attacker to brute force against either your live system or a database dump. Additionally, PBKDF2 utilizes salting, which protects against rainbow table attacks and protects users who have made the poor decision to reuse their password on multiple sites. PBKDF2 is not a perfect solution however. By intentionally slowing down the ability to compute a hash, it doesn’t only affect an attacker – choosing PBKDF2 means willfully wasting CPU cycles. While the reward may be worth the cost on a PC, PBKDF2 should be used very judiciously in the mobile arena where wasting CPU cycles wastes battery. Interestingly, Android devices rely on PBKDF2 for decrypting the device with the user supplied PIN on first boot. Additionally, PBKDF2 is not resistant to ASICs or FPGAs – purpose-built hardware designed to do a particular task especially efficiently in hardware. x86 architecture by its very design is built to be general purpose, but an attacker with enough spending power can throw hardware at the problem!

PBKDF2 as a symmetric key

Another popular way PBKDF2 is used is as a means of turning a user supplied password into a symmetric key suitable for use with the AES algorithm. This relies on the fact that AES can use any value as its input that meets certain length and entropy requirements and that PBKDF2 can produce a hash of any length which meets those requirements for entropy. This property is extremely handy for tools such as password vaults. By leveraging PBKDF2 with the user’s password at login time, a provider is able to ensure that its software can ONLY decrypt sensitive information while the user is logged in. This makes database dumps, authenticated attacks, and even buffer overflow attacks against the application itself useless to the attacker. However, this approach too has some downsides to consider. First and foremost, browser-based SSO such as SAML breaks this scheme, since SAML relies on trusted text and does not have a user input their password to the relying party application at all! (This is possible to overcome via having the PBKDF2 input come over as a SAML attribute in the assertion). Additionally, when the user changes their password, the application would have to hook into this event by decrypting everything encrypted with the old password and encrypting it with the new password instead – that’s quite a lot of overhead, and can result in a password changing experience taking minutes to hours. Not good!

PBKDF2 to decrypt a symmetric key

In order to get around hour+ long password reset times, one common practice is to PBKDF2’s output as a symmetric key which in turn decrypts another symmetric key. This prevents the need to rekey everything which exists in the system (since it was encrypted by a key that does not need to change). This approach retains the ability for an application to only have access to those fields during a user session however! This is accomplished by hooking into the user-change password, but only performing a single re-encryption operation – that of the user’s main symmetric key!

Conclusion

PBKDF2 is an especially interesting practical application of cryptographic concepts as it relies on the interplay between hashing, encryption, salting, message authentication codes, and key derivation. It is also commonly used in order to achieve a specific goal. What applications can you think of for PBKDF2?

Author: Jeremy Schatten
Published: 01/06/2021
Last Modified: 19/01/2022
Tags: #Articles

PBKDF2: Password Based Key Derivation (2024)

FAQs

PBKDF2: Password Based Key Derivation? ›

PBKDF2 stands for Password-Based Key Derivation Function 2, a widely adopted standard defined in RFC 2898. It enhances the security of hashed passwords in two significant ways: by using salts

salts
In cryptography, a salt is random data fed as an additional input to a one-way function that hashes data, a password or passphrase. Salting helps defend against attacks that use precomputed tables (e.g. rainbow tables), by vastly growing the size of table needed for a successful attack.
https://en.wikipedia.org › wiki › Salt_(cryptography)
and by applying many iterations of the hashing process.

What is password based key derivation function PBKDF2? ›

PBKDF2 (Password Based Key Derivation Function 2) is typically used for deriving a cryptographic key from a password. It may also be used for key storage, but an alternate key storage KDF such as Scrypt is generally considered a better solution. This class conforms to the KeyDerivationFunction interface.

Which is the best password based key derivation function? ›

scrypt. scrypt is a password-based key derivation function created by Colin Percival. While Argon2id should be the best choice for password hashing, scrypt should be used when the former is not available.

What is a feature of a password based key derivation function? ›

Modern password-based key derivation functions, such as PBKDF2 (specified in RFC 2898), are based on a recognized cryptographic hash, such as SHA-2, use more salt (at least 64 bits and chosen randomly) and a high iteration count. NIST recommends a minimum iteration count of 10,000.

What is the 2 key derivation of 1Password? ›

Two-key derivation (account password + Secret Key) Instead of relying on an account password alone, 1Password uses unique dual-key encryption. Without both keys, no one can access your account – not even us.

Is PBKDF2 outdated? ›

I've just learned that PBKDF2 encryption is outdated and vulnerable, and Argon2 or bcrypt are now the preferred password hashing implementation in modern password managers.

What's the difference between bcrypt and PBKDF2? ›

PBKDF2 (Password-Based Key Derivation Function 2) is a widely used algorithm that employs a salt to protect against brute force attacks. Bcrypt is a more advanced version of PBKDF2 and uses a high iteration count to slow down brute-force attempts.

Is Argon2id better than PBKDF2? ›

Default Argon2id settings are more secure than the default PBKDF2 settings.

How does PBKDF2 work? ›

PBKDF2: Strengthening Hashes with Salts and Iterations

Salting: PBKDF2 adds a random string, known as a salt, to the password before hashing it. This approach ensures that the same password will produce different hashes on each use, defeating rainbow table attacks.

Why do we use key derivation? ›

Its primary purpose is to protect sensitive data by miscarrying the attacker's temptations to predict or decrypt the used keys. Generally, a KDF takes as input a secret key, which can be a password, a master key, or some secret value.

What is the alternative to PBKDF2? ›

While PBKDF2 is a secure choice for key derivation, modern alternatives like bcrypt and scrypt offer advantages in specific contexts.

Is PBKDF2 quantum resistant? ›

SHA-2, PBKDF2, and BCRYPT hashes are more protective than Windows NT hashes. But if you're using the same cryptographic hash in both pre-quantum and post-quantum scenarios, you'll need to double your key size or password length to gain the same effective protection.

What is the difference between KDF and HKDF? ›

HKDF is a simple key derivation function (KDF) based on the HMAC message authentication code. It was initially proposed by its authors as a building block in various protocols and applications, as well as to discourage the proliferation of multiple KDF mechanisms.

Is 1Password owned by Apple? ›

1Password is a password manager developed by the Canadian software company AgileBits Inc. It supports multiple platforms such as iOS, Android, Windows, Linux, and macOS.

Is 1Password better than LastPass? ›

1Password vs. LastPass: Which should you choose? For almost everyone, 1Password is a better password manager than LastPass. There's so little difference between the general user experience, availability, and price of the two apps, that the additional security and transparency of 1Password make it the easy choice.

Is Bcrypt a key derivation function? ›

It is important to note that bcrypt is not a key derivation function (KDF).

What are the different types of key derivation functions? ›

Key derivation functions (KDFs) can be classified based on their algorithm and input type. One common approach to KDFs is to use hash functions, such as SHA-256 and SHA-3, to generate keys. KDFs that utilize hash functions are KDF1, KDF2, and PBKDF2.

What is key derivation in SSL? ›

Key derivation is the process of deriving one or more secret keys from a secret value such as a password or a passphrase. Several key derivation algoirthms have been standardized, and they are usually referred to a Key Derivation Functions (KDFs).

Is bcrypt a key derivation function? ›

It is important to note that bcrypt is not a key derivation function (KDF).

What is the recommended password iterations for PBKDF2? ›

The current recommendation from OWASP [5] is to use an iteration count of 600,000 for PBKDF2 with SHA-256 and an iteration count of 1,300,000 for PBKDF2 with SHA-1. In addition to AES-GCM and AES-CCM, we suggest to also add a reference to SP 800-38F [7] that defines AES-KW and AES-KWP.

Top Articles
Latest Posts
Article information

Author: Carmelo Roob

Last Updated:

Views: 5612

Rating: 4.4 / 5 (65 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Carmelo Roob

Birthday: 1995-01-09

Address: Apt. 915 481 Sipes Cliff, New Gonzalobury, CO 80176

Phone: +6773780339780

Job: Sales Executive

Hobby: Gaming, Jogging, Rugby, Video gaming, Handball, Ice skating, Web surfing

Introduction: My name is Carmelo Roob, I am a modern, handsome, delightful, comfortable, attractive, vast, good person who loves writing and wants to share my knowledge and understanding with you.