forked from data61/MP-SPDZ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTinyPrep.hpp
75 lines (69 loc) · 2.52 KB
/
TinyPrep.hpp
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
/*
* TinyPrep.cpp
*
*/
#include "TinierSharePrep.h"
#include "Protocols/MascotPrep.hpp"
namespace GC
{
template<class T>
void TinierSharePrep<T>::init_real(Player& P)
{
assert(real_triple_generator == 0);
auto& thread = ShareThread<secret_type>::s();
real_triple_generator = new typename T::whole_type::TripleGenerator(
BaseMachine::fresh_ot_setup(P), P.N, -1,
OnlineOptions::singleton.batch_size, 1, params,
thread.MC->get_alphai(), &P);
real_triple_generator->multi_threaded = false;
}
template<class T>
void TinierSharePrep<T>::buffer_secret_triples()
{
auto& thread = ShareThread<secret_type>::s();
auto& triple_generator = real_triple_generator;
assert(triple_generator != 0);
params.generateBits = false;
vector<array<T, 3>> triples;
TripleShuffleSacrifice<T> sacrifice;
size_t required;
required = sacrifice.minimum_n_inputs_with_combining();
while (triples.size() < required)
{
triple_generator->generatePlainTriples();
triple_generator->unlock();
assert(triple_generator->plainTriples.size() != 0);
for (size_t i = 0; i < triple_generator->plainTriples.size(); i++)
triple_generator->valueBits[2].set_portion(i,
triple_generator->plainTriples[i][2]);
triple_generator->run_multipliers({});
assert(triple_generator->plainTriples.size() != 0);
for (size_t i = 0; i < triple_generator->plainTriples.size(); i++)
{
int dl = secret_type::default_length;
for (int j = 0; j < dl; j++)
{
triples.push_back({});
for (int k = 0; k < 3; k++)
{
auto& share = triples.back()[k];
share.set_share(
triple_generator->plainTriples.at(i).at(k).get_bit(
j));
typename T::mac_type mac;
mac = thread.MC->get_alphai() * share.get_share();
for (auto& multiplier : triple_generator->ot_multipliers)
mac += multiplier->macs.at(k).at(i * dl + j);
share.set_mac(mac);
}
}
}
}
sacrifice.triple_sacrifice(triples, triples,
*thread.P, thread.MC->get_part_MC());
sacrifice.triple_combine(triples, triples, *thread.P,
thread.MC->get_part_MC());
for (auto& triple : triples)
this->triples.push_back(triple);
}
} /* namespace GC */