nqrand(3)
NAME
nqrand — random
bytes from the operating system
LIBRARY
libnoqtis, -lnoqtis
SYNOPSIS
#include
<noqtis.h>
int
nqrand(uint8_t
*buf, size_t
len);
DESCRIPTION
nqrand()
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,
BCryptGenRandom()
on Windows, and
getentropy(3)
under WebAssembly (WebCrypto
getRandomValues()
with emscripten, WASI
random_get()
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.
RETURN VALUES
NQOK- buf holds len random bytes. A len of 0 succeeds and writes nothing.
- [
NQEARG] - buf is
NULLand len is not 0. - [
NQERNG] - The operating system's source failed.
EXAMPLES
uint8_t key[32]; if (nqrand(key, sizeof key) != NQOK) abort(); /* ... use the key ... */ nqwipe(key, sizeof key);