rand.nx
buildroot/runtime/rand.nx
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
imports: syscalls.nx
imported by: csrf_token.nxdp.nxnanoid.nxoauth2_pkce.nxobs.nxsession_id.nxulid.nxuuid.nxx25519_ephemeral.nx
structs
| none |
consts
| none |
functions
| 22 | func rand_fd_slot() -> *i64 { |
| 41 | func rand_open_urandom() -> i64 {
called by 1: rand_bytes |
| 48 | func rand_bytes(out: *u8, n: i64) -> i64 {
called by 13: csrf_token_newdp_noisy_countdp_noisy_sumnanoidpkce_verifier_newspan_new+7 calls 2: rand_open_urandomsys_read |
| 68 | func rand_u64() -> i64 { |
| 77 | func rand_below(bound: i64) -> i64 {
calls 1: rand_u64 |