Make WordPress Core

Ticket #17647: 17647.diff

File 17647.diff, 1.0 KB (added by aaroncampbell, 14 years ago)
  • wp-includes/compat.php

     
    3131        $chars = is_null( $length )? array_slice( $match[0], $start ) : array_slice( $match[0], $start, $length );
    3232        return implode( '', $chars );
    3333}
     34
     35if ( !function_exists('hash_hmac') ):
     36function hash_hmac($algo, $data, $key, $raw_output = false) {
     37        return _hash_hmac($algo, $data, $key, $raw_output);
     38}
     39endif;
     40
     41function _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}