Commit 5619037f authored by Stephane Glondu's avatar Stephane Glondu
Browse files

Remove ELECTION_PARAMS

It was redundant with ELECTION_DATA.
parent f9442ef3
...@@ -94,20 +94,16 @@ module MakeLwtJsMonad (G : GROUP) = struct ...@@ -94,20 +94,16 @@ module MakeLwtJsMonad (G : GROUP) = struct
end end
let encryptBallot params cred plaintext () = let encryptBallot params cred plaintext () =
let module P = (val params : ELECTION_PARAMS) in let module P = (val params : ELECTION_DATA) in
let module G = P.G in let module G = P.G in
let module M = MakeLwtJsMonad (G) in let module M = MakeLwtJsMonad (G) in
let module E = Election.MakeElection (G) (M) in let module E = Election.MakeElection (G) (M) in
let e = {
e_params = P.params;
e_fingerprint = P.fingerprint;
} in
let sk = let sk =
let hex = derive_cred P.params.e_uuid cred in let hex = derive_cred P.election.e_params.e_uuid cred in
Z.(of_string_base 16 hex mod G.q) Z.(of_string_base 16 hex mod G.q)
in in
lwt randomness = E.make_randomness e () in lwt randomness = E.make_randomness P.election () in
lwt b = E.create_ballot e ~sk randomness plaintext () in lwt b = E.create_ballot P.election ~sk randomness plaintext () in
let s = string_of_ballot G.write b in let s = string_of_ballot G.write b in
setTextarea "ballot" s; setTextarea "ballot" s;
setNodeById "ballot_tracker" (sha256_b64 s); setNodeById "ballot_tracker" (sha256_b64 s);
...@@ -332,13 +328,14 @@ let loadElection () = ...@@ -332,13 +328,14 @@ let loadElection () =
setDisplayById "booth_div" "block"; setDisplayById "booth_div" "block";
let election_raw = getTextarea "election_params" |> drop_trailing_newline in let election_raw = getTextarea "election_params" |> drop_trailing_newline in
let election_params = Group.election_params_of_string election_raw in let election_params = Group.election_params_of_string election_raw in
let module P = (val election_params : ELECTION_PARAMS) in let module P = (val election_params : ELECTION_DATA) in
setNodeById "election_name" P.params.e_name; let params = P.election.e_params in
setNodeById "election_description" P.params.e_description; setNodeById "election_name" params.e_name;
setNodeById "election_uuid" (Uuidm.to_string P.params.e_uuid); setNodeById "election_description" params.e_description;
setNodeById "election_fingerprint" P.fingerprint; setNodeById "election_uuid" (Uuidm.to_string params.e_uuid);
setNodeById "election_fingerprint" P.election.e_fingerprint;
withElementById "intro" (fun e -> withElementById "intro" (fun e ->
let b = createStartButton election_params e P.params.e_questions in let b = createStartButton election_params e params.e_questions in
withElementById "input_code" (fun e -> Dom.appendChild e b) withElementById "input_code" (fun e -> Dom.appendChild e b)
) )
......
...@@ -43,7 +43,9 @@ let election_params_of_string x = ...@@ -43,7 +43,9 @@ let election_params_of_string x =
let {wpk_group=group; wpk_y=y} = params.e_public_key in let {wpk_group=group; wpk_y=y} = params.e_public_key in
let module X = struct let module X = struct
module G = (val Group_field.make group : Group_field.GROUP) module G = (val Group_field.make group : Group_field.GROUP)
let params = {params with e_public_key = y} let election = {
let fingerprint = sha256_b64 x e_params = {params with e_public_key = y};
e_fingerprint = sha256_b64 x;
}
end in end in
(module X : ELECTION_PARAMS) (module X : ELECTION_DATA)
...@@ -28,5 +28,5 @@ val of_string : string -> (module GROUP) ...@@ -28,5 +28,5 @@ val of_string : string -> (module GROUP)
val read : (module GROUP) reader val read : (module GROUP) reader
val election_params_of_string : string -> (module ELECTION_PARAMS) val election_params_of_string : string -> (module ELECTION_DATA)
(** Parse a [Serializable_t.params]. *) (** Parse a [Serializable_t.params]. *)
...@@ -92,13 +92,6 @@ module type GROUP = sig ...@@ -92,13 +92,6 @@ module type GROUP = sig
end end
(** Election params wrapped with its group. *)
module type ELECTION_PARAMS = sig
module G : GROUP
val params : G.t params
val fingerprint : string
end
(** Monad signature. *) (** Monad signature. *)
module type MONAD = sig module type MONAD = sig
type 'a t type 'a t
......
...@@ -44,7 +44,7 @@ end ...@@ -44,7 +44,7 @@ end
module type PARSED_PARAMS = sig module type PARSED_PARAMS = sig
include PARAMS include PARAMS
include ELECTION_PARAMS include ELECTION_DATA
end end
let parse_params p = let parse_params p =
...@@ -52,7 +52,7 @@ let parse_params p = ...@@ -52,7 +52,7 @@ let parse_params p =
let params = Group.election_params_of_string P.election in let params = Group.election_params_of_string P.election in
let module R = struct let module R = struct
include P include P
include (val params : ELECTION_PARAMS) include (val params : ELECTION_DATA)
end in end in
(module R : PARSED_PARAMS) (module R : PARSED_PARAMS)
...@@ -75,7 +75,7 @@ module Make (P : PARSED_PARAMS) : S = struct ...@@ -75,7 +75,7 @@ module Make (P : PARSED_PARAMS) : S = struct
| Some pks -> | Some pks ->
assert (Array.forall KG.check pks); assert (Array.forall KG.check pks);
let y' = KG.combine pks in let y' = KG.combine pks in
assert G.(params.e_public_key =~ y') assert G.(election.e_params.e_public_key =~ y')
| None -> () | None -> ()
let public_keys = let public_keys =
...@@ -89,11 +89,6 @@ module Make (P : PARSED_PARAMS) : S = struct ...@@ -89,11 +89,6 @@ module Make (P : PARSED_PARAMS) : S = struct
| Some pks -> pks | Some pks -> pks
| None -> failwith "missing public keys" | None -> failwith "missing public keys"
let e = {
e_params = params;
e_fingerprint = fingerprint;
}
(* Load ballots, if present *) (* Load ballots, if present *)
module GSet = Set.Make (G) module GSet = Set.Make (G)
...@@ -127,7 +122,7 @@ module Make (P : PARSED_PARAMS) : S = struct ...@@ -127,7 +122,7 @@ module Make (P : PARSED_PARAMS) : S = struct
) )
let cast (b, hash) = let cast (b, hash) =
if Lazy.force check_signature_present b && E.check_ballot e b if Lazy.force check_signature_present b && E.check_ballot election b
then M.cast b () then M.cast b ()
else Printf.ksprintf failwith "ballot %s failed tests" hash else Printf.ksprintf failwith "ballot %s failed tests" hash
...@@ -141,18 +136,18 @@ module Make (P : PARSED_PARAMS) : S = struct ...@@ -141,18 +136,18 @@ module Make (P : PARSED_PARAMS) : S = struct
| Some () -> | Some () ->
M.fold (fun () b t -> M.fold (fun () b t ->
M.return (E.combine_ciphertexts (E.extract_ciphertext b) t) M.return (E.combine_ciphertexts (E.extract_ciphertext b) t)
) (E.neutral_ciphertext e) () ) (E.neutral_ciphertext election) ()
) )
let vote privcred ballot = let vote privcred ballot =
let sk = let sk =
privcred |> option_map (fun cred -> privcred |> option_map (fun cred ->
let hex = derive_cred e.e_params.e_uuid cred in let hex = derive_cred election.e_params.e_uuid cred in
Z.(of_string_base 16 hex mod G.q) Z.(of_string_base 16 hex mod G.q)
) )
in in
let b = E.create_ballot e ?sk (E.make_randomness e ()) ballot () in let b = E.create_ballot election ?sk (E.make_randomness election ()) ballot () in
assert (E.check_ballot e b); assert (E.check_ballot election b);
string_of_ballot G.write b string_of_ballot G.write b
let decrypt privkey = let decrypt privkey =
...@@ -171,7 +166,7 @@ module Make (P : PARSED_PARAMS) : S = struct ...@@ -171,7 +166,7 @@ module Make (P : PARSED_PARAMS) : S = struct
let tally = Lazy.force encrypted_tally in let tally = Lazy.force encrypted_tally in
assert (Array.forall2 (E.check_factor tally) pks factors); assert (Array.forall2 (E.check_factor tally) pks factors);
let result = E.combine_factors (M.cardinal ()) tally factors in let result = E.combine_factors (M.cardinal ()) tally factors in
assert (E.check_result e pks result); assert (E.check_result election pks result);
string_of_result G.write result string_of_result G.write result
let verify () = let verify () =
...@@ -181,7 +176,7 @@ module Make (P : PARSED_PARAMS) : S = struct ...@@ -181,7 +176,7 @@ module Make (P : PARSED_PARAMS) : S = struct
); );
(match get_result () with (match get_result () with
| Some result -> | Some result ->
assert (E.check_result e pks (result_of_string G.read result)) assert (E.check_result election pks (result_of_string G.read result))
| None -> print_msg "W: no result to check" | None -> print_msg "W: no result to check"
); );
print_msg "I: all checks passed" print_msg "I: all checks passed"
......
...@@ -77,13 +77,8 @@ module T = Web_templates ...@@ -77,13 +77,8 @@ module T = Web_templates
let web_election_data (raw_election, web_params) = let web_election_data (raw_election, web_params) =
let params = Group.election_params_of_string raw_election in let params = Group.election_params_of_string raw_election in
let module P = (val params : ELECTION_PARAMS) in
let module D = struct let module D = struct
module G = P.G include (val params : ELECTION_DATA)
let election = {
e_params = P.params;
e_fingerprint = P.fingerprint;
}
include (val web_params : WEB_PARAMS) include (val web_params : WEB_PARAMS)
end in end in
(module D : WEB_ELECTION_DATA) (module D : WEB_ELECTION_DATA)
...@@ -108,8 +103,8 @@ let import_election f = ...@@ -108,8 +103,8 @@ let import_election f =
) )
in in
let params = Group.election_params_of_string raw_election in let params = Group.election_params_of_string raw_election in
let module P = (val params : ELECTION_PARAMS) in let module P = (val params : ELECTION_DATA) in
let uuid = Uuidm.to_string P.params.e_uuid in let uuid = Uuidm.to_string P.election.e_params.e_uuid in
lwt exists = lwt exists =
try_lwt try_lwt
lwt _ = Ocsipersist.find election_ptable uuid in lwt _ = Ocsipersist.find election_ptable uuid in
...@@ -159,7 +154,7 @@ let import_election f = ...@@ -159,7 +154,7 @@ let import_election f =
) in ) in
if not (Array.forall KG.check pks) then if not (Array.forall KG.check pks) then
failwith "Public keys are invalid."; failwith "Public keys are invalid.";
if not G.(P.params.e_public_key =~ KG.combine pks) then if not G.(P.election.e_params.e_public_key =~ KG.combine pks) then
failwith "Public keys mismatch with election public key."; failwith "Public keys mismatch with election public key.";
let public_creds = Lwt_io.lines_of_file f.f_public_creds in let public_creds = Lwt_io.lines_of_file f.f_public_creds in
lwt () = Lwt_stream.( lwt () = Lwt_stream.(
......
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