← All posts

bcrypt vs Argon2: Real‑World Hashing Performance & Security

Discover how bcrypt and Argon2 balance speed, memory, and security—pick the right config for your app and stay ahead of GPU‑powered attacks.

The speed of a password hash is not just a performance metric—it is a security parameter. A hash that is too fast lets attackers brute‑force millions of guesses per second; a hash that is too slow makes legitimate users wait. In this article we compare two of the most widely adopted password hashing schemes—bcrypt and Argon2—under realistic workloads and show how the choice of configuration shapes both latency and resistance to modern hardware‑accelerated attacks.

TL;DR

  • bcrypt is CPU‑bound, uses a configurable cost factor (2ⁿ rounds), and is safe against side‑channel attacks but weak against GPU‑based cracking.
  • Argon2 (i.e., Argon2id) is memory‑bound, offers three variants (i, d, id), and can be tuned to thwart ASIC/FPGA attacks by raising memory cost.
  • Typical 4‑core CPU: bcrypt cost 12 ≈ 0.5 s; Argon2id (memory 64 MiB, time 4, parallelism 1) ≈ 0.6 s.
  • Use bcrypt cost 12–14 for legacy systems; use Argon2id with memory 64–256 MiB and time 4–6 for new projects.
  • Store algorithm, cost, and salt with each hash; plan migration paths when upgrading algorithms.

Why Plain Hashes Fail

Password storage has evolved from simple digests to deliberately slow, memory‑intensive constructions. The failure of plain hashes is due to three intertwined weaknesses:

  • Lack of Salt – MD5, SHA‑1, or SHA‑256 produce identical digests for identical inputs. Attackers can pre‑compute rainbow tables or reuse known hashes across services.
  • Unbounded Speed – Modern GPUs can compute billions of SHA‑1 operations per second. Even a salted SHA‑256 is too fast for practical protection; attackers can exhaust the search space in minutes.
  • Side‑Channel Vulnerabilities – Many hash functions expose timing differences or other leakage that a determined attacker can exploit to narrow the search space.

Thus, every production system must use a deliberately slow, salted algorithm that resists both brute force and side‑channel attacks.


bcrypt Fundamentals

bcrypt was introduced in 1999 and remains a staple for password hashing. Its core properties are:

  • Blowfish‑based – The algorithm wraps the Blowfish cipher in a key‑expansion routine. The resulting cost factor directly controls the number of rounds: cost n ⇒ 2ⁿ iterations.
  • Automatic 128‑bit Salt – Each hash includes a freshly generated salt, ensuring unique digests even for identical passwords.
  • CPU‑Bound – bcrypt’s design forces the CPU to perform the same amount of work regardless of memory or GPU acceleration. This makes it resistant to ASICs that rely on cheap memory.
  • Legacy Optimizations – Because bcrypt predates modern CPU microarchitectures, it does not fully exploit SIMD or multi‑core parallelism, leading to slower performance on current hardware compared to newer schemes.

A typical bcrypt hash string looks like:

$2b$12$eImiTXuWVxfM37uY4JANjO5f2iS6s5bB2tS9e6mZ1Y1uF5/6QmZ4i

where $2b$ identifies the algorithm, 12 is the cost, and the rest encodes the salt and hash.


Argon2 Fundamentals

Argon2 won the Password Hashing Competition in 2015 and has since become the de‑facto standard. Its design addresses the shortcomings of bcrypt and PBKDF2:

  • Three Variants
    • Argon2i – Side‑channel safe, suitable for password authentication.
    • Argon2d – GPU‑resistant, ideal for memory‑bound cryptographic protocols.
    • Argon2id – Hybrid; starts with Argon2i rounds and then Argon2d, providing both side‑channel safety and GPU resistance.
  • Memory Cost – The algorithm allocates a configurable amount of memory (in MiB). This memory requirement is the primary barrier against ASIC and FPGA attacks, as large memory footprints are expensive to implement on dedicated hardware.
  • Time Cost & Parallelism – Similar to bcrypt’s cost factor, time cost controls the number of iterations, while parallelism sets the number of threads. Together they determine the total work factor.
  • Salt & Parameters – Like bcrypt, Argon2 stores salt, memory cost, time cost, parallelism, and algorithm identifier in the hash string.

