From ccdf14d31aa80b1f345ce82ac228b73e955a8a58 Mon Sep 17 00:00:00 2001 From: hashlag Date: Wed, 4 Feb 2026 00:25:15 +0300 Subject: [PATCH] Add Arc4GenTests, GenerateOutIteratorUsageTest. Harden against past-the-end write. --- ChaosTests/Cipher/Arc4GenTests.cpp | 56 ++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/ChaosTests/Cipher/Arc4GenTests.cpp b/ChaosTests/Cipher/Arc4GenTests.cpp index 1baab07..9448ba1 100644 --- a/ChaosTests/Cipher/Arc4GenTests.cpp +++ b/ChaosTests/Cipher/Arc4GenTests.cpp @@ -353,3 +353,59 @@ TEST(Arc4GenTests, UninitializedGenTest) ASSERT_THROW(gen.Drop(256), Chaos::Service::ChaosException); } } + +TEST(Arc4GenTests, GenerateOutIteratorUsageTest) +{ + { + uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + Arc4Gen gen(key, key + std::size(key)); + + std::array out; + out.fill(0); + + std::array expected = + { + 0xb2, 0x39, 0x63, 0x05, 0xf0, 0x3d, 0xc0, 0x27, + 0xcc, 0xc3, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 + }; + + gen.Generate(out.begin(), 11); + + ASSERT_EQ(expected, out); + } + + { + uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + Arc4Gen gen(key, key + std::size(key)); + + std::array out; + out.fill(0); + + std::array expected = + { + 0xb2, 0x39, 0x63, 0x05, 0xf0, 0x3d, 0xc0, 0x27, + 0xcc, 0xc3, 0x52, 0x4a, 0x0a, 0x11, 0x18, 0xa8, + 0x69, 0x82, 0x00, 0x00 + }; + + gen.Generate(out.begin(), 18); + + ASSERT_EQ(expected, out); + } + + { + uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + Arc4Gen gen(key, key + std::size(key)); + + std::array out; + out.fill(0); + + std::array expected; + expected.fill(0); + + gen.Generate(out.begin(), 0); + + ASSERT_EQ(expected, out); + } +}