Commit 7d274e7a authored by Stephane Glondu's avatar Stephane Glondu
Browse files

Use raw ballots for hashing

parent cf5d746a
......@@ -93,7 +93,7 @@ let load_elections_and_votes dirname =
Lwt_stream.map (fun x ->
let v = Serializable_compat_j.ballot_of_string Serializable_builtin_j.read_number x in
assert (Uuidm.equal uuid v.election_uuid);
v
x, v
)
) else Lwt_stream.from_direct (fun () -> None)
in
......@@ -102,37 +102,3 @@ let load_elections_and_votes dirname =
| None -> assert false
) else Lwt.return None
)
let concat s l f = String.concat s (List.map f (Array.to_list l))
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)
) ^
"#" ^
concat "|" a.individual_proofs (fun p ->
concat "/" p (fun pi ->
Printf.sprintf "%a,%a,%a,%a"
Z.sprint pi.dp_commitment.a
Z.sprint pi.dp_commitment.b
Z.sprint pi.dp_challenge
Z.sprint pi.dp_response
)
) ^
"#" ^
concat "/" a.overall_proof (fun pi ->
Printf.sprintf "%a,%a,%a,%a"
Z.sprint pi.dp_commitment.a
Z.sprint pi.dp_commitment.b
Z.sprint pi.dp_challenge
Z.sprint pi.dp_response
)
) ^
"#" ^ v.election_hash ^
"#" ^ (Uuidm.to_string v.election_uuid) |>
hashB
let hash_user v =
Serializable_compat_j.string_of_user v |>
hashB
......@@ -7,8 +7,7 @@ type election_data = {
public_data : Z.t election_public_data;
}
val load_elections_and_votes :
string -> (election_data * Z.t ballot Lwt_stream.t) Lwt_stream.t
val hashB : string -> string
val hash_ballot : Z.t ballot -> string
val hash_user : user -> string
val load_elections_and_votes :
string -> (election_data * (string * Z.t ballot) Lwt_stream.t) Lwt_stream.t
......@@ -32,8 +32,8 @@ let () =
lwt () = Ocsipersist.add elections_table uuid e in
let uuid_underscored = String.map (function '-' -> '_' | c -> c) uuid in
let table = Ocsipersist.open_table ("ballots_" ^ uuid_underscored) in
lwt () = Lwt_stream.iter_s (fun v ->
Ocsipersist.add table (Common.hash_ballot v) v
lwt () = Lwt_stream.iter_s (fun (r, v) ->
Ocsipersist.add table (Common.hashB r) v
) ballots in
return ()
) |>
......@@ -193,7 +193,7 @@ let () = Eliom_registration.Html5.register
if
Uuidm.equal uuid ballot.election_uuid &&
E.check_ballot (Serializable_compat.ballot ballot)
then `Valid (Common.hash_ballot ballot)
then `Valid (Common.hashB raw_ballot)
else `Invalid
with e -> `Malformed
in
......
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