Make WordPress Core

Changeset 18111


Ignore:
Timestamp:
06/02/2011 02:21:09 PM (13 years ago)
Author:
ryan
Message:

Resurrect hash_hmac() compat for hosts that --disable-hash. Props aaroncampbell. fixes #17647

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/compat.php

    r17933 r18111  
    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}
Note: See TracChangeset for help on using the changeset viewer.