Quote:
Originally Posted by eyu
Ah, I did not know that, thanks. I suppose it makes your passwords more secure?
|
Using a salt prevents the use of rainbow tables to determine the input value that generated a particular hash. A rainbow table is just a table mapping hash values to the strings that produce them.
http://en.wikipedia.org/wiki/Rainbow_table
http://en.wikipedia.org/wiki/Salt_(cryptography)
If I hash a passwords like this:
PHP Code:
$password = 'nullpointer';
$hash = md5($password);
$hash will be equal to 28fc730f2694ac90805b349f8d1bf28b. If someone attempting to find the string resulting in that hash were to use a rainbow table there is a good chance that that particular mapping would exist.
If I salt the password however:
PHP Code:
$password = 'nullpointer';
$salt = '8dF$d_3';
$hash = md5($salt . md5($password));
$hash will be equal to a09820febbd2f219e7d24d8a1b5d1e22 and a rainbow table would have to contain the string 8dF$d_328fc730f2694ac90805b349f8d1bf28b which is much less likely.
Another problem with md5 is that it is fast. A quick benchmark on my machine shows that I can generate 768,842 md5 hashes in a single second. That number would be even higher if I were running a threaded hash generator instead of just using the md5 function in PHP. Even at that rate I could brute force any 6 character password consisting of upper or lower case letters and digits in less than a day (62^6 / 768842).
Technically this isn't a problem with md5 so much as with how it is implemented using the md5 function in PHP. Normally the number of 'rounds' in an md5 hash is 64. You can increase that number arbitrarily however. The crypt function allows you to do this with SHA2 algos:
PHP Code:
$password = 'nullpointer';
$salt = '8dF$d_3';
$hash = crypt($password, '$6$rounds=5000$' . $salt . '$'); //5000 is actually the default
On my machine, using the method above, I can generate 74 SHA-512 hashes in a second, which is smaller than the number of md5 hashes I can generate by several orders of magnitude.
http://us2.php.net/manual/en/function.crypt.php
Last edited by NullPointer; 02-21-2011 at 10:50 AM..
|