|
rlib
Convenience library for useful things
|
OS-entropy sources plus cryptographic (ChaCha20 DRBG, system) and statistical (KISS, Mersenne Twister) PRNGs. More...
Go to the source code of this file.
Macros | |
| #define | r_rand_std_srand(seed) srand (seed) |
Seed the C-library rand() with seed. | |
| #define | r_rand_std_rand() rand () |
Single sample from the C-library rand(). | |
| #define | r_rand_prng_new r_prng_new_kiss |
| Default PRNG constructor (currently KISS). | |
| #define | r_prng_ref r_ref_ref |
| Take a reference (alias for r_ref_ref). | |
| #define | r_prng_unref r_ref_unref |
| Drop a reference (alias for r_ref_unref). | |
Typedefs | |
| typedef struct RPrng | RPrng |
| Opaque, refcounted PRNG handle. | |
Functions | |
| rboolean | r_rand_entropy_fill (ruint8 *buf, rsize size) |
Fill buf with size bytes of cryptographic-grade OS entropy. | |
| ruint64 | r_rand_entropy_u64 (void) |
| Read a 64-bit value from the OS entropy source. | |
| ruint32 | r_rand_entropy_u32 (void) |
| Read a 32-bit value from the OS entropy source. | |
| ruint64 | r_prng_get_u64 (RPrng *prng) |
Draw a 64-bit sample from prng. | |
| rboolean | r_prng_fill (RPrng *prng, ruint8 *buf, rsize size) |
Fill buf with size pseudo-random bytes from prng. | |
| rboolean | r_prng_fill_nonzero (RPrng *prng, ruint8 *buf, rsize size) |
| Like r_prng_fill, but every byte is guaranteed non-zero. | |
| rboolean | r_prng_fill_base64 (RPrng *prng, rchar *buf, rsize size) |
Fill buf with size base64-alphabet characters; useful for token / nonce generation. | |
PRNG constructors | |
| RPrng * | r_prng_new_crypto (void) |
| Cryptographically-secure PRNG: a ChaCha20 DRBG seeded from the OS entropy source and periodically reseeded. | |
| RPrng * | r_prng_new_system (void) |
| Cryptographically-secure PRNG that reads every output directly from the OS entropy source (see r_rand_entropy_fill). | |
| RPrng * | r_prng_new_kiss (void) |
| KISS PRNG seeded from OS entropy. | |
| RPrng * | r_prng_new_kiss_with_seed (ruint64 x, ruint64 y, ruint64 z, ruint64 c) |
| KISS PRNG with explicit four-component seed. | |
| RPrng * | r_prng_new_mt (void) |
| Mersenne Twister PRNG seeded from OS entropy. | |
| RPrng * | r_prng_new_mt_with_seed (ruint64 seed) |
| Mersenne Twister PRNG seeded from a single 64-bit value. | |
| RPrng * | r_prng_new_mt_with_seed_array (const ruint64 *array, rsize size) |
| Mersenne Twister PRNG seeded from an array of 64-bit values (recommended for reproducing a specific state). | |
OS-entropy sources plus cryptographic (ChaCha20 DRBG, system) and statistical (KISS, Mersenne Twister) PRNGs.