forked from bristolcrypto/SPDZ-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-passive.cpp
75 lines (65 loc) · 2.17 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
// (C) 2017 University of Bristol. See License.txt
#include "Math/gf2n.h"
#include "Math/gfp.h"
#include "Math/Setup.h"
#include <fstream>
#include <vector>
#include <numeric>
template <class T>
void check_triples(int n_players)
{
ifstream* inputFiles = new ifstream[n_players];
for (int i = 0; i < n_players; i++)
{
stringstream ss;
ss << get_prep_dir(n_players, 128, 128) << "Triples-" << T::type_char() << "-P" << i;
inputFiles[i].open(ss.str().c_str());
cout << "Opening file " << ss.str() << endl;
}
int j = 0;
while (inputFiles[0].peek() != EOF)
{
T a,b,c,cc,tmp;
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());
if (a * b != 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 " << a*b << 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(n_players, 128, 128);
gfp::init_field(gfp::pr(), false);
check_triples<gf2n>(n_players);
check_triples<gfp>(n_players);
}