forked from data61/MP-SPDZ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OTExtensionWithMatrix.h
129 lines (104 loc) · 3.71 KB
/
OTExtensionWithMatrix.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
/*
* OTExtensionWithMatrix.h
*
*/
#ifndef OT_OTEXTENSIONWITHMATRIX_H_
#define OT_OTEXTENSIONWITHMATRIX_H_
#include "OTExtension.h"
#include "BitMatrix.h"
#include "Math/gf2n.h"
#ifndef USE_KOS
namespace osuCrypto {
class Channel;
}
#endif
template <class U>
class OTCorrelator : public OTExtension
{
public:
vector<U> senderOutputMatrices;
vector<U> matrices;
U& receiverOutputMatrix;
U& t1;
U u;
OTCorrelator(TwoPartyPlayer* player,
OT_ROLE role=BOTH,
bool passive=false)
: OTExtension(player, role, passive),
senderOutputMatrices(2), matrices(2),
receiverOutputMatrix(matrices[0]), t1(matrices[1]) {}
OTCorrelator(BaseOT& baseOT, TwoPartyPlayer* player, bool passive) :
OTExtension(baseOT, player, passive),
senderOutputMatrices(2), matrices(2),
receiverOutputMatrix(matrices[0]), t1(matrices[1]) {}
void resize(int nOTs);
void expand(int start, int slice);
void setup_for_correlation(BitVector& baseReceiverInput,
vector<U>& baseSenderOutputs,
U& baseReceiverOutput);
void correlate(int start, int slice, BitVector& newReceiverInput, bool useConstantBase, int repeat = 1);
void expand_correlate_unchecked(const BitVector& delta, int n_bits = -1);
template <class T>
void reduce_squares(unsigned int nTriples, vector<T>& output,
int start = 0);
void common_seed(PRNG& G);
};
class OTExtensionWithMatrix : public OTCorrelator<BitMatrix>
{
static bool warned;
int nsubloops;
#ifndef USE_KOS
osuCrypto::Channel* channel;
#endif
bool agreed;
public:
PRNG G;
static OTExtensionWithMatrix setup(TwoPartyPlayer& player,
int128 delta, OT_ROLE role, bool passive);
OTExtensionWithMatrix(
TwoPartyPlayer* player,
OT_ROLE role=BOTH,
bool passive=false, int nsubloops = 1)
: OTCorrelator<BitMatrix>(player, role, passive),
nsubloops(nsubloops)
{
G.ReSeed();
agreed = false;
#ifndef USE_KOS
channel = 0;
#endif
}
OTExtensionWithMatrix(BaseOT& baseOT, TwoPartyPlayer* player, bool passive);
~OTExtensionWithMatrix();
void protocol_agreement();
void transfer(int nOTs, const BitVector& receiverInput, int nloops);
void extend(int nOTs, const BitVector& newReceiverInput);
void extend_correlated(const BitVector& newReceiverInput);
void extend_correlated(int nOTs, const BitVector& newReceiverInput);
void transpose(int start = 0, int slice = -1);
void expand_transposed();
template <class V>
void hash_outputs(int nOTs, vector<V>& senderOutput, V& receiverOutput,
bool correlated = true);
// SoftSpokenOT
void soft_sender(size_t nOTs);
void soft_receiver(size_t nOTs, const BitVector& newReceiverInput);
void print(BitVector& newReceiverInput, int i = 0);
template <class T>
void print_receiver(BitVector& newReceiverInput, BitMatrix& matrix, int i = 0, int offset = 0);
void print_sender(square128& square0, square128& square);
template <class T>
void print_post_correlate(BitVector& newReceiverInput, int i = 0, int offset = 0, int sender = 0);
void print_pre_correlate(int i = 0);
void print_post_transpose(BitVector& newReceiverInput, int i = 0, int sender = 0);
void print_pre_expand();
octet* get_receiver_output(int i);
octet* get_sender_output(int choice, int i);
protected:
void hash_outputs(int nOTs);
void check_correlation(int nOTs,
const BitVector& receiverInput);
void check_iteration(__m128i delta, __m128i q, __m128i q2,
__m128i t, __m128i t2, __m128i x);
};
#endif /* OT_OTEXTENSIONWITHMATRIX_H_ */