CryptoSys PKI  23.0.0
Public Types | Static Public Member Functions | List of all members
dipki::Rng Class Reference

Random Number Generator to NIST SP800-90. More...

Public Types

enum  Opts : unsigned int
 Rng options More...
 

Static Public Member Functions

static bvec_t Bytes (int n)
 Generate an array of random bytes. More...
 
static std::string Guid ()
 Generate a random 36-character Global Unique IDentifier (GUID) string according to RFC4122. More...
 
static int Initialize (const std::string &seedFile)
 Initialize the RNG generator using a seed file. More...
 
static int InitializeEx (Opts opts=Opts::Default)
 Query and initialize the RNG generator using Intel(R) DRNG, if available. More...
 
static int Number (int lower, int upper)
 Generate a random integer in a given range. More...
 
static int Octet ()
 Generate a single random octet (byte) More...
 
static int UpdateSeedFile (const std::string &seedFile)
 Update the RNG seed file with more entropy. More...
 

Detailed Description

Random Number Generator to NIST SP800-90.

Member Enumeration Documentation

◆ Opts

enum dipki::Rng::Opts : unsigned int

Rng options

Enumerator
Default 

Default options.

NoIntelDrng 

Turn off support for INTEL(R) DRNG for the current session.

Member Function Documentation

◆ Bytes()

static bvec_t dipki::Rng::Bytes ( int  n)
static

Generate an array of random bytes.

Parameters
nRequired number of random bytes
Returns
Array of random bytes

◆ Guid()

static std::string dipki::Rng::Guid ( )
static

Generate a random 36-character Global Unique IDentifier (GUID) string according to RFC4122.

Returns
String of the form "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" where 'x' is a hexadecimal digit [0-9a-f].
cout << dipki::Rng::Guid() << endl;
// 1a68cbf1-0ebb-43e8-a0a7-4d000c82e33c
static std::string Guid()
Generate a random 36-character Global Unique IDentifier (GUID) string according to RFC4122.

◆ Initialize()

static int dipki::Rng::Initialize ( const std::string &  seedFile)
static

Initialize the RNG generator using a seed file.

Parameters
seedFileFull path name of seed file.
Returns
Zero on success.
Remarks
If the seed file does not exist, it will be created. If it exists, it will be automatically updated with more entropy (the same as using Rng::UpdateSeedFile)

◆ InitializeEx()

static int dipki::Rng::InitializeEx ( Opts  opts = Opts::Default)
static

Query and initialize the RNG generator using Intel(R) DRNG, if available.

Parameters
optsOption flags (optional)
Returns
Support status for Intel(R) DRNG. If available, then a positive value (1,2,3); else a negative error code.

◆ Number()

static int dipki::Rng::Number ( int  lower,
int  upper 
)
static

Generate a random integer in a given range.

Parameters
lowerlower value of range
upperupper value of range
Returns
Random integer x: lower <= x <= upper

◆ Octet()

static int dipki::Rng::Octet ( )
static

Generate a single random octet (byte)

Returns
Integer value randomly chosen between 0 and 255.

◆ UpdateSeedFile()

static int dipki::Rng::UpdateSeedFile ( const std::string &  seedFile)
static

Update the RNG seed file with more entropy.

Parameters
seedFileFull path name of seed file.
Returns
Zero on success.
Copyright © 2004-24 D.I. Management Services Pty Limited t/a CryptoSys ABN 78 083 210 584 Australia. All rights reserved. <www.di-mgt.com.au> <www.cryptosys.net>. Generated on Mon Sep 23 2024 15:37:33 by Doxygen 1.9.1.