Attention une mise à jour du service Gitlab va être effectuée le mardi 18 janvier (et non lundi 17 comme annoncé précédemment) entre 18h00 et 18h30. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes.

Commit 97ce1d4d authored by Stephane Glondu's avatar Stephane Glondu
Browse files

Combinators take a list instead of an array

parent 1ca08985
......@@ -563,7 +563,7 @@ module MakeElection (G : GROUP) (M : RANDOM) = struct
type result = elt Serializable_t.result
type combinator = factor array -> elt array array
type combinator = factor list -> elt array array
let compute_result num_tallied encrypted_tally partial_decryptions combinator =
let factors = combinator partial_decryptions in
......
......@@ -125,7 +125,7 @@ type 'a encrypted_tally = 'a ciphertext list <ocaml repr="array"> list <ocaml re
type 'a result = {
num_tallied : int;
encrypted_tally : 'a encrypted_tally;
partial_decryptions : 'a partial_decryption list <ocaml repr="array">;
partial_decryptions : 'a partial_decryption list;
result : plaintext;
}
......
......@@ -223,9 +223,9 @@ module type ELECTION = sig
(** The election result. It contains the needed data to validate the
result from the encrypted tally. *)
type combinator = factor array -> elt array array
type combinator = factor list -> elt array array
val compute_result : int -> ciphertext -> factor array -> combinator -> result
val compute_result : int -> ciphertext -> factor list -> combinator -> result
(** Combine the encrypted tally and the factors from all trustees to
produce the election result. The first argument is the number of
tallied ballots. May raise [Invalid_argument]. *)
......@@ -274,5 +274,5 @@ module type PEDERSEN = sig
val combine : elt threshold_parameters -> elt
type checker = elt -> elt partial_decryption -> bool
val combine_factors : checker -> elt threshold_parameters -> elt partial_decryption array -> elt array array
val combine_factors : checker -> elt threshold_parameters -> elt partial_decryption list -> elt array array
end
......@@ -72,10 +72,13 @@ module MakeSimpleDistKeyGen (G : GROUP) (M : RANDOM) = struct
type checker = G.t -> G.t partial_decryption -> bool
let combine_factors checker pks pds =
assert (Array.length pds > 0);
let dummy = Array.mmap (fun _ -> G.one) pds.(0).decryption_factors in
assert (Array.forall (fun pk -> Array.exists (checker pk) pds) pks);
Array.fold_left (fun a b ->
let dummy =
match pds with
| x :: _ -> Array.mmap (fun _ -> G.one) x.decryption_factors
| [] -> failwith "no partial decryptions"
in
assert (Array.forall (fun pk -> List.exists (checker pk) pds) pks);
List.fold_left (fun a b ->
Array.mmap2 ( *~ ) a b.decryption_factors
) dummy pds
......@@ -238,8 +241,11 @@ module MakePedersen (G : GROUP) (M : RANDOM)
) Z.one indexes
let combine_factors checker t pds =
assert (Array.length pds > 0);
let dummy = Array.mmap (fun _ -> G.one) pds.(0).decryption_factors in
let dummy =
match pds with
| x :: _ -> Array.mmap (fun _ -> G.one) x.decryption_factors
| [] -> failwith "no partial decryptions"
in
let pds_with_ids =
List.map (fun pd ->
match Array.findi (fun i vk ->
......@@ -248,7 +254,7 @@ module MakePedersen (G : GROUP) (M : RANDOM)
with
| Some i -> i+1, pd
| None -> raise (PedersenFailure "a partial decryption does not correspond to any verification key")
) (Array.to_list pds)
) pds
in
let pds_with_ids =
let compare (a, _) (b, _) = Pervasives.compare a b in
......
......@@ -44,7 +44,7 @@ module MakeSimpleDistKeyGen (G : GROUP) (M : RANDOM) : sig
(** Combine all public key shares into an election public key. *)
type checker = G.t -> G.t partial_decryption -> bool
val combine_factors : checker -> G.t array -> G.t partial_decryption array -> G.t array array
val combine_factors : checker -> G.t array -> G.t partial_decryption list -> G.t array array
end
(** Simple distributed generation of an election public key. *)
......
......@@ -391,7 +391,7 @@ module Election : CMDLINER_MODULE = struct
let factors =
let fname = dir/"partial_decryptions.jsons" in
match load_from_file (fun x -> x) fname with
| Some factors -> Array.of_list factors
| Some factors -> factors
| None -> failwith "cannot load partial decryptions"
in
let oc = open_out (dir/"result.json") in
......
......@@ -38,7 +38,7 @@ module type S = sig
val vote : string option -> int array array -> string
val decrypt : string -> string
val tdecrypt : string -> string -> string
val finalize : string array -> string
val finalize : string list -> string
val verify : unit -> unit
end
......@@ -195,7 +195,7 @@ module Make (P : PARSED_PARAMS) : S = struct
string_of_partial_decryption G.write factor
let finalize factors =
let factors = Array.map (partial_decryption_of_string G.read) factors in
let factors = List.map (partial_decryption_of_string G.read) factors in
let tally = Lazy.force encrypted_tally in
let checker = E.check_factor tally in
let combinator =
......
......@@ -12,7 +12,7 @@ module type S = sig
val vote : string option -> int array array -> string
val decrypt : string -> string
val tdecrypt : string -> string -> string
val finalize : string array -> string
val finalize : string list -> string
val verify : unit -> unit
end
......
......@@ -251,7 +251,7 @@ module ToolElection = struct
end in
let module X = (val make (module P : PARAMS) : S) in
let factors = get_textarea "election_factors" |> split_lines in
set_textarea "election_result" (X.finalize (Array.of_list factors))
set_textarea "election_result" (X.finalize factors)
let cmds = [
"do_encrypt", create_ballot;
......
......@@ -1415,7 +1415,7 @@ let handle_election_tally_release (uuid, ()) () =
in
let checker = E.check_factor et in
let combinator = KG.combine_factors checker pks in
let result = E.compute_result ntallied et pds combinator in
let result = E.compute_result ntallied et (Array.to_list pds) combinator in
let%lwt () =
let open Lwt_io in
with_file
......
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