Bytesrw_sysrandomCryptographically secure pseudorandom byte streams and entropy.
This module provides cryptographically secure pseudorandom bytes and an entropy primitive using operating system sources. See the documentation of the primitives for details on the sources.
val reads :
?pos:Bytesrw.Bytes.Stream.pos ->
?slice_length:Bytesrw.Bytes.Slice.length ->
?length:int ->
unit ->
Bytesrw.Bytes.Reader.treads () is a stream of length, or unbounded if unspecified, cryptographically secure pseudorandom bytes in slice_length chunks (defaults to Bytesrw.Bytes.Slice.default_length).
Reads may raise Panic which is not turned into a stream error as it likely indicates a serious condition in the system, see the underlying call set_random.
string n are n cryptographically secure pseudorandom bytes. Raises Panic in case of problems, see the underlying call set_random.
bytes n are n cryptographically secure pseudorandom bytes. Raises Panic in case of problems, see the underlying call set_random.
Exception raised by primitives 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. It likely indicates a serious condition in the system.
val set_random : Bytesrw.Bytes.Slice.t -> unitset_random s writes the bytes in the slice range with cryptographically secure pseudorandom bytes. Theoretically this function should not block or error, 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).Panic otherwise.Raises Panic in case of problem, not meant to be handled.
val set_entropy : Bytesrw.Bytes.Slice.t -> unitset_entropy s write the bytes in the slice range with entropy from your operating system. The function blocks until enough entropy is gathered. The Bytesrw.Bytes.Slice.length of s must be smaller or equal to 256 or Invalid_argument is raised.
This uses:
getentropy on POSIX systems.RtlGenRandom on Windows (safe to use despite the availability warning).Panic otherwise.Raises Panic in case of problem, not meant to be handled.