# Hashing

A one-way computation that maps input data to a fixed-length digest used for integrity, identification, and specialized secret verification.

- Type: method
- Domain: Engineering & architecture
- Level: Intermediate
- Last reviewed: 2026-09-23
- Original: [Soroush’s Product Wiki](<https://wiki.soroush.uk/topic/hashing/>)

## What it means

A cryptographic hash function maps arbitrary input to a fixed-length digest and is designed to resist reversing the input and finding collisions. Hashing is not encryption because there is no decryption key. Password storage uses dedicated slow, salted password-hashing functions rather than fast general-purpose hashes.

## Why it matters

Hashes support integrity checks, digital signatures, content addressing, and password verification without storing plaintext passwords. Choosing the wrong function or omitting salts can make offline guessing and collision attacks practical.

## When to use it

Use approved hashes for integrity and protocol-defined purposes, and a current password-hashing function for stored passwords. Use a message authentication code when integrity must be proven with a shared secret, and encryption when data must later be recovered confidentially.

## How it works

1. Choose a function designed for the specific integrity, signature, or password-storage purpose.
2. Normalize and encode input unambiguously before hashing.
3. For passwords, generate a unique salt and apply a memory-hard or approved adaptive password hash with tuned cost.
4. Store the algorithm, parameters, salt, and digest rather than the password.
5. Compare results safely and upgrade weak parameters after successful authentication.

## A practical example

A product stores each password with Argon2id, a unique random salt, and recorded work parameters. On login it recomputes the digest, compares it safely, and rehashes successful logins when the cost policy increases.

## Where it breaks

Hashing does not hide low-entropy input from offline guessing, authenticate an untrusted digest, or preserve data for recovery. Algorithm safety changes, and collision resistance alone is not sufficient for every protocol.

## Common mistakes

- Storing passwords with a fast hash such as plain SHA-256.
- Using one salt for every account or treating a salt as a secret.
- Using a bare hash where an HMAC or digital signature is required.
- Describing base64 encoding or reversible encryption as hashing.

## Visualization

[View the visualization on the website](<https://wiki.soroush.uk/topic/hashing/#visualization-hashing>)

## Sources

1. [Secure Hash Standard \(FIPS 180-4\)](<https://csrc.nist.gov/pubs/fips/180-4/upd1/final>) — NIST · Government standard
2. [Password Storage Cheat Sheet](<https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html>) — OWASP Foundation · Security practice guidance

## Related topics

- [Encryption](<https://wiki.soroush.uk/topic/encryption/>)
- [Authentication](<https://wiki.soroush.uk/topic/authentication/>)
- [Secrets Management](<https://wiki.soroush.uk/topic/secrets-management/>)
