From 87533e7b9ab36a0a2be0d3c6e143e88cce7bee9d Mon Sep 17 00:00:00 2001 From: Paragon Initiative Enterprises Date: Wed, 23 Mar 2022 06:27:01 -0400 Subject: [PATCH] Fix myriad bugs with PHP 8.1 on x86 Related to #140, determined from local testing as per https://github.com/paragonie/sodium_compat/issues/140#issuecomment-1076132051 --- src/Core/BLAKE2b.php | 12 ++++++ src/Core/Util.php | 8 +++- src/Core32/Curve25519.php | 8 ++-- src/Core32/Curve25519/Fe.php | 3 ++ src/Core32/Int64.php | 6 +-- src/Core32/Poly1305/State.php | 2 +- tests/unit/Blake2bTest.php | 71 ++++++++++++++++++++++++++---- tests/unit/CryptoTest.php | 6 +-- tests/unit/Curve25519Test.php | 76 ++++++++++----------------------- tests/unit/Int32Test.php | 9 ---- tests/unit/Ristretto255Test.php | 21 +++++++++ tests/unit/Salsa20Test.php | 2 +- tests/unit/SipHashTest.php | 2 - tests/unit/UtilTest.php | 2 +- 14 files changed, 139 insertions(+), 89 deletions(-) diff --git a/src/Core/BLAKE2b.php b/src/Core/BLAKE2b.php index 78926fb5..6ad4ab7c 100644 --- a/src/Core/BLAKE2b.php +++ b/src/Core/BLAKE2b.php @@ -50,6 +50,9 @@ abstract class ParagonIE_Sodium_Core_BLAKE2b extends ParagonIE_Sodium_Core_Util */ public static function new64($high, $low) { + if (PHP_INT_SIZE === 4) { + throw new SodiumException("Error, use 32-bit"); + } $i64 = new SplFixedArray(2); $i64[0] = $high & 0xffffffff; $i64[1] = $low & 0xffffffff; @@ -86,6 +89,9 @@ protected static function to64($num) */ protected static function add64($x, $y) { + if (PHP_INT_SIZE === 4) { + throw new SodiumException("Error, use 32-bit"); + } $l = ($x[1] + $y[1]) & 0xffffffff; return self::new64( (int) ($x[0] + $y[0] + ( @@ -119,6 +125,9 @@ protected static function add364($x, $y, $z) */ protected static function xor64(SplFixedArray $x, SplFixedArray $y) { + if (PHP_INT_SIZE === 4) { + throw new SodiumException("Error, use 32-bit"); + } if (!is_numeric($x[0])) { throw new SodiumException('x[0] is not an integer'); } @@ -147,6 +156,9 @@ protected static function xor64(SplFixedArray $x, SplFixedArray $y) */ public static function rotr64($x, $c) { + if (PHP_INT_SIZE === 4) { + throw new SodiumException("Error, use 32-bit"); + } if ($c >= 64) { $c %= 64; } diff --git a/src/Core/Util.php b/src/Core/Util.php index bde9df11..13221b36 100644 --- a/src/Core/Util.php +++ b/src/Core/Util.php @@ -458,7 +458,7 @@ public static function load_4($string) } /** @var array $unpacked */ $unpacked = unpack('V', $string); - return (int) ($unpacked[1] & 0xffffffff); + return (int) $unpacked[1]; } /** @@ -613,7 +613,11 @@ public static function numericTo64BitInteger($num) { $high = 0; /** @var int $low */ - $low = $num & 0xffffffff; + if (PHP_INT_SIZE === 4) { + $low = (int) $num; + } else { + $low = $num & 0xffffffff; + } if ((+(abs($num))) >= 1) { if ($num > 0) { diff --git a/src/Core32/Curve25519.php b/src/Core32/Curve25519.php index 81cee425..92e4022c 100644 --- a/src/Core32/Curve25519.php +++ b/src/Core32/Curve25519.php @@ -1838,8 +1838,8 @@ public static function equal($b, $c) $c0 = $c & 0xffff; $c1 = ($c >> 16) & 0xffff; - $d0 = (($b0 ^ $c0) - 1) >> 15; - $d1 = (($b1 ^ $c1) - 1) >> 15; + $d0 = (($b0 ^ $c0) - 1) >> 31; + $d1 = (($b1 ^ $c1) - 1) >> 31; return ($d0 & $d1) & 1; } @@ -1857,7 +1857,6 @@ public static function negative($char) return $char < 0 ? 1 : 0; } /** @var string $char */ - /** @var int $x */ $x = self::chrToInt(self::substr($char, 0, 1)); return (int) ($x >> 31); } @@ -1963,7 +1962,6 @@ public static function ge_select($pos = 0, $b = 0) } $bnegative = self::negative($b); - /** @var int $babs */ $babs = $b - (((-$bnegative) & $b) << 1); $t = self::ge_precomp_0(); @@ -1971,7 +1969,7 @@ public static function ge_select($pos = 0, $b = 0) $t = self::cmov( $t, $base[$pos][$i], - self::equal($babs, $i + 1) + -self::equal($babs, $i + 1) ); } $minusT = new ParagonIE_Sodium_Core32_Curve25519_Ge_Precomp( diff --git a/src/Core32/Curve25519/Fe.php b/src/Core32/Curve25519/Fe.php index 27537a6f..21b31882 100644 --- a/src/Core32/Curve25519/Fe.php +++ b/src/Core32/Curve25519/Fe.php @@ -48,6 +48,9 @@ public static function fromArray($array, $save_indexes = null) } } else { for ($i = 0; $i < $count; ++$i) { + if (!($array[$i] instanceof ParagonIE_Sodium_Core32_Int32)) { + throw new TypeError('Expected ParagonIE_Sodium_Core32_Int32'); + } $array[$i]->overflow = 0; $obj->offsetSet($i, $array[$i]); } diff --git a/src/Core32/Int64.php b/src/Core32/Int64.php index dd06a3fb..e94d7982 100644 --- a/src/Core32/Int64.php +++ b/src/Core32/Int64.php @@ -337,9 +337,9 @@ public function multiplyLong(array $a, array $b, $baseLog2 = 16) $a_i = $a[$i]; for ($j = 0; $j < $a_l; ++$j) { $b_j = $b[$j]; - $product = ($a_i * $b_j) + $r[$i + $j]; - $carry = ($product >> $baseLog2 & 0xffff); - $r[$i + $j] = ($product - (int) ($carry * $base)) & 0xffff; + $product = (($a_i * $b_j) + $r[$i + $j]); + $carry = (((int) $product >> $baseLog2) & 0xffff); + $r[$i + $j] = ((int) $product - (int) ($carry * $base)) & 0xffff; $r[$i + $j + 1] += $carry; } } diff --git a/src/Core32/Poly1305/State.php b/src/Core32/Poly1305/State.php index d80e1ff9..e77a8f42 100644 --- a/src/Core32/Poly1305/State.php +++ b/src/Core32/Poly1305/State.php @@ -419,7 +419,7 @@ public function finish() $g4 = $g4->mask($mask); /** @var int $mask */ - $mask = (~$mask) & 0xffffffff; + $mask = ~$mask; $h0 = $h0->mask($mask)->orInt32($g0); $h1 = $h1->mask($mask)->orInt32($g1); diff --git a/tests/unit/Blake2bTest.php b/tests/unit/Blake2bTest.php index 869ae7fd..eeb0b6d5 100644 --- a/tests/unit/Blake2bTest.php +++ b/tests/unit/Blake2bTest.php @@ -253,20 +253,38 @@ public function testGenericHashUpdate() $hbufStr . $hbufStr ); - $exp = ParagonIE_Sodium_Core_BLAKE2b::init(); - ParagonIE_Sodium_Core_BLAKE2b::update($exp, $hbuf, (1 << $h)); - ParagonIE_Sodium_Core_BLAKE2b::update($exp, $hbuf, (1 << $h)); + if (PHP_INT_SIZE === 4) { + $exp = ParagonIE_Sodium_Core32_BLAKE2b::init(); + ParagonIE_Sodium_Core32_BLAKE2b::update($exp, $hbuf, (1 << $h)); + ParagonIE_Sodium_Core32_BLAKE2b::update($exp, $hbuf, (1 << $h)); + + $ctx = ParagonIE_Sodium_Core32_BLAKE2b::init(); + ParagonIE_Sodium_Core32_BLAKE2b::update($ctx, $buf, (1 << ($h + 1))); + } else { + $exp = ParagonIE_Sodium_Core_BLAKE2b::init(); + ParagonIE_Sodium_Core_BLAKE2b::update($exp, $hbuf, (1 << $h)); + ParagonIE_Sodium_Core_BLAKE2b::update($exp, $hbuf, (1 << $h)); - $ctx = ParagonIE_Sodium_Core_BLAKE2b::init(); - ParagonIE_Sodium_Core_BLAKE2b::update($ctx, $buf, (1 << ($h + 1))); + $ctx = ParagonIE_Sodium_Core_BLAKE2b::init(); + ParagonIE_Sodium_Core_BLAKE2b::update($ctx, $buf, (1 << ($h + 1))); + } for ($j = 0; $j < 5; ++$j) { $this->assertEquals($exp[$j], $ctx[$j], 'element ' . $j); } - $this->assertSame( - bin2hex(ParagonIE_Sodium_Core_BLAKE2b::contextToString($exp)), - bin2hex(ParagonIE_Sodium_Core_BLAKE2b::contextToString($ctx)), - 'h = ' . $h); + if (PHP_INT_SIZE === 4) { + $this->assertSame( + bin2hex(ParagonIE_Sodium_Core32_BLAKE2b::contextToString($exp)), + bin2hex(ParagonIE_Sodium_Core32_BLAKE2b::contextToString($ctx)), + 'h = ' . $h + ); + } else { + $this->assertSame( + bin2hex(ParagonIE_Sodium_Core_BLAKE2b::contextToString($exp)), + bin2hex(ParagonIE_Sodium_Core_BLAKE2b::contextToString($ctx)), + 'h = ' . $h + ); + } } } @@ -275,6 +293,9 @@ public function testGenericHashUpdate() */ public function testCounter() { + if (PHP_INT_SIZE === 4) { + $this->markTestSkipped("Ignored in 32-bit"); + } $ctx = ParagonIE_Sodium_Core_BLAKE2b::init(null, 32); ParagonIE_Sodium_Core_BLAKE2b::increment_counter($ctx, 1); @@ -296,6 +317,38 @@ public function testCounter() $this->assertEquals(1, $ctx[1][0][0]); } + /** + * @covers ParagonIE_Sodium_Core32_BLAKE2b::increment_counter() + */ + public function testCounter32() + { + if (PHP_INT_SIZE === 8) { + $this->markTestSkipped("32-bit only"); + } + $ctx = ParagonIE_Sodium_Core32_BLAKE2b::init(null, 32); + + ParagonIE_Sodium_Core32_BLAKE2b::increment_counter($ctx, 1); + $this->assertEquals(1, $ctx[1][0]->toInt()); + $this->assertEquals(0, $ctx[1][1]->toInt()); + + ParagonIE_Sodium_Core32_BLAKE2b::increment_counter($ctx, 1); + $this->assertEquals(2, $ctx[1][0]->toInt()); + $this->assertEquals(0, $ctx[1][1]->toInt()); + + ParagonIE_Sodium_Core32_BLAKE2b::increment_counter($ctx, 1024); + $this->assertEquals(1026, $ctx[1][0]->toInt()); + $this->assertEquals(0, $ctx[1][1]->toInt()); + + for ($i = 0; $i < 4; ++$i) { + ParagonIE_Sodium_Core32_BLAKE2b::increment_counter($ctx, 1 << 30); + } + + /** @var ParagonIE_Sodium_Core32_Int64 $c */ + $c = $ctx[1][0]->toArray(); + $this->assertEquals(1026, $c[1]); + $this->assertEquals(1, $c[0]); + } + /** * Make sure our 'context' string is consistent. * diff --git a/tests/unit/CryptoTest.php b/tests/unit/CryptoTest.php index f10bb389..a5133a4f 100644 --- a/tests/unit/CryptoTest.php +++ b/tests/unit/CryptoTest.php @@ -282,7 +282,7 @@ public function testCryptoBox32() public function testCryptoBox() { if (PHP_INT_SIZE === 4) { - return; + $this->markTestSkipped('Ignored on 32-bit'); } $nonce = str_repeat("\x00", 24); $message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; @@ -459,6 +459,7 @@ public function testScalarmult() ); } } + /** * @covers ParagonIE_Sodium_Crypto::sign_detached() * @throws SodiumException @@ -468,7 +469,6 @@ public function testSignDetached32() { if (PHP_INT_SIZE === 8) { $this->markTestSkipped('Only 32-bit'); - return; } $secret = ParagonIE_Sodium_Core_Util::hex2bin( 'fcdf31aae72e280cc760186d83e41be216fe1f2c7407dd393ad3a45a2fa501a4' . @@ -497,7 +497,7 @@ public function testSignDetached32() public function testSignDetached() { if (PHP_INT_SIZE === 4) { - return; + $this->markTestSkipped('Ignored on 32-bit'); } $secret = ParagonIE_Sodium_Core_Util::hex2bin( 'fcdf31aae72e280cc760186d83e41be216fe1f2c7407dd393ad3a45a2fa501a4' . diff --git a/tests/unit/Curve25519Test.php b/tests/unit/Curve25519Test.php index bc1e9cce..fd846930 100644 --- a/tests/unit/Curve25519Test.php +++ b/tests/unit/Curve25519Test.php @@ -244,7 +244,7 @@ public function testFeAdd() public function testFeSq() { if (PHP_INT_SIZE === 4) { - return; + $this->markTestSkipped('Not on 32-bit'); } $g = ParagonIE_Sodium_Core_Curve25519_Fe::fromArray( array( @@ -348,6 +348,7 @@ public function testFeSq32() public function testFeSqDouble() { if (PHP_INT_SIZE === 4) { + $this->markTestSkipped('Not on 32-bit'); return; } $g = ParagonIE_Sodium_Core_Curve25519_Fe::fromArray( @@ -399,7 +400,7 @@ public function testFeSqDouble32() $this->markTestSkipped('Only 32-bit'); return; } - $g = ParagonIE_Sodium_Core32_Curve25519_Fe::fromArray( + $g = ParagonIE_Sodium_Core32_Curve25519_Fe::fromIntArray( array( 70051, -1455864, @@ -414,7 +415,7 @@ public function testFeSqDouble32() ) ); - $expected = ParagonIE_Sodium_Core32_Curve25519_Fe::fromArray( + $expected = ParagonIE_Sodium_Core32_Curve25519_Fe::fromIntArray( array( -8161178, -16341160, @@ -631,6 +632,13 @@ public function testScMulAdd() ); } + public function testEqual() + { + $this->assertSame(1, ParagonIE_Sodium_Core32_Curve25519::equal(0, 0)); + $this->assertSame(1, ParagonIE_Sodium_Core32_Curve25519::equal(0x7fffffff, 0x7fffffff)); + $this->assertSame(0, ParagonIE_Sodium_Core32_Curve25519::equal(0x7ffffffe, 0x7fffffff)); + } + /** * @covers ParagonIE_Sodium_Core_Curve25519::ge_select() * @throws SodiumException @@ -642,47 +650,14 @@ public function testGeSelect() $this->assertEquals( ParagonIE_Sodium_Core32_Curve25519::ge_select(0, 6), new ParagonIE_Sodium_Core32_Curve25519_Ge_Precomp( - ParagonIE_Sodium_Core32_Curve25519_Fe::fromArray( - array( - ParagonIE_Sodium_Core32_Int32::fromInt(-15371964), - ParagonIE_Sodium_Core32_Int32::fromInt(-12862754), - ParagonIE_Sodium_Core32_Int32::fromInt(32573250), - ParagonIE_Sodium_Core32_Int32::fromInt(4720197), - ParagonIE_Sodium_Core32_Int32::fromInt(-26436522), - ParagonIE_Sodium_Core32_Int32::fromInt(5875511), - ParagonIE_Sodium_Core32_Int32::fromInt(-19188627), - ParagonIE_Sodium_Core32_Int32::fromInt(-15224819), - ParagonIE_Sodium_Core32_Int32::fromInt(-9818940), - ParagonIE_Sodium_Core32_Int32::fromInt(-12085777) - ) + ParagonIE_Sodium_Core32_Curve25519_Fe::fromIntArray( + array(-15371964, -12862754, 32573250, 4720197, -26436522, 5875511, -19188627, -15224819, -9818940, -12085777) ), - ParagonIE_Sodium_Core32_Curve25519_Fe::fromArray( - array( - ParagonIE_Sodium_Core32_Int32::fromInt(-8549212), - ParagonIE_Sodium_Core32_Int32::fromInt(109983), - ParagonIE_Sodium_Core32_Int32::fromInt(15149363), - ParagonIE_Sodium_Core32_Int32::fromInt(2178705), - ParagonIE_Sodium_Core32_Int32::fromInt(22900618), - ParagonIE_Sodium_Core32_Int32::fromInt(4543417), - ParagonIE_Sodium_Core32_Int32::fromInt(3044240), - ParagonIE_Sodium_Core32_Int32::fromInt(-15689887), - ParagonIE_Sodium_Core32_Int32::fromInt(1762328), - ParagonIE_Sodium_Core32_Int32::fromInt(14866737) - ) + ParagonIE_Sodium_Core32_Curve25519_Fe::fromIntArray( + array(-8549212, 109983, 15149363, 2178705, 22900618, 4543417, 3044240, -15689887, 1762328, 14866737) ), - ParagonIE_Sodium_Core32_Curve25519_Fe::fromArray( - array( - ParagonIE_Sodium_Core32_Int32::fromInt(-18199695), - ParagonIE_Sodium_Core32_Int32::fromInt(-15951423), - ParagonIE_Sodium_Core32_Int32::fromInt(-10473290), - ParagonIE_Sodium_Core32_Int32::fromInt(1707278), - ParagonIE_Sodium_Core32_Int32::fromInt(-17185920), - ParagonIE_Sodium_Core32_Int32::fromInt(3916101), - ParagonIE_Sodium_Core32_Int32::fromInt(-28236412), - ParagonIE_Sodium_Core32_Int32::fromInt(3959421), - ParagonIE_Sodium_Core32_Int32::fromInt(27914454), - ParagonIE_Sodium_Core32_Int32::fromInt(4383652) - ) + ParagonIE_Sodium_Core32_Curve25519_Fe::fromIntArray( + array(-18199695, -15951423, -10473290, 1707278, -17185920, 3916101, -28236412, 3959421, 27914454, 4383652) ) ), 'ge_select is not working.' @@ -715,7 +690,6 @@ public function testFeMul32() { if (PHP_INT_SIZE === 8) { $this->markTestSkipped('Only 32-bit'); - return; } $f = ParagonIE_Sodium_Core32_Curve25519_Fe::fromArray( array( @@ -879,7 +853,7 @@ public function testFeMul32() public function testFeMul() { if (PHP_INT_SIZE === 4) { - return; + $this->markTestSkipped('Not on 32-bit'); } $f = ParagonIE_Sodium_Core_Curve25519_Fe::fromArray( array( @@ -1407,7 +1381,7 @@ public function testGeMAdd32() public function testGeMAdd() { if (PHP_INT_SIZE === 4) { - return; + $this->markTestSkipped('Not on 32-bit'); } $p = new ParagonIE_Sodium_Core_Curve25519_Ge_P3( ParagonIE_Sodium_Core_Curve25519_Fe::fromArray( @@ -1566,7 +1540,6 @@ public function testGeScalarmultBase32() { if (PHP_INT_SIZE === 8) { $this->markTestSkipped('Only 32-bit'); - return; } $nonce = ParagonIE_Sodium_Core32_Util::hex2bin( 'a5cdb7382d5282472312e739b7b8fded4b0bc73a8d3b7ac24e6ee259df74800a' . @@ -1643,7 +1616,7 @@ public function testGeScalarmultBase32() public function testGeScalarmultBase() { if (PHP_INT_SIZE === 4) { - return; + $this->markTestSkipped('Not on 32-bit'); } $nonce = ParagonIE_Sodium_Core_Util::hex2bin( 'a5cdb7382d5282472312e739b7b8fded4b0bc73a8d3b7ac24e6ee259df74800a' . @@ -1724,7 +1697,6 @@ public function testGeDoubleScalarMultVartime32() { if (PHP_INT_SIZE === 8) { $this->markTestSkipped('Only 32-bit'); - return; } $h = ParagonIE_Sodium_Core32_Util::hex2bin( 'fc2ef90e2ddab38c55d0edbf41167048061a03b99d00112dcc92777c1b17300c' . @@ -1833,7 +1805,6 @@ public function testSlide32() { if (PHP_INT_SIZE === 8) { $this->markTestSkipped('Only 32-bit'); - return; } $a = ParagonIE_Sodium_Core32_Util::hex2bin( 'fc2ef90e2ddab38c55d0edbf41167048061a03b99d00112dcc92777c1b17300c' . @@ -1890,7 +1861,7 @@ public function testSlide32() public function testSlide() { if (PHP_INT_SIZE === 4) { - return; + $this->markTestSkipped('Not on 32-bit'); } $a = ParagonIE_Sodium_Core_Util::hex2bin( 'fc2ef90e2ddab38c55d0edbf41167048061a03b99d00112dcc92777c1b17300c' . @@ -1949,7 +1920,7 @@ public function testSlide() public function testGeDoubleScalarMultVartime() { if (PHP_INT_SIZE === 4) { - return; + $this->markTestSkipped('Not on 32-bit'); } $h = ParagonIE_Sodium_Core_Util::hex2bin( 'fc2ef90e2ddab38c55d0edbf41167048061a03b99d00112dcc92777c1b17300c' . @@ -2231,7 +2202,6 @@ public function test121666Mul32() { if (PHP_INT_SIZE === 8) { $this->markTestSkipped('Only 32-bit'); - return; } $f = array( 6334098, -296341, -25402037, 14130508, 28301433, 10881396, -32579582, 21932206, 23531802, -8703561 @@ -2316,7 +2286,7 @@ public function testFromBytes() public function test121666Mul() { if (PHP_INT_SIZE === 4) { - return; + $this->markTestSkipped('Not on 32-bit'); } $f = array( 6334098, -296341, -25402037, 14130508, 28301433, 10881396, -32579582, 21932206, 23531802, -8703561 diff --git a/tests/unit/Int32Test.php b/tests/unit/Int32Test.php index 8c6d30f2..fa537f56 100644 --- a/tests/unit/Int32Test.php +++ b/tests/unit/Int32Test.php @@ -16,7 +16,6 @@ public function testConversion() { if (PHP_INT_SIZE === 8) { $this->markTestSkipped('Only relevant to 32-bit platforms.'); - return; } $binary = ParagonIE_Sodium_Compat::hex2bin("12345678"); $from = ParagonIE_Sodium_Core32_Int32::fromString($binary); @@ -38,7 +37,6 @@ public function testAddInt32() { if (PHP_INT_SIZE === 8) { $this->markTestSkipped('Only relevant to 32-bit platforms.'); - return; } $one = new ParagonIE_Sodium_Core32_Int32( array(0x0000, 0x0001) @@ -99,7 +97,6 @@ public function testAddInt() { if (PHP_INT_SIZE === 8) { $this->markTestSkipped('Only relevant to 32-bit platforms.'); - return; } $one = new ParagonIE_Sodium_Core32_Int32( array(0x0000, 0x0001) @@ -141,7 +138,6 @@ public function testRotateLeft() { if (PHP_INT_SIZE === 8) { $this->markTestSkipped('Only relevant to 32-bit platforms.'); - return; } $begin = new ParagonIE_Sodium_Core32_Int32( array(0x1234, 0x5678) @@ -169,7 +165,6 @@ public function testMask() { if (PHP_INT_SIZE === 8) { $this->markTestSkipped('Only relevant to 32-bit platforms.'); - return; } $begin = new ParagonIE_Sodium_Core32_Int32( array(0x1234, 0x5678) @@ -193,7 +188,6 @@ public function testMult() { if (PHP_INT_SIZE === 8) { $this->markTestSkipped('Only relevant to 32-bit platforms.'); - return; } $begin = new ParagonIE_Sodium_Core32_Int32( array(0x1234, 0x5678) @@ -250,7 +244,6 @@ public function testShift() { if (PHP_INT_SIZE === 8) { $this->markTestSkipped('Only relevant to 32-bit platforms.'); - return; } $begin = new ParagonIE_Sodium_Core32_Int32( array(0x1234, 0x5678) @@ -274,7 +267,6 @@ public function testSubInt() { if (PHP_INT_SIZE === 8) { $this->markTestSkipped('Only relevant to 32-bit platforms.'); - return; } $four = new ParagonIE_Sodium_Core32_Int32( array(0x0000, 0x0004) @@ -317,7 +309,6 @@ public function testSubInt32() { if (PHP_INT_SIZE === 8) { $this->markTestSkipped('Only relevant to 32-bit platforms.'); - return; } $four = new ParagonIE_Sodium_Core32_Int32( array(0x0000, 0x0004) diff --git a/tests/unit/Ristretto255Test.php b/tests/unit/Ristretto255Test.php index 57738f1a..78a9986c 100644 --- a/tests/unit/Ristretto255Test.php +++ b/tests/unit/Ristretto255Test.php @@ -12,10 +12,16 @@ class Ristretto255Test extends PHPUnit_Framework_TestCase public function before() { ParagonIE_Sodium_Compat::$disableFallbackForUnitTests = true; + if (PHP_INT_SIZE === 4) { + $this->markTestSkipped('Ignore on 32-bit'); + } } public function testBadEncodings() { + if (PHP_INT_SIZE === 4) { + $this->markTestSkipped('Ignore on 32-bit'); + } $badHex = array( /* Non-canonical field encodings */ @@ -69,6 +75,9 @@ public function testBadEncodings() public function testFromHash() { + if (PHP_INT_SIZE === 4) { + $this->markTestSkipped('Ignore on 32-bit'); + } $inputHashes = array( "5d1be09e3d0c82fc538112490e35701979d99e06ca3e2b5b54bffe8b4dc772c1" . "4d98b696a1bbfb5ca32c436cc61c16563790306c79eaca7705668b47dffe5bb6", @@ -115,6 +124,9 @@ public function testFromHash() */ public function testScalarMult() { + if (PHP_INT_SIZE === 4) { + $this->markTestSkipped('Ignore on 32-bit'); + } $expected = array( '0000000000000000000000000000000000000000000000000000000000000000', 'e2f2ae0a6abc4e71a884a961c500515f58e30b6aa582dd8db6a65945e08d2d76', @@ -160,6 +172,9 @@ public function testScalarMult() public function testScalarOpMul() { + if (PHP_INT_SIZE === 4) { + $this->markTestSkipped('Ignore on 32-bit'); + } $x = sodium_hex2bin('5698f8e0556275ac6725829dcc8505a23349c49994db45b126e4234e8e081908'); $y = sodium_hex2bin('bf33fc4ef227d64aa6e257e544bad16b52a3185a38baa56ce21de8af97aa2606'); $expect = '9cc7e7bdad442f9734f404a9960e7a0ca16cdbe55f322bb5c5242cfbce071606'; @@ -175,6 +190,9 @@ public function testScalarOpMul() */ protected function assertValidPoint($s, $msg) { + if (PHP_INT_SIZE === 4) { + $this->markTestSkipped('Ignore on 32-bit'); + } $this->assertTrue( ParagonIE_Sodium_Compat::ristretto255_is_valid_point($s, true), $msg @@ -186,6 +204,9 @@ protected function assertValidPoint($s, $msg) */ public function testScalarMultTestVectors() { + if (PHP_INT_SIZE === 4) { + $this->markTestSkipped('Ignore on 32-bit'); + } $k = sodium_hex2bin('40a47d219ac550a3dcd7993356cfe639ff0e0cebbce2c82dd8010597db7d305d'); $a = sodium_hex2bin('9015dc069ae1fde7a640c8df344ae3753e691305a8e05199485c515f34d9bf13'); $b = sodium_crypto_scalarmult_ristretto255($k, $a); diff --git a/tests/unit/Salsa20Test.php b/tests/unit/Salsa20Test.php index db3099be..0da79cd4 100644 --- a/tests/unit/Salsa20Test.php +++ b/tests/unit/Salsa20Test.php @@ -16,7 +16,7 @@ public function before() public function testRotate() { if (PHP_INT_SIZE === 4) { - return; + $this->markTestSkipped("Ignored on 32-bit"); } $this->assertEquals( 0x00001000, diff --git a/tests/unit/SipHashTest.php b/tests/unit/SipHashTest.php index fc07418a..fb4f7a3b 100644 --- a/tests/unit/SipHashTest.php +++ b/tests/unit/SipHashTest.php @@ -17,7 +17,6 @@ public function testAdd() { if (PHP_INT_SIZE === 4) { $this->markTestSkipped('Test is not relevant to 32-bit'); - return; } $vectors = array( @@ -72,7 +71,6 @@ public function testRotl64() { if (PHP_INT_SIZE === 4) { $this->markTestSkipped('Test is not relevant to 32-bit'); - return; } $this->assertSame( array(0x00010000, 0x00000000), diff --git a/tests/unit/UtilTest.php b/tests/unit/UtilTest.php index 91a9ad18..845e3010 100644 --- a/tests/unit/UtilTest.php +++ b/tests/unit/UtilTest.php @@ -264,7 +264,7 @@ public function testStore64() public function testMul() { if (PHP_INT_SIZE === 4) { - return; + $this->markTestSkipped('Ignore on 32-bit'); } $arguments = array( array(1, 1),