Module Webs_cryptorand

Cryptographically 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.

Pseudo random bytes

val get_random : int -> string

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:

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.

Entropy

val get_entropy : int -> string

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:

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.