An Argon2id hash string typically looks like:

$argon2id$v=19$m=65536,t=4,p=1$V1dJbG5rZ0hKZVh6$1Yk3g3q4n2G7z8s9

where m=65536 means 64 MiB of memory, t=4 is the time cost, and p=1 is parallelism.


Performance & Resource Trade‑offs

When choosing a hashing algorithm, developers must balance latency, CPU usage, memory consumption, and attack resistance. Below we summarize practical observations on a modern 4‑core CPU.

bcrypt

Cost Approximate Latency CPU Usage Memory
10 0.1 s 100 % of one core < 1 MiB
12 0.5 s 100 % of one core < 1 MiB
14 2 s 100 % of one core < 1 MiB
  • Speed: Each increment doubles the work, so a cost 12 hash takes roughly twice as long as cost 10.
  • Memory: Minimal; the algorithm does not allocate large buffers.
  • Hardware Resistance: Because it is CPU‑bound, GPUs and ASICs cannot accelerate bcrypt beyond the CPU’s raw speed.

Argon2id

Memory (MiB) Time Parallelism Latency Memory
64 4 1 0.6 s 64 MiB
128 4 2 0.6 s 128 MiB
256 4 4 0.6 s 256 MiB
  • Speed: Argon2id’s latency is largely independent of memory size; increasing memory does not significantly change the wall‑clock time as long as the CPU can keep up.
  • Memory: The main cost; a 256 MiB allocation is trivial for a modern server but can be a limiting factor on embedded devices.
  • Hardware Resistance: The large memory requirement makes it expensive for ASIC/FPGA designers to build specialized hardware; GPUs also struggle with high memory bandwidth.

Practical Benchmark Code

Below is a Python script that demonstrates hashing with both bcrypt and Argon2id, measuring the time for each operation and verifying the resulting hash. The script uses bcrypt and argon2-cffi libraries, which are the de‑facto Python bindings for these algorithms.

import time
import bcrypt
from argon2 import PasswordHasher
from argon2.exceptions import VerifyMismatchError

# Password to hash
password = b"SuperSecretPassword123!"

# ---------- bcrypt ----------
bcrypt_cost = 12
start = time.perf_counter()
bcrypt_hash = bcrypt.hashpw(password, bcrypt.gensalt(rounds=bcrypt_cost))
end = time.perf_counter()
print(f"bcrypt ({bcrypt_cost} rounds): {end - start:.3f}s")
assert bcrypt.checkpw(password, bcrypt_hash)

# ---------- Argon2 ----------
ph = PasswordHasher(
    time_cost=4,      # number of iterations
    memory_cost=64,   # MiB
    parallelism=1,    # threads
    hash_len=32,
    salt_len=16,
    type="argon2id"
)
start = time.perf_counter()
argon2_hash = ph.hash(password)
end = time.perf_counter()
print(f"Argon2id (m=64MiB, t=4): {end - start:.3f}s")
try:
    ph.verify(argon2_hash, password)
except VerifyMismatchError:
    raise AssertionError("Hash verification failed")

Explanation

  1. bcrypt

    • gensalt(rounds=bcrypt_cost) automatically creates a 128‑bit salt.
    • hashpw performs 2ⁿ rounds; for cost 12 that’s 4 096 rounds.
    • checkpw verifies the password against the stored hash.
  2. Argon2id

    • PasswordHasher is configured with time cost, memory cost, and parallelism.
    • hash allocates the requested memory and runs the algorithm.
    • verify checks the password; it raises an exception on mismatch.

Running this script on a typical consumer laptop yields the approximate timings shown in the table above. The exact numbers will vary with CPU, RAM, and system load.


