00001 <?php
00002
00017 require_once 'Auth/OpenID.php';
00018
00023 define('Auth_OpenID_SHA1_BLOCKSIZE', 64);
00024
00025 function Auth_OpenID_SHA1($text)
00026 {
00027 if (function_exists('hash') &&
00028 function_exists('hash_algos') &&
00029 (in_array('sha1', hash_algos()))) {
00030
00031
00032 return hash('sha1', $text, true);
00033 } else if (function_exists('sha1')) {
00034
00035 $hex = sha1($text);
00036 $raw = '';
00037 for ($i = 0; $i < 40; $i += 2) {
00038 $hexcode = substr($hex, $i, 2);
00039 $charcode = (int)base_convert($hexcode, 16, 10);
00040 $raw .= chr($charcode);
00041 }
00042 return $raw;
00043 } else {
00044
00045 trigger_error('No SHA1 function found', E_USER_ERROR);
00046 }
00047 }
00048
00057 function Auth_OpenID_HMACSHA1($key, $text)
00058 {
00059 if (Auth_OpenID::bytes($key) > Auth_OpenID_SHA1_BLOCKSIZE) {
00060 $key = Auth_OpenID_SHA1($key, true);
00061 }
00062
00063 $key = str_pad($key, Auth_OpenID_SHA1_BLOCKSIZE, chr(0x00));
00064 $ipad = str_repeat(chr(0x36), Auth_OpenID_SHA1_BLOCKSIZE);
00065 $opad = str_repeat(chr(0x5c), Auth_OpenID_SHA1_BLOCKSIZE);
00066 $hash1 = Auth_OpenID_SHA1(($key ^ $ipad) . $text, true);
00067 $hmac = Auth_OpenID_SHA1(($key ^ $opad) . $hash1, true);
00068 return $hmac;
00069 }
00070
00071 if (function_exists('hash') &&
00072 function_exists('hash_algos') &&
00073 (in_array('sha256', hash_algos()))) {
00074 function Auth_OpenID_SHA256($text)
00075 {
00076
00077 return hash('sha256', $text, true);
00078 }
00079 define('Auth_OpenID_SHA256_SUPPORTED', true);
00080 } else {
00081 define('Auth_OpenID_SHA256_SUPPORTED', false);
00082 }
00083
00084 if (function_exists('hash_hmac') &&
00085 function_exists('hash_algos') &&
00086 (in_array('sha256', hash_algos()))) {
00087
00088 function Auth_OpenID_HMACSHA256($key, $text)
00089 {
00090
00091 return hash_hmac('sha256', $text, $key, true);
00092 }
00093
00094 define('Auth_OpenID_HMACSHA256_SUPPORTED', true);
00095 } else {
00096 define('Auth_OpenID_HMACSHA256_SUPPORTED', false);
00097 }
00098
00099 ?>