Secure Random Number Generator

#cryptxdevquotes: We get about 20% more entropy from this algorithm revision. In related news, I have about 20% less sanity today. - Anthony Cagliano

Module Functionality
Provides secure randomness that can be used for the creation of random artifacts — encryption secrets, salts, and nonces — for use with other modules.

The security of modern encryption depends almost entirely on the ability to generate secure randomness within your cryptosystem. Many random number generators, such as the rand() function in the toolchain, only appear random but are actually deterministic–a single output maps to a single computable output. This may suffice for your Solitare app’s card stack but not for generating an encryption key. Generators intended for use with cryptography need to operate within additional constraints centered around unpredictability. For details on what this means, as well as to view how this generator holds up, see the Analysis & Overview page.


uint32_t cryptx_csrand_get(void)

Returns a securely psuedo-random 32-bit integer.


A securely psuedo-random 32-bit integer.

// returning a single 32-bit random integer
uint32_t rand = cryptx_csrand_get();

bool cryptx_csrand_fill(void *buffer, size_t size)

Fills a buffer with securely pseduo-random bytes.

  • buffer – Pointer to a buffer to fill with random bytes.

  • size – Size of the buffer to fill.


true on success, false on failure.


buffer filled to size.

// filling a buffer with random bytes
#define BUFLEN  16
uint8_t rand[BUFLEN];
cryptx_csrand_fill(rand, BUFLEN);