package bytesrw
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha512=388858b0db210a62a16f56655746fdfadbc64b22c2abb5ed5a12b2872e4f8c34f045cdb953a5dda9b92f0003c7f9f34d70fa5b5bb19fd32fb6121bbaeb7ceba0
doc/bytesrw.sysrandom/Bytesrw_sysrandom/index.html
Module Bytesrw_sysrandomSource
Cryptographically 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.
Note. If you are already using Bytesrw_crypto rather use the randomness provided there.
Cryptographically secure pseurorandom bytes
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.
Primitives
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.
Cryptographically secure pseudorandom bytes
set_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:
getrandomon Linux.arc4random_bufon other Unixes.RtlGenRandomon Windows (safe to use despite the availability warning).- A stub that unconditionally raises
Panicotherwise.
Raises Panic in case of problem, not meant to be handled.
Entropy
set_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:
getentropyon POSIX systems.RtlGenRandomon Windows (safe to use despite the availability warning).- A stub that unconditionally raises
Panicotherwise.
Raises Panic in case of problem, not meant to be handled.