# Can hash collisions be eliminated by hashing twice? [duplicate]

Suppose I have a file `verified.txt` that has a certain hash X.

An attacker can form an `impostor.txt` that replicates the hash with different content, resulting in a collision for a given algorithm, and rendering the hash test useless.

However, could this be prevented by performing a second hash with a second algorithm, and comparing both hashes?

For example, are MD5 and SHA-1 dissimilar enough that a collision could not be created for both at once? Can I rely on the combination to be more secure?

Second hash will reduce probability of collision (i.e. it is more 'secure') but unfortunately it can not completely eliminate it.

From my point of view single long hash (such as sha512) is better than two short hashes because collision for two hashes can be searched in parallel and will take less time.

A second hash will be more "secure", the question is if it's secure enough for your threat model.

To find a collision for the two given algorithms an attacker should find collisions for one of the algorithms and check if the collision happens using the other.

This is possible to achieve as the group of infinite inputs that produce a collision for algorithm A and the group of infinite inputs that produce a collision for algorithm B are probable to have a non null intersection.

In order to do that, the attacker should at least have the computer power to produce an MD5 collision AND a SHA1 collision.

Whether this is currently possible in an amount of time that would imply a risk is impossible to tell as there are no known collisions for both algorithms (MD5 and SHA1) at the same time

Note: This is assuming that there is no algorithm better than bruteforce to find a collision for the two algorithms at the same time, for which there is no evidence that it exist