← back to cryptography

Hash Functions

Wikipedia · wpCryptographic hash function · CC BY-SA 4.0

A cryptographic hash function maps arbitrary-length input to a fixed-length output. It must be one-way (hard to invert), collision-resistant (hard to find two inputs with the same hash), and avalanche-prone (a small input change flips about half the output bits).

any length H(x) fixed length One-way: easy to compute, hard to invert.

One-way property

Given a hash output h, it should be computationally infeasible to find any input m such that H(m) = h. This is called preimage resistance. For a hash with n-bit output, a brute-force preimage attack takes about 2n tries.

Scheme

Collision resistance and the birthday attack

A collision is two different inputs that produce the same hash. For an n-bit hash, the birthday attack finds a collision in about 2n/2 tries (not 2n). This is why SHA-256 provides only 128 bits of collision resistance. The birthday paradox: in a room of 23 people, there is a 50% chance two share a birthday.

Scheme

Merkle-Damgard construction

SHA-256 processes the message in 512-bit blocks. Each block is fed into a compression function along with the previous hash state. The initial state is a fixed constant (IV). After all blocks, the final state is the hash. This iterative structure is the Merkle-Damgard construction.

Scheme
Neighbors

Cross-references

Foundations (Wikipedia)