Skip to content

Commit ee0e7b2

Browse files
committed
Resurrect hash_hmac() compat for hosts that --disable-hash. Props aaroncampbell. fixes #17647
git-svn-id: https://develop.svn.wordpress.org/trunk@18111 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 36f1805 commit ee0e7b2

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

wp-includes/compat.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,32 @@ function _mb_substr( $str, $start, $length=null, $encoding=null ) {
3131
$chars = is_null( $length )? array_slice( $match[0], $start ) : array_slice( $match[0], $start, $length );
3232
return implode( '', $chars );
3333
}
34+
35+
if ( !function_exists('hash_hmac') ):
36+
function hash_hmac($algo, $data, $key, $raw_output = false) {
37+
return _hash_hmac($algo, $data, $key, $raw_output);
38+
}
39+
endif;
40+
41+
function _hash_hmac($algo, $data, $key, $raw_output = false) {
42+
$packs = array('md5' => 'H32', 'sha1' => 'H40');
43+
44+
if ( !isset($packs[$algo]) )
45+
return false;
46+
47+
$pack = $packs[$algo];
48+
49+
if (strlen($key) > 64)
50+
$key = pack($pack, $algo($key));
51+
52+
$key = str_pad($key, 64, chr(0));
53+
54+
$ipad = (substr($key, 0, 64) ^ str_repeat(chr(0x36), 64));
55+
$opad = (substr($key, 0, 64) ^ str_repeat(chr(0x5C), 64));
56+
57+
$hmac = $algo($opad . pack($pack, $algo($ipad . $data)));
58+
59+
if ( $raw_output )
60+
return pack( $pack, $hmac );
61+
return $hmac;
62+
}

0 commit comments

Comments
 (0)