forked from data61/MP-SPDZ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProgramParty.hpp
108 lines (98 loc) · 2.18 KB
/
ProgramParty.hpp
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
/*
* ProgramParty.hpp
*
*/
#ifndef BMR_PROGRAMPARTY_HPP_
#define BMR_PROGRAMPARTY_HPP_
#include "Party.h"
#include "GC/ShareSecret.hpp"
template<class T>
ProgramPartySpec<T>* ProgramPartySpec<T>::singleton = 0;
template<class T>
ProgramPartySpec<T>::ProgramPartySpec() : MC(0)
{
assert(singleton == 0);
singleton = this;
}
template<class T>
ProgramPartySpec<T>::~ProgramPartySpec()
{
if (MC)
delete MC;
}
template<class T>
void ProgramPartySpec<T>::load(string progname)
{
program.parse(progname + "-0");
machine.reset(program, dynamic_memory);
processor.reset(program);
prf_machine.reset(program);
prf_processor.reset(program);
}
template<class T>
void ProgramPartySpec<T>::_check_evaluate()
{
#ifdef DEBUG_REGS
print_round_regs();
#endif
#ifdef VERBOSE
cerr << "Online time at evaluation start: " << online_timer.elapsed()
<< endl;
#endif
GC::BreakType next = GC::TIME_BREAK;
while (next == GC::TIME_BREAK)
{
load_garbled_circuit();
next = second_phase(program, processor, machine, dynamic_memory);
}
#ifdef VERBOSE
cerr << "Online time at evaluation stop: " << online_timer.elapsed()
<< endl;
#endif
if (next == GC::TIME_BREAK)
{
#ifdef DEBUG_STEPS
cout << "another round of garbling" << endl;
#endif
}
if (next == GC::CLEANING_BREAK)
return;
if (next != GC::DONE_BREAK)
{
#ifdef DEBUG_STEPS
cout << "another round of evaluation" << endl;
#endif
start_online_round();
}
else
{
Timer timer;
timer.start();
MC->Check(*P);
#ifdef VERBOSE
cerr << "Final check took " << timer.elapsed() << endl;
#endif
done();
machine.write_memory(N.my_num());
}
}
template<class T>
void ProgramPartySpec<T>::get_spdz_wire(SpdzOp op, DualWire<T>& spdz_wire)
{
while (true)
{
if (spdz_wires[op].empty())
throw runtime_error("no SPDZ wires available");
if (spdz_wires[op].front().done())
spdz_wires[op].pop_front();
else
break;
}
spdz_wire.unpack(spdz_wires[op].front(), get_n_parties());
spdz_counters[op]++;
#ifdef DEBUG_SPDZ_WIRE
cout << "get SPDZ wire of type " << op << ", " << spdz_wires[op].front().left() << " bytes left" << endl;
cout << "mask share for " << get_id() << ": " << spdz_wire.mask << endl;
#endif
}
#endif /* BMR_PROGRAMPARTY_HPP_ */