Rng class¶
- class crsyspqc.Rng¶
Random Number Generator to NIST SP800-90A.
- SEED_BYTES = 128¶
Size in bytes of seed file.
- class Strength¶
Required security strength for user-prompted entropy.
- BITS_112 = 0¶
112 bits of security
- BITS_128 = 1¶
128 bits of security (default)
- BITS_192 = 2¶
192 bits of security
- BITS_256 = 3¶
256 bits of security
- class Opts¶
RNG options.
- DEFAULT = 0¶
Default option
- NO_INTEL_DRNG = 524288¶
Turn off support for Intel(R) DRNG for the current session.
- static bytestring(n)¶
Generate an array of n random bytes.
- Parameters:
n (int) – Required number of random bytes.
- Returns:
Array of random bytes.
- Return type:
bytes
- static initialize(seedfilename)¶
Initialize the RNG generator using a seed file.
Use this function if Intel(R) DRNG is not available on your system (check using
Rng.initialize_ex()
). Call at the start of a session to load entropy stored in the seed file, and use again at the end of a session to save any accumulated entropy. If the seed file does not exist, it will be created using any available entropy. The seed file is automatically updated by this procedure. UseRng.make_seedfile()
to create the first time.- Parameters:
seedfilename (str) – Full path name of seed file.
- Returns:
Zero if successful.
- Return type:
int
- static initialize_ex(opts=0)¶
Query and initialize the RNG generator using Intel(R) DRNG, if available.
- Parameters:
opts (Rng.Opts) – Specify Rng.Opts.NO_INTEL_DRNG to explicitly turn off support.
- Returns:
Support status for Intel(R) DRNG. If available, then returns a positive value 1 or greater; else a negative error code.
- Return type:
int
- static make_seedfile(seedfilename, strength=1, prompt='')¶
Create a new seed file suitable for use with
Rng.initialize()
.This uses a dialog window and expects the user to type in random keystrokes. Such a GUI interface may not be appropriate in all circumstances.
- Parameters:
seedfilename (str) – Full path name of seed file to be created. Any existing file of the same name will be overwritten without warning.
strength (Rng.Strength) – Required security strength (default=128 bits).
prompt (str) – Optional prompt for dialog.
- Returns:
Zero if successful.
- Return type:
int