Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
belenios
belenios
Commits
cdd38a2b
Commit
cdd38a2b
authored
Jan 23, 2013
by
Stephane Glondu
Browse files
s/verify/check/g when a bool is returned
parent
b4a576b4
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/elGamal.ml
View file @
cdd38a2b
...
...
@@ -48,13 +48,13 @@ let make_ff_msubgroup ~p ~q ~g =
module
type
ELGAMAL_CRYPTO
=
sig
type
t
val
verify
_public_key
:
t
public_key
->
bool
val
verify
_private_key
:
t
private_key
->
bool
val
verify
_election_key
:
t
->
t
trustee_public_key
array
->
bool
val
verify
_ballot
:
t
election
->
string
->
t
ballot
->
bool
val
verify
_partial_decryptions
:
t
election
->
val
check
_public_key
:
t
public_key
->
bool
val
check
_private_key
:
t
private_key
->
bool
val
check
_election_key
:
t
->
t
trustee_public_key
array
->
bool
val
check
_ballot
:
t
election
->
string
->
t
ballot
->
bool
val
check
_partial_decryptions
:
t
election
->
t
trustee_public_key
array
->
t
result
->
bool
val
verify
_result
:
t
election
->
t
result
->
bool
val
check
_result
:
t
election
->
t
result
->
bool
val
compute_encrypted_tally
:
t
election
->
t
ballot
array
->
t
encrypted_tally
end
...
...
@@ -67,34 +67,34 @@ module Make (G : GROUP) = struct
let
check_exponent
x
=
check_modulo
q
x
let
one
=
g
**~
Z
.
zero
let
verify
_public_key
k
=
let
check
_public_key
k
=
let
{
g
=
g'
;
p
=
p'
;
q
=
q'
;
y
}
=
k
in
g
=~
g'
&&
p
=%
p'
&&
q
=%
q'
&&
check_element
y
let
verify
_private_key
k
=
let
check
_private_key
k
=
let
{
x
;
public_key
=
{
y
;
_
}}
=
k
in
check_exponent
x
&&
y
=~
g
**~
x
let
verify
_pok
y
pok
=
let
check
_pok
y
pok
=
let
{
pok_commitment
;
pok_challenge
;
pok_response
}
=
pok
in
(* NB: we don't check commitment and challenge thanks to hash *)
check_exponent
pok_response
&&
g
**~
pok_response
=~
pok_commitment
*~
y
**~
pok_challenge
&&
pok_challenge
=%
hash
[
pok_commitment
]
let
verify
_election_key
y
tpks
=
let
check
_election_key
y
tpks
=
let
n
=
Array
.
length
tpks
in
assert
(
n
>
0
);
let
rec
loop
i
accu
=
if
i
>=
0
then
let
tpk
=
tpks
.
(
i
)
in
let
{
g
=
g'
;
p
=
p'
;
q
=
q'
;
y
=
y'
}
=
tpk
.
trustee_public_key
in
g
=~
g'
&&
p
=%
p'
&&
q
=%
q'
&&
verify
_pok
y'
tpk
.
trustee_pok
&&
g
=~
g'
&&
p
=%
p'
&&
q
=%
q'
&&
check
_pok
y'
tpk
.
trustee_pok
&&
loop
(
pred
i
)
(
accu
*~
y'
)
else
accu
=~
y
in
loop
(
pred
n
)
one
let
verify
_disjunction
h
big_g
big_hs
proof
=
let
check
_disjunction
h
big_g
big_hs
proof
=
let
n
=
Array
.
length
big_hs
in
assert
(
n
>
0
);
n
=
Array
.
length
proof
&&
...
...
@@ -110,12 +110,12 @@ module Make (G : GROUP) = struct
hash
commitments
=%
Z
.(
challenges
mod
q
)
in
check
(
pred
n
)
[]
Z
.
zero
)
let
verify
_range
h
min
max
alpha
beta
proof
=
let
check
_range
h
min
max
alpha
beta
proof
=
Array
.
length
proof
=
2
&&
let
big_hs
=
Array
.
init
(
max
-
min
+
1
)
(
fun
i
->
beta
*~
inv
(
g
**~
Z
.
of_int
(
i
-
min
)))
in
verify
_disjunction
h
alpha
big_hs
proof
check
_disjunction
h
alpha
big_hs
proof
let
verify
_answer
y
question
answer
=
let
check
_answer
y
question
answer
=
let
{
q_max
;
q_min
;
q_answers
;
_
}
=
question
in
let
q_max
=
match
q_max
with
...
...
@@ -130,18 +130,18 @@ module Make (G : GROUP) = struct
let
{
alpha
;
beta
}
=
answer
.
choices
.
(
i
)
in
check_element
alpha
&&
check_element
beta
&&
verify
_range
y
0
1
alpha
beta
answer
.
individual_proofs
.
(
i
)
&&
check
_range
y
0
1
alpha
beta
answer
.
individual_proofs
.
(
i
)
&&
check
(
pred
i
)
(
alphas
*~
alpha
)
(
betas
*~
beta
)
else
verify
_range
y
q_min
q_max
alphas
betas
answer
.
overall_proof
check
_range
y
q_min
q_max
alphas
betas
answer
.
overall_proof
in
check
(
pred
nb
)
one
one
)
let
verify
_ballot
e
fingerprint
v
=
let
check
_ballot
e
fingerprint
v
=
v
.
election_hash
=
fingerprint
&&
e
.
e_uuid
=
v
.
election_uuid
&&
Array
.
forall2
(
verify
_answer
e
.
e_public_key
.
y
)
e
.
e_questions
v
.
answers
Array
.
forall2
(
check
_answer
e
.
e_public_key
.
y
)
e
.
e_questions
v
.
answers
let
verify
_equality
h
g'
h'
proof
=
let
check
_equality
h
g'
h'
proof
=
(* NB: similar to disjunctive, but with different challenge
checking... hardly factorizable *)
let
{
dp_commitment
=
{
a
;
b
};
dp_challenge
;
dp_response
}
=
proof
in
...
...
@@ -151,22 +151,22 @@ module Make (G : GROUP) = struct
h
**~
dp_response
=~
h'
**~
dp_challenge
*~
b
&&
dp_challenge
=%
hash
[
a
;
b
]
let
verify
_partial_decryption
election
tally
tpk
pds
=
let
check
_partial_decryption
election
tally
tpk
pds
=
let
y
=
tpk
.
trustee_public_key
.
y
in
let
{
decryption_factors
=
dfs
;
decryption_proofs
=
dps
}
=
pds
in
Array
.
foralli
(
fun
i
question
->
let
dfs_i
=
dfs
.
(
i
)
and
dps_i
=
dps
.
(
i
)
and
tally_i
=
tally
.
(
i
)
in
Array
.
foralli
(
fun
j
answer
->
verify
_equality
tally_i
.
(
j
)
.
alpha
y
dfs_i
.
(
j
)
dps_i
.
(
j
)
check
_equality
tally_i
.
(
j
)
.
alpha
y
dfs_i
.
(
j
)
dps_i
.
(
j
)
)
question
.
q_answers
)
election
.
e_questions
let
verify
_partial_decryptions
election
public_keys
r
=
Array
.
forall2
(
verify
_partial_decryption
election
r
.
encrypted_tally
.
tally
)
let
check
_partial_decryptions
election
public_keys
r
=
Array
.
forall2
(
check
_partial_decryption
election
r
.
encrypted_tally
.
tally
)
public_keys
r
.
partial_decryptions
let
verify
_result
election
public_data
=
let
check
_result
election
public_data
=
let
pds
=
public_data
.
partial_decryptions
in
let
tally
=
public_data
.
encrypted_tally
.
tally
in
let
result
=
public_data
.
result
in
...
...
src/elGamal.mli
View file @
cdd38a2b
...
...
@@ -41,13 +41,13 @@ val make_ff_msubgroup : p:Z.t -> q:Z.t -> g:Z.t -> (module GROUP with type t = Z
module
type
ELGAMAL_CRYPTO
=
sig
type
t
val
verify
_public_key
:
t
public_key
->
bool
val
verify
_private_key
:
t
private_key
->
bool
val
verify
_election_key
:
t
->
t
trustee_public_key
array
->
bool
val
verify
_ballot
:
t
election
->
string
->
t
ballot
->
bool
val
verify
_partial_decryptions
:
t
election
->
val
check
_public_key
:
t
public_key
->
bool
val
check
_private_key
:
t
private_key
->
bool
val
check
_election_key
:
t
->
t
trustee_public_key
array
->
bool
val
check
_ballot
:
t
election
->
string
->
t
ballot
->
bool
val
check
_partial_decryptions
:
t
election
->
t
trustee_public_key
array
->
t
result
->
bool
val
verify
_result
:
t
election
->
t
result
->
bool
val
check
_result
:
t
election
->
t
result
->
bool
val
compute_encrypted_tally
:
t
election
->
t
ballot
array
->
t
encrypted_tally
end
...
...
src/helios_registration.ml
View file @
cdd38a2b
...
...
@@ -188,7 +188,7 @@ let () = Eliom_registration.Html5.register
let
module
Crypto
=
ElGamal
.
Make
(
G
)
in
if
Uuidm
.
equal
uuid
ballot
.
election_uuid
&&
Crypto
.
verify
_ballot
election
.
Common
.
election
election
.
Common
.
fingerprint
ballot
Crypto
.
check
_ballot
election
.
Common
.
election
election
.
Common
.
fingerprint
ballot
then
`Valid
(
Common
.
hash_ballot
ballot
)
else
`Invalid
with
e
->
`Malformed
...
...
tests/sandbox.ml
View file @
cdd38a2b
...
...
@@ -81,7 +81,7 @@ let verbose_verify_election_test_data (e, ballots, signatures, private_data) =
let
module
G
=
(
val
ElGamal
.
make_ff_msubgroup
p
q
g
:
ElGamal
.
GROUP
with
type
t
=
Z
.
t
)
in
let
module
Crypto
=
ElGamal
.
Make
(
G
)
in
verbose_assert
"election key"
(
lazy
(
Crypto
.
verify
_election_key
Crypto
.
check
_election_key
e
.
election
.
e_public_key
.
y
e
.
public_data
.
public_keys
));
...
...
@@ -90,7 +90,7 @@ let verbose_verify_election_test_data (e, ballots, signatures, private_data) =
)
else
(
verbose_assert
"ballots"
(
lazy
(
Array
.
foralli
(
fun
_
x
->
Crypto
.
verify
_ballot
e
.
election
e
.
fingerprint
x
Crypto
.
check
_ballot
e
.
election
e
.
fingerprint
x
)
ballots
));
(
match
e
.
public_data
.
election_result
with
...
...
@@ -104,10 +104,10 @@ let verbose_verify_election_test_data (e, ballots, signatures, private_data) =
(
match
e
.
public_data
.
election_result
with
|
Some
r
->
verbose_assert
"partial decryptions"
(
lazy
(
Crypto
.
verify
_partial_decryptions
Crypto
.
check
_partial_decryptions
e
.
election
e
.
public_data
.
public_keys
r
));
verbose_assert
"result"
(
lazy
(
Crypto
.
verify
_result
e
.
election
r
));
verbose_assert
"result"
(
lazy
(
Crypto
.
check
_result
e
.
election
r
));
|
None
->
Printf
.
eprintf
" no results available
\n
%!"
);
verbose_assert
"signature count"
(
lazy
(
...
...
@@ -115,7 +115,7 @@ let verbose_verify_election_test_data (e, ballots, signatures, private_data) =
));
verbose_assert
"private keys"
(
lazy
(
Array
.
foralli
(
fun
_
k
->
Crypto
.
verify
_private_key
k
)
(
fun
_
k
->
Crypto
.
check
_private_key
k
)
private_data
.
private_keys
));;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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