From 6f6b93b01296bcbe17c44d0e2fa30ed4907b9340 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 5 Nov 2017 12:33:22 -0600 Subject: [PATCH] BigInteger/GMP: use gmp_import / gmp_export --- composer.json | 2 +- phpseclib/Math/BigInteger/Engines/GMP.php | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index a68d0c84..0da35fe1 100644 --- a/composer.json +++ b/composer.json @@ -53,7 +53,7 @@ "require": { "paragonie/constant_time_encoding": "^1", "paragonie/random_compat": "^1.4|^2.0", - "php": ">=5.6" + "php": ">=5.6.1" }, "require-dev": { "phing/phing": "~2.7", diff --git a/phpseclib/Math/BigInteger/Engines/GMP.php b/phpseclib/Math/BigInteger/Engines/GMP.php index 016530b3..e2f70911 100644 --- a/phpseclib/Math/BigInteger/Engines/GMP.php +++ b/phpseclib/Math/BigInteger/Engines/GMP.php @@ -137,7 +137,7 @@ class GMP extends Engine switch (abs($base)) { case 256: $sign = $this->is_negative ? '-' : ''; - $this->value = gmp_init($sign . '0x' . Hex::encode($this->value)); + $this->value = gmp_import($this->value); break; case 16: $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) : ''; } - $temp = gmp_strval(gmp_abs($this->value), 16); - $temp = (strlen($temp) & 1) ? '0' . $temp : $temp; - $temp = Hex::decode($temp); + $temp = gmp_export($this->value); return $this->precision > 0 ? substr(str_pad($temp, $this->precision >> 3, chr(0), STR_PAD_LEFT), -($this->precision >> 3)) :