OpenVPN 3 Core Library
Loading...
Searching...
No Matches
openvpn::MTRand Class Reference

#include <mtrandapi.hpp>

Inheritance diagram for openvpn::MTRand:
[legend]
Collaboration diagram for openvpn::MTRand:
[legend]

Public Types

typedef RCPtr< MTRandPtr
 
typedef std::mt19937_64 rand_type
 
- Public Types inherited from openvpn::WeakRandomAPI
typedef RCPtr< WeakRandomAPIPtr
 Smart pointer type for managing the ownership of WeakRandomAPI objects.
 
- Public Types inherited from openvpn::RandomAPI
typedef RCPtr< RandomAPIPtr
 Smart pointer type for managing the ownership of RandomAPI objects.
 
typedef unsigned int result_type
 
- Public Types inherited from openvpn::RC< thread_unsafe_refcount >
typedef RCPtr< RCPtr
 

Public Member Functions

 OPENVPN_EXCEPTION (mtrand_error)
 
 MTRand (RandomAPI &seed)
 
 MTRand ()
 
 MTRand (const rand_type::result_type seed)
 
std::string name () const override
 Get the name of the random number generation algorithm.
 
void rand_bytes (unsigned char *buf, size_t size) override
 Fill a buffer with random bytes.
 
bool rand_bytes_noexcept (unsigned char *buf, size_t size) override
 Fill a buffer with random bytes without throwing exceptions.
 
rand_type::result_type rand ()
 
- Public Member Functions inherited from openvpn::RandomAPI
template<typename T >
void rand_fill (T &obj)
 Fill a data object with random bytes.
 
template<typename T >
rand_get ()
 Create a data object filled with random bytes.
 
template<typename T >
rand_get_positive ()
 Create a data object filled with random bytes, always >= 0 for signed types.
 
template<typename T >
randrange (const T end)
 Return a uniformly distributed random number in the range [0, end)
 
template<typename T >
randrange (const T start, const T end)
 Return a uniformly distributed random number in the range [start, end].
 
std::uint32_t randrange32 (const std::uint32_t end)
 Return a uniformly distributed random number in the range [0, end)
 
std::uint32_t randrange32 (const std::uint32_t start, const std::uint32_t end)
 Return a uniformly distributed random number in the range [start, end].
 
std::uint8_t randbyte ()
 Return a random byte.
 
bool randbool ()
 Return a random boolean.
 
result_type operator() ()
 
- Public Member Functions inherited from openvpn::RC< thread_unsafe_refcount >
 RC () noexcept=default
 
 RC (const RC &)=delete
 
virtual ~RC ()=default
 
RCoperator= (const RC &)=delete
 
olong use_count () const noexcept
 Delegates call to RCImpl and returns the result.
 

Private Member Functions

bool rndbytes (unsigned char *buf, size_t size)
 

Static Private Member Functions

static rand_type::result_type gen_seed (RandomAPI &seed)
 
static rand_type::result_type gen_seed ()
 

Private Attributes

rand_type rng
 
RandomByteStore< rand_typerbs
 

Additional Inherited Members

- Static Public Member Functions inherited from openvpn::RandomAPI
static constexpr result_type min ()
 
static constexpr result_type max ()
 
- Static Public Member Functions inherited from openvpn::RC< thread_unsafe_refcount >
static constexpr bool is_thread_safe ()
 Delegates call to RCImpl and returns the result.
 

Detailed Description

Definition at line 25 of file mtrandapi.hpp.

Member Typedef Documentation

◆ Ptr

Definition at line 30 of file mtrandapi.hpp.

◆ rand_type

typedef std::mt19937_64 openvpn::MTRand::rand_type

Definition at line 31 of file mtrandapi.hpp.

Constructor & Destructor Documentation

◆ MTRand() [1/3]

openvpn::MTRand::MTRand ( RandomAPI seed)
inline

Definition at line 33 of file mtrandapi.hpp.

◆ MTRand() [2/3]

openvpn::MTRand::MTRand ( )
inline

Definition at line 38 of file mtrandapi.hpp.

◆ MTRand() [3/3]

openvpn::MTRand::MTRand ( const rand_type::result_type  seed)
inline

Definition at line 43 of file mtrandapi.hpp.

Member Function Documentation

◆ gen_seed() [1/2]

static rand_type::result_type openvpn::MTRand::gen_seed ( )
inlinestaticprivate

Definition at line 86 of file mtrandapi.hpp.

◆ gen_seed() [2/2]

static rand_type::result_type openvpn::MTRand::gen_seed ( RandomAPI seed)
inlinestaticprivate

Definition at line 81 of file mtrandapi.hpp.

◆ name()

std::string openvpn::MTRand::name ( ) const
inlineoverridevirtual

Get the name of the random number generation algorithm.

Returns
The name of the algorithm

Implements openvpn::RandomAPI.

Definition at line 49 of file mtrandapi.hpp.

◆ OPENVPN_EXCEPTION()

openvpn::MTRand::OPENVPN_EXCEPTION ( mtrand_error  )

◆ rand()

rand_type::result_type openvpn::MTRand::rand ( )
inline

Definition at line 68 of file mtrandapi.hpp.

◆ rand_bytes()

void openvpn::MTRand::rand_bytes ( unsigned char *  buf,
size_t  size 
)
inlineoverridevirtual

Fill a buffer with random bytes.

Parameters
bufPointer to the buffer
sizeNumber of bytes to generate

Implements openvpn::RandomAPI.

Definition at line 55 of file mtrandapi.hpp.

◆ rand_bytes_noexcept()

bool openvpn::MTRand::rand_bytes_noexcept ( unsigned char *  buf,
size_t  size 
)
inlineoverridevirtual

Fill a buffer with random bytes without throwing exceptions.

Parameters
bufPointer to the buffer
sizeNumber of bytes to generate
Returns
true on success
false on failure

Implements openvpn::RandomAPI.

Definition at line 63 of file mtrandapi.hpp.

◆ rndbytes()

bool openvpn::MTRand::rndbytes ( unsigned char *  buf,
size_t  size 
)
inlineprivate

Definition at line 74 of file mtrandapi.hpp.

Here is the caller graph for this function:

Member Data Documentation

◆ rbs

RandomByteStore<rand_type> openvpn::MTRand::rbs
private

Definition at line 96 of file mtrandapi.hpp.

◆ rng

rand_type openvpn::MTRand::rng
private

Definition at line 95 of file mtrandapi.hpp.


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