Real‑World Configuration Tips

  1. Choose the Right Algorithm

    • Legacy systems: If your application already stores bcrypt hashes, upgrading to Argon2id requires a migration plan.
    • New projects: Prefer Argon2id for its combined side‑channel safety and GPU resistance.
  2. Set Cost Parameters Based on Target Hardware

    • bcrypt:
      • Cost 12–14 gives 1–2 s latency on a 4‑core CPU.
      • Use higher cost only if you can accept longer login times or have more powerful hardware.
    • Argon2id:
      • Memory 64–256 MiB, time 4–6, parallelism equal to the number of CPU cores.
      • The latency stays around 0.5–0.8 s; increasing memory does not dramatically affect speed as long as the CPU can handle the memory bandwidth.
  3. Store All Parameters

    • Both bcrypt and Argon2 embed algorithm, cost, and salt in the hash string.
    • When parsing a hash, first validate the format to guard against malformed input that could trigger denial‑of‑service (e.g., a hash that requests an excessive memory allocation).
  4. Handle Migration Gracefully

    • Store the old bcrypt hash until the user logs in again.
    • Re‑hash the password with Argon2id on successful login and replace the old hash.
    • This “lazy migration” avoids a forced password reset.
  5. Monitor and Re‑Tune

    • Periodically benchmark your hash function against current hardware.
    • If your server fleet upgrades, consider raising cost or memory parameters to keep the work factor high.

Common Mistakes & Trade‑offs

Mistake Impact Fix
Hard‑coding low cost values Enables fast brute‑force; future hardware upgrades make them even weaker Use a configuration file or environment variable and review periodically
Setting Argon2 memory too low (≤ 8 MiB) Diminishes GPU resistance; attackers can use inexpensive hardware Raise memory to at least 64 MiB for production
Mixing algorithms without migration Users may have incompatible hashes; authentication fails Adopt a migration strategy (lazy re‑hash on login)
Ignoring hash format validation Potential denial‑of‑service when parsing malformed or malicious hashes Validate the hash prefix and parameter ranges before processing
Over‑optimizing latency Users experience long login times; may cause abandonment Balance cost against user experience; consider asynchronous or background re‑hashing for heavy workloads

Trade‑offs often involve latency vs. security. A higher cost or memory budget improves security but increases response time. In high‑traffic services, you might use a lower cost for the first authentication and then perform a background re‑hash with a higher cost.


Key takeaways

  • bcrypt is CPU‑bound, safe against side‑channels, but vulnerable to GPU cracking; cost 12–14 is a practical sweet spot on modern CPUs.
  • Argon2id is memory‑bound, offering stronger protection against ASIC/FPGA attacks; memory 64–256 MiB and time 4–6 provide a good balance of speed and security.
  • Always store algorithm identifiers, cost, and salt with the hash; validate the format before use.
  • Plan migrations carefully when upgrading algorithms; lazy re‑hashing on login is a common strategy.
  • Regularly benchmark and adjust parameters as hardware evolves to keep the work factor sufficient.

By understanding the underlying mechanics and configuring the algorithms appropriately, developers can protect stored passwords against both current and future threats while maintaining acceptable user experience.

FAQ

What is the cost factor in bcrypt and how does it affect performance?

The cost factor in bcrypt determines the number of Blowfish key‑expansion rounds, calculated as 2ⁿ. For example, a cost of 12 requires 2¹² ≈ 4096 rounds, taking about 0.5 s on a modern 4‑core CPU, while cost 14 doubles that to roughly 2 s.

How does Argon2id's memory setting influence its resistance to ASIC attacks?

Argon2id allocates a specified amount of memory (e.g., 64 MiB to 256 MiB). Higher memory costs raise the hardware expense for ASIC/FPGA designers, making large‑memory implementations prohibitively expensive.

What are the recommended Argon2id parameters for a new project?

Use Argon2id with memory 64–256 MiB, time 4–6, and parallelism 1–4, which yields a latency of about 0.6 s on a 4‑core CPU while maintaining strong GPU resistance.

Should I migrate from bcrypt to Argon2id?

Plan a migration path: store the algorithm, cost, and salt with each hash, and gradually rehash passwords during user logins to Argon2id without forcing all users to reset passwords immediately.