Commit e5296260 authored by Stephane Glondu's avatar Stephane Glondu

Abstract out group element type

parent d58d43e8
......@@ -6,15 +6,15 @@ type datetime <ocaml predef from="Core_datatypes"> = abstract
(** {1 ElGamal keys} *)
type public_key = {
g : number;
type 'a public_key = {
g : 'a;
p : number;
q : number;
y : number;
y : 'a;
}
type private_key = {
public_key : public_key;
type 'a private_key = {
public_key : 'a public_key;
x : number;
}
......@@ -45,13 +45,13 @@ type question = {
tally_type : tally_type;
} <ocaml field_prefix="q_">
type election = {
type 'a election = {
cast_url : string;
description : string;
frozen_at : datetime;
name : string;
openreg : bool;
public_key : public_key;
public_key : 'a public_key;
questions : question list <ocaml repr="array">;
uuid : uuid;
short_name : string;
......@@ -63,73 +63,73 @@ type election = {
(** {1 Ballots} *)
type choice = {
alpha : number;
beta : number;
type 'a choice = {
alpha : 'a;
beta : 'a;
}
type commitment = {
a <json name="A"> : number;
b <json name="B"> : number;
type 'a commitment = {
a <json name="A"> : 'a;
b <json name="B"> : 'a;
}
type proof = {
type 'a proof = {
challenge : number;
commitment : commitment;
commitment : 'a commitment;
response : number;
} <ocaml field_prefix="dp_">
type disjunctive_proof = proof list <ocaml repr="array">
type 'a disjunctive_proof = 'a proof list <ocaml repr="array">
type answer = {
choices : choice list <ocaml repr="array">;
individual_proofs : disjunctive_proof list <ocaml repr="array">;
overall_proof : disjunctive_proof;
type 'a answer = {
choices : 'a choice list <ocaml repr="array">;
individual_proofs : 'a disjunctive_proof list <ocaml repr="array">;
overall_proof : 'a disjunctive_proof;
}
type vote = {
answers : answer list <ocaml repr="array">;
type 'a vote = {
answers : 'a answer list <ocaml repr="array">;
election_hash : string;
election_uuid : uuid;
}
(** {1 Tally} *)
type tally = choice list <ocaml repr="array"> list <ocaml repr="array">
type 'a tally = 'a choice list <ocaml repr="array"> list <ocaml repr="array">
type encrypted_tally = {
type 'a encrypted_tally = {
num_tallied : int;
tally : tally;
tally : 'a tally;
}
(** {1 Partial decryptions} *)
type pok = {
type 'a pok = {
challenge : number;
commitment : number;
commitment : 'a;
response : number;
} <ocaml field_prefix="pok_">
type trustee_public_key = {
pok : pok;
public_key : public_key;
type 'a trustee_public_key = {
pok : 'a pok;
public_key : 'a public_key;
} <ocaml field_prefix="trustee_">
type partial_decryption = {
decryption_factors : number list <ocaml repr="array"> list <ocaml repr="array">;
decryption_proofs : proof list <ocaml repr="array"> list <ocaml repr="array">;
type 'a partial_decryption = {
decryption_factors : 'a list <ocaml repr="array"> list <ocaml repr="array">;
decryption_proofs : 'a proof list <ocaml repr="array"> list <ocaml repr="array">;
}
(** {1 Compound datastructures} *)
type election_public_data = {
public_keys : trustee_public_key list <ocaml repr="array">;
votes : vote list <ocaml repr="array">;
encrypted_tally : encrypted_tally;
partial_decryptions : partial_decryption list <ocaml repr="array">;
type 'a election_public_data = {
public_keys : 'a trustee_public_key list <ocaml repr="array">;
votes : 'a vote list <ocaml repr="array">;
encrypted_tally : 'a encrypted_tally;
partial_decryptions : 'a partial_decryption list <ocaml repr="array">;
result : int list <ocaml repr="array"> list <ocaml repr="array">;
}
type election_private_data = {
private_keys : private_key list <ocaml repr="array">;
type 'a election_private_data = {
private_keys : 'a private_key list <ocaml repr="array">;
}
......@@ -32,34 +32,50 @@ let check_modulo p x = Z.(geq x zero && lt x p)
let check_subgroup p q x = Z.(powm x q p =~ one)
module type TYPES = sig
type elt
type 'a t
val read : 'a t -> Yojson.Safe.lexer_state -> Lexing.lexbuf -> 'a
val write : 'a t -> Bi_outbuf.t -> 'a -> unit
val election : election t
val private_key : private_key t
val trustee_public_key : trustee_public_key t
val vote : vote t
val encrypted_tally : encrypted_tally t
val partial_decryption : partial_decryption t
val election_public_data : election_public_data t
val election_private_data : election_private_data t
val election : elt election t
val private_key : elt private_key t
val trustee_public_key : elt trustee_public_key t
val vote : elt vote t
val encrypted_tally : elt encrypted_tally t
val partial_decryption : elt partial_decryption t
val election_public_data : elt election_public_data t
val election_private_data : elt election_private_data t
end
module Types : TYPES = struct
module type SGROUP = sig
type t
val write : Bi_outbuf.t -> t -> unit
val read : Yojson.Safe.lexer_state -> Lexing.lexbuf -> t
end
module SFiniteFieldMult : SGROUP with type t = Z.t = struct
type t = Z.t
let write = Core_datatypes_j.write_number
let read = Core_datatypes_j.read_number
end
module MakeTypes (G : SGROUP) : TYPES with type elt = G.t = struct
open Helios_datatypes_j
type elt = G.t
type 'a t = (Yojson.Safe.lexer_state -> Lexing.lexbuf -> 'a) * (Bi_outbuf.t -> 'a -> unit)
let read = fst
let write = snd
let election = (read_election, write_election)
let private_key = (read_private_key, write_private_key)
let trustee_public_key = (read_trustee_public_key, write_trustee_public_key)
let vote = (read_vote, write_vote)
let encrypted_tally = (read_encrypted_tally, write_encrypted_tally)
let partial_decryption = (read_partial_decryption, write_partial_decryption)
let election_public_data = (read_election_public_data, write_election_public_data)
let election_private_data = (read_election_private_data, write_election_private_data)
let election = (read_election G.read, write_election G.write)
let private_key = (read_private_key G.read, write_private_key G.write)
let trustee_public_key = (read_trustee_public_key G.read, write_trustee_public_key G.write)
let vote = (read_vote G.read, write_vote G.write)
let encrypted_tally = (read_encrypted_tally G.read, write_encrypted_tally G.write)
let partial_decryption = (read_partial_decryption G.read, write_partial_decryption G.write)
let election_public_data = (read_election_public_data G.read, write_election_public_data G.write)
let election_private_data = (read_election_private_data G.read, write_election_private_data G.write)
end
module Types : TYPES with type elt = Z.t = MakeTypes (SFiniteFieldMult)
let load typ fname =
let i = open_in fname in
let buf = Lexing.from_channel i in
......@@ -85,11 +101,11 @@ let load_and_check ?(verbose=false) typ fname =
Sys.remove tempfname;
thing
type election_test_data = {
type 'a election_test_data = {
fingerprint : string;
election : election;
public_data : election_public_data;
private_data : election_private_data;
election : 'a election;
public_data : 'a election_public_data;
private_data : 'a election_private_data;
}
let first_line filename =
......
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