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

Remove compatibility layer that does no longer make any sense

parent 438cad86
Serializable_t
Signatures
Election
Serializable_compat_t
Serializable_compat
......@@ -3,6 +3,3 @@ Serializable_builtin_j
Serializable_t
Serializable_j
Election
Serializable_compat_t
Serializable_compat_j
Serializable_compat
(**************************************************************************)
(* BELENIOS *)
(* *)
(* Copyright © 2012-2013 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/>. *)
(**************************************************************************)
<doc text="Serializable datatypes (compatibility layer)">
(** {1 Core types} *)
type number <ocaml predef from="Serializable_builtin"> = abstract
type uuid <ocaml predef from="Serializable_builtin"> = abstract
type datetime <ocaml predef from="Serializable_builtin"> = abstract
type int_or_null <ocaml predef from="Serializable_builtin"> = abstract
(** {1 ElGamal keys} *)
type 'a public_key = {
g : 'a;
p : number;
q : number;
y : 'a;
}
type 'a private_key = {
public_key : 'a public_key;
x : number;
}
(** {1 Elections} *)
type tally_type = [
| Homomorphic <json name="homomorphic">
]
type choice_type = [
| Approval <json name="approval">
]
type result_type = [
| Absolute <json name="absolute">
| Relative <json name="relative">
]
type election_state = [
| Setup <json name="setup">
| Frozen <json name="frozen">
| Started <json name="started">
| Stopped <json name="stopped">
| Finished <json name="finished">
]
type question = {
answer_urls : unit list;
answers : string list <ocaml repr="array">;
choice_type : choice_type;
max : int_or_null;
min : int;
question : string;
result_type : result_type;
short_name : string;
tally_type : tally_type;
} <ocaml field_prefix="q_">
type 'a params = {
cast_url : string;
description : string;
frozen_at : datetime;
name : string;
openreg : bool;
public_key : 'a public_key;
questions : question list <ocaml repr="array">;
uuid : uuid;
short_name : string;
use_voter_aliases : bool;
voters_hash : unit;
voting_ends_at : unit;
voting_starts_at : unit;
} <ocaml field_prefix="e_">
(** {1 Ballots} *)
type 'a choice <ocaml predef from="Serializable" t="ciphertext"> = {
alpha : 'a;
beta : 'a;
}
type 'a commitment = {
a <json name="A"> : 'a;
b <json name="B"> : 'a;
}
type 'a proof = {
challenge : number;
commitment : 'a commitment;
response : number;
} <ocaml field_prefix="dp_">
type 'a disjunctive_proof = 'a proof list <ocaml repr="array">
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 'a ballot = {
answers : 'a answer list <ocaml repr="array">;
election_hash : string;
election_uuid : uuid;
}
(** {1 Tally} *)
type 'a tally = 'a choice list <ocaml repr="array"> list <ocaml repr="array">
type 'a encrypted_tally = {
num_tallied : int;
tally : 'a tally;
}
(** {1 Partial decryptions} *)
type 'a pok = {
challenge : number;
commitment : 'a;
response : number;
} <ocaml field_prefix="pok_">
type 'a trustee_public_key = {
pok : 'a pok;
public_key : 'a public_key;
} <ocaml field_prefix="trustee_">
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">;
}
type raw_result = int list <ocaml repr="array"> list <ocaml repr="array">
(**************************************************************************)
(* BELENIOS *)
(* *)
(* Copyright © 2012-2013 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
open Util
open Serializable_compat_t
let question q =
let {q_answers; q_min; q_max; q_question; _} = q in
let q_max = match q_max with
| Some i -> i
| None -> Array.length q_answers
in
let open Serializable_t in
{q_answers; q_min; q_max; q_question}
let params e =
let {
e_description; e_name; e_public_key;
e_questions; e_uuid; e_short_name;
_
} = e in
let e_public_key = e_public_key.y in
let e_questions = Array.map question e_questions in
let open Serializable_t in
{
e_description; e_name; e_public_key;
e_questions; e_uuid; e_short_name
}
let proof p =
let {dp_challenge; dp_response; _} = p in
let open Serializable_t in
{challenge = dp_challenge; response = dp_response}
let proofs ps = Array.map proof ps
let answer a =
let {choices; individual_proofs; overall_proof} = a in
let individual_proofs = Array.map proofs individual_proofs in
let overall_proof = proofs overall_proof in
let open Serializable_t in
{choices; individual_proofs; overall_proof}
let ballot b =
let {answers; election_hash; election_uuid} = b in
let answers = Array.map answer answers in
let signature = None in
let open Serializable_t in
{answers; election_hash; election_uuid; signature}
let partial_decryption p =
let {decryption_factors; decryption_proofs} = p in
let decryption_proofs = Array.mmap proof decryption_proofs in
let open Serializable_t in
{decryption_factors; decryption_proofs}
module MakeCompat (G : GROUP) = struct
open Serializable_t
open G
type election = G.t Signatures.election
(* The following duplicates parts of module Crypto, in order to
reconstruct commitments. *)
let dummy_ciphertext =
{
alpha = G.one;
beta = G.one;
}
let eg_combine c1 c2 =
{
alpha = c1.alpha *~ c2.alpha;
beta = c1.beta *~ c2.beta;
}
let dummy_proof =
let open Serializable_compat_t in
{
dp_commitment = {a = G.one; b = G.one};
dp_challenge = Z.zero;
dp_response = Z.zero;
}
let ( / ) x y = x *~ invert y
let invg = invert G.g
let d01 = [| G.one; invg |]
let make_d min max =
let n = max - min + 1 in
let d = Array.create n (invert (g **~ Z.of_int min)) in
for i = 1 to n-1 do
d.(i) <- d.(i-1) *~ invg
done;
d
let recommit y d proofs {alpha; beta} =
let n = Array.length d in
assert (n = Array.length proofs);
let result = Array.create n dummy_proof in
for i = 0 to n-1 do
let {challenge; response} = proofs.(i) in
let dp_commitment = {
a = g **~ response / alpha **~ challenge;
b = y **~ response / (beta *~ d.(i)) **~ challenge;
} in
let open Serializable_compat_t in
result.(i) <- {
dp_commitment;
dp_challenge = challenge;
dp_response = response;
};
done;
result
let answer y a q =
let {choices; individual_proofs; overall_proof} = a in
let individual_proofs =
Array.map2 (recommit y d01) individual_proofs choices
in
let sumc = Array.fold_left eg_combine dummy_ciphertext choices in
let overall_proof =
recommit y (make_d q.q_min q.q_max) overall_proof sumc
in
let open Serializable_compat_t in
{choices; individual_proofs; overall_proof}
let ballot e b =
let p = e.e_params in
let {answers; election_hash; election_uuid} = b in
let answers = Array.map2 (answer p.e_public_key) answers p.e_questions in
let open Serializable_compat_t in
{answers; election_hash; election_uuid}
let partial_decryption e c p =
let y = e.e_params.e_public_key in
let {decryption_factors; decryption_proofs} = p in
let decryption_proofs =
Array.mmap3 (fun {alpha; _} f {challenge; response} ->
let open Serializable_compat_t in
let dp_commitment = {
a = g **~ response / (y **~ challenge);
b = alpha **~ response / (f **~ challenge);
} in {
dp_commitment;
dp_challenge = challenge;
dp_response = response;
}
) c decryption_factors decryption_proofs
in
let open Serializable_compat_t in
{decryption_factors; decryption_proofs}
end
(**************************************************************************)
(* BELENIOS *)
(* *)
(* Copyright © 2012-2013 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/>. *)
(**************************************************************************)
(** Compatibility layer with the Helios reference implementation *)
open Serializable_compat_t
val params : 'a params -> 'a Serializable_t.params
val ballot : 'a ballot -> 'a Serializable_t.ballot
val partial_decryption :
'a partial_decryption -> 'a Serializable_t.partial_decryption
module MakeCompat (G : Signatures.GROUP) : sig
type election = G.t Signatures.election
val ballot : election -> G.t Serializable_t.ballot -> G.t ballot
val partial_decryption : election ->
G.t Serializable_t.ciphertext array array ->
G.t Serializable_t.partial_decryption -> G.t partial_decryption
end
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