System random number generation

OS-Entropy

The kernel's cryptographically secure random number generator, the right default

safe Safe API

About OS-Entropy

OS-Entropy is a system random number source from the Operating system RNG family. It is also known as os-rng and getrandom. NextSSL lists it in the safe tier and exposes it through the safe API.

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–2014
  1. Linux /dev/random introduced by Theodore Ts'o

  2. getrandom() system call added to Linux 3.17

How it works

  1. The kernel gathers entropy from hardware and system events into a pool.
  2. Once adequately seeded, a cryptographic generator (for example ChaCha20 on Linux) produces output.
  3. Applications request bytes through getrandom, getentropy or BCryptGenRandom.
  4. 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

Generating private keys and symmetric keysNonces, IVs, salts and session tokensSeeding HMAC_DRBG or other DRBGs

Sizes

The registry declares no fixed sizes for this algorithm.

Use it

from nextssl_demo import NextSSL

ns = NextSSL()              # safe API: safe and standard tiers
buf = ns.call("rng_fill", "os-entropy", None, 32)[0]

Calls follow the NextSSL C ABI and its language bindings. Buffer sizes are validated against the sizes above.

Frequently asked questions

What is OS-Entropy?

OS-Entropy is a RNG in the Operating system RNG family. The operating system RNG provides cryptographically secure random bytes seeded from hardware and environmental entropy. It is also known as os-rng, getrandom.

Is OS-Entropy safe to use?

OS-Entropy is in the safe tier. Modern and recommended. The default choice for new designs. It can be called from the safe API.