forked from data61/MP-SPDZ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OTTripleSetup.h
106 lines (87 loc) · 2.5 KB
/
OTTripleSetup.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
#ifndef OT_TRIPLESETUP_H_
#define OT_TRIPLESETUP_H_
#include "Networking/Player.h"
#include "OT/BaseOT.h"
#include "Tools/random.h"
#include "Tools/time-func.h"
#include <map>
/*
* Class for creating and storing base OTs between every pair of parties.
*/
class OTTripleSetup
{
BitVector base_receiver_inputs;
vector<BaseOT*> baseOTs;
PRNG G;
int nparties;
int my_num;
int nbase;
public:
map<string,Timer> timers;
vector<OffsetPlayer*> players;
vector< vector< array<BitVector, 2> > > baseSenderInputs;
vector< vector<BitVector> > baseReceiverOutputs;
int get_nparties() const { return nparties; }
int get_nbase() const { return nbase; }
int get_my_num() const { return my_num; }
int get_base_receiver_input(int i) const { return base_receiver_inputs[i]; }
OTTripleSetup(Player& N, bool real_OTs = true)
: nparties(N.num_players()), my_num(N.my_num()), nbase(128)
{
base_receiver_inputs.resize(nbase);
baseOTs.resize(nparties - 1);
baseSenderInputs.resize(nparties - 1);
baseReceiverOutputs.resize(nparties - 1);
#ifdef VERBOSE_BASEOT
if (real_OTs)
cout << "Doing real base OTs\n";
else
cout << "Doing fake base OTs\n";
#endif
for (int i = 0; i < nparties - 1; i++)
{
int other_player;
// i for indexing, other_player is actual number
if (i >= my_num)
other_player = i + 1;
else
other_player = i;
players.push_back(new OffsetPlayer(N, N.get_offset(other_player)));
// sets up a pair of base OTs, playing both roles
if (real_OTs)
{
baseOTs[i] = new BaseOT(nbase, 128, players[i]);
}
else
{
baseOTs[i] = new FakeOT(nbase, 128, players[i]);
}
}
setup();
close_connections();
}
// run the Base OTs
void setup();
// close down the sockets
void close_connections();
//template <class T>
//T get_mac_key();
OTTripleSetup get_fresh();
};
class OnDemandOTTripleSetup
{
map<Player*, OTTripleSetup*> setups;
public:
~OnDemandOTTripleSetup()
{
for (auto& setup : setups)
delete setup.second;
}
OTTripleSetup get_fresh(Player& P)
{
if (setups.find(&P) == setups.end())
setups[&P] = new OTTripleSetup(P, true);
return setups[&P]->get_fresh();
}
};
#endif