TSDuck v3.40-4033
MPEG Transport Stream Toolkit
|
Improved system-provided PRNG (pseudo-random numbers generator). More...
#include <tsBetterSystemRandomGenerator.h>
Public Member Functions | |
virtual UString | name () const override |
Algorithm name (informational only). | |
virtual bool | read (void *, size_t) override |
Get random data. | |
virtual bool | readByteBlock (ByteBlock &data, size_t size) |
Get random data in a byte block. | |
template<typename INT_T > requires std::integral<INT_T> | |
bool | readInt (INT_T &value, INT_T min=std::numeric_limits< INT_T >::min(), INT_T max=std::numeric_limits< INT_T >::max()) |
Get a random integer value inside a defined range. | |
virtual bool | ready () const override |
Check if the PRNG is ready. | |
virtual bool | seed (const void *, size_t) override |
Seed (add entropy) to the PRNG. | |
Static Public Member Functions | |
static BetterSystemRandomGenerator & | Instance () |
Get the instance of the singleton of this class. | |
Improved system-provided PRNG (pseudo-random numbers generator).
Use SystemRandomGenerator as base and add AES-based post-processing. Implemented as a thread-safe singleton.
An entropy state is stored in $HOME/.tsseed. The value of a state is initially loaded from this file. The first time the generator is used (no file), the state is loaded from the system PRNG.
A fixed AES-128 key K is used for the post-processing. The size of the state is 16 bytes, the AES block size.
Description of post-processing, added to the sytem PRNG:
Known limitations:
|
inlinestatic |
Get the instance of the singleton of this class.
|
overridevirtual |
Algorithm name (informational only).
Reimplemented from ts::SystemRandomGenerator.
|
overridevirtual |
Check if the PRNG is ready.
If not ready, it must be seeded again.
Reimplemented from ts::SystemRandomGenerator.
|
overridevirtual |
Get random data.
[out] | addr | Address of returned random data. |
[in] | size | Requested size in bytes of random data. The method always fill the buffer. |
Reimplemented from ts::SystemRandomGenerator.
|
overridevirtualinherited |
Seed (add entropy) to the PRNG.
[in] | addr | Address of entropy data. |
[in] | size | Size in bytes of entropy data. |
Implements ts::RandomGenerator.
|
virtualinherited |
Get random data in a byte block.
The default implementation uses read().
[out] | data | Returned random data. |
[in] | size | Requested size in bytes of random data. |
|
inherited |
Get a random integer value inside a defined range.
INT_T | An integer type for the result. |
[out] | value | The return integer value. |
[in] | min | Minimum value to return. |
[in] | max | Maximum value to return. |