randombytes(3)
π randombytes(3) β bestie's guide to filling a buffer with random data π
okay so this is randombytes(3), and honestly? she's that girl. let me put you on.
β¨ NAME β¨
randombytes β fill a buffer with random data π²β¨
πΈ SYNOPSIS πΈ
#include <randombytes.h>
unsigned char x[xbytes];
randombytes(x,xbytes);
Link with -lrandombytes. π
π¦ DESCRIPTION π¦
randombytes sets x[0], x[1], ..., x[xbytes-1] to random bytes of data. like, every single one. no skips. periodt. π
so here's the tea: randomness APIs all differ from each other in three major ways, and randombytes was literally designed to be the easy one in every single one of them. slay:
- Like
RAND_bytes,randombytesautomatically generates separate randomness for any number of bytes in any number of calls in any number of threads in any number of programs. π for comparison, some randomness APIs (e.g.,random) recycle randomness from one program to another unless the program does extra work to set a separate βseedβ, and can recycle randomness across multiple threads unless the program does further work. π - Like
getrandomandgetentropyandRAND_bytes,randombytesaims for the stringent goal of ensuring that no feasible computation will ever be able to tell the difference between the output bytes and true randomness. π the caller can treat each returned byte as the result of 8 fresh coin flips. πͺ for comparison, some randomness APIs (e.g.,random) do not aim for this goal and do not view detectable patterns as a bug, as long as most applications do not notice the patterns. π - Like
random,randombytesalways succeeds. β¨ any necessary resources (e.g., opening a file descriptor for/dev/urandom, on systems that need this) are allocated at program startup, rather than being deferred until the firstrandombytescall; also, dynamic failure cases such asEINTRare handled insiderandombytes. π«Ά for comparison, some randomness APIs (e.g.,getrandomandgetentropyandRAND_bytes) can return error codes to be handled by the caller. π
β οΈ okay bestie, listen: there are some programs that try to close all file descriptors. these programs must limit their library use to libraries that promise not to keep file descriptors open. in particular, these programs must not userandombytes(which keeps a file descriptor open on some systems) or other libraries callingrandombytes. no cap, that's a hard rule. π«
π LINK DETAILS π
currently -lrandombytes is a frontend symbolic link to either -lrandombytes-kernel or -lrandombytes-openssl as a backend library. π¦ to simplify system-wide replacement of the backend library, typical applications should dynamically link to -lrandombytes rather than to -lrandombytes-kernel or -lrandombytes-openssl. iykyk. π
applications that link statically to -lrandombytes also need -lcrypto if -lrandombytes is -lrandombytes-openssl. π
currently randombytes is a macro, where the function actually linked is randombytes_internal_void_voidstar_longlong. yes that's the real name, she's iconic like that. π
π HISTORY π
the randombytes API was introduced in 2008 as part of the SUPERCOP (https://bench.cr.yp.to) benchmarking framework for cryptographic software. β
similar previous APIs include RAND_bytes and arc4random_buf, but RAND_bytes was allowed to return failures and arc4random_buf was using the broken RC4 stream cipher. π not the RC4 jumpscare fr fr.
π SEE ALSO π
getrandom(2)getentropy(2)rand(3)random(3)arc4random(3)urandom(4)
and that's the whole page bestie π₯° it's from the randombytes(3) manual β no version number, no date, just vibes and bytes. go forth and be random πβ¨ππ¦πΈπ
π«Ά
π¦ where this page comes from
- debian trixie: librandombytes-dev 0~20240318-3 Β· LicenseRef-PD-hp OR CC0-1.0 OR 0BSD OR MIT-0 OR MIT
- fedora 43: librandombytes-devel 20240318-1.fc43 Β· LicenseRef-Fedora-Public-Domain OR 0BSD OR MIT-0 OR MIT
- fedora 43: librandombytes-devel 20240318-1.fc43 Β· LicenseRef-Fedora-Public-Domain OR 0BSD OR MIT-0 OR MIT
- fedora 44: librandombytes-devel 20240318-1.fc44 Β· LicenseRef-Fedora-Public-Domain OR 0BSD OR MIT-0 OR MIT
- fedora 44: librandombytes-devel 20240318-1.fc44 Β· LicenseRef-Fedora-Public-Domain OR 0BSD OR MIT-0 OR MIT
- nixos 26.05: librandombytes 20240318
- nixpkgs unstable: librandombytes 20240318
- ubuntu noble: librandombytes-dev 0~20230919-4 Β· LicenseRef-PD-hp OR CC0-1.0 OR 0BSD OR MIT-0 OR MIT
- ubuntu questing: librandombytes-dev 0~20240318-3build1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms