Compare SHA, bcrypt, Argon2 for passwords securely
Data security does not rely on secrecy alone. It relies on transformation. In modern systems, sensitive information like passwords is not stored directly. Instead, it is transformed using cryptographic hashing — a process that converts data into a fixed-length representation that cannot be reversed.
But not all hashing algorithms serve the same purpose. Some are designed for speed, others for security against brute-force attacks. Understanding these differences is essential for building secure systems.
Understanding Cryptographic Hashing
This blog takes a theoretical yet intuitive approach to explain:
- What hashing really represents
- Why different hashing algorithms exist
- Why fast hashing can be insecure for passwords
- How modern password hashing resists attacks
Hashing as a Mathematical Transformation
A cryptographic hash function is a deterministic mathematical function:
h = H(x)
Where:
- x is input data
- h is the fixed-length hash output
- H is the hash function
A secure hash function has key properties:
Deterministic: Same input always produces same output
Preimage Resistant: Cannot recover input from hash
Collision Resistant: Different inputs should not produce same output
Avalanche Effect: Small input change causes large output change
Hashing is not encryption. Encryption is reversible with a key. Hashing is designed to be one-way.
Why We Need Different Hashing Algorithms
At a high level, hashing algorithms fall into two categories based on design goals:
1. Fast Hash Functions
Designed for speed and data integrity.
2. Slow Hash Functions
Designed for security against brute-force attacks.
This distinction is critical in password storage. Speed is beneficial for data verification but dangerous for password protection.
SHA Family: Designed for Integrity, Not Password Security
Secure Hash Algorithm (SHA) functions, such as SHA-256 and SHA-512, are widely used cryptographic hash functions.
Key Characteristics
- Extremely fast computation
- Fixed output size
- Designed for digital signatures and data integrity
- No built-in resistance to brute-force attacks
Because SHA is fast, attackers can compute billions of hashes per second using modern hardware. This makes SHA unsuitable for password hashing, even though it is cryptographically secure.
bcrypt: Hashing Designed to Be Slow
bcrypt was specifically designed for password storage. Its core philosophy is simple:
Make hashing computationally expensive to slow down attackers.
Key Characteristics
Adaptive Cost Parameter
The work factor controls how slow hashing is. As hardware improves, cost can be increased.
Built-in Salting
bcrypt automatically adds randomness to inputs, preventing identical passwords from producing identical hashes.
Resistant to GPU Acceleration
bcrypt’s design makes large-scale parallel attacks less efficient.
bcrypt transforms password hashing from a pure mathematical transformation into a controlled computational process.
Argon2: Memory-Hard Password Hashing
Argon2 is a modern password hashing algorithm designed to resist both CPU and GPU attacks.
Key Characteristics
Memory Hardness
Requires significant memory to compute hashes, making large-scale attacks expensive.
Configurable Parameters
Controls include time cost, memory usage, and parallelism.
Designed for Modern Threat Models
Specifically built to defend against hardware-accelerated brute-force attacks.
Argon2 does not just slow computation — it forces attackers to consume hardware resources.
Why Fast Hashing Fails for Password Security
If passwords are hashed with fast algorithms like SHA:
Attackers can test billions of guesses quickly
Password databases become vulnerable to dictionary attacks
Hardware acceleration makes brute-force feasible
Security requires making each guess expensive. Slow hashing transforms attack feasibility from trivial to costly.
Viewing Hashing as an Optimization Trade-Off
Choosing a hashing algorithm involves balancing:
Speed vs Security
Usability vs Resistance to Attack
Computation vs Resource Cost
For data integrity tasks, fast hashing is ideal.
For password storage, computational resistance is essential.
Practical Comparison of Hashing Algorithms
SHA-256
Purpose: Data integrity, digital signatures
Speed: Very fast
Password Security: Poor
bcrypt
Purpose: Password hashing
Speed: Intentionally slow
Security: Strong against brute-force
Argon2
Purpose: Modern password hashing
Speed: Configurable
Security: Strong with memory hardness
The key distinction is not cryptographic strength alone, but resistance to large-scale guessing attacks.
Why Salt Matters in Password Hashing
A salt is random data added to input before hashing:
h = H(password + salt)
Salting prevents:
Identical passwords producing identical hashes
Precomputed rainbow table attacks
Mass cracking of password databases
bcrypt and Argon2 incorporate salting automatically.
Why Modern Systems Prefer Adaptive Hashing
Security requirements change as hardware improves. Adaptive hashing allows systems to increase computational cost over time.
This ensures:
Long-term security
Resistance to evolving attack capabilities
Controlled performance trade-offs
Static hashing algorithms cannot provide this adaptability.
Final Thought
Hashing is not a single tool but a design philosophy shaped by purpose. Fast hash functions protect data integrity, while slow, adaptive hashing protects secrets.
Security is not achieved by making transformation irreversible alone — it is achieved by making attack economically impractical.
In password protection, the goal is not merely to hash data, but to make guessing prohibitively expensive.

Top comments (0)