diff --git a/ChaosTests/Cipher/Arc4CryptTests.cpp b/ChaosTests/Cipher/Arc4CryptTests.cpp index b2192bc..8abc503 100644 --- a/ChaosTests/Cipher/Arc4CryptTests.cpp +++ b/ChaosTests/Cipher/Arc4CryptTests.cpp @@ -107,3 +107,121 @@ TEST(Arc4CryptTests, RekeyTest) ciphertext); } } + +TEST(Arc4CryptTests, EncryptOutIteratorUsageTest) +{ + const std::vector data = StrToU8Vec("The quick brown fox jumps over the lazy dog."); + + { + std::array key = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + + Arc4Crypt crypt(key.begin(), key.end()); + + std::array out; + out.fill(0); + + std::array expected = + { + 0xe6, 0x51, 0x06, 0x25, 0x81, 0x48, 0xa9, 0x44, 0xa7, 0xe3, 0x30, + 0x38, 0x65, 0x66, 0x76, 0x88, 0x0f, 0xed, 0xec, 0x6f, 0x72, 0x89, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + crypt.Encrypt(out.begin(), data.begin(), 22); + + ASSERT_EQ(expected, out); + } + + { + std::array key = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + + Arc4Crypt crypt(key.begin(), key.end()); + + std::array out; + out.fill(0); + + std::array expected = + { + 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + crypt.Encrypt(out.begin(), data.begin(), 27); + + ASSERT_EQ(expected, out); + } + + { + std::array key = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + + Arc4Crypt crypt(key.begin(), key.end()); + + std::array out; + out.fill(0); + + std::array expected; + expected.fill(0); + + crypt.Encrypt(out.begin(), data.begin(), 0); + + ASSERT_EQ(expected, out); + } +} + +TEST(Arc4CryptTests, DecryptOutIteratorUsageTest) +{ + const std::array data = { 0x45, 0xA0, 0x1F, 0x64, 0x5F, 0xC3, 0x5B, + 0x38, 0x35, 0x52, 0x54, 0x4B, 0x9B, 0xF5 }; + const std::vector key = StrToU8Vec("Secret"); + + { + Arc4Crypt crypt(key.begin(), key.end()); + + std::array out; + out.fill(0); + + std::array expected = + { + 'A', 't', 't', 'a', 'c', 'k', ' ', 'a', 't', ' ', 'd', 'a', + 0x00, 0x00 + }; + + crypt.Decrypt(out.begin(), data.begin(), 12); + + ASSERT_EQ(expected, out); + } + + { + Arc4Crypt crypt(key.begin(), key.end()); + + std::array out; + out.fill(0); + + std::array expected = + { + 'A', 't', 't', 'a', 'c', 'k', ' ', + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + crypt.Decrypt(out.begin(), data.begin(), 7); + + ASSERT_EQ(expected, out); + } + + { + Arc4Crypt crypt(key.begin(), key.end()); + + std::array out; + out.fill(0); + + std::array expected; + expected.fill(0); + + crypt.Decrypt(out.begin(), data.begin(), 0); + + ASSERT_EQ(expected, out); + } +} 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); + } +}