Commit 7a32ae5e authored by Stephane Glondu's avatar Stephane Glondu

Move question-specific code out of Election

parent 4badf1c4
Pipeline #67192 passed with stages
in 16 minutes and 44 seconds
......@@ -19,7 +19,7 @@
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
open Signatures
open Signatures_core
module Array : sig
include module type of Array
......
This diff is collapsed.
......@@ -21,14 +21,11 @@
(** Election primitives *)
open Serializable_t
open Signatures
val of_string : string -> Yojson.Safe.json election
val get_group : Yojson.Safe.json election -> (module ELECTION_DATA)
val question_length : question -> int
module Make (W : ELECTION_DATA) (M : RANDOM) :
ELECTION with type elt = W.G.t and type 'a m = 'a M.t
(** Implementation of {!Signatures.ELECTION}. *)
(**************************************************************************)
(* BELENIOS *)
(* *)
(* Copyright © 2012-2019 Inria *)
(* *)
(* This program is free software: you can redistribute it and/or modify *)
(* it under the terms of the GNU Affero General Public License as *)
(* published by the Free Software Foundation, either version 3 of the *)
(* License, or (at your option) any later version, with the additional *)
(* exemption that compiling, linking, and/or using OpenSSL is allowed. *)
(* *)
(* This program is distributed in the hope that it will be useful, but *)
(* WITHOUT ANY WARRANTY; without even the implied warranty of *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *)
(* Affero General Public License for more details. *)
(* *)
(* You should have received a copy of the GNU Affero General Public *)
(* License along with this program. If not, see *)
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
open Signatures_core
open Serializable_core_t
type question = Question_std_t.question
let read_question = Question_std_j.read_question
let write_question = Question_std_j.write_question
module type S = sig
type elt
type 'a m
val create_answer : question -> public_key:elt -> prefix:string -> int array -> Yojson.Safe.json m
val verify_answer : question -> public_key:elt -> prefix:string -> Yojson.Safe.json -> bool
val extract_ciphertexts : Yojson.Safe.json -> elt ciphertext array
end
module Make (M : RANDOM) (G : GROUP) = struct
type elt = G.t
type 'a m = 'a M.t
let ( >>= ) = M.bind
module Q = Question_std.Make (M) (G)
let create_answer q ~public_key ~prefix m =
Q.create_answer q ~public_key ~prefix m >>= fun answer ->
answer
|> Question_std_j.string_of_answer G.write
|> Yojson.Safe.from_string
|> M.return
let verify_answer q ~public_key ~prefix a =
a
|> Yojson.Safe.to_string
|> Question_std_j.answer_of_string G.read
|> Q.verify_answer q ~public_key ~prefix
let extract_ciphertexts a =
a
|> Yojson.Safe.to_string
|> Question_std_j.answer_of_string G.read
|> Q.extract_ciphertexts
end
(**************************************************************************)
(* BELENIOS *)
(* *)
(* Copyright © 2012-2019 Inria *)
(* *)
(* This program is free software: you can redistribute it and/or modify *)
(* it under the terms of the GNU Affero General Public License as *)
(* published by the Free Software Foundation, either version 3 of the *)
(* License, or (at your option) any later version, with the additional *)
(* exemption that compiling, linking, and/or using OpenSSL is allowed. *)
(* *)
(* This program is distributed in the hope that it will be useful, but *)
(* WITHOUT ANY WARRANTY; without even the implied warranty of *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *)
(* Affero General Public License for more details. *)
(* *)
(* You should have received a copy of the GNU Affero General Public *)
(* License along with this program. If not, see *)
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
open Signatures_core
open Serializable_core_t
type question = Question_std_t.question
val read_question : Yojson.Safe.lexer_state -> Lexing.lexbuf -> question
val write_question : Bi_outbuf.t -> question -> unit
module type S = sig
type elt
type 'a m
val create_answer : question -> public_key:elt -> prefix:string -> int array -> Yojson.Safe.json m
val verify_answer : question -> public_key:elt -> prefix:string -> Yojson.Safe.json -> bool
val extract_ciphertexts : Yojson.Safe.json -> elt ciphertext array
end
module Make (M : RANDOM) (G : GROUP) : S with type 'a m = 'a M.t and type elt = G.t
This diff is collapsed.
(**************************************************************************)
(* BELENIOS *)
(* *)
(* Copyright © 2012-2019 Inria *)
(* *)
(* This program is free software: you can redistribute it and/or modify *)
(* it under the terms of the GNU Affero General Public License as *)
(* published by the Free Software Foundation, either version 3 of the *)
(* License, or (at your option) any later version, with the additional *)
(* exemption that compiling, linking, and/or using OpenSSL is allowed. *)
(* *)
(* This program is distributed in the hope that it will be useful, but *)
(* WITHOUT ANY WARRANTY; without even the implied warranty of *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *)
(* Affero General Public License for more details. *)
(* *)
(* You should have received a copy of the GNU Affero General Public *)
(* License along with this program. If not, see *)
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
open Signatures_core
open Question_std_t
val question_length : question -> int
module type S = sig
type elt
type 'a m
val create_answer : question -> public_key:elt -> prefix:string -> int array -> elt answer m
val verify_answer : question -> public_key:elt -> prefix:string -> elt answer -> bool
val extract_ciphertexts : elt answer -> elt ciphertext array
end
module Make (M : RANDOM) (G : GROUP) : S with type 'a m = 'a M.t and type elt = G.t
......@@ -28,7 +28,7 @@ type number <ocaml predef from="Serializable_builtin"> = abstract
type uuid <ocaml predef from="Serializable_builtin"> = abstract
type 'a ciphertext <ocaml predef from="Serializable_core"> = abstract
type proof <ocaml predef from="Serializable_core"> = abstract
type question <ocaml predef from="Question_std"> = abstract
type question <ocaml module="Question"> = abstract
(** {2 Basic cryptographic datastructures} *)
......
......@@ -171,14 +171,7 @@ module type ELECTION = sig
answers and cryptographic proofs that they satisfy the election
constraints. *)
type randomness
(** Randomness needed to create a ballot. *)
val make_randomness : unit -> randomness m
(** Creates randomness for [create_ballot] below. The result can be
kept for Benaloh-style auditing. *)
val create_ballot : ?sk:private_key -> randomness -> plaintext -> ballot m
val create_ballot : ?sk:private_key -> plaintext -> ballot m
(** [create_ballot r answers] creates a ballot, or raises
[Invalid_argument] if [answers] doesn't satisfy the election
constraints. The private key, if given, will be used to sign
......
(**************************************************************************)
(* BELENIOS *)
(* *)
(* Copyright © 2012-2019 Inria *)
(* *)
(* This program is free software: you can redistribute it and/or modify *)
(* it under the terms of the GNU Affero General Public License as *)
(* published by the Free Software Foundation, either version 3 of the *)
(* License, or (at your option) any later version, with the additional *)
(* exemption that compiling, linking, and/or using OpenSSL is allowed. *)
(* *)
(* This program is distributed in the hope that it will be useful, but *)
(* WITHOUT ANY WARRANTY; without even the implied warranty of *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *)
(* Affero General Public License for more details. *)
(* *)
(* You should have received a copy of the GNU Affero General Public *)
(* License along with this program. If not, see *)
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
open Platform
(** Helpers for interacting with atd stuff *)
type 'a reader = Yojson.Safe.lexer_state -> Lexing.lexbuf -> 'a
type 'a writer = Bi_outbuf.t -> 'a -> unit
(** A group suitable for discrete logarithm-based cryptography. *)
module type GROUP = sig
(** The following interface is redundant: it is assumed, but not
checked, that usual mathematical relations hold. *)
type t
(** The type of elements. Note that it may be larger than the group
itself, hence the [check] function below. *)
val check : t -> bool
(** Check group membership. *)
val one : t
(** The neutral element of the group. *)
val g : t
(** A generator of the group. *)
val q : Z.t
(** The order of [g]. *)
val ( *~ ) : t -> t -> t
(** Multiplication. *)
val ( **~ ) : t -> Z.t -> t
(** Exponentiation. *)
val ( =~ ) : t -> t -> bool
(** Equality test. *)
val invert : t -> t
(** Inversion. *)
val to_string : t -> string
(** Conversion to string. *)
val of_string : string -> t
(** Conversion from string. *)
val read : t reader
(** Reading from a stream. *)
val write : t writer
(** Writing to a stream. *)
val hash : string -> t array -> Z.t
(** Hash an array of elements into an integer mod [q]. The string
argument is a string that is prepended before computing the hash. *)
val compare : t -> t -> int
(** A total ordering over the elements of the group. *)
type group
(** Serializable description of the group. *)
val group : group
val write_group : group writer
end
(** Monad signature. *)
module type MONAD = sig
type 'a t
val return : 'a -> 'a t
val bind : 'a t -> ('a -> 'b t) -> 'b t
val fail : exn -> 'a t
end
(** Random number generation. *)
module type RANDOM = sig
include MONAD
val random : Z.t -> Z.t t
(** [random q] returns a random number modulo [q]. *)
end
......@@ -160,7 +160,7 @@ module Make (P : PARSED_PARAMS) : S = struct
CD.derive election.e_params.e_uuid cred
)
in
let b = E.create_ballot ?sk (E.make_randomness ()) ballot in
let b = E.create_ballot ?sk ballot in
assert (E.check_ballot b);
string_of_ballot G.write b
......
......@@ -50,8 +50,7 @@ let encryptBallot params cred plaintext () =
let module E = Election.Make (P) (LwtJsRandom) in
let module CD = Credential.MakeDerive (G) in
let sk = CD.derive P.election.e_params.e_uuid cred in
let%lwt randomness = E.make_randomness () () in
let%lwt b = E.create_ballot ~sk randomness plaintext () in
let%lwt b = E.create_ballot ~sk plaintext () in
let s = string_of_ballot G.write b in
set_textarea "ballot" s;
set_content "ballot_tracker" (sha256_b64 s);
......@@ -256,7 +255,7 @@ let addQuestions sk params qs =
let n = Array.length qs in
let qs =
Array.to_list qs |>
List.map (fun q -> q, Array.make (Election.question_length q) 0)
List.map (fun q -> q, Array.make (Question_std.question_length q) 0)
in
match qs with
| [] -> failwith "no questions"
......
......@@ -4,6 +4,8 @@ Serializable_builtin_t
Serializable_builtin_j
Serializable_core_j
Question_std_j
Question_std
Question
Serializable_j
Common
Group_field
......
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