# Difference between second pre-image resistance attack and collision attack

According to my understanding of hashing algorithms -:

Collision attack is an attack wherein we have a hash(x) and we try to find hash(y) such that x!=y while hash(x)=hash(y).

Second pre-image resistance is where we have a message x and a hash(x) and try to find another message y such that hash(x)=hash(y).

According to me the collision attack and second pre-image resistance attack seems similar as in the case of both, we need to find two different hashes which are same while the message associated with the hash is completely different.

You are mistaken. A collision attack is where you need to find any $x$ and $y$ such that $hash(x)=hash(y)$. Thus, you have much more freedom in finding the collision. This makes it "easier" for the adversary.

• Thanks for the clarification. So collision attack is where we have to find x and y such that hash(x)= hash(y) but the second pre-image resistance is also similar where we are given x and we need to find y such that hash(x)=hash(y). I am not able to catch the difference. – Skynet Feb 4 '18 at 6:56
• @Skynet - Yehuda (of course) explained this perfectly. Your mis-understanding of collision resistance is the problem. With collision resistance, it's not that you have msg x and need to find a 2nd (and different) msg with a colliding hash; you just need to find //any 2 different// preimages that hash to the same value (collision). This is much easier/faster than finding a 2nd pre-image that hashes to an exact value due to something called the Birthday Paradox (quick web search will explain the Birthday paradox) – Dan Feb 4 '18 at 7:06