# 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.

## marked as duplicate by Gilles 'SO- stop being evil', Maarten Bodewes♦, Community♦Dec 12 '16 at 3:53

• @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