From 4ce7a0f63a540cc5e9a68e66232f000f522a5f47 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 10 Aug 2014 02:03:58 -0500 Subject: [PATCH 1/2] BigInteger: small optimization to bitwise_not --- phpseclib/Math/BigInteger.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpseclib/Math/BigInteger.php b/phpseclib/Math/BigInteger.php index 8b84aed6..7da338f3 100644 --- a/phpseclib/Math/BigInteger.php +++ b/phpseclib/Math/BigInteger.php @@ -2904,7 +2904,7 @@ class Math_BigInteger $leading_ones = chr((1 << ($new_bits & 0x7)) - 1) . str_repeat(chr(0xFF), $new_bits >> 3); $this->_base256_lshift($leading_ones, $current_bits); - $temp = str_pad($temp, ceil(strlen($this->toBits()) / 8), chr(0), STR_PAD_LEFT); + $temp = str_pad($temp, ceil(strlen($temp) / 8), chr(0), STR_PAD_LEFT); return $this->_normalize(new Math_BigInteger($leading_ones | $temp, 256)); } From 33182bb2de2816c5851d3607aa252ca6e0bde285 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 10 Aug 2014 14:47:08 -0500 Subject: [PATCH 2/2] BigInteger: fix previous fix --- phpseclib/Math/BigInteger.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpseclib/Math/BigInteger.php b/phpseclib/Math/BigInteger.php index 7da338f3..ff6c69f6 100644 --- a/phpseclib/Math/BigInteger.php +++ b/phpseclib/Math/BigInteger.php @@ -2904,7 +2904,7 @@ class Math_BigInteger $leading_ones = chr((1 << ($new_bits & 0x7)) - 1) . str_repeat(chr(0xFF), $new_bits >> 3); $this->_base256_lshift($leading_ones, $current_bits); - $temp = str_pad($temp, ceil(strlen($temp) / 8), chr(0), STR_PAD_LEFT); + $temp = str_pad($temp, strlen($leading_ones), chr(0), STR_PAD_LEFT); return $this->_normalize(new Math_BigInteger($leading_ones | $temp, 256)); }