Skip to content

nqrand(3)

nqrand — random bytes from the operating system

libnoqtis, -lnoqtis

#include <noqtis.h>

int
nqrand(uint8_t *buf, size_t len);

() fills buf with len bytes from the operating system's cryptographically secure random source: getrandom(2) on Linux, arc4random_buf(3) on macOS and the BSDs, () on Windows, and getentropy(3) under WebAssembly (WebCrypto () with emscripten, WASI () with wasi-sdk). Large requests are made in chunks. There is no fallback source and no user-space generator: when the operating system's source fails, so does nqrand().

Every function of noqtis(3) that needs randomness (key generation, hedged signing, encapsulation, mask shares) takes it from here.

buf holds len random bytes. A len of 0 succeeds and writes nothing.
[NQEARG]
buf is NULL and len is not 0.
[NQERNG]
The operating system's source failed.

uint8_t key[32];
if (nqrand(key, sizeof key) != NQOK)
  abort();
/* ... use the key ... */
nqwipe(key, sizeof key);

noqtis(3), nqwipe(3)