Course contentsShow
← Security
Lesson 200 of 3,0525. Cryptographic Hashing and MACsFree lesson

Second Preimage Resistance

Understanding why finding a different input with the same hash as a known input must be infeasible.

Second Preimage Resistance

What you'll learn: Why cryptographic hash functions must make it infeasible to find a different input that produces the same hash as a known input.

The Core Idea

You already learned about preimage resistance (lesson 199) — the difficulty of finding any input that produces a target hash. Second preimage resistance is closely related but different: given a specific message and its hash, can an attacker find a different message that produces the same hash?

This property protects against substitution attacks. Imagine you hash a document and store both the document and its hash. An attacker who has access to both shouldn't be able to create a different document with the identical hash value.

Why This Matters

Without second preimage resistance, attackers could:

  • Replace legitimate files with malicious ones while keeping the same hash
  • Forge documents that appear authentic based on their hash
  • Substitute contracts, code, or messages in systems relying on hash verification

Analogy: Think of a fingerprint. Preimage resistance means you can't manufacture a finger to match a fingerprint you found. Second preimage resistance means even if you have someone's actual finger and their fingerprint, you still can't create a different finger that leaves the same print.

The Technical Requirement

For a hash function with an n-bit output, finding a second preimage should require approximately 2^n operations — computationally infeasible for secure hash sizes (256 bits or more). This is a brute-force bound: trying random different inputs until one matches.

Key Takeaway: Second preimage resistance ensures that having a message and its hash doesn't let an attacker craft an alternative message with the same hash, preventing substitution attacks.