123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- require_once 'Auth/OpenID.php';
- define('Auth_OpenID_SHA1_BLOCKSIZE', 64);
- function Auth_OpenID_SHA1($text)
- {
- if (function_exists('hash') &&
- function_exists('hash_algos') &&
- (in_array('sha1', hash_algos()))) {
-
-
- return hash('sha1', $text, true);
- } else if (function_exists('sha1')) {
-
- $hex = sha1($text);
- $raw = '';
- for ($i = 0; $i < 40; $i += 2) {
- $hexcode = substr($hex, $i, 2);
- $charcode = (int)base_convert($hexcode, 16, 10);
- $raw .= chr($charcode);
- }
- return $raw;
- } else {
-
- trigger_error('No SHA1 function found', E_USER_ERROR);
- }
- }
- function Auth_OpenID_HMACSHA1($key, $text)
- {
- if (Auth_OpenID::bytes($key) > Auth_OpenID_SHA1_BLOCKSIZE) {
- $key = Auth_OpenID_SHA1($key, true);
- }
- if (function_exists('hash_hmac') &&
- function_exists('hash_algos') &&
- (in_array('sha1', hash_algos()))) {
- return hash_hmac('sha1', $text, $key, true);
- }
-
- $key = str_pad($key, Auth_OpenID_SHA1_BLOCKSIZE, chr(0x00));
- $ipad = str_repeat(chr(0x36), Auth_OpenID_SHA1_BLOCKSIZE);
- $opad = str_repeat(chr(0x5c), Auth_OpenID_SHA1_BLOCKSIZE);
- $hash1 = Auth_OpenID_SHA1(($key ^ $ipad) . $text, true);
- $hmac = Auth_OpenID_SHA1(($key ^ $opad) . $hash1, true);
- return $hmac;
- }
- if (function_exists('hash') &&
- function_exists('hash_algos') &&
- (in_array('sha256', hash_algos()))) {
- function Auth_OpenID_SHA256($text)
- {
-
- return hash('sha256', $text, true);
- }
- define('Auth_OpenID_SHA256_SUPPORTED', true);
- } else {
- define('Auth_OpenID_SHA256_SUPPORTED', false);
- }
- if (function_exists('hash_hmac') &&
- function_exists('hash_algos') &&
- (in_array('sha256', hash_algos()))) {
- function Auth_OpenID_HMACSHA256($key, $text)
- {
-
- return hash_hmac('sha256', $text, $key, true);
- }
- define('Auth_OpenID_HMACSHA256_SUPPORTED', true);
- } else {
- define('Auth_OpenID_HMACSHA256_SUPPORTED', false);
- }
|