Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
belenios
belenios
Commits
c2857da9
Commit
c2857da9
authored
Aug 14, 2017
by
Stephane Glondu
Browse files
Election.Make now takes ELECTION_DATA
parent
d43a8438
Changes
9
Hide whitespace changes
Inline
Side-by-side
src/booth/booth.ml
View file @
c2857da9
...
...
@@ -103,11 +103,11 @@ end
let
encryptBallot
params
cred
plaintext
()
=
let
module
P
=
(
val
params
:
ELECTION_DATA
)
in
let
module
G
=
P
.
G
in
let
module
E
=
Election
.
Make
(
G
)
(
LwtJsRandom
)
in
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
lwt
randomness
=
E
.
make_randomness
P
.
election
()
in
lwt
b
=
E
.
create_ballot
P
.
election
~
sk
randomness
plaintext
()
in
lwt
randomness
=
E
.
make_randomness
()
()
in
lwt
b
=
E
.
create_ballot
~
sk
randomness
plaintext
()
in
let
s
=
string_of_ballot
G
.
write
b
in
setTextarea
"ballot"
s
;
setNodeById
"ballot_tracker"
(
sha256_b64
s
);
...
...
src/lib/election.ml
View file @
c2857da9
...
...
@@ -54,7 +54,8 @@ let question_length q =
(** Homomorphic elections *)
module
Make
(
G
:
GROUP
)
(
M
:
RANDOM
)
=
struct
module
Make
(
W
:
ELECTION_DATA
)
(
M
:
RANDOM
)
=
struct
open
W
open
G
type
'
a
m
=
'
a
M
.
t
...
...
@@ -63,7 +64,6 @@ module Make (G : GROUP) (M : RANDOM) = struct
type
elt
=
G
.
t
type
t
=
elt
election
type
private_key
=
Z
.
t
type
public_key
=
elt
...
...
@@ -84,9 +84,9 @@ module Make (G : GROUP) (M : RANDOM) = struct
beta
=
c1
.
beta
*~
c2
.
beta
;
}
let
neutral_ciphertext
e
=
Array
.
map
(
fun
q
->
let
neutral_ciphertext
()
=
Array
.
map
(
fun
q
->
Array
.
make
(
question_length
q
)
dummy_ciphertext
)
e
.
e_params
.
e_questions
)
e
lection
.
e_params
.
e_questions
let
combine_ciphertexts
=
Array
.
mmap2
eg_combine
...
...
@@ -438,10 +438,10 @@ module Make (G : GROUP) (M : RANDOM) = struct
let
blank_proof
=
None
in
return
{
choices
;
individual_proofs
;
overall_proof
;
blank_proof
}
let
make_randomness
e
=
let
make_randomness
()
=
sswap
(
Array
.
map
(
fun
q
->
Array
.
init
(
question_length
q
)
(
fun
_
->
random
G
.
q
)
)
e
.
e_params
.
e_questions
)
)
e
lection
.
e_params
.
e_questions
)
let
make_sig_prefix
zkp
commitment
=
"sig|"
^
zkp
^
"|"
^
G
.
to_string
commitment
^
"|"
...
...
@@ -457,8 +457,8 @@ module Make (G : GROUP) (M : RANDOM) = struct
)
(
Array
.
to_list
answers
)
)
|>
Array
.
of_list
let
create_ballot
e
?
sk
r
m
=
let
p
=
e
.
e_params
in
let
create_ballot
?
sk
r
m
=
let
p
=
e
lection
.
e_params
in
let
sk
,
zkp
=
match
sk
with
|
None
->
None
,
""
...
...
@@ -479,7 +479,7 @@ module Make (G : GROUP) (M : RANDOM) = struct
)
>>=
fun
signature
->
return
{
answers
;
election_hash
=
e
.
e_fingerprint
;
election_hash
=
e
lection
.
e_fingerprint
;
election_uuid
=
p
.
e_uuid
;
signature
;
}
...
...
@@ -503,10 +503,10 @@ module Make (G : GROUP) (M : RANDOM) = struct
eg_disj_verify
y
d
zkp
a
.
overall_proof
sumc
|
_
,
_
->
false
let
check_ballot
e
b
=
let
p
=
e
.
e_params
in
let
check_ballot
b
=
let
p
=
e
lection
.
e_params
in
b
.
election_uuid
=
p
.
e_uuid
&&
b
.
election_hash
=
e
.
e_fingerprint
&&
b
.
election_hash
=
e
lection
.
e_fingerprint
&&
let
ok
,
zkp
=
match
b
.
signature
with
|
Some
{
s_public_key
=
y
;
s_challenge
;
s_response
}
->
let
zkp
=
G
.
to_string
y
in
...
...
src/lib/election.mli
View file @
c2857da9
...
...
@@ -29,6 +29,6 @@ val get_group : Yojson.Safe.json election -> (module ELECTION_DATA)
val
question_length
:
question
->
int
module
Make
(
G
:
GROUP
)
(
M
:
RANDOM
)
:
ELECTION
with
type
elt
=
G
.
t
and
type
'
a
m
=
'
a
M
.
t
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}. *)
src/lib/signatures.mli
View file @
c2857da9
...
...
@@ -141,7 +141,6 @@ module type ELECTION = sig
type
elt
type
t
=
elt
election
type
private_key
=
Z
.
t
type
public_key
=
elt
...
...
@@ -150,7 +149,7 @@ module type ELECTION = sig
type
ciphertext
=
elt
Serializable_t
.
ciphertext
array
array
(** A ciphertext that can be homomorphically combined. *)
val
neutral_ciphertext
:
t
->
ciphertext
val
neutral_ciphertext
:
uni
t
->
ciphertext
(** The neutral element for [combine_ciphertext] below. *)
val
combine_ciphertexts
:
ciphertext
->
ciphertext
->
ciphertext
...
...
@@ -172,18 +171,17 @@ module type ELECTION = sig
type
randomness
(** Randomness needed to create a ballot. *)
val
make_randomness
:
t
->
randomness
m
val
make_randomness
:
uni
t
->
randomness
m
(** Creates randomness for [create_ballot] below. The result can be
kept for Benaloh-style auditing. *)
val
create_ballot
:
t
->
?
sk
:
private_key
->
randomness
->
plaintext
->
ballot
m
val
create_ballot
:
?
sk
:
private_key
->
randomness
->
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
the ballot. *)
val
check_ballot
:
t
->
ballot
->
bool
val
check_ballot
:
ballot
->
bool
(** [check_ballot b] checks all the cryptographic proofs in [b]. All
ballots produced by [create_ballot] should pass this check. *)
...
...
src/tool/tool_election.ml
View file @
c2857da9
...
...
@@ -59,7 +59,7 @@ let parse_params p =
module
Make
(
P
:
PARSED_PARAMS
)
:
S
=
struct
open
P
module
E
=
Election
.
Make
(
G
)
(
DirectRandom
)
module
E
=
Election
.
Make
(
P
)
(
DirectRandom
)
module
KG
=
Trustees
.
MakeSimple
(
G
)
(
DirectRandom
)
...
...
@@ -135,7 +135,7 @@ module Make (P : PARSED_PARAMS) : S = struct
)
let
cast
(
b
,
hash
)
=
if
Lazy
.
force
check_signature_present
b
&&
E
.
check_ballot
election
b
if
Lazy
.
force
check_signature_present
b
&&
E
.
check_ballot
b
then
()
else
Printf
.
ksprintf
failwith
"ballot %s failed tests"
hash
...
...
@@ -150,7 +150,7 @@ module Make (P : PARSED_PARAMS) : S = struct
|
Some
ballots
->
List
.
fold_left
(
fun
accu
(
b
,
_
)
->
E
.
combine_ciphertexts
(
E
.
extract_ciphertext
b
)
accu
)
(
E
.
neutral_ciphertext
election
)
ballots
,
)
(
E
.
neutral_ciphertext
()
)
ballots
,
List
.
length
ballots
)
...
...
@@ -161,8 +161,8 @@ module Make (P : PARSED_PARAMS) : S = struct
CD
.
derive
election
.
e_params
.
e_uuid
cred
)
in
let
b
=
E
.
create_ballot
election
?
sk
(
E
.
make_randomness
election
)
ballot
in
assert
(
E
.
check_ballot
election
b
);
let
b
=
E
.
create_ballot
?
sk
(
E
.
make_randomness
()
)
ballot
in
assert
(
E
.
check_ballot
b
);
string_of_ballot
G
.
write
b
let
decrypt
privkey
=
...
...
src/tool/tool_js_pd.ml
View file @
c2857da9
...
...
@@ -68,7 +68,7 @@ let compute_partial_decryption _ =
Js
.
Opt
.
option
!
election
>>=
fun
e
->
let
election
=
Election
.(
get_group
(
of_string
e
))
in
let
module
P
=
(
val
election
)
in
let
module
E
=
Election
.
Make
(
P
.
G
)
(
DirectRandom
)
in
let
module
E
=
Election
.
Make
(
P
)
(
DirectRandom
)
in
Js
.
Opt
.
option
!
encrypted_tally
>>=
fun
e
->
let
encrypted_tally
=
encrypted_tally_of_string
P
.
G
.
read
e
in
document
##
getElementById
(
Js
.
string
"private_key"
)
>>=
fun
e
->
...
...
src/tool/tool_verifydiff.ml
View file @
c2857da9
...
...
@@ -113,7 +113,7 @@ let verifydiff dir1 dir2 =
(* the public keys / threshold parameters must be valid *)
let
module
ED
=
(
val
Election
.(
get_group
(
of_string
election
)))
in
let
open
ED
in
let
module
E
=
Election
.
Make
(
G
)
(
DirectRandom
)
in
let
module
E
=
Election
.
Make
(
ED
)
(
DirectRandom
)
in
let
y
=
match
threshold
with
|
None
->
...
...
@@ -172,7 +172,7 @@ let verifydiff dir1 dir2 =
match
load_from_file
(
ballot_of_string
G
.
read
)
(
dir
/
"ballots.jsons"
)
with
|
None
->
raise
(
VerifydiffError
MissingBallots
)
|
Some
ballots
->
if
not
(
List
.
for_all
(
E
.
check_ballot
election
)
ballots
)
then
if
not
(
List
.
for_all
E
.
check_ballot
ballots
)
then
raise
(
VerifydiffError
InvalidBallot
);
(* return the set of ballots indexed by the public keys used to sign *)
List
.
fold_left
(
fun
accu
x
->
...
...
src/web/web_election.ml
View file @
c2857da9
...
...
@@ -36,7 +36,7 @@ module Make (D : ELECTION_DATA) (M : RANDOM with type 'a t = 'a Lwt.t) : WEB_ELE
let
uuid
=
D
.
election
.
e_params
.
e_uuid
module
G
=
D
.
G
module
E
=
Election
.
Make
(
G
)
(
M
)
module
E
=
Election
.
Make
(
D
)
(
M
)
module
B
:
WEB_BALLOT_BOX
=
struct
...
...
@@ -106,7 +106,7 @@ module Make (D : ELECTION_DATA) (M : RANDOM with type 'a t = 'a Lwt.t) : WEB_ELE
match
old_cred
,
old_record
with
|
None
,
None
->
(* first vote *)
if
E
.
check_ballot
D
.
election
ballot
then
(
if
E
.
check_ballot
ballot
then
(
let
hash
=
sha256_b64
rawballot
in
Ocsipersist
.
add
cred_table
credential
(
Some
hash
)
>>
Ocsipersist
.
add
ballots_table
hash
rawballot
>>
...
...
@@ -119,7 +119,7 @@ module Make (D : ELECTION_DATA) (M : RANDOM with type 'a t = 'a Lwt.t) : WEB_ELE
|
Some
h
,
Some
(
_
,
old_credential
)
->
(* revote *)
if
credential
=
old_credential
then
(
if
E
.
check_ballot
D
.
election
ballot
then
(
if
E
.
check_ballot
ballot
then
(
Ocsipersist
.
remove
ballots_table
h
>>
let
hash
=
sha256_b64
rawballot
in
Ocsipersist
.
add
cred_table
credential
(
Some
hash
)
>>
...
...
@@ -212,7 +212,7 @@ module Make (D : ELECTION_DATA) (M : RANDOM with type 'a t = 'a Lwt.t) : WEB_ELE
let
ballot
=
ballot_of_string
G
.
read
rawballot
in
let
ciphertext
=
E
.
extract_ciphertext
ballot
in
return
(
n
+
1
,
E
.
combine_ciphertexts
accu
ciphertext
))
ballots_table
(
0
,
E
.
neutral_ciphertext
D
.
election
)
ballots_table
(
0
,
E
.
neutral_ciphertext
()
)
in
let
tally
=
string_of_encrypted_tally
G
.
write
tally
in
Lwt_mutex
.
with_lock
mutex
(
fun
()
->
...
...
src/web/web_site.ml
View file @
c2857da9
...
...
@@ -1364,7 +1364,7 @@ let () =
in
let
%
lwt
election
=
find_election
uuid
in
let
module
W
=
(
val
Election
.
get_group
election
)
in
let
module
E
=
Election
.
Make
(
W
.
G
)
(
LwtRandom
)
in
let
module
E
=
Election
.
Make
(
W
)
(
LwtRandom
)
in
let
%
lwt
pks
=
match
%
lwt
Web_persist
.
get_threshold
uuid
with
|
Some
tp
->
...
...
@@ -1402,7 +1402,7 @@ let handle_election_tally_release (uuid, ()) () =
let
%
lwt
election
=
find_election
uuid
in
let
%
lwt
metadata
=
Web_persist
.
get_election_metadata
uuid
in
let
module
W
=
(
val
Election
.
get_group
election
)
in
let
module
E
=
Election
.
Make
(
W
.
G
)
(
LwtRandom
)
in
let
module
E
=
Election
.
Make
(
W
)
(
LwtRandom
)
in
if
metadata
.
e_owner
=
Some
u
then
(
let
%
lwt
npks
,
ntallied
=
match
%
lwt
Web_persist
.
get_election_state
uuid
with
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment