Hash functions: frequently asked questions
Short answers to the most common doubts about cryptographic hash functions.
Is a hash function a form of encryption?
No. Encryption is reversible with the key; a hash function is not, and uses no keys.
Can two different files have the same hash value?
In theory yes, because the possible values are finite. With robust functions such as SHA-256, however, finding two is practically impossible.
Can MD5 still be used?
To spot duplicate files or transmission errors, yes; for any security purpose, no, because collisions are easy to find.
Is SHA-3 better than SHA-2?
It is not more secure in practical terms: both are considered robust. SHA-3 has a different architecture that makes it immune to some structural attacks, such as length extension.
Why are passwords not stored with SHA-256?
Because it is too fast: whoever steals the database can try billions of passwords per second. Slow, salted functions designed for the purpose are needed.
What is a “salt”?
A random value, different for each password, added before computing the hash: it prevents the use of precomputed tables and the recognition of identical 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: 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.