Skip to content

Commit

Permalink
Update Wycheproof tests from C2SP
Browse files Browse the repository at this point in the history
Project Wycheproof is now part of C2SP. This pulls in the latest test vectors for ChaCha20-Poly1305, XChaCha20-Poly1305, and X25519. Additionally, we add the SipHash-2-4 tests from Wycheproof.

The X25519 tests still take several minutes to run on a decent machine, so they are still gated behind the pedantic test flag.
  • Loading branch information
paragonie-security committed Apr 5, 2024
1 parent 3aa40cc commit 76c9df2
Show file tree
Hide file tree
Showing 6 changed files with 7,219 additions and 3,835 deletions.
37 changes: 37 additions & 0 deletions tests/unit/WycheproofTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ public function testXChaCha20Poly1305()
$this->mainTestingLoop('xchacha20_poly1305_test.json', 'doXChaCha20Poly1305Test', false);
}

/**
* @throws Exception
*/
public function testSipHash24()
{
if (empty($this->dir)) {
$this->before();
}
$this->mainTestingLoop('siphash_2_4_test.json', 'doSipHash24Test', false);
}

/**
* @throws Exception
*/
Expand Down Expand Up @@ -98,7 +109,9 @@ public function mainTestingLoop($filename, $method, $progress = false)

/**
* @param array $test
* @param bool $verbose
* @return bool
* @throws SodiumException
*/
public function doChaCha20Poly1305Test(array $test, $verbose = false)
{
Expand All @@ -125,7 +138,9 @@ public function doChaCha20Poly1305Test(array $test, $verbose = false)

/**
* @param array $test
* @param bool $verbose
* @return bool
* @throws SodiumException
*/
public function doXChaCha20Poly1305Test(array $test, $verbose = false)
{
Expand All @@ -152,7 +167,9 @@ public function doXChaCha20Poly1305Test(array $test, $verbose = false)

/**
* @param array $test
* @param bool $verbose
* @return bool
* @throws SodiumException
*/
public function doX25519Test(array $test, $verbose = false)
{
Expand All @@ -169,6 +186,26 @@ public function doX25519Test(array $test, $verbose = false)
return ParagonIE_Sodium_Core_Util::hashEquals($shared, $scalarmult);
}

/**
* @param array $test
* @param bool $verbose
* @return bool
* @throws SodiumException
*/
public function doSipHash24Test(array $test, $verbose = false)
{
$key = ParagonIE_Sodium_Compat::hex2bin($test['key']);
$msg = ParagonIE_Sodium_Compat::hex2bin($test['msg']);
$tag = ParagonIE_Sodium_Compat::hex2bin($test['tag']);
$result = ParagonIE_Sodium_Compat::crypto_shorthash($msg, $key);
if ($verbose && !ParagonIE_Sodium_Core_Util::hashEquals($tag, $result)) {
echo 'Difference in Wycheproof test vectors:', PHP_EOL;
echo '- ', ParagonIE_Sodium_Core_Util::bin2hex($tag), PHP_EOL;
echo '+ ', ParagonIE_Sodium_Core_Util::bin2hex($result), PHP_EOL;
}
return ParagonIE_Sodium_Core_Util::hashEquals($tag, $result);
}

/**
* @param string $file
*
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/wycheproof/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Wycheproof Tests

Sourced from Google's [Project Wycheproof](https://github.com/google/wycheproof/tree/master/testvectors).
Sourced from [Project Wycheproof](https://github.com/C2SP/wycheproof/tree/master/testvectors_v1).
Loading

0 comments on commit 76c9df2

Please sign in to comment.