package mirage-crypto-rng

  1. Overview
  2. Docs
A cryptographically secure PRNG

Install

dune-project
 Dependency

Authors

Maintainers

Sources

mirage-crypto-2.4.1.tbz
sha256=332886c365c6035077e3ce676a63da8f7500c15a1628b3c07e139b0e551f1f6f
sha512=cb8f4de93241cde0582bcd0283766c681a02dbcb9f3b4786eb0656c651f42ba2db467ff63bff79c5eacfd410e410d77dc31bfc51049c39e1e86685ec0a884c1f

doc/src/mirage-crypto-rng.unix/urandom.ml.html

Source file urandom.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
type g = Unix.file_descr

let block = 1

let create ?time:_ () =
  let fd =
    Unix.openfile "/dev/urandom" [ Unix.O_RDONLY; Unix.O_CLOEXEC ] 0
  in
  at_exit (fun () -> Unix.close fd);
  fd

let rec generate_into ~g buf ~off len =
  if len > 0 then
    try
      let n = Unix.read g buf off len in
      if n = 0 then failwith "couldn't read enough bytes from /dev/urandom"
      else generate_into ~g buf ~off:(off + n) (len - n)
    with
    | Unix.Unix_error (Unix.EINTR, _, _) -> generate_into ~g buf ~off len

let reseed ~g:_ _data = ()

let accumulate ~g:_ _source =
  `Acc (fun _data -> ())

let seeded ~g:_ = true

let pools = 0