Attention une mise à jour du service Gitlab va être effectuée le mardi 30 novembre entre 17h30 et 18h00. 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. Cette mise à jour intermédiaire en version 14.0.12 nous permettra de rapidement pouvoir mettre à votre disposition une version plus récente.

Commit 5de170a2 authored by Stephane Glondu's avatar Stephane Glondu
Browse files

Add the notion of serializable description of a group

parent 36ad3adf
......@@ -9,7 +9,7 @@ let hashB x = Cryptokit.(x |>
(* Setup group *)
module G = Election.DefaultGroup;;
assert G.(Election.check_finite_field ~p ~q ~g);;
assert (Election.check_finite_field G.group);;
module M = Election.MakeSimpleMonad(G);;
......@@ -146,7 +146,7 @@ let list_save_to filename writer xs =
let save_to_disk () =
let params = { params with
e_public_key = G.({ g; p; q; y })
e_public_key = G.({group; y})
} in
let ballots = Array.of_list (M.fold_ballots (fun x xs () -> x::xs) [] ()) in
let dir = Printf.sprintf "demo/data/%s" (Uuidm.to_string params.e_uuid) in
......
......@@ -3,7 +3,7 @@ open Util
(* Setup group *)
module G = Election.DefaultGroup;;
assert G.(Election.check_finite_field ~p ~q ~g);;
assert (Election.check_finite_field G.group);;
(* Some helpers *)
......
......@@ -59,10 +59,11 @@ let params, election_fingerprint =
| Some [e] -> e
| _ -> failwith "invalid election file"
let {g; p; q; y} = params.e_public_key
let () = assert (Election.check_finite_field ~p ~q ~g)
let {group; y} = params.e_public_key
let {g; p; q} = group
let () = assert (Election.check_finite_field group)
module G = (val Election.finite_field ~g ~p ~q : Election.FF_GROUP)
module G = (val Election.finite_field group : Election.FF_GROUP)
module M = Election.MakeSimpleMonad(G)
(* Load and check trustee keys, if present *)
......
......@@ -4,7 +4,7 @@ open Serializable_t
(* Setup group *)
module G = Election.DefaultGroup;;
assert G.(Election.check_finite_field ~p ~q ~g);;
assert (Election.check_finite_field G.group);;
module M = Election.MakeSimpleMonad(G);;
......
......@@ -18,19 +18,19 @@ let map_and_concat_with_commas f xs =
(** Finite field arithmetic *)
let check_finite_field ~p ~q ~g =
let check_finite_field {p; q; g} =
Z.probab_prime p 10 > 0 &&
Z.probab_prime q 10 > 0 &&
check_modulo p g &&
check_modulo p q &&
Z.(powm g q p =% one)
module type FF_GROUP = sig
include GROUP with type t = Z.t
val p : Z.t
end
module type FF_GROUP = GROUP
with type t = Z.t
and type group = ff_params
let finite_field ~p ~q ~g =
let finite_field group =
let {p; q; g} = group in
let module G = struct
open Z
type t = Z.t
......@@ -49,13 +49,17 @@ let finite_field ~p ~q ~g =
let z = Z.of_string_base 16 (sha256_hex x) in
Z.(z mod q)
let compare = Z.compare
type group = ff_params
let group = group
end in (module G : FF_GROUP)
let p = Z.of_string "16328632084933010002384055033805457329601614771185955389739167309086214800406465799038583634953752941675645562182498120750264980492381375579367675648771293800310370964745767014243638518442553823973482995267304044326777047662957480269391322789378384619428596446446984694306187644767462460965622580087564339212631775817895958409016676398975671266179637898557687317076177218843233150695157881061257053019133078545928983562221396313169622475509818442661047018436264806901023966236718367204710755935899013750306107738002364137917426595737403871114187750804346564731250609196846638183903982387884578266136503697493474682071"
let q = Z.of_string "61329566248342901292543872769978950870633559608669337131139375508370458778917"
let g = Z.of_string "14887492224963187634282421537186040801304008017743492304481737382571933937568724473847106029915040150784031882206090286938661464458896494215273989547889201144857352611058572236578734319505128042602372864570426550855201448111746579871811249114781674309062693442442368697449970648232621880001709535143047913661432883287150003429802392229361583608686643243349727791976247247948618930423866180410558458272606627111270040091203073580238905303994472202930783207472394578498507764703191288249547659899997131166130259700604433891232298182348403175947450284433411265966789131024573629546048637848902243503970966798589660808533"
let default_ff_params = {
p = Z.of_string "16328632084933010002384055033805457329601614771185955389739167309086214800406465799038583634953752941675645562182498120750264980492381375579367675648771293800310370964745767014243638518442553823973482995267304044326777047662957480269391322789378384619428596446446984694306187644767462460965622580087564339212631775817895958409016676398975671266179637898557687317076177218843233150695157881061257053019133078545928983562221396313169622475509818442661047018436264806901023966236718367204710755935899013750306107738002364137917426595737403871114187750804346564731250609196846638183903982387884578266136503697493474682071";
q = Z.of_string "61329566248342901292543872769978950870633559608669337131139375508370458778917";
g = Z.of_string "14887492224963187634282421537186040801304008017743492304481737382571933937568724473847106029915040150784031882206090286938661464458896494215273989547889201144857352611058572236578734319505128042602372864570426550855201448111746579871811249114781674309062693442442368697449970648232621880001709535143047913661432883287150003429802392229361583608686643243349727791976247247948618930423866180410558458272606627111270040091203073580238905303994472202930783207472394578498507764703191288249547659899997131166130259700604433891232298182348403175947450284433411265966789131024573629546048637848902243503970966798589660808533";
}
module DefaultGroup = (val finite_field ~p ~q ~g : FF_GROUP)
module DefaultGroup = (val finite_field default_ff_params : FF_GROUP)
(** Parameters *)
......
......@@ -2,17 +2,16 @@
open Signatures
module type FF_GROUP = sig
include GROUP with type t = Z.t
val p : Z.t
end
(** Multiplicative subgroup of F[p]. *)
module type FF_GROUP = GROUP
with type t = Z.t
and type group = Serializable_t.ff_params
(** Multiplicative subgroup of a finite field. *)
val finite_field : p:Z.t -> q:Z.t -> g:Z.t -> (module FF_GROUP)
(** [finite_field p q g] builds the multiplicative subgroup of F[p],
generated by [g], of order [q]. *)
val finite_field : Serializable_t.ff_params -> (module FF_GROUP)
(** [finite_field params] builds the multiplicative subgroup of
F[params.p], generated by [params.g], of order [params.q]. *)
val check_finite_field : p:Z.t -> q:Z.t -> g:Z.t -> bool
val check_finite_field : Serializable_t.ff_params -> bool
(** Check consistency of finite field parameters. *)
module DefaultGroup : FF_GROUP
......
......@@ -32,13 +32,20 @@ type 'a trustee_public_key = {
(** {2 Elections} *)
type ff_pubkey = {
type ff_params = {
g : number;
p : number;
q : number;
y : number;
}
<doc text="Parameters for a multiplicative subgroup of a finite field, with a public key.">
<doc text="Parameters for a multiplicative subgroup of a finite field.">
type ('a, 'b) wrapped_pubkey = {
group : 'a;
y : 'b;
}
<doc text="A public key wrapped with its group parameters.">
type ff_pubkey = (ff_params, number) wrapped_pubkey
type question = {
answers : string list <ocaml repr="array">;
......
......@@ -42,6 +42,11 @@ module type GROUP = sig
val compare : t -> t -> int
(** A total ordering over the elements of the group. *)
type group
(** Serializable description of the group. *)
val group : group
end
(** Monad signature. *)
......
......@@ -158,9 +158,9 @@ lwt election_table =
can_read = Any;
can_vote;
}) in
let {g; p; q; y} = params.e_public_key in
let {group; y} = params.e_public_key in
let module G = (val
Election.finite_field ~p ~q ~g : Election.FF_GROUP
Election.finite_field group : Election.FF_GROUP
) in
let module P = struct
module G = G
......
......@@ -4,7 +4,7 @@ open Serializable_t
(* Setup group *)
module G = Election.DefaultGroup;;
assert G.(Election.check_finite_field ~p ~q ~g);;
assert (Election.check_finite_field G.group);;
module M = Election.MakeSimpleMonad(G);;
......@@ -35,7 +35,7 @@ let y = KG.combine public_keys
let params = {
e_description = "This is a test election.";
e_name = "Test election";
e_public_key = G.({g; p; q; y});
e_public_key = G.({group; y});
e_questions =
[|
{
......
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