Commit 6be755f1 authored by Stephane Glondu's avatar Stephane Glondu
Browse files

Move randomness into Crypto

parent 40ab5e1a
......@@ -59,12 +59,19 @@ let check_election p =
(** Simple monad *)
let prng = lazy (Cryptokit.Random.(pseudo_rng (string secure_rng 32)))
module MakeSimpleMonad (G : GROUP) = struct
type 'a t = 'a
let ballots = ref []
let return x = x
let bind x f = f x
let random q = Util.random q
let random q =
let size = Z.size q * Sys.word_size / 8 in
let r = Cryptokit.Random.string (Lazy.force prng) size in
Z.(of_bits r mod q)
type ballot = G.t Serializable_t.ballot
let cast x = ballots := x :: !ballots
let fold f x = List.fold_left (fun accu b -> f b accu) x !ballots
......
......@@ -148,12 +148,3 @@ let non_empty_lines_of_file fname =
Lwt_io.lines_of_file fname |>
Lwt_stream.filter (fun s -> s <> "") |>
Lwt_stream.to_list
let seed = lazy (Cryptokit.Random.(string secure_rng 32))
let prng = Cryptokit.Random.(pseudo_rng (Lazy.force seed))
let random q =
let size = Z.size q * Sys.word_size / 8 in
let r = Cryptokit.Random.string prng size in
Z.(of_bits r mod q)
......@@ -39,5 +39,3 @@ val hashB : string -> string
val load_from_file : (Yojson.lexer_state -> Lexing.lexbuf -> 'a) ->
string -> 'a
val non_empty_lines_of_file : string -> string list Lwt.t
val random : Z.t -> Z.t
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment