forked from FudanMPL/Garnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
YaoEvaluator.cpp
executable file
·98 lines (87 loc) · 1.94 KB
/
YaoEvaluator.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
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
/*
* YaoEvaluator.cpp
*
*/
#include "YaoEvaluator.h"
#include "GC/Machine.hpp"
#include "GC/Program.hpp"
#include "GC/Processor.hpp"
#include "GC/Secret.hpp"
#include "GC/Thread.hpp"
#include "GC/ThreadMaster.hpp"
#include "Tools/MMO.hpp"
#include "YaoWire.hpp"
thread_local YaoEvaluator* YaoEvaluator::singleton = 0;
YaoEvaluator::YaoEvaluator(int thread_num, YaoEvalMaster& master) :
Thread<GC::Secret<YaoEvalWire>>(thread_num, master),
YaoCommon<YaoEvalWire>(master),
master(master),
player(N, 0, "thread" + to_string(thread_num)),
ot_ext(OTExtensionWithMatrix::setup(player, {}, RECEIVER, true))
{
set_n_program_threads(master.machine.nthreads);
this->init(*this);
}
void YaoEvaluator::pre_run()
{
if (master.opts.cmd_private_output_file.empty())
processor.out.activate(not continuous());
if (not continuous())
receive_to_store(*P);
}
void YaoEvaluator::run(GC::Program& program)
{
singleton = this;
if (continuous())
run(program, *P);
else
{
run_from_store(program);
}
}
void YaoEvaluator::run(GC::Program& program, Player& P)
{
auto next = GC::TIME_BREAK;
do
{
receive(P);
try
{
next = program.execute(processor, master.memory, -1);
}
catch (needs_cleaning& e)
{
}
}
while(GC::DONE_BREAK != next);
}
void YaoEvaluator::run_from_store(GC::Program& program)
{
machine.reset_timer();
do
{
gates_store.pop(gates);
output_masks_store.pop(output_masks);
}
while(GC::DONE_BREAK != program.execute(processor, master.memory, -1));
}
bool YaoEvaluator::receive(Player& P)
{
if (P.receive_long(0) == YaoCommon::DONE)
return false;
P.receive_player(0, gates);
P.receive_player(0, output_masks);
#ifdef DEBUG_YAO
cout << "received " << gates.size() << " gates and " << output_masks.size()
<< " output masks at " << processor.PC << endl;
#endif
return true;
}
void YaoEvaluator::receive_to_store(Player& P)
{
while (receive(P))
{
gates_store.push(gates);
output_masks_store.push(output_masks);
}
}