From ee0e7b23dbb319ddd5830439ba071adceea5214e Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Thu, 2 Jun 2011 14:21:09 +0000 Subject: [PATCH] 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 --- wp-includes/compat.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/wp-includes/compat.php b/wp-includes/compat.php index e1e0fa5323..e84ba3c97d 100644 --- a/wp-includes/compat.php +++ b/wp-includes/compat.php @@ -31,3 +31,32 @@ function _mb_substr( $str, $start, $length=null, $encoding=null ) { $chars = is_null( $length )? array_slice( $match[0], $start ) : array_slice( $match[0], $start, $length ); return implode( '', $chars ); } + +if ( !function_exists('hash_hmac') ): +function hash_hmac($algo, $data, $key, $raw_output = false) { + return _hash_hmac($algo, $data, $key, $raw_output); +} +endif; + +function _hash_hmac($algo, $data, $key, $raw_output = false) { + $packs = array('md5' => 'H32', 'sha1' => 'H40'); + + if ( !isset($packs[$algo]) ) + return false; + + $pack = $packs[$algo]; + + if (strlen($key) > 64) + $key = pack($pack, $algo($key)); + + $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)); + + $hmac = $algo($opad . pack($pack, $algo($ipad . $data))); + + if ( $raw_output ) + return pack( $pack, $hmac ); + return $hmac; +}