forked from data61/MP-SPDZ
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathYaoAndJob.h
88 lines (77 loc) · 1.6 KB
/
YaoAndJob.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
/*
* YaoAndJob.h
*
*/
#ifndef YAO_YAOANDJOB_H_
#define YAO_YAOANDJOB_H_
#include "YaoGarbleWire.h"
#include "Tools/Worker.h"
enum YaoJobType
{
YAO_AND_JOB,
YAO_XOR_JOB,
YAO_NO_JOB
};
template<class T>
class YaoAndJob
{
GC::Processor< GC::Secret<T> >* processor;
const vector<int>* args;
size_t start, end, n_gates;
YaoGate* gate;
long counter;
PRNG prng;
map<string, Timer> timers;
bool repeat;
typename T::Party& party;
YaoJobType type;
public:
Worker<YaoAndJob> worker;
YaoAndJob(typename T::Party& party) :
processor(0), args(0), start(0), end(0), n_gates(0), gate(0),
counter(0), repeat(0), party(party), type(YAO_NO_JOB)
{
prng.ReSeed();
}
~YaoAndJob()
{
#ifdef VERBOSE
for (auto& x : timers)
cerr << x.first << " time:" << x.second.elapsed() << endl;
#endif
}
void dispatch(YaoJobType type,
GC::Processor<GC::Secret<T> >& processor, const vector<int>& args,
size_t start, size_t end, size_t n_gates,
YaoGate* gate, long counter, bool repeat)
{
this->type = type;
this->processor = &processor;
this->args = &args;
this->start = start;
this->end = end;
this->n_gates = n_gates;
this->gate = gate;
this->counter = counter;
this->repeat = repeat;
worker.request(*this);
}
int run()
{
switch(type)
{
case YAO_AND_JOB:
T::and_(processor->S, *args, start, end, n_gates, gate, counter,
prng, timers, repeat, party);
break;
case YAO_XOR_JOB:
T::xors(*processor, *args, start, end);
break;
default:
throw runtime_error("job not specified: " + to_string(type));
}
type = YAO_NO_JOB;
return 0;
}
};
#endif /* YAO_YAOANDJOB_H_ */