-
Notifications
You must be signed in to change notification settings - Fork 1
/
proof.cpp
204 lines (170 loc) · 6.36 KB
/
proof.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/**
* Copyright (c) 2016-2018 Koninklijke Philips N.V. All rights reserved. A
* copyright license for redistribution and use in source and binary forms,
* with or without modification, is hereby granted for non-commercial,
* experimental and research purposes, provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimers.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimers in the
* documentation and/or other materials provided with the distribution. If
* you wish to use this software commercially, kindly contact
* [email protected] to obtain a commercial license.
*
* This license extends only to copyright and does not include or grant any
* patent license or other license whatsoever.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "base.h"
#include "modp.h"
#include "key.h"
#include "proof.h"
#include <fstream>
using namespace std;
datablock::datablock() {
comm = g10;
commal = g20;
}
datablock operator+(const datablock& b1, const datablock& b2) {
datablock ret;
ret.comm = b1.comm + b2.comm;
ret.commal = b1.commal + b2.commal;
return ret;
}
datablock operator*(modp fac, datablock orig) {
datablock ret;
ret.comm = orig.comm^fac;
ret.commal = orig.commal^fac;
return ret;
}
datablock operator-(datablock p1, datablock p2) {
return p1 + -1*p2;
}
std::ostream& operator<<(std::ostream& os, const datablock& x) {
os << "geppetri_datablock [ " << x.comm << " " << x.commal << " ]";
return os;
}
std::istream& operator>>(std::istream& is, datablock& x) {
string checktok; is >> checktok;
if (checktok != "geppetri_datablock") throw std::ios_base::failure((string("Expected \"geppetri_datablock\", got \"") + checktok + "\"").c_str());
char br; is >> br;
if (br != '[') throw std::ios_base::failure((string("Bad datablock: expected \"[\", got \"") + br + "\"").c_str());
is >> x.comm >> x.commal;
is >> br;
if (br != ']') throw std::ios_base::failure((string("Bad datablock: expected \"]\", got \"") + br + "\"").c_str());
return is;
}
blockproof::blockproof() {
comm = g10;
commal = g20;
commz = g10;
}
std::ostream& operator<<(std::ostream& os, const blockproof& x) {
os << "[ " << x.comm << " " << x.commal << " " << x.commz << " ]";
return os;
}
std::istream& operator>>(std::istream& is, blockproof& x) {
char br; is >> br;
if (br != '[') throw std::ios_base::failure((string("Bad blockproof: expected \"[\", got \"") + br + "\"").c_str());
is >> x.comm >> x.commal >> x.commz;
is >> br;
if (br != ']') throw std::ios_base::failure((string("Bad blockproof: expected \"]\", got \"") + br + "\"").c_str());
return is;
}
qapproof::qapproof() {
p_rvx = g10;
p_rwx = g20;
p_ryx = g10;
p_ravx = g20;
p_rawx = g10;
p_rayx = g20;
p_z = g10;
}
std::ostream& operator<<(std::ostream& os, const qapproof& x) {
os << "geppetri_qapproof [ " << endl;
os << " " << x.p_rvx << endl;
os << " " << x.p_rwx << endl;
os << " " << x.p_ryx << endl;
os << " " << x.p_ravx << endl;
os << " " << x.p_rawx << endl;
os << " " << x.p_rayx << endl;
os << " " << x.p_z << endl;
os << " " << x.p_h << endl;
for (auto const& it: x.blocks) {
os << " " << it.first << " " << it.second << endl;
}
os << "]" << endl;
return os;
}
std::istream& operator>>(std::istream& is, qapproof& x) {
string checktok; is >> checktok;
if (checktok != "geppetri_qapproof") throw std::ios_base::failure((string("Expected \"geppetri_qapproof\", got \"") + checktok + "\"").c_str());
char br; is >> br;
if (br != '[') throw std::ios_base::failure((string("Bad qapproof: expected \"[\", got \"") + br + "\"").c_str());
is >> x.p_rvx >> x.p_rwx >> x.p_ryx >> x.p_ravx >> x.p_rawx >> x.p_rayx >> x.p_z >> x.p_h;
string tok;
while (!(is>>tok).eof() && tok!="]") {
// cerr << "reading block " << tok << endl;
is >> x.blocks[tok];
}
if (tok != "]") throw std::ios_base::failure((string("Bad qapproof: expected \"]\", got \"") + br + "\"").c_str());
return is;
}
blockproof operator*(modp fac, blockproof orig) {
blockproof ret;
ret.comm = orig.comm^fac;
ret.commal = orig.commal^fac;
ret.commz = orig.commz^fac;
return ret;
}
blockproof operator-(blockproof p1, blockproof p2) {
return p1+(-1)*p2;
}
blockproof operator+(blockproof p1, blockproof p2) {
blockproof ret;
ret.comm = p1.comm + p2.comm;
ret.commal = p1.commal + p2.commal;
ret.commz = p1.commz + p2.commz;
return ret;
}
qapproof operator*(modp fac, qapproof orig) {
qapproof ret;
for (auto const& it: orig.blocks) ret.blocks[it.first]=fac*it.second;
ret.p_rvx = orig.p_rvx^fac;
ret.p_rwx = orig.p_rwx^fac;
ret.p_ryx = orig.p_ryx^fac;
ret.p_ravx = orig.p_ravx^fac;
ret.p_rawx = orig.p_rawx^fac;
ret.p_rayx = orig.p_rayx^fac;
ret.p_z = orig.p_z^fac;
ret.p_h = orig.p_h^fac;
return ret;
}
qapproof operator-(qapproof p1, qapproof p2) {
return p1+(-1)*p2;
}
qapproof operator+(qapproof p1, qapproof p2) {
qapproof ret;
for (auto const& it: p1.blocks) ret.blocks[it.first]=it.second+p2.blocks[it.first];
ret.p_rvx = p1.p_rvx+p2.p_rvx;
ret.p_rwx = p1.p_rwx+p2.p_rwx;
ret.p_ryx = p1.p_ryx+p2.p_ryx;
ret.p_ravx = p1.p_ravx+p2.p_ravx;
ret.p_rawx = p1.p_rawx+p2.p_rawx;
ret.p_rayx = p1.p_rayx+p2.p_rayx;
ret.p_z = p1.p_z+p2.p_z;
ret.p_h = p1.p_h+p2.p_h;
return ret;
}