11NAMESPACE_BEGIN(CryptoPP)
25#ifndef LCRNG_ORIGINAL_NUMBERS
26const word32 LC_RNG::m=2147483647L;
27const word32 LC_RNG::q=44488L;
29const word16 LC_RNG::a=(
unsigned int)48271L;
30const word16 LC_RNG::r=3399;
32const word32 LC_RNG::m=2147483647L;
33const word32 LC_RNG::q=127773L;
35const word16 LC_RNG::a=16807;
36const word16 LC_RNG::r=2836;
45 const sword64 test = a*lo - r*hi;
48 seed =
static_cast<word32>(test);
50 seed =
static_cast<word32>(test + m);
52 *output++ =
byte((GETBYTE(seed, 0) ^ GETBYTE(seed, 1) ^ GETBYTE(seed, 2) ^ GETBYTE(seed, 3)));
58#ifndef CRYPTOPP_IMPORTS
62 m_size(m_cipher->BlockSize()),
64 m_randseed(seed, m_size),
66 m_deterministicTimeVector(deterministicTimeVector, deterministicTimeVector ? m_size : 0)
72 memset(m_datetime, 0x00, m_size);
73 memset(m_lastBlock, 0x00, m_size);
76 if (!deterministicTimeVector)
78 time_t tstamp1 = ::time(NULLPTR);
79 xorbuf(m_datetime, (
byte *)&tstamp1,
UnsignedMin(
sizeof(tstamp1), m_size));
81 clock_t tstamp2 = clock();
82 xorbuf(m_datetime, (
byte *)&tstamp2,
UnsignedMin(
sizeof(tstamp2), m_size));
99 if (m_deterministicTimeVector.
size())
101 m_cipher->
ProcessBlock(m_deterministicTimeVector, m_datetime);
107 xorbuf(m_datetime, (
byte *)&c,
UnsignedMin(
sizeof(c), m_size));
108 time_t t = ::time(NULLPTR);
114 xorbuf(m_randseed, m_datetime, m_size);
118 if (memcmp(m_lastBlock, m_randseed, m_size) == 0)
119 throw SelfTestFailure(
"X917RNG: Continuous random number generator test failed.");
127 memcpy(m_lastBlock, m_randseed, m_size);
128 xorbuf(m_randseed, m_datetime, m_size);
138 for (
unsigned i=0; i<V; i++)
146 byte inByte = *inString++;
148 sum += ::log(
double(n - tab[inByte]));
155double MaurerRandomnessTest::GetTestValue()
const
160 double fTu = (sum/(n-Q))/::log(2.0);
162 double value = fTu * 0.1392;
163 return value > 1.0 ? 1.0 : value;
Copy input to a memory buffer.
Base class for all exceptions thrown by the library.
@ OTHER_ERROR
Some other error occurred not belonging to other categories.
void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
MaurerRandomnessTest()
Construct a MaurerRandomnessTest.
unsigned int BytesNeeded() const
Provides the number of bytes of input is needed by the test.
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
size_type size() const
Provides the count of elements in the SecBlock.
X917RNG(BlockTransformation *cipher, const byte *seed, const byte *deterministicTimeVector=NULLPTR)
Construct a X917RNG.
void GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword size)
Generate random bytes into a BufferedTransformation.
unsigned char byte
8-bit unsigned datatype
unsigned int word32
32-bit unsigned datatype
unsigned short word16
16-bit unsigned datatype
word64 lword
Large word type.
Classes and functions for the FIPS 140-2 validated library.
void IncrementCounterByOne(byte *inout, unsigned int size)
Performs an addition with carry on a block of bytes.
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
const T1 UnsignedMin(const T1 &a, const T2 &b)
Safe comparison of values that could be negative and incorrectly promoted.
Miscellaneous classes for RNGs.