Dec 8

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.

  • Digg
  • StumbleUpon
  • del.icio.us
  • Reddit

5 Responses

  1. G-Brain Says:

    Nice, and the article you link to is excellent indeed.

  2. admin Says:

    That article more or less sums up the scope of my understanding of cryptography. :P

  3. G-Brain Says:

    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"? :P

  4. admin Says:

    Fuck you. :P

  5. Indy Says:

    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.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.