-
Notifications
You must be signed in to change notification settings - Fork 111
/
mult3.ag2pc.cpp
72 lines (64 loc) · 2.13 KB
/
mult3.ag2pc.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
#include <emp-tool/emp-tool.h>
#include "emp-ag2pc/emp-ag2pc.h"
#include "test/single_execution.h"
using namespace std;
using namespace emp;
//const string circuit_file_location = macro_xstr(EMP_CIRCUIT_PATH);
void test(int party, NetIO* io, string name, string check_output = "") {
// read in the circuit from the location where it was generated
string file = "./" + name;
cout << file << endl;
BristolFormat cf(file.c_str());
//
// initialize some timing stuff?
auto t1 = clock_start();
C2PC<NetIO> twopc(io, party, &cf);
io->flush();
cout << "one time:\t"<<party<<"\t" <<time_from(t1)<<endl;
// preprocessing (make AND triples)
t1 = clock_start();
twopc.function_independent();
io->flush();
cout << "inde:\t"<<party<<"\t"<<time_from(t1)<<endl;
// garbling (takes two parties)
t1 = clock_start();
twopc.function_dependent();
io->flush();
cout << "dep:\t"<<party<<"\t"<<time_from(t1)<<endl;
// create and fill in input vectors (to all zeros with memset)
bool *in = new bool[max(cf.n1, cf.n2)];
cout << "input size: max " << cf.n1 << "\t" << cf.n2 << endl;
cout << "input for " << party << ": 0" << endl;
bool * out = new bool[cf.n3];
if (party == ALICE) {
memset(in, false, max(cf.n1, cf.n2));
} else {
memset(in, false, max(cf.n1, cf.n2));
}
memset(out, false, cf.n3);
// evaluate: online protocol execution
t1 = clock_start();
twopc.online(in, out);
cout << "online:\t"<<party<<"\t"<<time_from(t1)<<endl;
// compare result to our hardcoded expected result
if(party == BOB and check_output.size() > 0){
string res = "";
for(int i = 0; i < cf.n3; ++i)
res += (out[i]?"1":"0");
cout << "result: " << res << endl;
cout << "expected result (this is hardcoded): " << hex_to_binary(check_output) << endl;
cout << (res == hex_to_binary(check_output)? "GOOD!":"BAD!")<<endl;
}
delete[] in;
delete[] out;
}
int main(int argc, char** argv) {
// set up parties
int party, port;
parse_party_and_port(argv, &party, &port);
NetIO* io = new NetIO(party==ALICE ? nullptr:IP, port);
io->set_nodelay();
test(party, io, "mult3.circuit.txt", string("0000"));
delete io;
return 0;
}