Network Security

a cryptographic hash

Imagine a machine that reads any document — one word or a whole library — and stamps out a short, fixed-length fingerprint, say 64 characters. Change even a single comma in the document and the fingerprint comes out completely different. You can't reverse the fingerprint back into the document, and you can't find two different documents that happen to produce the same fingerprint. A cryptographic hash function is exactly this fingerprint machine for digital data.

Precisely, a hash function takes an input of any size and returns a fixed-size output (the hash or digest), with three properties that make it cryptographic. It's deterministic: the same input always gives the same digest. It's one-way (preimage resistant): given a digest, you can't feasibly find an input that produces it. And it's collision resistant: you can't feasibly find two different inputs with the same digest. A tiny change in the input avalanches into a totally different output. Common functions are SHA-256 and SHA-3; older ones like MD5 and SHA-1 are now broken for security use because collisions were found.

Why it matters: a hash is the workhorse of integrity. Download a file and compare its hash to the published one — if they match, the file wasn't altered in transit. Hashes are the core of message authentication codes, digital signatures (you sign the small hash, not the huge document), and how passwords are stored (the system keeps the hash, not the password). The honest caveat: a plain hash by itself proves integrity only against accidental change. An attacker who alters the data can simply recompute the hash too — so to detect malicious tampering you must combine the hash with a secret (a MAC) or a private key (a signature).

SHA-256 of the text 'hello' is a fixed 64-hex-character string; SHA-256 of 'hellp' (one letter changed) is a completely different 64-character string with no resemblance. That avalanche is what makes the smallest tampering jump out when you compare digests.

Any input, a fixed fingerprint; one bit changes everything.

A bare hash sent alongside data stops accidents, not attackers — anyone who edits the data can recompute the hash. Tamper detection against an active adversary needs a key: that's the difference between a hash and a MAC.

Also called
hash functionmessage digestdigest密碼雜湊雜湊函數訊息摘要