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

#include <rand.hpp>

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

Public Types

typedef RCPtr< MbedTLSRandomPtr
 
- Public Types inherited from openvpn::StrongRandomAPI
typedef RCPtr< StrongRandomAPIPtr
 Smart pointer type for managing the ownership of StrongRandomAPI 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 (rand_error_mbedtls)
 
 MbedTLSRandom (StrongRandomAPI::Ptr entropy_source)
 
 MbedTLSRandom ()
 
virtual ~MbedTLSRandom ()
 
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.
 
mbedtls_ctr_drbg_context * get_ctr_drbg_ctx ()
 
- 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

int rndbytes (unsigned char *buf, size_t size)
 

Static Private Member Functions

static int entropy_poll (void *arg, unsigned char *output, size_t len)
 

Private Attributes

mbedtls_ctr_drbg_context ctx
 
RandomAPI::Ptr entropy
 

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 30 of file rand.hpp.

Member Typedef Documentation

◆ Ptr

Definition at line 35 of file rand.hpp.

Constructor & Destructor Documentation

◆ MbedTLSRandom() [1/2]

openvpn::MbedTLSRandom::MbedTLSRandom ( StrongRandomAPI::Ptr  entropy_source)
inline

Definition at line 38 of file rand.hpp.

◆ MbedTLSRandom() [2/2]

openvpn::MbedTLSRandom::MbedTLSRandom ( )
inline

Definition at line 50 of file rand.hpp.

◆ ~MbedTLSRandom()

virtual openvpn::MbedTLSRandom::~MbedTLSRandom ( )
inlinevirtual

Definition at line 55 of file rand.hpp.

Member Function Documentation

◆ entropy_poll()

static int openvpn::MbedTLSRandom::entropy_poll ( void *  arg,
unsigned char *  output,
size_t  len 
)
inlinestaticprivate

Definition at line 103 of file rand.hpp.

Here is the caller graph for this function:

◆ get_ctr_drbg_ctx()

mbedtls_ctr_drbg_context * openvpn::MbedTLSRandom::get_ctr_drbg_ctx ( )
inline

function to get the mbedtls_ctr_drbg_context. This is needed for the pk_parse methods in mbed TLS 3.0 that require a random number generator to avoid side channel attacks when loading private keys. The returned context is tied to the internal state of this random number generator.

Definition at line 92 of file rand.hpp.

Here is the caller graph for this function:

◆ name()

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

Get the name of the random number generation algorithm.

Returns
The name of the algorithm

Implements openvpn::RandomAPI.

Definition at line 62 of file rand.hpp.

◆ OPENVPN_EXCEPTION()

openvpn::MbedTLSRandom::OPENVPN_EXCEPTION ( rand_error_mbedtls  )

◆ rand_bytes()

void openvpn::MbedTLSRandom::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 72 of file rand.hpp.

◆ rand_bytes_noexcept()

bool openvpn::MbedTLSRandom::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 81 of file rand.hpp.

◆ rndbytes()

int openvpn::MbedTLSRandom::rndbytes ( unsigned char *  buf,
size_t  size 
)
inlineprivate

Definition at line 98 of file rand.hpp.

Here is the caller graph for this function:

Member Data Documentation

◆ ctx

mbedtls_ctr_drbg_context openvpn::MbedTLSRandom::ctx
private

Definition at line 124 of file rand.hpp.

◆ entropy

RandomAPI::Ptr openvpn::MbedTLSRandom::entropy
private

Definition at line 125 of file rand.hpp.


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