forked from data61/MP-SPDZ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNPartyTripleGenerator.h
215 lines (160 loc) · 5.47 KB
/
NPartyTripleGenerator.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
#ifndef OT_NPARTYTRIPLEGENERATOR_H_
#define OT_NPARTYTRIPLEGENERATOR_H_
#include "Networking/Player.h"
#include "OT/BaseOT.h"
#include "Tools/random.h"
#include "Tools/time-func.h"
#include "Processor/InputTuple.h"
#include "OT/OTTripleSetup.h"
#include "OT/MascotParams.h"
#include "OT/OTMultiplier.h"
#include <map>
#include <vector>
#define N_AMPLIFY 3
template <class T, int N>
class ShareTriple;
template <class T, int N>
class PlainTriple;
class GeneratorThread
{
protected:
pthread_mutex_t mutex;
pthread_cond_t ready;
public:
int nTriples;
map<string,Timer> timers;
bool multi_threaded;
GeneratorThread() : nTriples(0), multi_threaded(true) {}
virtual ~GeneratorThread() {};
virtual void generate() = 0;
void lock();
void unlock();
void signal();
void wait();
};
template<class T>
class OTTripleGenerator : public GeneratorThread
{
typedef typename T::open_type open_type;
typedef typename T::mac_key_type mac_key_type;
protected:
//OTTripleSetup* setup;
Player& globalPlayer;
Player* parentPlayer;
int thread_num;
int nbase;
struct timeval last_lap;
ofstream outputFile;
SeededPRNG share_prg;
mac_key_type mac_key;
void start_progress();
void print_progress(int k);
void signal_multipliers(MultJob job);
void wait_for_multipliers();
typename T::Multiplier* new_multiplier(int i);
public:
// TwoPartyPlayer's for OTs, n-party Player for sacrificing
vector<TwoPartyPlayer*> players;
vector<typename T::Multiplier*> ot_multipliers;
//vector<OTMachine*> machines;
BitVector baseReceiverInput; // same for every set of OTs
vector< vector< array<BitVector, 2> > > baseSenderInputs;
vector< vector<BitVector> > baseReceiverOutputs;
vector<BitVector> valueBits;
BitVector b_padded_bits;
int my_num;
int nTriplesPerLoop;
int nloops;
int field_size;
int nAmplify;
int nPreampTriplesPerLoop;
int repeat[3];
int nparties;
MascotParams& machine;
vector<PlainTriple<open_type, N_AMPLIFY>> preampTriples;
vector<array<open_type, 3>> plainTriples;
vector<open_type> plainBits;
typename T::MAC_Check* MC;
OTTripleGenerator(const OTTripleSetup& setup, const Names& names,
int thread_num, int nTriples, int nloops, MascotParams& machine,
mac_key_type mac_key,
Player* parentPlayer = 0);
~OTTripleGenerator();
void generate() { throw not_implemented(); }
void generatePlainTriples();
void plainTripleRound(int k = 0);
void generatePlainBits();
void run_multipliers(MultJob job);
mac_key_type get_mac_key() const { return mac_key; }
Player& get_player() { return globalPlayer; }
};
template<class T>
class NPartyTripleGenerator : public OTTripleGenerator<T>
{
typedef typename T::open_type open_type;
typedef typename T::mac_key_type mac_key_type;
virtual void generateTriples() { throw not_implemented(); }
virtual void generateBits() { throw not_implemented(); }
public:
vector<InputTuple<typename T::input_type>> inputs;
NPartyTripleGenerator(const OTTripleSetup& setup, const Names& names,
int thread_num, int nTriples, int nloops, MascotParams& machine,
mac_key_type mac_key,
Player* parentPlayer = 0);
virtual ~NPartyTripleGenerator() {}
void generate();
void generateInputs(int player);
};
template<class T>
class SimpleMascotTripleGenerator : public NPartyTripleGenerator<T>
{
typedef typename T::mac_key_type mac_key_type;
typedef typename T::MAC_Check MAC_Check;
virtual void sacrifice(typename T::MAC_Check&, PRNG&) { throw not_implemented(); }
public:
vector< ShareTriple<T, 2> > uncheckedTriples;
SimpleMascotTripleGenerator(const OTTripleSetup& setup, const Names& names,
int thread_num, int nTriples, int nloops, MascotParams& machine,
mac_key_type mac_key,
Player* parentPlayer = 0);
virtual ~SimpleMascotTripleGenerator() {}
void generateTriples();
};
template<class T>
class MascotTripleGenerator : public SimpleMascotTripleGenerator<T>
{
typedef typename T::open_type open_type;
typedef typename T::mac_key_type mac_key_type;
typedef typename T::MAC_Check MAC_Check;
void generateBits();
void generateBitsGf2n();
template <int X, int L>
void generateBitsFromTriples(MAC_Check& MC, ofstream& outputFile, gfp_<X, L>);
template <class U>
void generateBitsFromTriples(MAC_Check& MC, ofstream& outputFile, U);
void sacrifice(typename T::MAC_Check& MC, PRNG& G);
public:
vector<T> bits;
MascotTripleGenerator(const OTTripleSetup& setup, const Names& names,
int thread_num, int nTriples, int nloops, MascotParams& machine,
mac_key_type mac_key,
Player* parentPlayer = 0);
};
template<class T>
class Spdz2kTripleGenerator : public NPartyTripleGenerator<T>
{
typedef typename T::open_type open_type;
typedef typename T::mac_key_type mac_key_type;
typedef typename T::sacri_type sacri_type;
void generateBits() { throw not_implemented(); }
template<class U>
void sacrificeZ2k(U& MC, PRNG& G);
public:
vector< ShareTriple<Share<sacri_type>, 2> > uncheckedTriples;
Spdz2kTripleGenerator(const OTTripleSetup& setup, const Names& names,
int thread_num, int nTriples, int nloops, MascotParams& machine,
mac_key_type mac_key,
Player* parentPlayer = 0);
void generateTriples();
};
#endif