Correct key padding and add support for raw_output in hash_hmac. Fixes #10284 props mdawaffe.

git-svn-id: http://svn.automattic.com/wordpress/trunk@11921 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
westi 2009-09-12 22:03:14 +00:00
parent b45dcf2df5
commit 50a2f86dda

View File

@ -72,13 +72,17 @@ function _hash_hmac($algo, $data, $key, $raw_output = false) {
if (strlen($key) > 64)
$key = pack($pack, $algo($key));
else if (strlen($key) < 64)
$key = str_pad($key, 64, chr(0));
$key = str_pad($key, 64, chr(0));
$ipad = (substr($key, 0, 64) ^ str_repeat(chr(0x36), 64));
$opad = (substr($key, 0, 64) ^ str_repeat(chr(0x5C), 64));
return $algo($opad . pack($pack, $algo($ipad . $data)));
$hmac = $algo($opad . pack($pack, $algo($ipad . $data)));
if ( $raw_output )
return pack( $pack, $hmac );
return $hmac;
}
if ( !function_exists('mb_substr') ):