MAJ terminée. Nous sommes passés en version 14.6.2 . Pour consulter les "releases notes" associées c'est ici :

https://about.gitlab.com/releases/2022/01/11/security-release-gitlab-14-6-2-released/
https://about.gitlab.com/releases/2022/01/04/gitlab-14-6-1-released/

Commit 1a3a3762 authored by Stephane Glondu's avatar Stephane Glondu
Browse files

Monadification

parent aea5f2e8
open Util
open Serializable_t
open Crypto_sigs
(** Helper functions *)
......@@ -44,23 +45,42 @@ let finite_field ~p ~q ~g =
let check x = check_modulo p x && x **~ q =~ one
let hash xs = hashZ (map_and_concat_with_commas Z.to_string xs)
let compare = Z.compare
end in (module G : Crypto_sigs.GROUP with type t = Z.t)
end in (module G : GROUP with type t = Z.t)
(** Parameters *)
let check_election p =
let module P = (val p : Crypto_sigs.ELECTION_PARAMS) in
let module P = (val p : ELECTION_PARAMS) in
let open P in
let open G in
(* check public key *)
let computed = Array.fold_left ( *~ ) G.one public_keys in
computed =~ params.e_public_key
(** Dummy monad *)
module MakeDummyMonad (G : GROUP) = struct
type 'a t = 'a
let return x = x
let bind x f = f x
let random q = Util.random q
type ballot = G.t Serializable_t.ballot
let cast x = ()
let fold f x = return x
end
(** Homomorphic elections *)
module MakeElection (P : Crypto_sigs.ELECTION_PARAMS) = struct
module MakeElection
(P : ELECTION_PARAMS)
(M : ELECTION_MONAD with type ballot = P.G.t Serializable_t.ballot)
=
struct
open P
open G
type 'a m = 'a
type elt = G.t
type private_key = Z.t
type public_key = elt
......
(** Cryptographic primitives *)
open Crypto_sigs
val finite_field : p:Z.t -> q:Z.t -> g:Z.t ->
(module Crypto_sigs.GROUP with type t = Z.t)
(module GROUP with type t = Z.t)
(** [finite_field p q g] builds the multiplicative subgroup of F[p],
generated by [g], of order [q]. *)
val check_finite_field : p:Z.t -> q:Z.t -> g:Z.t -> bool
(** Check consistency of finite field parameters. *)
val check_election : (module Crypto_sigs.ELECTION_PARAMS) -> bool
val check_election : (module ELECTION_PARAMS) -> bool
(** Check consistency of election parameters. *)
module MakeElection (P : Crypto_sigs.ELECTION_PARAMS) :
Crypto_sigs.ELECTION with type elt = P.G.t
module MakeDummyMonad (G : GROUP) : ELECTION_MONAD
with type ballot = G.t Serializable_t.ballot
and type 'a t = 'a
module MakeElection
(P : ELECTION_PARAMS)
(M : ELECTION_MONAD with type ballot = P.G.t Serializable_t.ballot)
: ELECTION
with type elt = P.G.t
and type 'a m = 'a
......@@ -40,6 +40,33 @@ module type GROUP = sig
(** A total ordering over the elements of the group. *)
end
(** Monad capturing impure operations used by elections. *)
module type ELECTION_MONAD = sig
(** {2 Usual monadic operations} *)
type 'a t
val return : 'a -> 'a t
val bind : 'a t -> ('a -> 'b t) -> 'b t
(** {2 General-purpose impure operations} *)
val random : Z.t -> Z.t t
(** [random q] returns a random number modulo [q]. *)
(** {2 Election-specific operations} *)
type ballot
(** The type of ballots. The monad is supposed to keep track of all
cast ballots (e.g. in a database). *)
val cast : ballot -> unit t
(** Cast a ballot. *)
val fold : (ballot -> 'a -> 'a t) -> 'a -> 'a t
(** [fold f a] computes [(f bN ... (f b2 (f b1 a))...)], where [b1
... bN] are all cast ballots. *)
end
(** Parameters for an election. *)
module type ELECTION_PARAMS = sig
module G : GROUP
......@@ -58,6 +85,9 @@ end
(** Cryptographic primives for an election with homomorphic tally. *)
module type ELECTION = sig
type 'a m
(** The type of monadic values. *)
(** {2 Election parameters} *)
(** Ballots are encrypted using public-key cryptography secured by
......@@ -95,11 +125,11 @@ module type ELECTION = sig
type randomness = Z.t array array
(** Randomness needed to create a ballot. *)
val create_randomness : unit -> randomness
val create_randomness : unit -> randomness m
(** Creates randomness for [create_ballot] below. The result can be
kept for Benaloh-style auditing. *)
val create_ballot : randomness -> plaintext -> ballot
val create_ballot : randomness -> plaintext -> ballot m
(** [create_ballot r answers] creates a ballot, or raises
[Invalid_argument] if [answers] doesn't satisfy the election
constraints. *)
......@@ -118,7 +148,7 @@ module type ELECTION = sig
private key share and the encrypted tally, and contains a
cryptographic proof that he or she didn't cheat. *)
val compute_factor : ciphertext -> private_key -> factor
val compute_factor : ciphertext -> private_key -> factor m
val check_factor : ciphertext -> public_key -> factor -> bool
(** [check_factor c pk f] checks that [f], supposedly submitted by a
......
......@@ -93,7 +93,7 @@ let verbose_verify_election_test_data (e, ballots, signatures, private_data) =
verbose_assert "election key" (lazy (
Crypto.check_election (module P : Crypto_sigs.ELECTION_PARAMS)
));
let module Election = Crypto.MakeElection(P) in
let module Election = Crypto.MakeElection(P)(Crypto.MakeDummyMonad(P.G)) in
if Array.length ballots = 0 then (
Printf.eprintf " no ballots available\n%!"
) else (
......@@ -177,7 +177,7 @@ module P = struct
let fingerprint = e.fingerprint
end
module Election = Crypto.MakeElection(P)
module Election = Crypto.MakeElection(P)(Crypto.MakeDummyMonad(P.G))
module Compat = Serializable_compat.MakeCompat(P)
let nballots = Array.map Serializable_compat.of_ballot ballots;;
......
......@@ -192,7 +192,7 @@ let () = Eliom_registration.Html5.register
let params = Serializable_compat.of_election election.Common.election
let fingerprint = assert false
end in
let module Election = Crypto.MakeElection(P) in
let module Election = Crypto.MakeElection(P)(Crypto.MakeDummyMonad(P.G)) in
if
Uuidm.equal uuid ballot.election_uuid &&
Election.check_ballot (Serializable_compat.of_ballot ballot)
......
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