Cryptographic hash functions: the fingerprint of data
What cryptographic hash functions are, the properties they must have, the birthday paradox, the history from MD5 to SHA-3, known attacks and today’s uses, from signatures to blockchain.
A cryptographic hash function takes as input data of any size — a word, a book, an entire disk — and returns a fixed-length string, called a hash value or digest. The same input always gives the same value; a minimal change produces a completely different value; and the data cannot be recovered from the value.
They are among the least visible and most used tools of cryptography. They protect passwords in websites’ databases, guarantee that a downloaded file has not been altered, are at the heart of digital signatures and certificates, hold together the blocks of a blockchain and make it possible to prove in court that digital evidence has not changed.
The required properties
- Determinism
- The same data always produce the same value.
- Efficiency
- The value is computed quickly even for large amounts of data.
- Preimage resistance
- Given a value, it is infeasible to find data that produce it.
- Second-preimage resistance
- Given a message, it is infeasible to find another with the same value.
- Collision resistance
- It is infeasible to find any two messages with the same value.
- Avalanche effect
- Changing one input bit changes on average half the bits of the value.
For the use of hash values in investigations see digital forensics; here we explore how they work. Hash functions are the basis of HMAC, digital signatures and the algorithms for password storage.
The pages of this topic
Hash 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: worked example
SHA-256 values of similar words and phrases, to see the avalanche effect, and the official test vectors.
Hash functions: weaknesses and attacks
MD5 and SHA-1 collisions, chosen-prefix attacks, length extension and precomputed tables for passwords.
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.