#keywords PHP,PHP4,HMAC,Hash some.php {{{#!php }}} lib\hash_hmac.php {{{#!php , Arpad Ray * @link http://php.net/function.hash_hmac * @author revulo * @since PHP 5.1.2 * @require PHP 4.0.1 (str_pad) */ function php_compat_hash_hmac($algo, $data, $key, $raw_output = false) { // Block size (byte) for MD5, SHA-1 and SHA-256. $blocksize = 64; $ipad = str_repeat("\x36", $blocksize); $opad = str_repeat("\x5c", $blocksize); if (strlen($key) > $blocksize) { $key = hash($algo, $key, true); } else { $key = str_pad($key, $blocksize, "\x00"); } $ipad ^= $key; $opad ^= $key; return hash($algo, $opad . hash($algo, $ipad . $data, true), $raw_output); } // Define if (!function_exists('hash_hmac')) { function hash_hmac($algo, $data, $key, $raw_output = false) { return php_compat_hash_hmac($algo, $data, $key, $raw_output); } } }}} lib\hash.php {{{#!php , Arpad Ray * @link http://php.net/function.hash * @author revulo * @since PHP 5.1.2 * @require PHP 4.0.0 (user_error) */ function php_compat_hash($algo, $data, $raw_output = false) { $algo = strtolower($algo); switch ($algo) { case 'md5': $hash = md5($data); break; case 'sha1': if (!function_exists('sha1')) { require dirname(__FILE__) . '/sha1.php'; } $hash = sha1($data); break; case 'sha256': //if (!function_exists('php_compat_sha256')) { // require dirname(__FILE__) . '/_sha256.php'; //} //$hash = php_compat_sha256($data); require_once dirname(__FILE__) . '/sha256.php'; $hash = SHA256::hash($data); break; default: user_error('hash(): Unknown hashing algorithm: ' . $algo, E_USER_WARNING); return false; } if ($raw_output) { return pack('H*', $hash); } else { return $hash; } } // Define if (!function_exists('hash')) { function hash($algo, $data, $raw_output = false) { return php_compat_hash($algo, $data, $raw_output); } } }}} attachment:sha256.php