A hash function maps a message of any length to a fixed -bit digest . It is public and keyless.
A cryptographically secure hash function is:
- Computationally efficient
is fast to compute for any . - Deterministic
The same always gives the same digest. - One-way
Preimage resistant, defined below. - Collision resistant
Defined below.
Strict Avalanche Criterion
Also called SAC or bit diffusion. When a single input bit is flipped, about 50% of the output bits flip on average, and the probability that any given output bit flips is independent of which input bit was flipped and of the input value.
Properties
Each property is stated as work an attacker cannot afford. is modelled to be a uniformly random function, for the below analysis.
Preimage Resistance
Given a digest , an attacker cannot find any with practically.
The attacker is aiming at one fixed digest . Each trial message lands on it with chance in , so about trials are needed.
Weak Collision Resistance
Aka. second-preimage resistance. Given a fixed message , an attacker cannot find a different with .
Again one fixed target, the digest of the given . Each trial lands on it with chance in , so about trials are needed, the same as preimage resistance.
Strong Collision Resistance
An attacker cannot find any pair with , both of their choosing.
Any two of the attacker’s own messages sharing a digest is a win. Each new message can pair with every earlier one, so after hashing messages there are about candidate pairs. That many pairs cover the possible digests once , so the work drops to the square root.
Same effect as the birthday problem: matching one given birthday needs about people, but finding any shared birthday needs only about .
Uses
Cryptographic uses:
- Padding
Randomised padding schemes such as OAEP mix message bits with hash output before public key encryption. - Signing
A signature is computed over , so it covers an input of any length at fixed cost. - Key derivation
A raw secret is hashed to produce a symmetric key of the required length with no algebraic structure.
In real world:
- File integrity
A published digest lets anyone check a downloaded file was not altered. - Blockchain security
Each block stores the digest of the previous block, so any edit breaks the chain. - Password storage
The database keeps , not the password. Even if the database leaks, the attacker cannot reverse the digests back to plaintext passwords.
Examples
OAEP
Optimal Asymmetric Encryption Padding. A randomised padding applied to a message before RSA encryption.
It is a 2-round Feistel network over the message and a random seed , with round functions built from a hash :
- , where expands to the block width.
- .
- The RSA input is .
Effects:
- Randomised
The same encrypts differently each run through . - All-or-nothing
Every output bit depends on every bit of and , so a tampered block fails the padding check on decryption.
This makes RSA encryption secure against chosen-ciphertext attacks. The hash is used only as padding, so no collision property is relied on.