Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

md5 hash collisions.

If counting from 1 to X, where X is the first number to have an md5 collision with a previous number, what number is X?

I want to know if I'm using md5 for serial numbers, how many units I can expect to be able to enumerate before I get a collision.

like image 451
John Lewis Avatar asked Jul 30 '11 19:07

John Lewis


1 Answers

Theoretically, you can expect collisions for X around 264. For a hash function with an output of n bits, first collisions appear when you have accumulated about 2n/2 outputs (it does not matter how you choose the inputs; sequential integer values are nothing special in that respect).

Of course, MD5 has been shown not to be a good hash function. Also, the 2n/2 is only an average. So, why don't you try it ? Take a MD5 implementation, hash your serial numbers, and see if you get a collision. A basic MD5 implementation should be able to hash a few million values per second, and, with a reasonable hard disk, you could accumulate a few billions of outputs, sort them, and see if there is a collision.

like image 199
Thomas Pornin Avatar answered Nov 16 '22 04:11

Thomas Pornin