Key Stretching Explained: bcrypt vs. PBKDF2 for Security+

 Key Stretching

Key stretching is a way of slowing the attacker down from discovering a password in a hashed format. This method uses thousands of rounds of hashing. It first hashes the password, then hashes the hash, and continues this process.

The attacker would have to guess the password and start the hashing process by testing each hash until they find a match.

There are two main methods of key stretching: bcrypt & PBKDF2 (Password-Based Key Derivation 2)

How bcrypt Works

bcrypt is a key-stretching function built around the Blowfish cipher. Instead of a fixed number of rounds, it uses a cost factor (also called a work factor) that you can dial up over time — each increment roughly doubles the computation required. That's what keeps bcrypt relevant even as hardware gets faster: you just raise the cost factor and every new password hash gets proportionally harder to crack. One limitation worth knowing: bcrypt only processes the first 72 bytes of a password, so anything beyond that is silently ignored.

How PBKDF2 Works

PBKDF2 (Password-Based Key Derivation Function 2) takes a different approach: it repeatedly applies an HMAC (a keyed hashing function) to the password, often hundreds of thousands of times, combined with a random salt. The iteration count plays the same role as bcrypt's cost factor — more iterations means more time per guess for an attacker. PBKDF2's main advantage is that it's FIPS 140-validated, which makes it the required choice in many government and regulated environments, even though it's less resistant to GPU-based cracking than newer alternatives.

Newer Alternatives: scrypt and Argon2

bcrypt and PBKDF2 both became industry standards, but neither is memory-hard — they mainly demand CPU time, which GPUs and custom ASIC hardware can parallelize cheaply. Two newer algorithms address that gap:

  • scrypt forces an attacker to use a large, unpredictable amount of memory per guess, not just CPU cycles, which makes GPU/ASIC cracking far more expensive.
  • Argon2 (specifically Argon2id) is the current recommendation for new systems. It lets you tune memory usage, time cost, and parallelism independently, giving the strongest resistance to hardware-accelerated cracking of the group.

Key Stretching vs. Salting: Two Different Jobs

It's easy to blur key stretching together with salting, but they solve different problems. A salt is random data added to each password before hashing so that identical passwords don't produce identical hashes — this defeats precomputed rainbow table attacks. Key stretching makes each individual hash computation slow, which defeats brute-force and dictionary attacks regardless of whether a rainbow table is in play. Modern password storage uses both together: a unique salt per password, run through a key-stretching algorithm like bcrypt, PBKDF2, or Argon2.

CompTIA Exam Tip

Key stretching falls under cryptographic concepts in the Security+ (SY0-701) objectives. You should be able to name bcrypt and PBKDF2 as key-stretching algorithms, recognize that a higher cost factor or iteration count means stronger (but slower) protection, and distinguish key stretching from salting — they're often tested as a pair since real systems use both. If a scenario mentions memory-hard hashing or resistance to GPU cracking, that's pointing at scrypt or Argon2.

Key Takeaways

  • Key stretching repeatedly hashes a password so each guess costs an attacker significant time, defeating brute-force attacks even on weak passwords.
  • bcrypt uses a tunable cost factor based on the Blowfish cipher; PBKDF2 uses repeated HMAC iterations and is FIPS 140-validated.
  • scrypt and Argon2 add memory-hardness, making them far more resistant to GPU and ASIC cracking than bcrypt or PBKDF2.
  • Key stretching and salting solve different problems and are used together: salting stops rainbow tables, key stretching slows brute force.
  • Argon2id is the current best-practice recommendation for new systems; PBKDF2 remains required in FIPS-regulated environments.

Comments