A few months ago I read this excellent article on password hashing schemes and I found some things out that I hadn't previously thought about. For instance, this sounds like a pretty novel thing, but speed in a hashing algorithm is not what you're looking for, and some hashing algorithms are much slower than others by design. Well, the other day someone on IRC didn't believe that crypt() would take a significant time more than md5(). Well, of course, I had to test it. So here's what I came up with to benchmark the two:
$t = microtime(true);
for($i=0;$i<5000;$i++){
$m = md5('password');
}
$diff = microtime(true) - $t;
$t2 = microtime(true);
for($i=0;$i<5000;$i++){
$m = crypt('password');
}
$diff2 = microtime(true) - $t2;
echo("MD5: " . $diff . "\\n");
echo("crypt (DES): " . $diff2 . "\\n");
echo("MD5 was " . $diff2/$diff . " times faster than crypt");
My average results with this say that md5() is something close to 125 times faster than crypt(). If you were just hashing one password, the difference would be negligible to the user. However, if someone is trying to brute one versus the other, the time will definitely make a difference. The moral of the story? Sometimes slower is better.
I apologize to any cryptographers who were hurt while reading this post; it's not very scientific, but it is the simplest way I can think of to demonstrate the time difference between these two algorithms. I'm sure you could do it better, and I encourage anyone who knows more than I do to let me know in the comments.




December 8th, 2007 at 1:26 pm
Nice, and the article you link to is excellent indeed.
December 8th, 2007 at 7:21 pm
That article more or less sums up the scope of my understanding of cryptography.
December 9th, 2007 at 4:06 am
Haha, I saw your comment there. It also sums up your knowledge of the English language, I mean… "This has convinced of what I already suspected"?
December 10th, 2007 at 6:05 pm
Fuck you.
December 16th, 2007 at 3:46 am
The md5() function is highly optimized for speed, where as crypt() is made to be compatible with different algorithms, so no wonder md5() is so fast.