Correct key padding and add support for raw_output in hash_hmac. Fixes #10284 props mdawaffe.
git-svn-id: https://develop.svn.wordpress.org/trunk@11921 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
772b9e3392
commit
a7311d5079
@ -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') ):
|
||||
|
Loading…
Reference in New Issue
Block a user