Webs_cryptorandCryptographically secure pseudorandom bytes and entropy.
This modules provides cryptographically secure pseudorandom bytes and entropy by using operating system sources. See the invidual functions for details on the used C functions.
get_random n returns n cryptographically secure pseudorandom bytes. Theoretically this function should not block, except perhaps if you try to use it in early OS boot phase.
This uses:
getrandom on Linux.arc4random_buf on other Unixes.RtlGenRandom on Windows (safe to use despite the availability warning).Sys_error otherwise.Raises Sys_error in case of problem. If this happens do not try to handle the exception, log it at the toplevel of your program and abort the program or the server request. It likely indicates a serious error condition in the system.
get_entropy n returns n bytes of entropy from your operating system. The function blocks until enough entropy is gathered. n must be smaller or equal to 256.
This uses:
getentropy on POSIX systems.RtlGenRandom on Windows (safe to use despite the availability warning).Sys_error otherwise.Raises Sys_error in case of problem. If this happen do not try to handle the exception, log it at the toplevel of your program and abort the program or the server request. It likely indicates a serious error condition in the system.