Skip to content

Commit

Permalink
Add compatibility test to prevent #125 from regressing
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-security committed Apr 14, 2021
1 parent efcecfb commit 8fb0f27
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/compat/PHP72Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,36 @@ public function testAdd()
$this->assertEquals("\x11\x34\x56\x78", $tmp);
}

/**
* See Issue #125
* @ref https://github.com/paragonie/sodium_compat/issues/125
* @throws SodiumException
*/
public function testAeadXChaCha20EmptyAad()
{
$key = sodium_crypto_aead_xchacha20poly1305_ietf_keygen();
$nonce = random_bytes(24);
$message = 'Pi day was a month ago and I suddenly crave pie.';

$c1 = sodium_crypto_aead_xchacha20poly1305_ietf_encrypt($message, '', $nonce, $key);
$c2 = sodium_crypto_aead_xchacha20poly1305_ietf_encrypt($message, NULL, $nonce, $key);
$c3 = ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_encrypt($message, '', $nonce, $key);
$c4 = ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_encrypt($message, NULL, $nonce, $key);

$this->assertEquals(sodium_bin2hex($c1), sodium_bin2hex($c2));
$this->assertEquals(sodium_bin2hex($c1), sodium_bin2hex($c3));
$this->assertEquals(sodium_bin2hex($c1), sodium_bin2hex($c4));

$p1 = sodium_crypto_aead_xchacha20poly1305_ietf_decrypt($c1, '', $nonce, $key);
$p2 = sodium_crypto_aead_xchacha20poly1305_ietf_decrypt($c1, NULL, $nonce, $key);
$p3 = ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt($c1, '', $nonce, $key);
$p4 = ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt($c1, NULL, $nonce, $key);
$this->assertSame($message, $p1);
$this->assertSame($message, $p2);
$this->assertSame($message, $p3);
$this->assertSame($message, $p4);
}

/**
* @covers ParagonIE_Sodium_Core_Util::compare()
*/
Expand Down

0 comments on commit 8fb0f27

Please sign in to comment.