Every cryptographic hash function is a hash function. But not every hash function is a cryptographic hash.
The ideal cryptographic hash function has six main properties:
- Deterministic: the same message always results in the same hash;
- Quick: it is quick to compute the hash value for any given message;
- One-way function: it is infeasible to generate a message from its hash value except by trying all possible messages;
- Avalanche effect: a small change to a message should change the hash value so extensively that the new hash value appears uncorrelated with the old hash value;
- Collision resistant
- weak collision resistance (given a message
m1
it must be difficult to find a different messagem2
so thatm1
andm2
yield the same hash) - strong collision resistance (it should be difficult to find any messages
m1
andm2
that yield the same hash)
- weak collision resistance (given a message
- Pre-image attack resistant: given a hash
h
it must be difficult to find a messagem
that yieldsh
when hashed. A cryptographic hash function should resist attacks on its pre-image.
Non cryptographic hash functions just try to avoid collisions for non malicious input. In exchange for weaker guarantees they are typically (much) faster.