forked from data61/MP-SPDZ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TrustedParty.h
128 lines (91 loc) · 2.74 KB
/
TrustedParty.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
/*
* TrustedParty.h
*
*/
#ifndef PROTOCOL_TRUSTEDPARTY_H_
#define PROTOCOL_TRUSTEDPARTY_H_
#include "BooleanCircuit.h"
#include "network/Node.h"
#include <atomic>
#include "Register.h"
#include "CommonParty.h"
class BaseTrustedParty : virtual public CommonFakeParty {
public:
vector<ReceivedMsg> prf_outputs;
vector<SendBuffer> msg_input_masks;
BaseTrustedParty();
virtual ~BaseTrustedParty();
/* From NodeUpdatable class */
virtual void NodeReady();
void NewMessage(int from, ReceivedMsg& msg);
void NodeAborted(struct sockaddr_in* from) { (void)from; }
void Start();
protected:
boost::mutex _print_mx;
std::atomic_uint _num_prf_received;
std::atomic_uint _received_gc_received;
std::atomic_uint n_received;
vector<SendBuffer> msg_keys;
int randomfd;
bool done_filling;
virtual bool _fill_keys() = 0;
void _compute_send_garbled_circuit();
virtual void _launch_online() = 0;
void prepare_randomness();
void send_randomness();
virtual void send_input_masks(party_id_t pid) = 0;
virtual void send_output_masks() = 0;
virtual void garble() = 0;
void add_keys(const Register& reg);
};
class TrustedProgramParty : public BaseTrustedParty {
public:
SendBuffer msg_output_masks;
TrustedProgramParty(int argc, char** argv);
~TrustedProgramParty();
void NodeReady();
void store_spdz_wire(SpdzOp op, const Register& reg);
void store_wire(const Register& reg);
void load_wire(Register& reg);
const Key& delta(int i) { return deltas[i]; }
const KeyVector& get_deltas() { return deltas; }
private:
friend class GarbleRegister;
friend class RandomRegister;
static TrustedProgramParty* singleton;
static TrustedProgramParty& s();
GC::Machine< GC::Secret<GarbleRegister> > machine;
GC::Processor< GC::Secret<GarbleRegister> > processor;
GC::Program program;
GC::Machine< GC::Secret<RandomRegister> > random_machine;
GC::Processor< GC::Secret<RandomRegister> > random_processor;
KeyVector deltas;
vector<octetStream> spdz_wires[SPDZ_OP_N];
vector< Share<gf2n_long> > mask_shares;
Timer random_timer;
bool _fill_keys();
void _launch_online();
void send_input_masks(party_id_t pid);
void send_output_masks();
void garble();
void add_all_keys(const Register& reg, bool external);
};
inline void BaseTrustedParty::add_keys(const Register& reg)
{
for(int p = 0; p < get_n_parties(); p++)
reg.keys.serialize(msg_keys[p], p + 1);
}
inline void TrustedProgramParty::add_all_keys(const Register& reg, bool external)
{
for(int p = 0; p < get_n_parties(); p++)
for (int i = 0; i < get_n_parties(); i++)
reg.keys[external][i].serialize(msg_keys[p]);
}
inline TrustedProgramParty& TrustedProgramParty::s()
{
if (singleton)
return *singleton;
else
throw runtime_error("no singleton");
}
#endif /* PROTOCOL_TRUSTEDPARTY_H_ */