OpenVPN 3 Core Library
Loading...
Searching...
No Matches
openvpn::RandomAPI Class Referenceabstract

Abstract base class for random number generators. More...

#include <randapi.hpp>

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

Public Types

typedef RCPtr< RandomAPIPtr
 Smart pointer type for managing the ownership of RandomAPI objects.
 
- Public Types inherited from openvpn::RC< thread_unsafe_refcount >
typedef RCPtr< RCPtr
 

Public Member Functions

virtual std::string name () const =0
 Get the name of the random number generation algorithm.
 
virtual void rand_bytes (unsigned char *buf, size_t size)=0
 Fill a buffer with random bytes.
 
virtual bool rand_bytes_noexcept (unsigned char *buf, size_t size)=0
 Fill a buffer with random bytes without throwing exceptions.
 
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.
 
- 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

 RandomAPI ()=default
 

Friends

class StrongRandomAPI
 
class WeakRandomAPI
 

UniformRandomBitGenerator members

These members implement the C++11 UniformRandomBitGenerator requirements so that RandomAPI instances can be used with std::shuffle (and others). See https://en.cppreference.com/w/cpp/named_req/UniformRandomBitGenerator

typedef unsigned int result_type
 
result_type operator() ()
 
static constexpr result_type min ()
 
static constexpr result_type max ()
 

Additional Inherited Members

- 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

Abstract base class for random number generators.

This class cannot be inherited from directly, use StrongRandomAPI or WeakRandomAPI to implement random number generators.

Definition at line 38 of file randapi.hpp.

Member Typedef Documentation

◆ Ptr

Smart pointer type for managing the ownership of RandomAPI objects.

Definition at line 45 of file randapi.hpp.

◆ result_type

typedef unsigned int openvpn::RandomAPI::result_type

Definition at line 199 of file randapi.hpp.

Constructor & Destructor Documentation

◆ RandomAPI()

openvpn::RandomAPI::RandomAPI ( )
privatedefault

Member Function Documentation

◆ max()

static constexpr result_type openvpn::RandomAPI::max ( )
inlinestaticconstexpr

Definition at line 204 of file randapi.hpp.

◆ min()

static constexpr result_type openvpn::RandomAPI::min ( )
inlinestaticconstexpr

Definition at line 200 of file randapi.hpp.

◆ name()

virtual std::string openvpn::RandomAPI::name ( ) const
pure virtual

Get the name of the random number generation algorithm.

Returns
The name of the algorithm

Implemented in openvpn::AppleRandom, openvpn::MbedTLSRandom, openvpn::OpenSSLRandom, openvpn::DevURand, openvpn::MTRand, FakeSecureRand, and IntegralMin< IntegralT >.

Here is the caller graph for this function:

◆ operator()()

result_type openvpn::RandomAPI::operator() ( )
inline

Definition at line 208 of file randapi.hpp.

◆ rand_bytes()

virtual void openvpn::RandomAPI::rand_bytes ( unsigned char *  buf,
size_t  size 
)
pure virtual

Fill a buffer with random bytes.

Parameters
bufPointer to the buffer
sizeNumber of bytes to generate

Implemented in openvpn::AppleRandom, openvpn::MbedTLSRandom, openvpn::OpenSSLRandom, openvpn::DevURand, openvpn::MTRand, FakeSecureRand, and IntegralMin< IntegralT >.

Here is the caller graph for this function:

◆ rand_bytes_noexcept()

virtual bool openvpn::RandomAPI::rand_bytes_noexcept ( unsigned char *  buf,
size_t  size 
)
pure virtual

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

Implemented in openvpn::AppleRandom, openvpn::MbedTLSRandom, openvpn::OpenSSLRandom, openvpn::DevURand, openvpn::MTRand, FakeSecureRand, and IntegralMin< IntegralT >.

Here is the caller graph for this function:

◆ rand_fill()

template<typename T >
void openvpn::RandomAPI::rand_fill ( T &  obj)
inline

Fill a data object with random bytes.

Template Parameters
TType of the object
Parameters
objReference to the object to be filled

Definition at line 75 of file randapi.hpp.

Here is the caller graph for this function:

◆ rand_get()

template<typename T >
T openvpn::RandomAPI::rand_get ( )
inline

Create a data object filled with random bytes.

Template Parameters
TType of the object
Returns
The generated object

Definition at line 86 of file randapi.hpp.

Here is the caller graph for this function:

◆ rand_get_positive()

template<typename T >
T openvpn::RandomAPI::rand_get_positive ( )
inline

Create a data object filled with random bytes, always >= 0 for signed types.

Template Parameters
TType of the object
Returns
The generated data object

Definition at line 99 of file randapi.hpp.

◆ randbool()

bool openvpn::RandomAPI::randbool ( )
inline

Return a random boolean.

Returns
The generated random boolean

Definition at line 186 of file randapi.hpp.

Here is the caller graph for this function:

◆ randbyte()

std::uint8_t openvpn::RandomAPI::randbyte ( )
inline

Return a random byte.

Returns
The generated random byte

Definition at line 175 of file randapi.hpp.

Here is the caller graph for this function:

◆ randrange() [1/2]

template<typename T >
T openvpn::RandomAPI::randrange ( const T  end)
inline

Return a uniformly distributed random number in the range [0, end)

Template Parameters
TType of the object
Parameters
endThe upper bound (exclusive)
Returns
The generated random number

Definition at line 117 of file randapi.hpp.

Here is the caller graph for this function:

◆ randrange() [2/2]

template<typename T >
T openvpn::RandomAPI::randrange ( const T  start,
const T  end 
)
inline

Return a uniformly distributed random number in the range [start, end].

Template Parameters
TType of the object
Parameters
startThe lower bound
endThe upper bound
Returns
The generated random number

Definition at line 130 of file randapi.hpp.

◆ randrange32() [1/2]

std::uint32_t openvpn::RandomAPI::randrange32 ( const std::uint32_t  end)
inline

Return a uniformly distributed random number in the range [0, end)

Parameters
endThe upper bound (exclusive)
Returns
The generated random number

If end==0 or end==1, will always return 0. This version is strictly 32-bit only and optimizes by avoiding integer division.

Definition at line 147 of file randapi.hpp.

Here is the caller graph for this function:

◆ randrange32() [2/2]

std::uint32_t openvpn::RandomAPI::randrange32 ( const std::uint32_t  start,
const std::uint32_t  end 
)
inline

Return a uniformly distributed random number in the range [start, end].

Parameters
startThe lower bound
endThe upper bound
Returns
The generated random number

This version is strictly 32-bit only and optimizes by avoiding integer division.

Definition at line 163 of file randapi.hpp.

Friends And Related Symbol Documentation

◆ StrongRandomAPI

friend class StrongRandomAPI
friend

Definition at line 215 of file randapi.hpp.

◆ WeakRandomAPI

friend class WeakRandomAPI
friend

Definition at line 216 of file randapi.hpp.


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