Arc4CryptTests: Add rekey test
This commit is contained in:
@@ -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<uint8_t> data = StrToU8Vec("The quick brown fox jumps over the lazy dog.");
|
||||
|
||||
{
|
||||
const std::vector<uint8_t> key = { 0x01, 0x02, 0x03, 0x04, 0x05 };
|
||||
|
||||
std::vector<uint8_t> ciphertext;
|
||||
ciphertext.resize(data.size());
|
||||
|
||||
arc4.Rekey(key.begin(), key.end());
|
||||
arc4.Encrypt(ciphertext.begin(), data.begin(), data.size());
|
||||
|
||||
ASSERT_EQ(std::vector<uint8_t>({ 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<uint8_t> key = { 0x05, 0x04, 0x03, 0x02, 0x01 };
|
||||
|
||||
std::vector<uint8_t> ciphertext;
|
||||
ciphertext.resize(data.size());
|
||||
|
||||
arc4.Rekey(key.begin(), key.end());
|
||||
arc4.Encrypt(ciphertext.begin(), data.begin(), data.size());
|
||||
|
||||
ASSERT_EQ(std::vector<uint8_t>({ 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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user