code wiki / (root) / rand.nx

rand.nx

buildroot/runtime/rand.nx

3577 B98 linesdepth 3pulls 3 transitivereach 9 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

rand.nx -- cryptographically secure random bytes via /dev/urandom. Phase G5 in the roadmap. Opens /dev/urandom once, reads on demand. Used for session tokens, CSRF, post IDs, crypto nonces. Not suitable for massive random streams (~200 MB/s ceiling); good enough for the compiler + server use cases. Lifecycle: first call to rand_bytes() or rand_u64() lazily opens /dev/urandom and caches the fd in a heap-stored i64. Subsequent calls reuse the same fd. Two primary entry points: rand_bytes(out, n) -- fill `n` bytes into `out`; returns bytes read rand_u64() -- return a single 64-bit value

dependencies 1 imports · 9 importers

syscalls.nx rand.nx csrf_token.nx dp.nx nanoid.nx oauth2_pkce.nx obs.nx session_id.nx ulid.nx uuid.nx x25519_ephemeral.nx

imports: syscalls.nx

imported by: csrf_token.nxdp.nxnanoid.nxoauth2_pkce.nxobs.nxsession_id.nxulid.nxuuid.nxx25519_ephemeral.nx

structs

none

consts

none

functions

22func rand_fd_slot() -> *i64 {
41func rand_open_urandom() -> i64 {
called by 1: rand_bytes
48func rand_bytes(out: *u8, n: i64) -> i64 {
68func rand_u64() -> i64 {
called by 1: rand_below calls 1: rand_bytes
77func rand_below(bound: i64) -> i64 {
calls 1: rand_u64