From 59ffa0e30b14414a9cad06420923100a6f8390b7 Mon Sep 17 00:00:00 2001 From: hashlag <90853356+hashlag@users.noreply.github.com> Date: Wed, 17 Sep 2025 00:25:18 +0300 Subject: [PATCH] Arc4CryptTests: Add rekey test --- ChaosTests/Cipher/Arc4CryptTests.cpp | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/ChaosTests/Cipher/Arc4CryptTests.cpp b/ChaosTests/Cipher/Arc4CryptTests.cpp index 05842c7..c423296 100644 --- a/ChaosTests/Cipher/Arc4CryptTests.cpp +++ b/ChaosTests/Cipher/Arc4CryptTests.cpp @@ -81,3 +81,42 @@ TEST(Arc4CryptTests, UninitializedArc4CryptTest) ASSERT_THROW(arc4.Decrypt(out.begin(), in.begin(), in.size()), Chaos::Service::ChaosException); } } + +TEST(Arc4CryptTests, RekeyTest) +{ + Arc4Crypt arc4; + + const std::vector data = StrToU8Vec("The quick brown fox jumps over the lazy dog."); + + { + const std::vector key = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + + std::vector ciphertext; + ciphertext.resize(data.size()); + + arc4.Rekey(key.begin(), key.end()); + arc4.Encrypt(ciphertext.begin(), data.begin(), data.size()); + + ASSERT_EQ(std::vector({ 0xe6, 0x51, 0x06, 0x25, 0x81, 0x48, 0xa9, 0x44, 0xa7, 0xe3, 0x30, + 0x38, 0x65, 0x66, 0x76, 0x88, 0x0f, 0xed, 0xec, 0x6f, 0x72, 0x89, + 0xef, 0xa5, 0xfa, 0xe4, 0x6c, 0xd2, 0x1f, 0x7f, 0x29, 0x6d, 0xde, + 0xea, 0x58, 0xae, 0xec, 0x6f, 0xa1, 0x02, 0x47, 0x23, 0x0b, 0x96 }), + ciphertext); + } + + { + const std::vector key = { 0x05, 0x04, 0x03, 0x02, 0x01 }; + + std::vector ciphertext; + ciphertext.resize(data.size()); + + arc4.Rekey(key.begin(), key.end()); + arc4.Encrypt(ciphertext.begin(), data.begin(), data.size()); + + ASSERT_EQ(std::vector({ 0x18, 0x4a, 0x2e, 0x05, 0xc2, 0x8e, 0x5b, 0x26, 0xfa, 0x47, 0x44, + 0x0d, 0x12, 0x28, 0xb4, 0x45, 0x06, 0xc3, 0x5a, 0x17, 0xeb, 0xad, + 0x60, 0xb2, 0x16, 0x17, 0x29, 0x4d, 0xaa, 0xcb, 0x27, 0xd1, 0x45, + 0xa8, 0xb9, 0xc0, 0x02, 0xd3, 0x4a, 0x9d, 0xe8, 0xde, 0x63, 0x30 }), + ciphertext); + } +}