Hash functions: worked example
SHA-256 values of similar words and phrases, to see the avalanche effect, and the official test vectors.
The standard’s documents give test values that anyone can verify. For SHA-256:
SHA-256("abc") = ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
SHA-256("") = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855The second line is the value of an empty file: those who work with hash values learn to recognise it, because it immediately signals that a file contains no data.
The avalanche effect
Try computing the values of “abc” and “abd”. The two strings differ by a single letter, that is by two bits; the values have nothing in common that can be recognised by eye. There is no “closeness” between values that reflects closeness between messages.
| Input | Length | SHA-256 value length |
|---|---|---|
| One letter | 1 byte | 256 bits |
| A novel | about 1 MB | 256 bits |
| A disk | 2 TB | 256 bits |
Hash functions: weaknesses and attacks
MD5 and SHA-1 collisions, chosen-prefix attacks, length extension and precomputed tables for passwords.
The pages of this topic
Back to the overviewHash functions: how they work
How a hash function compresses data of any length into a fixed value: blocks, internal state, the Merkle-Damgård construction and the sponge construction.
Hash functions: history
From the first cryptographic hash functions to the SHA family, from MD5’s success to collisions, to the competition that produced SHA-3.
Hash functions: the maths
The birthday paradox and why security against collisions is half the length of the value, with the pigeonhole principle.
Hash functions today
Where hash functions are used every day: digital signatures, certificates, downloads, passwords, blockchain, version control and digital evidence.
Hash functions: try it yourself
Hands-on exercises to compute hash values, observe the avalanche effect and estimate the birthday paradox.
Hash functions: frequently asked questions
Short answers to the most common doubts about cryptographic hash functions.