Ase::KeccakRng class

KeccakRng - A KeccakF1600 based pseudo-random number generator. The permutation steps are derived from the Keccak specification Keccak11 . For further details about this implementation, see also: http://testbit.eu/ This class is primarily used to implement more fine tuned generators, such as: KeccakCryptoRng, KeccakGoodRng and KeccakFastRng.

Derived classes

class KeccakCryptoRng
class KeccakFastRng
class KeccakGoodRng

Public types

using result_type = uint64_t
Integral type of the KeccakRng generator results.

Constructors, destructors, conversion operators

KeccakRng(uint16_t hidden_state_capacity, uint16_t n_rounds) explicit
Create an unseeded Keccak PRNG with specific capacity and number of rounds, for experts only.
~KeccakRng()
The destructor resets the generator state to avoid leaving memory trails.

Public functions

void auto_seed()
Seed the generator from a system specific nondeterministic random source.
auto bit_capacity() const →  size_t
Amount of bits used to store hidden random number generator state.
void discard(unsigned long long count)
void forget()
template <typename RandomAccessIterator>
void generate(RandomAccessIterator begin, RandomAccessIterator end)
Fill the range [begin, end) with random unsigned integer values.
auto max() const →  result_type
Maximum of the result type, for uint64_t that is 18446744073709551615.
auto min() const →  result_type
Minimum of the result type, for uint64_t that is 0.
auto n_nums() const →  size_t
Amount of 64 bit random numbers per generated block.
auto operator()() →  result_type
Generate uniformly distributed 32 bit pseudo random number.
auto random() →  uint64_t
void seed(uint64_t seed_value = 1)
Reinitialize the generator state using a 64 bit seed_value.
void seed(const uint64_t* seeds, size_t n_seeds)
Reinitialize the generator state using a nuber of 64 bit seeds.
template <class SeedSeq>
void seed(SeedSeq& seed_sequence)
Seed the generator state from a seed_sequence.
void xor_seed(const uint64_t* seeds, size_t n_seeds)

Friends

auto operator!=(const KeccakRng& lhs, const KeccakRng& rhs) →  bool
Compare two generators for state inequality.
template <typename CharT, typename Traits>
auto operator<<(std::basic_ostream<CharT, Traits>& os, const KeccakRng& self) →  std::basic_ostream<CharT, Traits>&
Serialize generator state into an OStream.
auto operator==(const KeccakRng& lhs, const KeccakRng& rhs) →  bool
Compare two generators for state equality.
template <typename CharT, typename Traits>
auto operator>>(std::basic_istream<CharT, Traits>& is, KeccakRng& self) →  std::basic_istream<CharT, Traits>&
Deserialize generator state from an IStream.

Function documentation

void Ase::KeccakRng::discard(unsigned long long count)

Discard count consecutive random values. This function is slightly faster than calling operator()() exactly count times.

void Ase::KeccakRng::forget()

Discard 2^256 bits of the current generator state. This makes it practically infeasible to guess previous generator states or deduce generated values from the past. Use this for forward security Security03 of generated security tokens like session keys.

uint64_t Ase::KeccakRng::random()

Generate uniformly distributed 64 bit pseudo random number. A new block permutation is carried out every n_nums() calls, see also xor_seed().

void Ase::KeccakRng::xor_seed(const uint64_t* seeds, size_t n_seeds)

Incorporate seed_values into the current generator state. A block permutation to advance the generator state is carried out per n_nums() seed values. After calling this function, generating the next n_nums() random values will not need to block for a new permutation.