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

Remove ELECTION_PARAMS

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