Hash Functions

A hash function HH maps a message mm of any length to a fixed nn-bit digest H(m)H(m). It is public and keyless.

Chains of trust use hashes to verify each component before it runs.

Strict Avalanche Criterion

Also known as 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

HH is the hash function and is modelled to be a uniformly random function.

Computationally Efficient

H(m)H(m) is fast to compute for any mm and does not vary much.

Deterministic

Same plaintext input produces the same digest.

Preimage Resistance

Given a digest dd, an attacker cannot find any mm with H(m)=dH(m) = d practically.

The attacker is aiming at one fixed digest dd. Each trial message lands on it with chance 11 in 2n2^n, so about 2n2^n trials are needed.

Weak Collision Resistance

Also known as second-preimage resistance. Given a fixed message mm, an attacker cannot find a different m′m' with H(m′)=H(m)H(m') = H(m).

Again one fixed target, the digest of the given mm. Each trial m′m' lands on it with chance 11 in 2n2^n, so about 2n2^n trials are needed, the same as preimage resistance.

Strong Collision Resistance

An attacker cannot find any pair m≠m′m \neq m' with H(m)=H(m′)H(m) = H(m'), 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 kk messages there are about k2/2k^2/2 candidate pairs. That many pairs cover the 2n2^n possible digests once k≈2n/2k \approx 2^{n/2}, so the work drops to the square root.

Same effect as the birthday problem: matching one given birthday needs about 365365 people, but finding any shared birthday needs only about 2323.

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 H(m)H(m), 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 H(password)H(\text{password}), not the password. Even if the database leaks, the attacker cannot reverse the digests back to plaintext passwords.

Examples

Basic Mathematical Hash Functions

The following functions map non-negative integers to a fixed range. They illustrate hashing, but they are not cryptographically secure.

H1(x)=x mod 10H_1(x) = x \bmod 10 H2(x)=(7x+3) mod 10H_2(x) = (7x + 3) \bmod 10

Examples:

  • H1(42)=2H_1(42) = 2
  • H1(52)=2H_1(52) = 2
  • H2(7)=2H_2(7) = 2
  • H2(17)=2H_2(17) = 2

Both functions have collisions. 4242 and 5252 have the same digest under H1H_1. 77 and 1717 have the same digest under H2H_2. A digest of 22 does not identify a unique input.

OAEP

Also known as Optimal Asymmetric Encryption Padding. A randomised padding applied to a message before RSA encryption.

It is a 2-round Feistel network over the message MM and a random seed rr, with round functions built from a hash HH:

  • maskedM=(M ∥ padding)⊕G(r)\text{maskedM} = (M \,\|\, \text{padding}) \oplus G(r), where GG expands rr to the block width.
  • maskedR=r⊕H(maskedM)\text{maskedR} = r \oplus H(\text{maskedM}).
  • The RSA input is maskedM ∥ maskedR\text{maskedM} \,\|\, \text{maskedR}.

Effects:

  • Randomised
    The same MM encrypts differently each run through rr.
  • All-or-nothing
    Every output bit depends on every bit of MM and rr, 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.

Written by October 30, 2026 4 min read
Was this helpful?