Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Macros
Pages
proofs
proofofshuffleofciphers.cpp
Go to the documentation of this file.
1
12
#include "
proofofshuffleofciphers.hpp
"
13
14
15
using namespace
proofs;
16
17
18
ProofOfShuffleOfCiphers::ProofOfShuffleOfCiphers
(
19
bool
&readingWasOK,
20
XmlConfig
* config,
21
std::vector<uint8_t> prefix,
22
arithm::ArrayOfElmts
pedersen,
23
unsigned
int
N,
24
arithm::Field
* randomizerGrp,
25
elGamal::CipherGroup
cipherTextsGrp,
26
arithm::Elmt
elGamalPkey,
27
elGamal::ArrayOfCiphers
inputCiphers,
28
elGamal::ArrayOfCiphers
outputCiphers,
29
verifierUtils::ByteTree
* commitmentFSproof,
30
verifierUtils::ByteTree
* replyFSproof)
31
:
32
Verification
(config,prefix,N),
33
u(pedersen),
34
R(randomizerGrp),
35
C(cipherTextsGrp),
36
pk(elGamalPkey),
37
w(inputCiphers),
38
wPrime(outputCiphers)
39
{
40
readingWasOK =
true
;
41
42
// checking the arrays' sizes
43
if
(
u
.
size
() !=
n0
)
44
{
45
std::cout<<
"ERROR: in ProofOfShuffleOfCommitments:"
46
<<
"u is not of the correct size."
47
<<
"u->getSize()="
<<
u
.
size
()
48
<<
"n0="
<<
n0
<<std::endl;
49
readingWasOK =
false
;
50
}
51
if
(
w
.
size
() !=
n0
)
52
{
53
std::cout<<
"ERROR: in ProofOfShuffleOfCiphers:"
54
<<
"number of input ciphers does not match N:"
55
<<
"\nN="
<<
n0
56
<<
"\nw->getSize()="
<<
w
.
size
()<<std::endl;
57
readingWasOK =
false
;
58
}
59
if
(
wPrime
.
size
() !=
n0
)
60
{
61
std::cout<<
"ERROR: in ProofOfShuffleOfCiphers:"
62
<<
"number of output ciphers does not match N:"
63
<<
"\nN="
<<
n0
64
<<
"\nwPrime->getSize()="
<<
wPrime
.
size
()<<std::endl;
65
readingWasOK =
false
;
66
}
67
68
// initializing the bytetrees
69
tau
= commitmentFSproof;
70
if
((
tau
->
size
()<2) || (!
tau
->
isNode
()))
71
{
72
std::cout<<
"ERROR: in ProofOfShuffleOfCiphers:"
73
<<
"tau is not valid.\ntau="
<<std::endl;
74
tau
->
prettyPrint
(
""
);
75
std::cout<<std::endl;
76
readingWasOK =
false
;
77
}
78
sigma
= replyFSproof;
79
if
((
sigma
->
size
()<3) || (!
sigma
->
isNode
())
80
|| (!
sigma
->
getChild
(0)->
isLeaf
())
81
|| (!
sigma
->
getChild
(1)->
isLeaf
())
82
|| (!
sigma
->
getChild
(2)->
isNode
()) || (
sigma
->
getChild
(2)->
size
() !=
n0
)
83
)
84
{
85
std::cout<<
"ERROR: in ProofOfShuffleOfCiphers:"
86
<<
"sigma is not valid.\nsigma="
<<std::endl;
87
sigma
->
prettyPrint
(
""
);
88
std::cout<<std::endl;
89
readingWasOK =
false
;
90
}
91
}
92
93
94
95
bool
ProofOfShuffleOfCiphers::isEverythingOK
()
96
{
97
// 1-a Parsing tau
98
arithm::Elmt
Aprime =
gq
->
getElmt
(
tau
->
getChild
(0));
99
elGamal::CipherText
Bprime =
C
.
getCipherText
(
tau
->
getChild
(1));
100
101
// 1-b Parsing sigma
102
arithm::Elmt
103
kA =
zq
->
getElmt
(
sigma
->
getChild
(0)),
104
kB =
R
->
getElmt
(
sigma
->
getChild
(1));
105
arithm::ArrayOfElmts
kE =
zq
->
getArray
(
sigma
->
getChild
(2));
106
107
// 2- compute the bytetree part of s
108
std::vector<uint8_t> s;
109
verifierUtils::ByteTree
* bts =
new
verifierUtils::Node
();
110
bts->
addChild
(
gq
->
getGenerator
().
toByteTree
());
111
bts->
addChild
(
h
.
toByteTree
());
112
bts->
addChild
(
u
.
toByteTree
());
113
bts->
addChild
(
elGamal::CipherText
(
gq
->
getGenerator
(),
pk
).toByteTree());
114
bts->
addChild
(
w
.
toByteTree
());
115
bts->
addChild
(
wPrime
.
toByteTree
());
116
117
// 3- compute A
118
arithm::ArrayOfElmts
e =
randomExponents
(bts,s);
119
arithm::Elmt
A =
gq
->
expProduct
(
u
,e);
120
121
// 4- compute a challenge v
122
arithm::Elmt
v =
getChallenge
(s);
123
124
// 5- compute B
125
elGamal::CipherText
B =
C
.
expProduct
(
w
,e);
126
127
// First verification
128
arithm::Elmt
129
lhs =
gq
->
multiplication
(
130
gq
->
exponentiation
(A,v),
131
Aprime
132
),
133
rhs =
gq
->
multiplication
(
134
gq
->
exponentiation
(
gq
->
getGenerator
(),kA),
135
gq
->
expProduct
(
h
,kE)
136
);
137
if
( !
gq
->
compare
(lhs,rhs) )
138
{
139
std::cout<<
"In ProofOfShuffleOfCiphers, $A^vA'$ does not"
140
<<
" equal $g^{k_A}\\prod_{i=0}^{N_0-1}"
141
<<
"h_i^{k_{E,i}}$"
<<std::endl;
142
return
false
;
143
}
144
145
// Second verification
146
elGamal::CipherText
147
lhsBis =
C
.
multiplication
(
148
C
.
exponentiation
(B,v),
149
Bprime
150
),
151
rhsBis =
C
.
multiplication
(
152
C
.
enc
(
pk
,
zq
->
getOne
(),
R
->
addInverse
(kB)),
153
C
.
expProduct
(
wPrime
,kE)
154
);
155
if
(!
C
.
compare
(lhsBis,rhsBis) )
156
{
157
std::cout<<
"In ProofOfShuffleOfCiphers, $B^vB'$ does "
158
<<
"not equal $Enc_{pk}(1,-k_B)\\prod_{i=0}^"
159
<<
"{N_0-1}w'_i^{k_{E,i}}$"
<<std::endl;
160
return
false
;
161
}
162
163
// if this point is reached, then the proof is valid
164
return
true
;
165
}