Hash functions compress arbitrary data into fixed-size digests. The security depends on three core properties: preimage resistance, second preimage resistance, and collision resistance.
Key properties
- Preimage resistance: given a digest, it should be infeasible to recover the input.
- Second preimage resistance: given one input, it should be hard to find another with the same digest.
- Collision resistance: it should be hard to find any two distinct inputs with the same digest.
Common mistakes
- Using fast hashes like
MD5orSHA1for passwords. - Skipping a unique salt per user.
- Reusing a single hash for both integrity and authentication.
Safer patterns
- Password storage:
Argon2idorbcryptwith strong parameters. - Integrity only:
SHA-256orSHA-3with a trusted channel. - Authentication: use HMAC with a secret key.
Next up: a quick lab for benchmarking hashes and comparing cost factors.
BACK TO BLOG ->