Add the Arc4 PRNG draft implementation
This commit is contained in:
@@ -1,9 +1,112 @@
|
|||||||
#ifndef CHAOS_CIPHER_ARC4_HPP
|
#ifndef CHAOS_CIPHER_ARC4_HPP
|
||||||
#define CHAOS_CIPHER_ARC4_HPP
|
#define CHAOS_CIPHER_ARC4_HPP
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "Service/ChaosException.hpp"
|
||||||
|
|
||||||
namespace Chaos::Cipher::Arc4
|
namespace Chaos::Cipher::Arc4
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class Arc4Gen
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Arc4Gen()
|
||||||
|
: IsInitialized_(false)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
template<typename InputIt>
|
||||||
|
Arc4Gen(InputIt keyBegin, InputIt keyEnd)
|
||||||
|
{
|
||||||
|
RekeyImpl(keyBegin, keyEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename InputIt>
|
||||||
|
void Rekey(InputIt keyBegin, InputIt keyEnd)
|
||||||
|
{
|
||||||
|
RekeyImpl(keyBegin, keyEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename OutputIt>
|
||||||
|
void Generate(OutputIt out, uint64_t bytesCount)
|
||||||
|
{
|
||||||
|
EnsureInitialized();
|
||||||
|
|
||||||
|
for (uint64_t cnt = 0; cnt < bytesCount; ++cnt)
|
||||||
|
{
|
||||||
|
Step();
|
||||||
|
*out++ = Lookup_[static_cast<uint8_t>(Lookup_[I_] + Lookup_[J_])];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Drop(uint64_t bytesCount)
|
||||||
|
{
|
||||||
|
EnsureInitialized();
|
||||||
|
|
||||||
|
for (uint64_t cnt = 0; cnt < bytesCount; ++cnt)
|
||||||
|
{
|
||||||
|
Step();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool IsInitialized_;
|
||||||
|
|
||||||
|
uint8_t I_;
|
||||||
|
uint8_t J_;
|
||||||
|
std::array<uint8_t, 256> Lookup_;
|
||||||
|
|
||||||
|
void EnsureInitialized() const
|
||||||
|
{
|
||||||
|
if (!IsInitialized_)
|
||||||
|
{
|
||||||
|
throw Service::ChaosException("Arc4Gen: not initialized");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename InputIt>
|
||||||
|
void RekeyImpl(InputIt keyBegin, InputIt keyEnd)
|
||||||
|
{
|
||||||
|
I_ = 0;
|
||||||
|
J_ = 0;
|
||||||
|
|
||||||
|
for (uint64_t idx = 0; idx < Lookup_.size(); ++idx)
|
||||||
|
{
|
||||||
|
Lookup_[idx] = static_cast<uint8_t>(idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<uint8_t> key(keyBegin, keyEnd);
|
||||||
|
|
||||||
|
if (key.size() < 5)
|
||||||
|
{
|
||||||
|
throw Service::ChaosException("Arc4Gen: key is too small");
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t a = 0;
|
||||||
|
uint8_t b = 0;
|
||||||
|
|
||||||
|
for (uint64_t idx = 0; idx < Lookup_.size(); ++idx)
|
||||||
|
{
|
||||||
|
a = static_cast<uint8_t>(idx);
|
||||||
|
b = b + Lookup_[a] + key[a % key.size()];
|
||||||
|
|
||||||
|
std::swap(Lookup_[a], Lookup_[b]);
|
||||||
|
}
|
||||||
|
|
||||||
|
IsInitialized_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Step()
|
||||||
|
{
|
||||||
|
I_ = I_ + 1;
|
||||||
|
J_ = J_ + Lookup_[I_];
|
||||||
|
|
||||||
|
std::swap(Lookup_[I_], Lookup_[J_]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace Chaos::Cipher::Arc4
|
} // namespace Chaos::Cipher::Arc4
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
31
Chaos/Service/ChaosException.hpp
Normal file
31
Chaos/Service/ChaosException.hpp
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#ifndef CHAOS_SERVICE_CHAOSEXCEPTION_HPP
|
||||||
|
#define CHAOS_SERVICE_CHAOSEXCEPTION_HPP
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace Chaos::Service
|
||||||
|
{
|
||||||
|
|
||||||
|
class ChaosException
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ChaosException(std::string && message)
|
||||||
|
: Message_(std::move(message))
|
||||||
|
{ }
|
||||||
|
|
||||||
|
ChaosException(const std::string & message)
|
||||||
|
: Message_(message)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
const std::string & GetMessage() const
|
||||||
|
{
|
||||||
|
return Message_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string Message_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Chaos::Service
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -13,7 +13,8 @@ FetchContent_MakeAvailable(googletest)
|
|||||||
|
|
||||||
set(ChaosTests_SOURCE Hash/Md4HasherTests.cpp
|
set(ChaosTests_SOURCE Hash/Md4HasherTests.cpp
|
||||||
Hash/Md5HasherTests.cpp
|
Hash/Md5HasherTests.cpp
|
||||||
Mac/HmacTests.cpp)
|
Mac/HmacTests.cpp
|
||||||
|
Cipher/Arc4Tests.cpp)
|
||||||
|
|
||||||
add_executable(ChaosTests ${ChaosTests_SOURCE})
|
add_executable(ChaosTests ${ChaosTests_SOURCE})
|
||||||
target_link_libraries(ChaosTests gtest gtest_main)
|
target_link_libraries(ChaosTests gtest gtest_main)
|
||||||
|
|||||||
@@ -3,3 +3,353 @@
|
|||||||
#include "Cipher/Arc4.hpp"
|
#include "Cipher/Arc4.hpp"
|
||||||
|
|
||||||
using namespace Chaos::Cipher::Arc4;
|
using namespace Chaos::Cipher::Arc4;
|
||||||
|
|
||||||
|
TEST(Arc4GenTests, RFCTest)
|
||||||
|
{
|
||||||
|
Arc4Gen gen;
|
||||||
|
|
||||||
|
// Key: 0x0102030405 (40 bits)
|
||||||
|
|
||||||
|
{
|
||||||
|
uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
|
||||||
|
gen.Rekey(key, key + std::size(key));
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> expected =
|
||||||
|
{
|
||||||
|
0xb2, 0x39, 0x63, 0x05, 0xf0, 0x3d, 0xc0, 0x27,
|
||||||
|
0xcc, 0xc3, 0x52, 0x4a, 0x0a, 0x11, 0x18, 0xa8,
|
||||||
|
0x69, 0x82, 0x94, 0x4f, 0x18, 0xfc, 0x82, 0xd5,
|
||||||
|
0x89, 0xc4, 0x03, 0xa4, 0x7a, 0x0d, 0x09, 0x19
|
||||||
|
};
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> fact;
|
||||||
|
|
||||||
|
gen.Generate(fact.begin(), fact.size());
|
||||||
|
|
||||||
|
ASSERT_EQ(expected, fact);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
|
||||||
|
gen.Rekey(key, key + std::size(key));
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> expected =
|
||||||
|
{
|
||||||
|
0x28, 0xcb, 0x11, 0x32, 0xc9, 0x6c, 0xe2, 0x86,
|
||||||
|
0x42, 0x1d, 0xca, 0xad, 0xb8, 0xb6, 0x9e, 0xae,
|
||||||
|
0x1c, 0xfc, 0xf6, 0x2b, 0x03, 0xed, 0xdb, 0x64,
|
||||||
|
0x1d, 0x77, 0xdf, 0xcf, 0x7f, 0x8d, 0x8c, 0x93
|
||||||
|
};
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> fact;
|
||||||
|
|
||||||
|
gen.Drop(240);
|
||||||
|
gen.Generate(fact.begin(), fact.size());
|
||||||
|
|
||||||
|
ASSERT_EQ(expected, fact);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
|
||||||
|
gen.Rekey(key, key + std::size(key));
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> expected =
|
||||||
|
{
|
||||||
|
0x42, 0xb7, 0xd0, 0xcd, 0xd9, 0x18, 0xa8, 0xa3,
|
||||||
|
0x3d, 0xd5, 0x17, 0x81, 0xc8, 0x1f, 0x40, 0x41,
|
||||||
|
0x64, 0x59, 0x84, 0x44, 0x32, 0xa7, 0xda, 0x92,
|
||||||
|
0x3c, 0xfb, 0x3e, 0xb4, 0x98, 0x06, 0x61, 0xf6
|
||||||
|
};
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> fact;
|
||||||
|
|
||||||
|
gen.Drop(496);
|
||||||
|
gen.Generate(fact.begin(), fact.size());
|
||||||
|
|
||||||
|
ASSERT_EQ(expected, fact);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
|
||||||
|
gen.Rekey(key, key + std::size(key));
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> expected =
|
||||||
|
{
|
||||||
|
0x45, 0x12, 0x90, 0x48, 0xe6, 0xa0, 0xed, 0x0b,
|
||||||
|
0x56, 0xb4, 0x90, 0x33, 0x8f, 0x07, 0x8d, 0xa5,
|
||||||
|
0x30, 0xab, 0xbc, 0xc7, 0xc2, 0x0b, 0x01, 0x60,
|
||||||
|
0x9f, 0x23, 0xee, 0x2d, 0x5f, 0x6b, 0xb7, 0xdf
|
||||||
|
};
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> fact;
|
||||||
|
|
||||||
|
gen.Drop(1008);
|
||||||
|
gen.Generate(fact.begin(), fact.size());
|
||||||
|
|
||||||
|
ASSERT_EQ(expected, fact);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
|
||||||
|
gen.Rekey(key, key + std::size(key));
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> expected =
|
||||||
|
{
|
||||||
|
0x1e, 0xb1, 0x4a, 0x0c, 0x13, 0xb3, 0xbf, 0x47,
|
||||||
|
0xfa, 0x2a, 0x0b, 0xa9, 0x3a, 0xd4, 0x5b, 0x8b,
|
||||||
|
0xcc, 0x58, 0x2f, 0x8b, 0xa9, 0xf2, 0x65, 0xe2,
|
||||||
|
0xb1, 0xbe, 0x91, 0x12, 0xe9, 0x75, 0xd2, 0xd7
|
||||||
|
};
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> fact;
|
||||||
|
|
||||||
|
gen.Drop(2032);
|
||||||
|
gen.Generate(fact.begin(), fact.size());
|
||||||
|
|
||||||
|
ASSERT_EQ(expected, fact);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
|
||||||
|
gen.Rekey(key, key + std::size(key));
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> expected =
|
||||||
|
{
|
||||||
|
0x06, 0x83, 0x26, 0xa2, 0x11, 0x84, 0x16, 0xd2,
|
||||||
|
0x1f, 0x9d, 0x04, 0xb2, 0xcd, 0x1c, 0xa0, 0x50,
|
||||||
|
0xff, 0x25, 0xb5, 0x89, 0x95, 0x99, 0x67, 0x07,
|
||||||
|
0xe5, 0x1f, 0xbd, 0xf0, 0x8b, 0x34, 0xd8, 0x75
|
||||||
|
};
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> fact;
|
||||||
|
|
||||||
|
gen.Drop(4080);
|
||||||
|
gen.Generate(fact.begin(), fact.size());
|
||||||
|
|
||||||
|
ASSERT_EQ(expected, fact);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
|
||||||
|
gen.Rekey(key, key + std::size(key));
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> expected =
|
||||||
|
{
|
||||||
|
0x06, 0x83, 0x26, 0xa2, 0x11, 0x84, 0x16, 0xd2,
|
||||||
|
0x1f, 0x9d, 0x04, 0xb2, 0xcd, 0x1c, 0xa0, 0x50,
|
||||||
|
0xff, 0x25, 0xb5, 0x89, 0x95, 0x99, 0x67, 0x07,
|
||||||
|
0xe5, 0x1f, 0xbd, 0xf0, 0x8b, 0x34, 0xd8, 0x75
|
||||||
|
};
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> fact;
|
||||||
|
|
||||||
|
gen.Drop(4080);
|
||||||
|
gen.Generate(fact.begin(), fact.size());
|
||||||
|
|
||||||
|
ASSERT_EQ(expected, fact);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Key: 0x0102030405060708090a (80 bits)
|
||||||
|
|
||||||
|
{
|
||||||
|
uint8_t key[] =
|
||||||
|
{
|
||||||
|
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||||
|
0x08, 0x09, 0x0a
|
||||||
|
};
|
||||||
|
|
||||||
|
gen.Rekey(key, key + std::size(key));
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> expected =
|
||||||
|
{
|
||||||
|
0xed, 0xe3, 0xb0, 0x46, 0x43, 0xe5, 0x86, 0xcc,
|
||||||
|
0x90, 0x7d, 0xc2, 0x18, 0x51, 0x70, 0x99, 0x02,
|
||||||
|
0x03, 0x51, 0x6b, 0xa7, 0x8f, 0x41, 0x3b, 0xeb,
|
||||||
|
0x22, 0x3a, 0xa5, 0xd4, 0xd2, 0xdf, 0x67, 0x11
|
||||||
|
};
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> fact;
|
||||||
|
|
||||||
|
gen.Generate(fact.begin(), fact.size());
|
||||||
|
|
||||||
|
ASSERT_EQ(expected, fact);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
uint8_t key[] =
|
||||||
|
{
|
||||||
|
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||||
|
0x08, 0x09, 0x0a
|
||||||
|
};
|
||||||
|
|
||||||
|
gen.Rekey(key, key + std::size(key));
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> expected =
|
||||||
|
{
|
||||||
|
0xb5, 0x5a, 0x0a, 0x5b, 0x51, 0xa1, 0x2a, 0x8b,
|
||||||
|
0xe3, 0x48, 0x99, 0xc3, 0xe0, 0x47, 0x51, 0x1a,
|
||||||
|
0xd9, 0xa0, 0x9c, 0xea, 0x3c, 0xe7, 0x5f, 0xe3,
|
||||||
|
0x96, 0x98, 0x07, 0x03, 0x17, 0xa7, 0x13, 0x39
|
||||||
|
};
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> fact;
|
||||||
|
|
||||||
|
gen.Drop(2032);
|
||||||
|
gen.Generate(fact.begin(), fact.size());
|
||||||
|
|
||||||
|
ASSERT_EQ(expected, fact);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Key: 0x0102030405060708090a0b0c0d0e0f10 (128 bits)
|
||||||
|
|
||||||
|
{
|
||||||
|
uint8_t key[] =
|
||||||
|
{
|
||||||
|
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||||
|
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
|
||||||
|
0x0f, 0x10
|
||||||
|
};
|
||||||
|
|
||||||
|
gen.Rekey(key, key + std::size(key));
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> expected =
|
||||||
|
{
|
||||||
|
0x9a, 0xc7, 0xcc, 0x9a, 0x60, 0x9d, 0x1e, 0xf7,
|
||||||
|
0xb2, 0x93, 0x28, 0x99, 0xcd, 0xe4, 0x1b, 0x97,
|
||||||
|
0x52, 0x48, 0xc4, 0x95, 0x90, 0x14, 0x12, 0x6a,
|
||||||
|
0x6e, 0x8a, 0x84, 0xf1, 0x1d, 0x1a, 0x9e, 0x1c
|
||||||
|
};
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> fact;
|
||||||
|
|
||||||
|
gen.Generate(fact.begin(), fact.size());
|
||||||
|
|
||||||
|
ASSERT_EQ(expected, fact);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
uint8_t key[] =
|
||||||
|
{
|
||||||
|
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||||
|
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
|
||||||
|
0x0f, 0x10
|
||||||
|
};
|
||||||
|
|
||||||
|
gen.Rekey(key, key + std::size(key));
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> expected =
|
||||||
|
{
|
||||||
|
0xd0, 0x3d, 0x1b, 0xc0, 0x3c, 0xd3, 0x3d, 0x70,
|
||||||
|
0xdf, 0xf9, 0xfa, 0x5d, 0x71, 0x96, 0x3e, 0xbd,
|
||||||
|
0x8a, 0x44, 0x12, 0x64, 0x11, 0xea, 0xa7, 0x8b,
|
||||||
|
0xd5, 0x1e, 0x8d, 0x87, 0xa8, 0x87, 0x9b, 0xf5
|
||||||
|
};
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> fact;
|
||||||
|
|
||||||
|
gen.Drop(2032);
|
||||||
|
gen.Generate(fact.begin(), fact.size());
|
||||||
|
|
||||||
|
ASSERT_EQ(expected, fact);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Key: 0x0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20 (256 bits)
|
||||||
|
|
||||||
|
{
|
||||||
|
uint8_t key[] =
|
||||||
|
{
|
||||||
|
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||||
|
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
|
||||||
|
0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
|
||||||
|
0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c,
|
||||||
|
0x1d, 0x1e, 0x1f, 0x20
|
||||||
|
};
|
||||||
|
|
||||||
|
gen.Rekey(key, key + std::size(key));
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> expected =
|
||||||
|
{
|
||||||
|
0xea, 0xa6, 0xbd, 0x25, 0x88, 0x0b, 0xf9, 0x3d,
|
||||||
|
0x3f, 0x5d, 0x1e, 0x4c, 0xa2, 0x61, 0x1d, 0x91,
|
||||||
|
0xcf, 0xa4, 0x5c, 0x9f, 0x7e, 0x71, 0x4b, 0x54,
|
||||||
|
0xbd, 0xfa, 0x80, 0x02, 0x7c, 0xb1, 0x43, 0x80
|
||||||
|
};
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> fact;
|
||||||
|
|
||||||
|
gen.Generate(fact.begin(), fact.size());
|
||||||
|
|
||||||
|
ASSERT_EQ(expected, fact);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
uint8_t key[] =
|
||||||
|
{
|
||||||
|
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||||
|
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
|
||||||
|
0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
|
||||||
|
0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c,
|
||||||
|
0x1d, 0x1e, 0x1f, 0x20
|
||||||
|
};
|
||||||
|
|
||||||
|
gen.Rekey(key, key + std::size(key));
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> expected =
|
||||||
|
{
|
||||||
|
0xf6, 0x56, 0xab, 0xcc, 0xf8, 0x8d, 0xd8, 0x27,
|
||||||
|
0x02, 0x7b, 0x2c, 0xe9, 0x17, 0xd4, 0x64, 0xec,
|
||||||
|
0x18, 0xb6, 0x25, 0x03, 0xbf, 0xbc, 0x07, 0x7f,
|
||||||
|
0xba, 0xbb, 0x98, 0xf2, 0x0d, 0x98, 0xab, 0x34
|
||||||
|
};
|
||||||
|
|
||||||
|
std::array<uint8_t, 32> fact;
|
||||||
|
|
||||||
|
gen.Drop(2032);
|
||||||
|
gen.Generate(fact.begin(), fact.size());
|
||||||
|
|
||||||
|
ASSERT_EQ(expected, fact);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Arc4GenTests, TooSmallKeyTest)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
const char * key = "smal";
|
||||||
|
|
||||||
|
Arc4Gen gen;
|
||||||
|
ASSERT_THROW(gen.Rekey(key, key + strlen(key)), Chaos::Service::ChaosException);
|
||||||
|
|
||||||
|
ASSERT_THROW(Arc4Gen(key, key + strlen(key)), Chaos::Service::ChaosException);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Arc4GenTests, UninitializedGenTest)
|
||||||
|
{
|
||||||
|
std::array<uint8_t, 10> out;
|
||||||
|
|
||||||
|
{
|
||||||
|
Arc4Gen gen;
|
||||||
|
|
||||||
|
ASSERT_THROW(gen.Generate(out.begin(), out.size()), Chaos::Service::ChaosException);
|
||||||
|
|
||||||
|
ASSERT_THROW(gen.Drop(0), Chaos::Service::ChaosException);
|
||||||
|
ASSERT_THROW(gen.Drop(1), Chaos::Service::ChaosException);
|
||||||
|
ASSERT_THROW(gen.Drop(20), Chaos::Service::ChaosException);
|
||||||
|
ASSERT_THROW(gen.Drop(256), Chaos::Service::ChaosException);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const char * key = "smal";
|
||||||
|
|
||||||
|
Arc4Gen gen;
|
||||||
|
|
||||||
|
ASSERT_THROW(gen.Rekey(key, key + strlen(key)), Chaos::Service::ChaosException);
|
||||||
|
|
||||||
|
ASSERT_THROW(gen.Generate(out.begin(), out.size()), Chaos::Service::ChaosException);
|
||||||
|
|
||||||
|
ASSERT_THROW(gen.Drop(0), Chaos::Service::ChaosException);
|
||||||
|
ASSERT_THROW(gen.Drop(1), Chaos::Service::ChaosException);
|
||||||
|
ASSERT_THROW(gen.Drop(20), Chaos::Service::ChaosException);
|
||||||
|
ASSERT_THROW(gen.Drop(256), Chaos::Service::ChaosException);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user