Anklang 0.3.0-460-gc4ef46ba
ASE — Anklang Sound Engine (C++)

« « « Anklang Documentation
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Friends | List of all members
Ase::KeccakRng Class Reference

#include "randomhash.hh"

Inheritance diagram for Ase::KeccakRng:
[legend]

Public Types

typedef uint64_t result_type
 Integral type of the KeccakRng generator results.
 

Public Member Functions

 KeccakRng (const KeccakRng &)=default
 
size_t n_nums () const
 Amount of 64 bit random numbers per generated block.
 
size_t bit_capacity () const
 Amount of bits used to store hidden random number generator state.
 
 ~KeccakRng ()
 The destructor resets the generator state to avoid leaving memory trails.
 
 KeccakRng (uint16_t hidden_state_capacity, uint16_t n_rounds)
 Create an unseeded Keccak PRNG with specific capacity and number of rounds, for experts only.
 
void forget ()
 
void discard (unsigned long long count)
 
void xor_seed (const uint64_t *seeds, size_t n_seeds)
 
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 auto_seed ()
 Seed the generator from a system specific nondeterministic random source.
 
uint64_t random ()
 
result_type operator() ()
 Generate uniformly distributed 32 bit pseudo random number.
 
template<typename RandomAccessIterator >
void generate (RandomAccessIterator begin, RandomAccessIterator end)
 Fill the range [begin, end) with random unsigned integer values.
 
result_type min () const
 Minimum of the result type, for uint64_t that is 0.
 
result_type max () const
 Maximum of the result type, for uint64_t that is 18446744073709551615.
 

Friends

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

Detailed Description

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.

Definition at line 233 of file randomhash.hh.

Member Typedef Documentation

◆ result_type

Integral type of the KeccakRng generator results.

Definition at line 241 of file randomhash.hh.

Constructor & Destructor Documentation

◆ ~KeccakRng()

Ase::KeccakRng::~KeccakRng ( )

The destructor resets the generator state to avoid leaving memory trails.

Definition at line 197 of file randomhash.cc.

References std::fill(), forget(), and n_nums().

◆ KeccakRng()

Ase::KeccakRng::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.

Definition at line 249 of file randomhash.hh.

References ASE_ASSERT_RETURN.

Member Function Documentation

◆ auto_seed()

void Ase::KeccakRng::auto_seed ( )

Seed the generator from a system specific nondeterministic random source.

Definition at line 190 of file randomhash.cc.

References seed().

Referenced by Ase::KeccakCryptoRng::KeccakCryptoRng(), Ase::KeccakFastRng::KeccakFastRng(), and Ase::KeccakGoodRng::KeccakGoodRng().

◆ bit_capacity()

size_t Ase::KeccakRng::bit_capacity ( ) const

Amount of bits used to store hidden random number generator state.

Definition at line 245 of file randomhash.hh.

◆ discard()

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

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

Definition at line 152 of file randomhash.cc.

References std::min(), and n_nums().

◆ forget()

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.

Definition at line 142 of file randomhash.cc.

References std::fill().

Referenced by ~KeccakRng().

◆ generate()

template<typename RandomAccessIterator >
void Ase::KeccakRng::generate ( RandomAccessIterator  begin,
RandomAccessIterator  end 
)

Fill the range [begin, end) with random unsigned integer values.

Definition at line 294 of file randomhash.hh.

References operator()(), and uint64_t.

◆ max()

result_type Ase::KeccakRng::max ( ) const

Maximum of the result type, for uint64_t that is 18446744073709551615.

Definition at line 328 of file randomhash.hh.

References std::numeric_limits::max().

◆ min()

result_type Ase::KeccakRng::min ( ) const

Minimum of the result type, for uint64_t that is 0.

Definition at line 322 of file randomhash.hh.

References std::numeric_limits::min().

◆ n_nums()

size_t Ase::KeccakRng::n_nums ( ) const

Amount of 64 bit random numbers per generated block.

Definition at line 243 of file randomhash.hh.

Referenced by discard(), random(), xor_seed(), and ~KeccakRng().

◆ operator()()

result_type Ase::KeccakRng::operator() ( )

Generate uniformly distributed 32 bit pseudo random number.

Definition at line 291 of file randomhash.hh.

References random().

Referenced by generate().

◆ random()

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().

Definition at line 284 of file randomhash.hh.

References n_nums().

Referenced by operator()().

◆ seed() [1/3]

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

Reinitialize the generator state using a nuber of 64 bit seeds.

Definition at line 263 of file randomhash.hh.

References xor_seed().

◆ seed() [2/3]

template<class SeedSeq >
void Ase::KeccakRng::seed ( SeedSeq &  seed_sequence)

Seed the generator state from a seed_sequence.

Definition at line 270 of file randomhash.hh.

References seed(), uint32_t, and uint64_t.

◆ seed() [3/3]

void Ase::KeccakRng::seed ( uint64_t  seed_value = 1)

Reinitialize the generator state using a 64 bit seed_value.

Definition at line 260 of file randomhash.hh.

References seed().

Referenced by auto_seed(), Ase::KeccakCryptoRng::KeccakCryptoRng(), Ase::KeccakFastRng::KeccakFastRng(), Ase::KeccakGoodRng::KeccakGoodRng(), seed(), and seed().

◆ 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.

Definition at line 170 of file randomhash.cc.

References std::min(), and n_nums().

Referenced by seed().

Friends And Related Symbol Documentation

◆ operator!=

bool operator!= ( const KeccakRng lhs,
const KeccakRng rhs 
)
friend

Compare two generators for state inequality.

Definition at line 316 of file randomhash.hh.

◆ operator<<

template<typename CharT , typename Traits >
std::basic_ostream< CharT, Traits > & operator<< ( std::basic_ostream< CharT, Traits > &  os,
const KeccakRng self 
)
friend

Serialize generator state into an OStream.

Definition at line 334 of file randomhash.hh.

◆ operator==

bool operator== ( const KeccakRng lhs,
const KeccakRng rhs 
)
friend

Compare two generators for state equality.

Definition at line 307 of file randomhash.hh.

◆ operator>>

template<typename CharT , typename Traits >
std::basic_istream< CharT, Traits > & operator>> ( std::basic_istream< CharT, Traits > &  is,
KeccakRng self 
)
friend

Deserialize generator state from an IStream.

Definition at line 353 of file randomhash.hh.


The documentation for this class was generated from the following files: