From 8879fa001858b1cda2e5a0c4185fab931b6de9cd Mon Sep 17 00:00:00 2001 From: terrafrost Date: Mon, 22 Jan 2018 00:13:14 -0600 Subject: [PATCH 1/3] Tests/BigInteger: add bitwise_xor test --- tests/Unit/Math/BigInteger/TestCase.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/Unit/Math/BigInteger/TestCase.php b/tests/Unit/Math/BigInteger/TestCase.php index d5a6b75b..3338aadb 100644 --- a/tests/Unit/Math/BigInteger/TestCase.php +++ b/tests/Unit/Math/BigInteger/TestCase.php @@ -212,6 +212,18 @@ abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase $z = $this->getInstance('BC98BC98BC98BC98BC98BC98', 16); $this->assertSame($z->toHex(), $x->bitwise_XOR($y)->toHex()); + + // @group github1245 + + $a = $this->getInstance(1); + $b = $this->getInstance(-2); + $c = $a->bitwise_xor($b); + $this->assertSame("$c", '3'); + + $a = $this->getInstance('-6725760161961546982'); + $b = $this->getInstance(51); + $c = $a->bitwise_xor($b); + $this->assertSame("$c", '6725760161961546965'); } public function testBitwiseNOT() From 92623daba8caecc6d6c97157bb2fa126d7653fa2 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Mon, 22 Jan 2018 00:38:42 -0600 Subject: [PATCH 2/3] BigInteger: fix issues with bitwise_xor --- phpseclib/Math/BigInteger.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpseclib/Math/BigInteger.php b/phpseclib/Math/BigInteger.php index e2a219c7..969c9ad6 100644 --- a/phpseclib/Math/BigInteger.php +++ b/phpseclib/Math/BigInteger.php @@ -2905,7 +2905,7 @@ class Math_BigInteger switch (MATH_BIGINTEGER_MODE) { case MATH_BIGINTEGER_MODE_GMP: $temp = new Math_BigInteger(); - $temp->value = gmp_xor($this->value, $x->value); + $temp->value = gmp_xor(gmp_abs($this->value), gmp_abs($x->value)); return $this->_normalize($temp); case MATH_BIGINTEGER_MODE_BCMATH: @@ -2922,6 +2922,7 @@ class Math_BigInteger $length = max(count($this->value), count($x->value)); $result = $this->copy(); + $result->is_negative = false; $result->value = array_pad($result->value, $length, 0); $x->value = array_pad($x->value, $length, 0); From 3030f08148c3ba485da60e7405183768cd55b25b Mon Sep 17 00:00:00 2001 From: terrafrost Date: Mon, 22 Jan 2018 06:56:26 -0600 Subject: [PATCH 3/3] rm PHP 5.4 from Travis --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5c78741d..9ede299b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 5.4 - 5.5.9 - 5.5 - 5.6