forked from data61/MP-SPDZ
-
Notifications
You must be signed in to change notification settings - Fork 1
/
YaoGate.cpp
43 lines (40 loc) · 1.39 KB
/
YaoGate.cpp
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
/*
* YaoGate.cpp
*
*/
#include "YaoGate.h"
#include "YaoGarbler.h"
#include "YaoEvaluator.h"
#include "BMR/prf.h"
#include "Tools/MMO.h"
YaoFullGate::YaoFullGate(const YaoGarbleWire& out, const YaoGarbleWire& left,
const YaoGarbleWire& right, Function func)
{
const Key& delta = YaoGarbler::s().get_delta();
MMO& mmo = YaoGarbler::s().mmo;
Key hashes[4];
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
hashes[2 * i + j] = mmo.hash(
E_input(left.key() ^ (i ? delta : 0),
right.key() ^ (j ? delta : 0),
YaoGarbler::s().get_gate_id()));
garble(out, hashes, left.mask(), right.mask(), func, delta);
#ifdef DEBUG
cout << "left " << left.mask() << " " << left.key() << " " << (left.key() ^ delta) << endl;
cout << "right " << right.mask() << " " << right.key() << " " << (right.key() ^ delta) << endl;
cout << "out " << out.mask() << " " << out.key() << " " << (out.key() ^ delta) << endl;
#endif
}
void YaoFullGate::eval(YaoEvalWire& out, const YaoEvalWire& left, const YaoEvalWire& right)
{
MMO& mmo = YaoEvaluator::s().mmo;
Key key = E_input(left.key(), right.key(), YaoEvaluator::s().get_gate_id());
Key hash = mmo.hash(key);
eval(out, &hash, left, right);
#ifdef DEBUG
cout << "external " << left.external() << " " << right.external() << endl;
cout << "entry " << get_entry(left.external(), right.external()) << endl;
cout << "out " << out.key() << endl;
#endif
}