mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-11-16 18:25:13 +00:00
Merge branch 'gmp-1.0' into gmp-2.0
This commit is contained in:
commit
58768cb5aa
@ -360,8 +360,12 @@ class BigInteger
|
||||
case 256:
|
||||
switch (MATH_BIGINTEGER_MODE) {
|
||||
case self::MODE_GMP:
|
||||
$sign = $this->is_negative ? '-' : '';
|
||||
$this->value = gmp_init($sign . '0x' . bin2hex($x));
|
||||
$this->value = function_exists('gmp_import') ?
|
||||
gmp_import($x) :
|
||||
gmp_init('0x' . bin2hex($x));
|
||||
if ($this->is_negative) {
|
||||
$this->value = gmp_neg($this->value);
|
||||
}
|
||||
break;
|
||||
case self::MODE_BCMATH:
|
||||
// round $len to the nearest 4 (thanks, DavidMJ!)
|
||||
@ -548,9 +552,13 @@ class BigInteger
|
||||
return $this->precision > 0 ? str_repeat(chr(0), ($this->precision + 1) >> 3) : '';
|
||||
}
|
||||
|
||||
if (function_exists('gmp_export')) {
|
||||
$temp = gmp_export($this->value);
|
||||
} else {
|
||||
$temp = gmp_strval(gmp_abs($this->value), 16);
|
||||
$temp = (strlen($temp) & 1) ? '0' . $temp : $temp;
|
||||
$temp = pack('H*', $temp);
|
||||
}
|
||||
|
||||
return $this->precision > 0 ?
|
||||
substr(str_pad($temp, $this->precision >> 3, chr(0), STR_PAD_LEFT), -($this->precision >> 3)) :
|
||||
|
Loading…
Reference in New Issue
Block a user