mirror of
https://github.com/danog/phpseclib.git
synced 2024-11-27 04:46:26 +01:00
BigInteger: use gmp_import / gmp_export when available
This commit is contained in:
parent
76070ff5e2
commit
b6d0e37432
@ -360,8 +360,12 @@ class Math_BigInteger
|
||||
case 256:
|
||||
switch (MATH_BIGINTEGER_MODE) {
|
||||
case MATH_BIGINTEGER_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 MATH_BIGINTEGER_MODE_BCMATH:
|
||||
// round $len to the nearest 4 (thanks, DavidMJ!)
|
||||
@ -563,9 +567,13 @@ class Math_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