File: prngtest.ml

package info (click to toggle)
cryptokit 1.21.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 904 kB
  • sloc: ansic: 6,655; ml: 4,790; makefile: 5
file content (49 lines) | stat: -rw-r--r-- 1,802 bytes parent folder | download | duplicates (4)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(***********************************************************************)
(*                                                                     *)
(*                      The Cryptokit library                          *)
(*                                                                     *)
(*            Xavier Leroy, projet Gallium, INRIA Paris                *)
(*                                                                     *)
(*  Copyright 2017 Institut National de Recherche en Informatique et   *)
(*  en Automatique.  All rights reserved.  This file is distributed    *)
(*  under the terms of the GNU Library General Public License, with    *)
(*  the special exception on linking described in file LICENSE.        *)
(*                                                                     *)
(***********************************************************************)

(* Generate pseudorandom data on stdout, for testing with "dieharder" *)

open Cryptokit

let output_pr_data rng =
  let b = Bytes.create 64 in
  while true do
    rng#random_bytes b 0 64;
    output stdout b 0 64
  done

let usage() =
  prerr_string {|Usage:
    ./prngtest.native aes-ctr  | dieharder -a -g 200
    ./prngtest.native chacha20 | dieharder -a -g 200
    ./prngtest.native hardware | dieharder -a -g 200
Warning: each dieharder run takes a long time.
|};
  exit 2

let _ =
  let seed =
    if Array.length Sys.argv > 2
    then Sys.argv.(2)
    else "Supercalifragilistusexpialidolcius" in
  let rng =
    if Array.length Sys.argv > 1 then begin
      match Sys.argv.(1) with
      | "aes-ctr"  -> Random.pseudo_rng_aes_ctr seed
      | "chacha20" -> Random.pseudo_rng seed
      | "hardware" -> Random.hardware_rng ()
      | _          -> usage()
    end else usage() in
  output_pr_data rng