Y!!, on 24 November 2009 - 07:24 AM, said:
Well I guess a salt should be something not related to the actual data being hashed. I'm not sure how exactly hmac works, but I guess when you use the data being hashed as secret key, it could be exploitable if an attacker knows indeed that you're doing so.
So if the password is "12345" and the secret key is also "12345", you can imagine it doesn't fit to the bolded part of the text below I've copied from Wikipedia.
Well, if the salt is the hashed data, maybe it's not very secure, but if you save the salt somewhere (because you
need it later) then it's not very secure too.
I believe "
the size and quality of the key" is simply related to the usual concept of "secure key" as you could bruteforce it.
This is a PHP hmac implementation I've found here:
http://php.net/manua...n.hash-hmac.php
function custom_hmac($algo, $data, $key, $raw_output = false)
{
$algo = strtolower($algo);
$pack = 'H'.strlen($algo('test'));
$size = 64;
$opad = str_repeat(chr(0x5C), $size);
$ipad = str_repeat(chr(0x36), $size);
if (strlen($key) > $size) {
$key = str_pad(pack($pack, $algo($key)), $size, chr(0x00));
} else {
$key = str_pad($key, $size, chr(0x00));
}
for ($i = 0; $i < strlen($key) - 1; $i++) {
$opad[$i] = $opad[$i] ^ $key[$i];
$ipad[$i] = $ipad[$i] ^ $key[$i];
}
$output = $algo($opad.pack($pack, $algo($ipad.$data)));
return ($raw_output) ? pack($pack, $output) : $output;
}
Where with salt+password the security margin is very low, hmac seems like a much more sophisticated solution.