# Why does second pre-image resistance imply pre-image resistance? [duplicate]

Definitions here:

• Pre-image resistance

Given a hash value h it should be difficult to find any message m such that h = hash(m).

• Second pre-image resistance

Given an input m1 it should be difficult to find different input m2 such that hash(m1) = hash(m2).

Wikipedia says:

These properties form a hierarchy, in that collision resistance implies second pre-image resistance, which in turns implies pre-image resistance, while the converse is not true in general.

Assuming pre-image resistance is broken, we have a function pre(h) which can easily find m such that h = hash(m). How is it helpful in finding a different m2 such that hash(m1) = hash(m2)? What if pre(m1) always returns m1?

Edit. The definition on Wikipedia is not quite formal. A better explanation is here.

• One importance of finding different m2 is faking. Note that pre(m1) cannot always returns m1, because the length of hash input is infinite while the outputs length is finite. – Meysam Ghahramani Dec 11 '16 at 21:27
• @MeysamGhahramani Assuming the hash value is k bits, then pre can have2^k different answers. In reality enumerating all 2^k values is not practical if you consider k is usually 128 or larger, therefore pre has a lot of leeway. – Cyker Dec 12 '16 at 3:15