Module Bytesrw_crypto.Random

Cryptographically secure pseudorandom byte streams.

This module provides cryptographically secure pseudorandom bytes. See the documentation of the primitive for details on the source.

Note. If you are only interested in this bit from the library you may want to use Bytesrw_sysrandom which depends only on your operating system.

Cryptographically secure pseurorandom bytes

val reads : ?pos:Bytesrw.Bytes.Stream.pos -> ?slice_length:Bytesrw.Bytes.Slice.length -> ?length:int -> unit -> Bytesrw.Bytes.Reader.t

reads () 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.

val string : int -> string

string n are n cryptographically secure pseudorandom bytes. Raises Panic in case of problems, see the underlying call set_random.

val bytes : int -> bytes

bytes n are n cryptographically secure pseudorandom bytes. Raises Panic in case of problems, see the underlying call set_random.

Primitive

val set_random : Bytesrw.Bytes.Slice.t -> unit

set_random s writes the bytes in the slice range with cryptographically secure pseudorandom bytes.

This uses:

Raises Panic if Psa.generate_random errors. 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.