forked from data61/MP-SPDZ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Party.h
221 lines (156 loc) · 4.77 KB
/
Party.h
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
* Party.h
*
*/
#ifndef PROTOCOL_PARTY_H_
#define PROTOCOL_PARTY_H_
#include "Register.h"
#include "GarbledGate.h"
#include "network/Node.h"
#include "CommonParty.h"
#include "SpdzWire.h"
#include "AndJob.h"
#include "GC/Machine.h"
#include "GC/Program.h"
#include "GC/Processor.h"
#include "GC/Secret.h"
#include "GC/RuntimeBranching.h"
#include "Tools/Worker.h"
#define SERVER_ID (0)
#define INPUT_KEYS_MSG_TYPE_SIZE (16) // so memory will by alligned
#ifndef N_EVAL_THREADS
// Default Intel desktop processor has 8 half cores.
// This is beneficial if only one AES available per full core.
#define N_EVAL_THREADS (thread::hardware_concurrency())
#endif
class PartyProperties
{
protected:
party_id_t _id;
Timer online_timer;
Key delta;
public:
PartyProperties() : _id(-1) {}
party_id_t get_id() { return _id; }
Key get_delta() { return delta; }
};
class BaseParty : virtual public CommonFakeParty, virtual public PartyProperties
{
public:
BaseParty();
virtual ~BaseParty();
/* From NodeUpdatable class */
void NodeReady();
void NewMessage(int from, ReceivedMsg& msg);
void NodeAborted(struct sockaddr_in* from) { (void)from; }
void Start();
protected:
virtual void _compute_prfs_outputs(Key* keys) = 0;
void _send_prfs();
virtual void store_garbled_circuit(ReceivedMsg& msg) = 0;
virtual void _check_evaluate() = 0;
virtual void mask_output(ReceivedMsg& msg) = 0;
virtual void mask_input(ReceivedMsg& msg) = 0;
void done();
virtual void start_online_round() = 0;
virtual void receive_spdz_wires(ReceivedMsg& msg) = 0;
};
class ProgramParty : virtual public CommonParty, virtual public PartyProperties, public GC::RuntimeBranching
{
protected:
friend class PRFRegister;
friend class EvalRegister;
friend class Register;
vector<char> prf_output;
deque<octetStream> spdz_wires[SPDZ_OP_N];
size_t spdz_storage;
size_t garbled_storage;
vector<size_t> spdz_counters;
Worker<AndJob>* eval_threads;
vector<AndJob> and_jobs;
ReceivedMsgStore output_masks_store;
ReceivedMsgStore input_masks_store;
GC::Machine< GC::Secret<EvalRegister> > machine;
GC::Processor<GC::Secret<EvalRegister> > processor;
GC::Program program;
GC::Machine< GC::Secret<PRFRegister> > prf_machine;
GC::Processor<GC::Secret<PRFRegister> > prf_processor;
void store_garbled_circuit(ReceivedMsg& msg);
void load_garbled_circuit();
virtual void _check_evaluate() = 0;
virtual void done() = 0;
virtual void receive_keys(Register& reg) = 0;
virtual void receive_all_keys(Register& reg, bool external) = 0;
virtual void process_prf_output(PRFOutputs& prf_output,
PRFRegister* out, const PRFRegister* left, const PRFRegister* right) = 0;
void start_online_round();
void mask_output(ReceivedMsg& msg) { output_masks_store.push(msg); }
void mask_input(ReceivedMsg& msg) { input_masks_store.push(msg); }
public:
static ProgramParty* singleton;
LocalBuffer garbled_circuit;
ReceivedMsgStore garbled_circuits;
LocalBuffer output_masks;
LocalBuffer input_masks;
Player* P;
Names N;
int threshold;
Integer convcbit;
static ProgramParty& s();
ProgramParty();
virtual ~ProgramParty();
void reset();
void store_wire(const Register& reg);
void load_wire(Register& reg);
};
template<class T>
class ProgramPartySpec : public ProgramParty
{
static ProgramPartySpec* singleton;
protected:
GC::Memory<T> dynamic_memory;
void _check_evaluate();
public:
typename T::MAC_Check* MC;
static ProgramPartySpec& s();
ProgramPartySpec();
~ProgramPartySpec();
void load(string progname);
void get_spdz_wire(SpdzOp op, DualWire<T>& spdz_wire);
};
typedef ProgramPartySpec<Share<gf2n_long>> FakeProgramPartySuper;
class FakeProgramParty : virtual public BaseParty, virtual public FakeProgramPartySuper
{
Key* keys_for_prf;
void _compute_prfs_outputs(Key* keys);
void store_garbled_circuit(ReceivedMsg& msg) { ProgramParty::store_garbled_circuit(msg); }
void _check_evaluate();
void receive_keys(Register& reg);
void receive_all_keys(Register& reg, bool external);
void process_prf_output(PRFOutputs& prf_output, PRFRegister* out,
const PRFRegister* left, const PRFRegister* right);
void receive_spdz_wires(ReceivedMsg& msg);
void start_online_round() { FakeProgramPartySuper::start_online_round(); }
void mask_output(ReceivedMsg& msg) { ProgramParty::mask_output(msg); }
void mask_input(ReceivedMsg& msg) { ProgramParty::mask_input(msg); }
void done() { BaseParty::done(); }
public:
FakeProgramParty(int argc, const char** argv);
~FakeProgramParty();
};
inline ProgramParty& ProgramParty::s()
{
if (singleton)
return *singleton;
else
throw runtime_error("no singleton");
}
template<class T>
inline ProgramPartySpec<T>& ProgramPartySpec<T>::s()
{
if (singleton)
return *singleton;
else
throw runtime_error("no singleton");
}
#endif /* PROTOCOL_PARTY_H_ */