forked from data61/MP-SPDZ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OTMultiplier.h
199 lines (156 loc) · 5.06 KB
/
OTMultiplier.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
/*
* OTMultiplier.h
*
*/
#ifndef OT_OTMULTIPLIER_H_
#define OT_OTMULTIPLIER_H_
#include <vector>
using namespace std;
#include "OT/OTExtensionWithMatrix.h"
#include "OT/OTVole.h"
#include "OT/Rectangle.h"
#include "Tools/random.h"
#include "Tools/CheckVector.h"
template<class T>
class NPartyTripleGenerator;
template<class T>
class OTTripleGenerator;
class MultJob
{
public:
Dtype type;
bool input;
int player;
int n_inputs;
MultJob(Dtype type = N_DTYPE) : type(type), input(false), player(-1), n_inputs(0) {}
MultJob(int player, int n_inputs) : type(N_DTYPE), input(true), player(player), n_inputs(n_inputs) {}
};
class OTMultiplierBase
{
public:
pthread_t thread;
WaitQueue<MultJob> inbox;
WaitQueue<MultJob> outbox;
virtual ~OTMultiplierBase() {}
virtual void multiply() = 0;
};
template <class V, class W>
class OTMultiplierMac : public OTMultiplierBase
{
public:
vector< vector<V> > macs;
vector<W> input_macs;
};
template <class T>
class OTMultiplier : public OTMultiplierMac<typename T::sacri_type, typename T::mac_type>
{
protected:
BitVector keyBits;
vector< array<BitVector, 2> > senderOutput;
vector<BitVector> receiverOutput;
void multiplyForTriples();
virtual void multiplyForBits();
virtual void multiplyForMixed();
virtual void multiplyForInputs(MultJob job) = 0;
virtual void after_correlation() = 0;
virtual void init_authenticator(const BitVector& baseReceiverInput,
const vector< array<BitVector, 2> >& baseSenderInput,
const vector<BitVector>& baseReceiverOutput) = 0;
public:
OTTripleGenerator<T>& generator;
int thread_num;
OTExtensionWithMatrix rot_ext;
OTCorrelator<Matrix<typename T::Rectangle> > otCorrelator;
OTMultiplier(OTTripleGenerator<T>& generator, int thread_num);
virtual ~OTMultiplier();
void multiply();
};
template <class T>
class MascotMultiplier : public OTMultiplier<T>
{
OTCorrelator<Matrix<typename T::Square> > auth_ot_ext;
void after_correlation();
void init_authenticator(const BitVector& baseReceiverInput,
const vector< array<BitVector, 2> >& baseSenderInput,
const vector<BitVector>& baseReceiverOutput);
void multiplyForBits();
template <int = 0>
void multiplyForBits(true_type);
template <int = 0>
void multiplyForBits(false_type);
public:
vector<typename T::open_type> c_output;
MascotMultiplier(OTTripleGenerator<T>& generator, int thread_num);
void multiplyForInputs(MultJob job);
};
template <class T>
class TinyMultiplier : public OTMultiplier<T>
{
OTVole<typename T::part_type::sacri_type> mac_vole;
void after_correlation();
void init_authenticator(const BitVector& baseReceiverInput,
const vector< array<BitVector, 2> >& baseSenderInput,
const vector<BitVector>& baseReceiverOutput);
public:
vector<typename T::open_type> c_output;
TinyMultiplier(OTTripleGenerator<T>& generator, int thread_num);
void multiplyForInputs(MultJob job) { (void) job; throw not_implemented(); }
};
template <class T>
class TinierMultiplier : public OTMultiplier<T>
{
OTExtensionWithMatrix auth_ot_ext;
void after_correlation();
void init_authenticator(const BitVector& baseReceiverInput,
const vector< array<BitVector, 2> >& baseSenderInput,
const vector<BitVector>& baseReceiverOutput);
public:
vector<typename T::open_type> c_output;
TinierMultiplier(OTTripleGenerator<T>& generator, int thread_num);
void multiplyForInputs(MultJob job);
};
template <int K, int S> class Spdz2kShare;
template <int K, int S>
class Spdz2kMultiplier: public OTMultiplier<Spdz2kShare<K, S>>
{
typedef Spdz2kShare<K, S> T;
void after_correlation();
void init_authenticator(const BitVector& baseReceiverInput,
const vector< array<BitVector, 2> >& baseSenderInput,
const vector<BitVector>& baseReceiverOutput);
void multiplyForInputs(MultJob job);
public:
static const int TAU = TAU(K, S);
static const int PASSIVE_MULT_BITS = K + S;
static const int MAC_BITS = K + 2 * S;
vector<Z2kRectangle<TAU, PASSIVE_MULT_BITS> > c_output;
OTVoleBase<Z2<MAC_BITS>>* mac_vole;
OTVoleBase<Z2<K + S>>* input_mac_vole;
Spdz2kMultiplier(OTTripleGenerator<T>& generator, int thread_num);
~Spdz2kMultiplier();
};
template<class T>
class SemiMultiplier : public OTMultiplier<T>
{
void multiplyForInputs(MultJob job)
{
(void) job;
throw not_implemented();
}
void multiplyForBits();
void multiplyForMixed();
void after_correlation();
void init_authenticator(const BitVector& baseReceiverInput,
const vector< array<BitVector, 2> >& baseSenderInput,
const vector<BitVector>& baseReceiverOutput)
{
(void) baseReceiverInput, (void) baseReceiverOutput, (void) baseSenderInput;
}
public:
CheckVector<typename T::open_type> c_output;
SemiMultiplier(OTTripleGenerator<T>& generator, int i) :
OTMultiplier<T>(generator, i)
{
}
};
#endif /* OT_OTMULTIPLIER_H_ */