Kelly Mears

Hash Function

A function mapping arbitrary input to a fixed-size digest, used for identity, integrity, and addressing.

Systems & Tooling2 min read201 words7 out · 4 in
also calledHashingContent addressing

A hash function maps input of any size to a fixed-size value. The properties that matter are determinism (same input, same digest) and collision resistance (finding two inputs with the same digest should be infeasible).

The uses divide cleanly. Content addressing names a thing by its digest, so identity and integrity are the same fact — the model behind Git's object store and behind content-hashed asset filenames, where a changed file necessarily has a new name and cache invalidation becomes unnecessary. Integrity checking verifies that a download matches what was published. Cache keys summarise a set of inputs so that a change to any of them is detectable; see Fingerprint. Password storage uses deliberately slow functions designed for exactly that, and nothing else.

Two practical cautions. A hash covers exactly what was fed into it — including ordering, so a digest over a list changes when the order changes even if the membership does not, which produces "identical content, different hash" surprises across tools that enumerate in different orders.

And a hash used to derive a value from a small space — a port number, a bucket index — collides regularly. Hashing does not eliminate collisions; it only makes them uniform.

See also4

Hand-picked in the note itself — the neighbours worth reading next.

Related3

Nearby in the graph rather than deliberately chosen. Looser, sometimes surprising.

Linked from4

Notes elsewhere in the wiki that reach for this one.