Commit dbc13f50 authored by Stephane Glondu's avatar Stephane Glondu
Browse files

MakeLwtRandom does not depend on a group

parent 5de170a2
......@@ -170,11 +170,12 @@ lwt election_table =
let metadata = metadata
end in
let module X : Web_common.WEB_ELECTION = struct
open Web_common
module G = G
module M = Web_common.MakeLwtRandom(G)
module M = MakeLwtRandom(struct let rng = make_rng () end)
module P = P
module E = Election.MakeElection(P)(M)
module B = Web_common.MakeBallotBox(P)(E)
module B = MakeBallotBox(P)(E)
let election_web = election_web
end in
X.B.inject_creds public_creds >>
......
......@@ -52,21 +52,25 @@ let load_from_file read fname =
close_in i;
result
module MakeLwtRandom (G : Signatures.GROUP) = struct
let make_rng = Lwt_preemptive.detach (fun () ->
Cryptokit.Random.(pseudo_rng (string secure_rng 16))
)
module type LWT_RNG = sig
val rng : Cryptokit.Random.rng Lwt.t
end
module MakeLwtRandom (X : LWT_RNG) = struct
type 'a t = 'a Lwt.t
let return = Lwt.return
let bind = Lwt.bind
let fail = Lwt.fail
let prng = Lwt_preemptive.detach (fun () ->
Cryptokit.Random.(pseudo_rng (string secure_rng 16))
) ()
let random q =
let size = Z.size q * Sys.word_size / 8 in
lwt prng = prng in
let r = Cryptokit.Random.string prng size in
lwt rng = X.rng in
let r = Cryptokit.Random.string rng size in
return Z.(of_bits r mod q)
end
......
......@@ -28,7 +28,13 @@ type election_web = {
can_vote : acl;
}
module MakeLwtRandom (G : Signatures.GROUP) : sig
val make_rng : unit -> Cryptokit.Random.rng Lwt.t
module type LWT_RNG = sig
val rng : Cryptokit.Random.rng Lwt.t
end
module MakeLwtRandom (X : LWT_RNG) : sig
(** {2 Monadic definitions} *)
......
Markdown is supported
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