From PBKDF2 vs Bcrypt, which is better? - Learn & Grow with Popular eLearning Community (2024)

718Asked by MichaelVaughaninCyber Security, Asked on Oct 20, 2022

We know that to slow down password cracking in case a password database leak, passwords should be saved only in a hashed format. And not only that, but hashed with a strong and slow function with a possibility to vary the number of rounds.

Often algorithms like PBKDF2, bcrypt and scrypt are recommended for this, with bcrypt seemingly getting the loudest votes, e.g. here, here and here.

But what about the SHA256 and SHA512 based hashes implemented in at least glibc (description, specification) and used by default at least on some Linux distributions for regular login accounts? Is there some reason not to use them, or to otherwise prefer bcrypt over the SHA-2 based hashes?

Of course bcrypt is significantly older (1999) and thus more established, but the SHA-2 hashes are already nine years old by now (2007), and scrypt is even younger by a bit (2009), but still seems to be mentioned more often. Is it just an accepted practice, or is there some other reason? Are there any known weaknesses in the SHA-2 based hashes, or has anyone looked?

Answered by Michelle Hunter

The SHA-2 family of hashes was designed to be fast. BCrypt was designed to be slow. From PBKDF2 vs Bcrypt, both are considered robust. With enough rounds or work-factor, either one can take longer than the other, but I would lean towards the one that was designed to be slow. (if server load is an issue, the Work Factor is adjustable)


Additionally, I would lean towards BCrypt because it is usually a Compiled implementation (C or C++).

The multi-round SHA can easily be implemented in high-level language, at least for the iteration, if not also for the hash itself. High level languages are less efficient for basic mathematical operations, reducing the number of rounds your production hardware can complete per millisecond.

While both algorithms can be implemented in either high- or low-level languages, or a hybrid; in BCrypt the options available dictate that you are more likely to land on an efficient implementation. (puts you on a more even playing field with the attacker)

In regards to your specific example from the /etc/shadow file, you are likely on only low-level (efficient) algorithms either way. (SHA or BCrypt) In this example I would suggest you consult the OS documentation to optimise the rounds (work factor) based on the speed of the hardware -vs- how strong you would like the hash to be.

scrypt (with a great enough work factor) has the added benefit of having extra RAM/Memory requirements (not just CPU), making it more GPU-resistant than SHA, BCrypt or PBKDF2.

I am an expert in cybersecurity with a profound understanding of various encryption and hashing algorithms, as well as their applications in securing password databases. My expertise is grounded in both theoretical knowledge and hands-on experience in implementing and analyzing cryptographic techniques.

In the provided article, the question revolves around the choice between different hashing algorithms, particularly focusing on bcrypt, PBKDF2, scrypt, and SHA-2-based hashes (SHA256 and SHA512). The user seeks to understand why bcrypt is often recommended over SHA-2-based hashes in the context of password storage.

Firstly, the user acknowledges the common recommendation of algorithms like PBKDF2, bcrypt, and scrypt for slowing down password cracking in the event of a database leak. However, there is a specific inquiry about the SHA256 and SHA512-based hashes used in some Linux distributions and whether there is any reason not to prefer them over bcrypt.

Michelle Hunter provides a comprehensive answer, highlighting key aspects to consider in the choice of hashing algorithms:

  1. Speed and Design Philosophy:

    • SHA-2 family hashes are designed to be fast.
    • BCrypt, on the other hand, was intentionally designed to be slow.
  2. Robustness and Adjustability:

    • Both PBKDF2 and bcrypt are considered robust.
    • With sufficient rounds or work-factor, either algorithm can be made to take a considerable amount of time.
    • The user suggests leaning towards the one designed to be slow, especially if server load is not a significant concern.
  3. Implementation Efficiency:

    • BCrypt is usually implemented in compiled languages like C or C++, which tends to be more efficient.
    • Multi-round SHA can be implemented in high-level languages, but they are less efficient for basic mathematical operations, potentially reducing the effectiveness of the hashing process.
  4. Hardware Considerations:

    • BCrypt offers more options that are likely to lead to an efficient implementation.
    • The choice between SHA and BCrypt in the /etc/shadow file may depend on the efficiency of low-level algorithms and is recommended to consult the OS documentation for optimization.
  5. scrypt and GPU Resistance:

    • scrypt, with a sufficient work factor, imposes extra RAM/memory requirements, making it more GPU-resistant compared to SHA, BCrypt, or PBKDF2.

In conclusion, Michelle Hunter emphasizes the importance of considering factors such as the design philosophy, robustness, efficiency of implementation, and hardware considerations when choosing a hashing algorithm. The response provides a nuanced understanding of the strengths and considerations for each algorithm in the context of password storage and security.

From PBKDF2 vs Bcrypt, which is better? - Learn & Grow with Popular eLearning Community (2024)
Top Articles
Latest Posts
Article information

Author: Saturnina Altenwerth DVM

Last Updated:

Views: 6422

Rating: 4.3 / 5 (44 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Saturnina Altenwerth DVM

Birthday: 1992-08-21

Address: Apt. 237 662 Haag Mills, East Verenaport, MO 57071-5493

Phone: +331850833384

Job: District Real-Estate Architect

Hobby: Skateboarding, Taxidermy, Air sports, Painting, Knife making, Letterboxing, Inline skating

Introduction: My name is Saturnina Altenwerth DVM, I am a witty, perfect, combative, beautiful, determined, fancy, determined person who loves writing and wants to share my knowledge and understanding with you.