Commit fb0af322 authored by Stephane Glondu's avatar Stephane Glondu

s/vote/ballot/g

Technical terminology:
 * EN: 1 vote = 1 signature + 1 ballot
 * FR: 1 vote = 1 émargement + 1 suffrages
parent 24b229ee
......@@ -399,7 +399,7 @@ let election_view ~election ~user =
] in
base ~title:election.Common.election.e_name ~header:[] ~content
let vote_cast ~election ~result =
let cast_ballot ~election ~result =
let title = election.Common.election.e_name in
let content = [
h2 ~a:[a_class ["title"]] [
......@@ -407,7 +407,7 @@ let vote_cast ~election ~result =
];
br ();
div [
pcdata "Your vote in ";
pcdata "Your ballot for ";
em [pcdata election.Common.election.e_name];
(match result with
| `Valid hash -> pcdata (" is valid, its hash is " ^ hash)
......
......@@ -38,12 +38,12 @@ let load_elections_and_votes dirname =
load_from_file (Helios_datatypes_j.read_election_public_data Core_datatypes_j.read_number)
in
let fingerprint = hashB raw in
let votes =
let file = data "votes.json" in
let ballots =
let file = data "ballots.json" in
if Sys.file_exists file then (
Lwt_io.lines_of_file file |>
Lwt_stream.map (fun x ->
let v = Helios_datatypes_j.vote_of_string Core_datatypes_j.read_number x in
let v = Helios_datatypes_j.ballot_of_string Core_datatypes_j.read_number x in
assert (Uuidm.equal uuid v.election_uuid);
v
)
......@@ -60,14 +60,14 @@ let load_elections_and_votes dirname =
) else Lwt_stream.from_direct (fun () -> None)
in
let election_data = { raw; fingerprint; election; public_data } in
Lwt.return (Some (election_data, votes, voters))
Lwt.return (Some (election_data, ballots, voters))
| None -> assert false
) else Lwt.return None
)
let concat s l f = String.concat s (List.map f (Array.to_list l))
let hash_vote v =
let hash_ballot v =
concat "//" v.answers (fun a ->
concat "|" a.choices (fun c ->
Printf.sprintf "%s,%s" (Z.to_string c.alpha) (Z.to_string c.beta)
......
......@@ -8,7 +8,7 @@ type election_data = {
}
val load_elections_and_votes :
string -> (election_data * Z.t vote Lwt_stream.t * voter Lwt_stream.t) Lwt_stream.t
string -> (election_data * Z.t ballot Lwt_stream.t * voter Lwt_stream.t) Lwt_stream.t
val hash_vote : Z.t vote -> string
val hash_ballot : Z.t ballot -> string
val hash_user : user -> string
......@@ -59,14 +59,14 @@ module type ELGAMAL_CRYPTO = sig
val verify_disjunction : t -> t -> t array -> t proof array -> bool
val verify_range : t -> int -> int -> t -> t -> t proof array -> bool
val verify_answer : t -> question -> t answer -> bool
val verify_vote : t election -> string -> t vote -> bool
val verify_ballot : t election -> string -> t ballot -> bool
val verify_equality : t -> t -> t -> t proof -> bool
val verify_partial_decryption : t election ->
t tally -> t trustee_public_key -> t partial_decryption -> bool
val verify_partial_decryptions : t election ->
t trustee_public_key array -> t result -> bool
val verify_result : t election -> t result -> bool
val compute_encrypted_tally : t election -> t vote array -> t encrypted_tally
val compute_encrypted_tally : t election -> t ballot array -> t encrypted_tally
end
module Make (G : GROUP) = struct
......@@ -144,7 +144,7 @@ module Make (G : GROUP) = struct
verify_range y q_min q_max alphas betas answer.overall_proof
in check (pred nb) one one)
let verify_vote e fingerprint v =
let verify_ballot e fingerprint v =
v.election_hash = fingerprint &&
e.e_uuid = v.election_uuid &&
Array.forall2 (verify_answer e.e_public_key.y) e.e_questions v.answers
......
......@@ -31,14 +31,14 @@ module type ELGAMAL_CRYPTO = sig
val verify_disjunction : t -> t -> t array -> t proof array -> bool
val verify_range : t -> int -> int -> t -> t -> t proof array -> bool
val verify_answer : t -> question -> t answer -> bool
val verify_vote : t election -> string -> t vote -> bool
val verify_ballot : t election -> string -> t ballot -> bool
val verify_equality : t -> t -> t -> t proof -> bool
val verify_partial_decryption : t election ->
t tally -> t trustee_public_key -> t partial_decryption -> bool
val verify_partial_decryptions : t election ->
t trustee_public_key array -> t result -> bool
val verify_result : t election -> t result -> bool
val compute_encrypted_tally : t election -> t vote array -> t encrypted_tally
val compute_encrypted_tally : t election -> t ballot array -> t encrypted_tally
end
module Make (G : GROUP) : ELGAMAL_CRYPTO with type t := G.t
......@@ -96,7 +96,7 @@ type 'a answer = {
overall_proof : 'a disjunctive_proof;
}
type 'a vote = {
type 'a ballot = {
answers : 'a answer list <ocaml repr="array">;
election_hash : string;
election_uuid : uuid;
......
......@@ -25,17 +25,17 @@ let () =
Ocsigen_messages.debug
(fun () -> "Loading elections from " ^ dir ^ "...");
Common.load_elections_and_votes dir |>
Lwt_stream.iter_s (fun (e, votes, voters) ->
Lwt_stream.iter_s (fun (e, ballots, voters) ->
let uuid = Uuidm.to_string e.Common.election.e_uuid in
Ocsigen_messages.debug
(fun () -> Printf.sprintf "-- loading %s (%s)" uuid e.Common.election.e_short_name);
lwt () = Ocsipersist.add elections_table uuid e in
let uuid_underscored = String.map (function '-' -> '_' | c -> c) uuid in
let table = Ocsipersist.open_table ("votes_" ^ uuid_underscored) in
let table = Ocsipersist.open_table ("ballots_" ^ uuid_underscored) in
let voters_table = Ocsipersist.open_table ("voters_" ^ uuid_underscored) in
lwt () = Lwt_stream.iter_s (fun v ->
Ocsipersist.add table (Common.hash_vote v) v
) votes in
Ocsipersist.add table (Common.hash_ballot v) v
) ballots in
lwt () = Lwt_stream.iter_s (fun v ->
Ocsipersist.add voters_table (Common.hash_user v.voter_user) v
) voters in
......@@ -130,9 +130,9 @@ let () = Eliom_registration.String.register
(if_eligible
(fun uuid election user () ->
let uuid_underscored = String.map (function '-' -> '_' | c -> c) (Uuidm.to_string uuid) in
let table = Ocsipersist.open_table ("votes_" ^ uuid_underscored) in
let table = Ocsipersist.open_table ("ballots_" ^ uuid_underscored) in
lwt ballots = Ocsipersist.fold_step (fun hash v res ->
let s = Helios_datatypes_j.string_of_vote Core_datatypes_j.write_number v ^ "\n" in
let s = Helios_datatypes_j.string_of_ballot Core_datatypes_j.write_number v ^ "\n" in
return (s :: res)
) table [] in
let result = String.concat "" ballots in
......@@ -179,20 +179,20 @@ let () = Eliom_registration.Redirection.register
let () = Eliom_registration.Html5.register
~service:Helios_services.election_cast_post
(if_eligible
(fun uuid election user evote ->
(fun uuid election user raw_ballot ->
let result =
try
let vote = Helios_datatypes_j.vote_of_string Core_datatypes_j.read_number evote in
let ballot = Helios_datatypes_j.ballot_of_string Core_datatypes_j.read_number raw_ballot in
let {g; p; q; y} = election.Common.election.e_public_key in
let module G = (val ElGamal.make_ff_msubgroup p q g : ElGamal.GROUP with type t = Z.t) in
let module Crypto = ElGamal.Make (G) in
if
Uuidm.equal uuid vote.election_uuid &&
Crypto.verify_vote election.Common.election election.Common.fingerprint vote
then `Valid (Common.hash_vote vote)
Uuidm.equal uuid ballot.election_uuid &&
Crypto.verify_ballot election.Common.election election.Common.fingerprint ballot
then `Valid (Common.hash_ballot ballot)
else `Invalid
with e -> `Malformed
in
Helios_templates.vote_cast ~election ~result
Helios_templates.cast_ballot ~election ~result
)
)
......@@ -10,7 +10,7 @@ module type TYPES = sig
val election : elt election t
val private_key : elt private_key t
val trustee_public_key : elt trustee_public_key t
val vote : elt vote t
val ballot : elt ballot t
val encrypted_tally : elt encrypted_tally t
val partial_decryption : elt partial_decryption t
val election_public_data : elt election_public_data t
......@@ -38,7 +38,7 @@ module MakeTypes (G : SGROUP) : TYPES with type elt = G.t = struct
let election = (read_election G.read, write_election G.write)
let private_key = (read_private_key G.read, write_private_key G.write)
let trustee_public_key = (read_trustee_public_key G.read, write_trustee_public_key G.write)
let vote = (read_vote G.read, write_vote G.write)
let ballot = (read_ballot G.read, write_ballot G.write)
let encrypted_tally = (read_encrypted_tally G.read, write_encrypted_tally G.write)
let partial_decryption = (read_partial_decryption G.read, write_partial_decryption G.write)
let election_public_data = (read_election_public_data G.read, write_election_public_data G.write)
......@@ -75,7 +75,7 @@ let verbose_assert msg it =
let r = Lazy.force it in
Printf.eprintf " %s\n%!" (if r then "OK" else "failed!")
let verbose_verify_election_test_data (e, votes, voters, private_data) =
let verbose_verify_election_test_data (e, ballots, voters, private_data) =
Printf.eprintf "Verifying election %S:\n%!" e.election.e_short_name;
let {g; p; q; y} = e.election.e_public_key in
let module G = (val ElGamal.make_ff_msubgroup p q g : ElGamal.GROUP with type t = Z.t) in
......@@ -85,18 +85,18 @@ let verbose_verify_election_test_data (e, votes, voters, private_data) =
e.election.e_public_key.y
e.public_data.public_keys
));
if Array.length votes = 0 then (
Printf.eprintf " no votes available\n%!"
if Array.length ballots = 0 then (
Printf.eprintf " no ballots available\n%!"
) else (
verbose_assert "votes" (lazy (
verbose_assert "ballots" (lazy (
Array.foralli (fun _ x ->
Crypto.verify_vote e.election e.fingerprint x
) votes
Crypto.verify_ballot e.election e.fingerprint x
) ballots
));
(match e.public_data.election_result with
| Some r ->
verbose_assert "encrypted tally" (lazy (
r.encrypted_tally = Crypto.compute_encrypted_tally e.election votes
r.encrypted_tally = Crypto.compute_encrypted_tally e.election ballots
))
| None -> ()
);
......@@ -111,7 +111,7 @@ let verbose_verify_election_test_data (e, votes, voters, private_data) =
| None -> Printf.eprintf " no results available\n%!"
);
verbose_assert "voter count" (lazy (
Array.length voters = Array.length votes
Array.length voters = Array.length ballots
));
verbose_assert "private keys" (lazy (
Array.foralli
......@@ -122,11 +122,11 @@ let verbose_verify_election_test_data (e, votes, voters, private_data) =
let load_election_and_verify_it_all dirname =
load_elections_and_votes dirname |>
Lwt_stream.to_list |> Lwt_main.run |>
List.map (fun (e, v, voters) ->
let votes = Lwt_stream.to_list v |> Lwt_main.run |> Array.of_list in
List.map (fun (e, ballots, voters) ->
let ballots = Lwt_stream.to_list ballots |> Lwt_main.run |> Array.of_list in
let voters = Lwt_stream.to_list voters |> Lwt_main.run |> Array.of_list in
let private_data = load_election_private_data dirname (Uuidm.to_string e.election.e_uuid) in
(e, votes, voters, private_data)
(e, ballots, voters, private_data)
) |>
List.iter verbose_verify_election_test_data;;
......
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