1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16:
17: require_once 'Auth/OpenID.php';
18:
19: 20: 21: 22:
23: define('Auth_OpenID_SHA1_BLOCKSIZE', 64);
24:
25: function Auth_OpenID_SHA1($text)
26: {
27: if (function_exists('hash') &&
28: function_exists('hash_algos') &&
29: (in_array('sha1', hash_algos()))) {
30:
31:
32: return hash('sha1', $text, true);
33: } else if (function_exists('sha1')) {
34:
35: $hex = sha1($text);
36: $raw = '';
37: for ($i = 0; $i < 40; $i += 2) {
38: $hexcode = substr($hex, $i, 2);
39: $charcode = (int)base_convert($hexcode, 16, 10);
40: $raw .= chr($charcode);
41: }
42: return $raw;
43: } else {
44:
45: trigger_error('No SHA1 function found', E_USER_ERROR);
46: }
47: }
48:
49: 50: 51: 52: 53: 54: 55: 56:
57: function Auth_OpenID_HMACSHA1($key, $text)
58: {
59: if (Auth_OpenID::bytes($key) > Auth_OpenID_SHA1_BLOCKSIZE) {
60: $key = Auth_OpenID_SHA1($key, true);
61: }
62:
63: if (function_exists('hash_hmac') &&
64: function_exists('hash_algos') &&
65: (in_array('sha1', hash_algos()))) {
66: return hash_hmac('sha1', $text, $key, true);
67: }
68:
69:
70: $key = str_pad($key, Auth_OpenID_SHA1_BLOCKSIZE, chr(0x00));
71: $ipad = str_repeat(chr(0x36), Auth_OpenID_SHA1_BLOCKSIZE);
72: $opad = str_repeat(chr(0x5c), Auth_OpenID_SHA1_BLOCKSIZE);
73: $hash1 = Auth_OpenID_SHA1(($key ^ $ipad) . $text, true);
74: $hmac = Auth_OpenID_SHA1(($key ^ $opad) . $hash1, true);
75: return $hmac;
76: }
77:
78: if (function_exists('hash') &&
79: function_exists('hash_algos') &&
80: (in_array('sha256', hash_algos()))) {
81: function Auth_OpenID_SHA256($text)
82: {
83:
84: return hash('sha256', $text, true);
85: }
86: define('Auth_OpenID_SHA256_SUPPORTED', true);
87: } else {
88: define('Auth_OpenID_SHA256_SUPPORTED', false);
89: }
90:
91: if (function_exists('hash_hmac') &&
92: function_exists('hash_algos') &&
93: (in_array('sha256', hash_algos()))) {
94:
95: function Auth_OpenID_HMACSHA256($key, $text)
96: {
97:
98: return hash_hmac('sha256', $text, $key, true);
99: }
100:
101: define('Auth_OpenID_HMACSHA256_SUPPORTED', true);
102: } else {
103: define('Auth_OpenID_HMACSHA256_SUPPORTED', false);
104: }
105:
106: