# Second pre-image resistance vs Collision resistance

From Wikipedia:

## Second pre-image resistance

Given an input $m_1$ it should be difficult to find another input $m_2$ such that $m_1$ ≠ $m_2$ and $\operatorname{hash}(m_1) = \operatorname{hash}(m_2)$. Functions that lack this property are vulnerable to second-preimage attacks.

## Collision resistance

It should be difficult to find two different messages $m_1$ and $m_2$ such that $\operatorname{hash}(m_1) = \operatorname{hash}(m_2)$. Such a pair is called a cryptographic hash collision.

Could someone explain the difference between these two please? They very much appear to be identical to me, as in both definitions $m_1 \neq m_2$ and $\operatorname{hash}(m_1) = \operatorname{hash}(m_2)$.

The difference is in the choice of $m_1$.
• In the first case (second preimage resistance), the attacker is handed a fixed $m_1$ to which he has to find a different $m_2$ with equal hash. In particular, he can't choose $m_1$.
• In the second case (collision resistance), the attacker can freely choose both messages $m_1$ and $m_2$, with the only requirement that they are different (and hash to the same value).
(From this, it is also obvious that collision resistance implies second preimage resistance: An attacker can just choose an arbitrary $m_1$ and compute a second preimage $m_2$ to obtain a collision.)
{"ft_lang_label":"__label__en","ft_lang_prob":0.8490349,"math_prob":0.998337,"size":690,"snap":"2019-51-2020-05","text_gpt3_token_len":193,"char_repetition_ratio":0.17492712,"word_repetition_ratio":0.022222223,"special_character_ratio":0.26811594,"punctuation_ratio":0.071428575,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99787384,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-12-14T15:39:47Z\",\"WARC-Record-ID\":\"<urn:uuid:25935bbc-3137-4a89-99c7-bbecf61ac3fa>\",\"Content-Length\":\"135101\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:b74649fd-221a-467a-b439-9644bd54e6e5>\",\"WARC-Concurrent-To\":\"<urn:uuid:189dbf72-dcac-4803-9702-60e9d1ad228c>\",\"WARC-IP-Address\":\"151.101.1.69\",\"WARC-Target-URI\":\"https://crypto.stackexchange.com/questions/20997/second-pre-image-resistance-vs-collision-resistance\",\"WARC-Payload-Digest\":\"sha1:S3TH6DDYSYAAQ3QH7BU32ZEXR5CIY5CR\",\"WARC-Block-Digest\":\"sha1:6PLKFJ4UH5TIHXWGEXK5OCZWRUAOLA2Z\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-51/CC-MAIN-2019-51_segments_1575541281438.51_warc_CC-MAIN-20191214150439-20191214174439-00111.warc.gz\"}"}