21 require_once
'Auth/OpenID/CryptUtil.php';
26 require_once
'Auth/OpenID.php';
47 $cmp = $this->cmp($long, 0);
49 $msg = __FUNCTION__ .
" takes only positive integers.";
50 trigger_error($msg, E_USER_ERROR);
60 while ($this->cmp($long, 0) > 0) {
61 array_unshift($bytes, $this->mod($long, 256));
62 $long = $this->div($long, pow(2, 8));
65 if ($bytes && ($bytes[0] > 127)) {
66 array_unshift($bytes, 0);
70 foreach ($bytes as $byte) {
71 $string .= pack(
'C', $byte);
94 $bytes = array_merge(unpack(
'C*', $str));
98 if ($bytes && ($bytes[0] > 127)) {
99 trigger_error(
"bytesToNum works only for positive integers.",
104 foreach ($bytes as $byte) {
105 $n = $this->mul(
$n, pow(2, 8));
106 $n = $this->add(
$n, $byte);
114 $b64 = base64_decode($str);
116 if ($b64 ===
false) {
144 static $duplicate_cache = array();
149 if (array_key_exists($rbytes, $duplicate_cache)) {
150 list($duplicate, $nbytes) = $duplicate_cache[$rbytes];
152 if ($rbytes[0] ==
"\x00") {
158 $mxrand = $this->pow(256, $nbytes);
162 $duplicate = $this->mod($mxrand, $stop);
164 if (count($duplicate_cache) > 10) {
165 $duplicate_cache = array();
168 $duplicate_cache[$rbytes] = array($duplicate, $nbytes);
175 }
while ($this->cmp(
$n, $duplicate) < 0);
177 return $this->mod(
$n, $stop);
195 return bcadd($x, $y);
200 return bcsub($x, $y);
203 function pow($base, $exponent)
205 return bcpow($base, $exponent);
210 return bccomp($x, $y);
213 function init($number, $base = 10)
218 function mod($base, $modulus)
220 return bcmod($base, $modulus);
225 return bcmul($x, $y);
230 return bcdiv($x, $y);
240 $square = $this->
mod($base, $modulus);
242 while($this->
cmp($exponent, 0) > 0) {
243 if ($this->
mod($exponent, 2)) {
246 $square = $this->
mod($this->
mul($square, $square), $modulus);
247 $exponent = $this->
div($exponent, 2);
252 function powmod($base, $exponent, $modulus)
254 if (function_exists(
'bcpowmod')) {
255 return bcpowmod($base, $exponent, $modulus);
257 return $this->
_powmod($base, $exponent, $modulus);
281 return gmp_add($x, $y);
286 return gmp_sub($x, $y);
289 function pow($base, $exponent)
291 return gmp_pow($base, $exponent);
296 return gmp_cmp($x, $y);
299 function init($number, $base = 10)
301 return gmp_init($number, $base);
304 function mod($base, $modulus)
306 return gmp_mod($base, $modulus);
311 return gmp_mul($x, $y);
316 return gmp_div_q($x, $y);
319 function powmod($base, $exponent, $modulus)
321 return gmp_powm($base, $exponent, $modulus);
326 return gmp_strval($num);
347 if (!defined(
'Auth_OpenID_BUGGY_GMP')) {
349 array(
'modules' => array(
'gmp',
'php_gmp'),
350 'extension' =>
'gmp',
351 'class' =>
'Auth_OpenID_GmpMathWrapper');
354 $result[] = array(
'modules' => array(
'bcmath',
'php_bcmath'),
355 'extension' =>
'bcmath',
356 'class' =>
'Auth_OpenID_BcMathWrapper');
368 $hasDl = function_exists(
'dl');
369 foreach ($exts as $extension) {
370 if (extension_loaded($extension[
'extension'])) {
420 if ($ext ===
false) {
423 $tried[] = $extinfo[
'extension'];
425 $triedstr = implode(
", ", $tried);
434 $class = $ext[
'class'];
442 if (!defined(
'Auth_OpenID_NO_MATH_SUPPORT')) {
443 define(
'Auth_OpenID_NO_MATH_SUPPORT',
true);
449 return defined(
'Auth_OpenID_NO_MATH_SUPPORT');