Tests/LibCrypto: Make ChaCha20 tests roundtrip and decrypt in place

This is more to show how the API can be used than to add test coverage.
This commit is contained in:
Lucas Chollet
2026-03-09 15:19:58 +01:00
parent 3f622564b3
commit 632001fc77

View File

@@ -12,9 +12,14 @@ static void test_chacha20(ReadonlyBytes key, ReadonlyBytes nonce, u32 initial_bl
{
VERIFY(plaintext.size() == ciphertext.size());
auto result = MUST(ByteBuffer::create_uninitialized(plaintext.size()));
Crypto::Cipher::ChaCha20 cipher(key, nonce, initial_block_counter);
cipher.encrypt(plaintext, result);
EXPECT_EQ(result.bytes(), ciphertext);
Crypto::Cipher::ChaCha20 cipher2(key, nonce, initial_block_counter);
cipher2.decrypt(result, result);
EXPECT_EQ(result.bytes(), plaintext);
}
// https://datatracker.ietf.org/doc/html/rfc7539#appendix-A.2