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; +}