liveBook · Manning

Second pre-image resistance

As explained in Real-World Cryptography

Second pre-image resistance is the property that, given an input and its hash output, it is computationally infeasible to find a different input with the same output.

Second pre-image resistance means that, given an input and its digest, an attacker should not be able to find a different input producing the same digest. The input is fixed; the attacker searches for its substitute. section 2.2 section 2.7

Keep these nearby distinctions in mind:

  • Pre-image resistance hides the original input when only its digest is known. section 2.2
  • Second pre-image resistance starts with one known input and prevents finding a different input with the same digest. section 2.2
  • Collision resistance prevents an attacker from choosing both different inputs, making it a different threat model. section 2.2

Checking a downloaded file

A website publishes a file and its SHA-256 digest. Running `openssl dgst -sha256 downloaded_file` lets you compare the local digest with the published value. If the digest is trustworthy, second pre-image resistance makes substituting a different file with that same value computationally infeasible. The digest itself is not automatically trustworthy: someone who can replace the webpage can replace the published digest too. section 2.1

When encoding breaks the protection

Hashing transaction fields by simple concatenation can make different transactions produce identical byte strings. For example, `Alice`, `Bob`, `100`, `15` and `Alice`, `Bob`, `1001`, `5` produce the same SHA3-256 digest under the shown encoding. Prefixing each field with its length, or using TupleHash, makes the serialization unambiguous before hashing. section 2.5.4

Short digests are dangerous

A short authenticated string can make a second pre-image search practical. With a 20-bit truncated hash, an attacker may need only about 2^20 computations to generate a public key yielding a chosen matching value. A commitment that fixes the first public key before the other key is revealed removes the attacker’s ability to choose both sides freely. section 11.3.3

How Real-World Cryptography covers it

How deep it goes
Defines the threat model, contrasts related properties, and demonstrates encoding and digest-size failure modes without proving hash internals.
Examples
Uses downloaded files, SHA-256 commands, ambiguous transactions, TupleHash encoding, and truncated short authenticated strings.
What it assumes
Assumes only a basic understanding of inputs and hash outputs while introducing the three core hash security properties from zero.
What you can do after
Diagnose substitution risks by checking digest size, trustworthy digest distribution, and unambiguous serialization before hashing.
How it connects
Connects hash functions with pre-image resistance, collision resistance, serialization, digital signatures, commitments, and man-in-the-middle attacks.

Also explained in

Compare how 2 books explain second pre-image resistance →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Real-World Cryptography. The section links point to the parts of the book it draws on.