forked from data61/MP-SPDZ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-passive.cpp
87 lines (77 loc) · 2.52 KB
/
check-passive.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
#include "Math/gf2n.h"
#include "Math/gfp.hpp"
#include "Math/Z2k.h"
#include "Math/Setup.h"
#include "Protocols/Share.h"
#include <fstream>
#include <vector>
#include <numeric>
#include "Math/Z2k.hpp"
template <class T>
void check_triples(int n_players, string type_char = "")
{
ifstream* inputFiles = new ifstream[n_players];
for (int i = 0; i < n_players; i++)
{
stringstream ss;
ss << get_prep_sub_dir<Share<T>>(n_players) << "Triples-";
if (type_char.size())
ss << type_char;
else
ss << T::type_char();
ss << "-P" << i;
inputFiles[i].open(ss.str().c_str());
cout << "Opening file " << ss.str() << endl;
octetStream tmp, tmp2 = file_signature<T>();
tmp.input(inputFiles[i]);
assert(tmp == tmp2);
}
int j = 0;
while (inputFiles[0].peek() != EOF)
{
T a,b,c,cc,tmp,prod;
vector<T> as(n_players), bs(n_players), cs(n_players);
for (int i = 0; i < n_players; i++)
{
as[i].input(inputFiles[i], false);
bs[i].input(inputFiles[i], false);
cs[i].input(inputFiles[i], false);
}
a = accumulate(as.begin(), as.end(), T());
b = accumulate(bs.begin(), bs.end(), T());
c = accumulate(cs.begin(), cs.end(), T());
prod = a * b;
if (prod != c)
{
cout << T::type_string() << ": Error in " << j << endl;
cout << "a " << a << " " << as[0] << " " << as[1] << endl;
cout << "b " << b << " " << bs[0] << " " << bs[1] << endl;
cout << "c " << c << " " << cs[0] << " " << cs[1] << endl;
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
{
tmp = as[i] * bs[j];
cc += tmp;
cout << "a" << i << " * b" << j << " " << tmp << endl;
}
cout << "cc " << cc << endl;
cout << "a*b " << prod << endl;
cout << "DID YOU INDICATE THE CORRECT NUMBER OF PLAYERS?" << endl;
return;
}
j++;
}
cout << j << " correct triples of type " << T::type_string() << endl;
delete[] inputFiles;
}
int main(int argc, char** argv)
{
int n_players = 2;
if (argc > 1)
n_players = atoi(argv[1]);
read_setup(get_prep_sub_dir<Share<gfp>>(PREP_DIR, n_players, 128));
gfp::init_field(gfp::pr(), false);
gf2n::init_field();
check_triples<gf2n>(n_players);
check_triples<gfp>(n_players);
}