Operating system RNG
The kernel's cryptographically secure random number generator, the right default
Overview
The operating system RNG provides cryptographically secure random bytes seeded from hardware and environmental entropy. It is the correct source for keys, nonces, salts and tokens, and the recommended seed for any user-space DRBG.
Modern kernels collect entropy from interrupt timing, hardware random number instructions such as RDRAND and RDSEED, boot-time seeds and other sources, and feed it into a cryptographic generator. Linux uses a ChaCha20-based design behind getrandom(2) and /dev/urandom; Windows exposes BCryptGenRandom; macOS and the BSDs provide getentropy and arc4random. These interfaces are designed to block only until the generator is initially seeded and then never run out.
Calling the OS RNG directly avoids most failure modes of user-space generators: state duplication after fork, poor seeding at boot and implementation bugs. NextSSL's os-entropy wraps the platform interface, preferring system calls such as getrandom over device files. On Linux, getrandom blocks only until the generator is first seeded, while on Windows, BCryptGenRandom is available from boot. Where a platform cannot provide secure randomness, the correct behaviour is to fail loudly rather than return weak output.
History
1994–2014Linux /dev/random introduced by Theodore Ts'o
getrandom() system call added to Linux 3.17
How it works
- The kernel gathers entropy from hardware and system events into a pool.
- Once adequately seeded, a cryptographic generator (for example ChaCha20 on Linux) produces output.
- Applications request bytes through getrandom, getentropy or BCryptGenRandom.
- The kernel reseeds periodically and on events such as VM resume, where supported.
Security notes
Considered the safest default. Early-boot or freshly cloned virtual machines can have reduced entropy on some platforms; avoid reading device files that may be unavailable in sandboxes, and check for errors rather than falling back to weak sources.
Typical uses
Variants in NextSSL
1| Algorithm | Tier | Sizes (bytes) | Standards | API |
|---|---|---|---|---|
| OS-Entropy os-entropy |
safe | — | — | safe |
Frequently asked questions
Which Operating system RNG variants does NextSSL include?
NextSSL registers 1 Operating system RNG variant: os-entropy.
Related
ARX stream cipher with a one-time Poly1305 MAC; fast and constant-time in software
HMAC_DRBGNIST SP 800-90A deterministic random bit generator built on HMAC
ML-KEMNIST's primary post-quantum key encapsulation mechanism, standardised in FIPS 203
HMACThe standard way to build a MAC from a cryptographic hash (RFC 2104, FIPS 198-1)
EdDSADeterministic Edwards-curve signatures: Ed25519 and Ed448
ChaChaBernstein's ARX stream cipher; ChaCha20 secures much of today's TLS, SSH and VPN traffic