NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
ndn::random Namespace Reference

Typedefs

using RandomNumberEngine = std::mt19937
 

Functions

uint32_t generateSecureWord32 ()
 Generate a cryptographically secure random integer from the range [0, 2^32) More...
 
uint64_t generateSecureWord64 ()
 Generate a cryptographically secure random integer from the range [0, 2^64) More...
 
void generateSecureBytes (span< uint8_t > buffer)
 Fill buffer with cryptographically secure random bytes. More...
 
RandomNumberEnginegetRandomNumberEngine ()
 Returns a reference to a thread-local instance of a properly seeded PRNG. More...
 
uint32_t generateWord32 ()
 Generate a non-cryptographically-secure random integer in the range [0, 2^32) More...
 
uint64_t generateWord64 ()
 Generate a non-cryptographically-secure random integer in the range [0, 2^64) More...
 

Typedef Documentation

◆ RandomNumberEngine

using ndn::random::RandomNumberEngine = typedef std::mt19937

Definition at line 57 of file random.hpp.

Function Documentation

◆ generateSecureWord32()

uint32_t ndn::random::generateSecureWord32 ( )

Generate a cryptographically secure random integer from the range [0, 2^32)

Exceptions
std::runtime_errorif generation fails.

Definition at line 29 of file random.cpp.

References generateSecureBytes().

◆ generateSecureWord64()

uint64_t ndn::random::generateSecureWord64 ( )

Generate a cryptographically secure random integer from the range [0, 2^64)

Exceptions
std::runtime_errorif generation fails.

Definition at line 37 of file random.cpp.

References generateSecureBytes().

Referenced by ndn::security::tpm::BackEnd::constructAsymmetricKeyName().

◆ generateSecureBytes()

void ndn::random::generateSecureBytes ( span< uint8_t >  buffer)

Fill buffer with cryptographically secure random bytes.

Exceptions
std::runtime_errorif generation fails.

Definition at line 45 of file random.cpp.

References NDN_THROW, and ndn::to_string().

Referenced by ndn::security::transform::PrivateKey::decrypt(), generateSecureWord32(), generateSecureWord64(), and ndn::security::InterestSigner::makeSignedInterest().

◆ getRandomNumberEngine()

RandomNumberEngine & ndn::random::getRandomNumberEngine ( )

Returns a reference to a thread-local instance of a properly seeded PRNG.

Warning
The returned RandomNumberEngine MUST NOT be used when cryptographically secure random numbers are needed.

Definition at line 54 of file random.cpp.

Referenced by nfd::fw::asf::ProbingModule::afterForwardingProbe(), nfd::fw::RandomStrategy::afterReceiveInterest(), generateWord32(), generateWord64(), nfd::fw::asf::ProbingModule::isProbingNeeded(), and nfd::rib::randomizeTimer().

◆ generateWord32()

uint32_t ndn::random::generateWord32 ( )

Generate a non-cryptographically-secure random integer in the range [0, 2^32)

This version is faster than generateSecureWord32, but it must not be used when cryptographically secure random integers are needed (e.g., when creating signing or encryption keys)

Definition at line 66 of file random.cpp.

References getRandomNumberEngine().

Referenced by ndn::generateNonce(), and ndn::util::NotificationSubscriberBase::stop().

◆ generateWord64()

uint64_t ndn::random::generateWord64 ( )

Generate a non-cryptographically-secure random integer in the range [0, 2^64)

This version is faster than generateSecureWord64, but it must not be used when cryptographically secure random integers are needed (e.g., when creating signing or encryption keys)

Definition at line 73 of file random.cpp.

References getRandomNumberEngine().

Referenced by ndn::security::InterestSigner::makeCommandInterest().