BigInteger/GMP: use gmp_import / gmp_export

This commit is contained in:
terrafrost 2017-11-05 12:33:22 -06:00
parent 5801806d23
commit 6f6b93b012
2 changed files with 3 additions and 5 deletions

View File

@ -53,7 +53,7 @@
"require": { "require": {
"paragonie/constant_time_encoding": "^1", "paragonie/constant_time_encoding": "^1",
"paragonie/random_compat": "^1.4|^2.0", "paragonie/random_compat": "^1.4|^2.0",
"php": ">=5.6" "php": ">=5.6.1"
}, },
"require-dev": { "require-dev": {
"phing/phing": "~2.7", "phing/phing": "~2.7",

View File

@ -137,7 +137,7 @@ class GMP extends Engine
switch (abs($base)) { switch (abs($base)) {
case 256: case 256:
$sign = $this->is_negative ? '-' : ''; $sign = $this->is_negative ? '-' : '';
$this->value = gmp_init($sign . '0x' . Hex::encode($this->value)); $this->value = gmp_import($this->value);
break; break;
case 16: case 16:
$temp = $this->is_negative ? '-0x' . $this->value : '0x' . $this->value; $temp = $this->is_negative ? '-0x' . $this->value : '0x' . $this->value;
@ -174,9 +174,7 @@ class GMP extends Engine
return $this->precision > 0 ? str_repeat(chr(0), ($this->precision + 1) >> 3) : ''; return $this->precision > 0 ? str_repeat(chr(0), ($this->precision + 1) >> 3) : '';
} }
$temp = gmp_strval(gmp_abs($this->value), 16); $temp = gmp_export($this->value);
$temp = (strlen($temp) & 1) ? '0' . $temp : $temp;
$temp = Hex::decode($temp);
return $this->precision > 0 ? return $this->precision > 0 ?
substr(str_pad($temp, $this->precision >> 3, chr(0), STR_PAD_LEFT), -($this->precision >> 3)) : substr(str_pad($temp, $this->precision >> 3, chr(0), STR_PAD_LEFT), -($this->precision >> 3)) :