Closed (fixed)
Project:
OpenID
Version:
4.7.x-2.x-dev
Component:
OpenID Client
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
28 Jan 2007 at 22:37 UTC
Updated:
2 Mar 2007 at 19:15 UTC
function bcpowmod($gen, $private, $mod) is used in openid.module, which makes the code php5-exclusive.
Info in the php-manual: http://be2.php.net/function.bcpowmod
We might consider making it php4-compatible, by adding some extra code, copied from the comment of 'ewilde aht bsmdevelopment dawt com' in the manual:
function PowModSim($Value, $Exponent, $Modulus)
{
// Check if simulation is even necessary.
if (function_exists("bcpowmod"))
return (bcpowmod($Value, $Exponent, $Modulus));
// Loop until the exponent is reduced to zero.
$Result = "1";
while (TRUE)
{
if (bcmod($Exponent, 2) == "1")
$Result = bcmod(bcmul($Result, $Value), $Modulus);
if (($Exponent = bcdiv($Exponent, 2)) == "0") break;
$Value = bcmod(bcmul($Value, $Value), $Modulus);
}
return ($Result);
}
(I got some division by zero errors, when adding this code, so maybe it is not a perfect solution)
Comments
Comment #1
Jo Wouters commented(better title, and making it a feature request)
Comment #2
aaron commentedfrom http://us2.php.net/function.bcpowmod --
laysoft at gmail dot com
30-Jan-2007 05:34
I found a better way to emulate bcpowmod on PHP 4, which works with very big numbers too:
function powmod($m,$e,$n) {
if (intval(PHP_VERSION)>4) {
return(bcpowmod($m,$e,$n));
} else {
$r="";
while ($e!="0") {
$t=bcmod($e,"4096");
$r=substr("000000000000".decbin(intval($t)),-12).$r;
$e=bcdiv($e,"4096");
}
$r=preg_replace("!^0+!","",$r);
if ($r=="") $r="0";
$m=bcmod($m,$n);
$erb=strrev($r);
$q="1";
$a[0]=$m;
for ($i=1;$i $a[$i]=bcmod(bcmul($a[$i-1],$a[$i-1]),$n);
}
for ($i=0;$i if ($erb[$i]=="1") {
$q=bcmod(bcmul($q,$a[$i]),$n);
}
}
return($q);
}
}
Comment #3
aaron commentedoops. here it is encoded:
Comment #4
Jo Wouters commentedThank you Aaron!
Unfortunately I still get division by zero errors:
# warning: bcmod(): Division by zero in /home/planetca/public_html/openid/modules/openid/openid.module on line 21.
# warning: bcmod(): Division by zero in /home/planetca/public_html/openid/modules/openid/openid.module on line 26.
# warning: bcmod(): Division by zero in /home/planetca/public_html/openid/modules/openid/openid.module on line 26.
... (a lot of repetition)
# warning: bcmod(): Division by zero in /home/planetca/public_html/openid/modules/openid/openid.module on line 30.
# OpenID Association failed
Comment #5
walkah commentedcommitted a fix for this. thanks.
Comment #6
(not verified) commented