forked from data61/MP-SPDZ
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathYaoGarbleWire.h
134 lines (111 loc) · 3.06 KB
/
YaoGarbleWire.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* YaoWire.h
*
*/
#ifndef YAO_YAOGARBLEWIRE_H_
#define YAO_YAOGARBLEWIRE_H_
#include "BMR/Key.h"
#include "BMR/Register.h"
#include "config.h"
#include "YaoWire.h"
#include "Processor/Instruction.h"
#include <map>
class YaoGarbler;
class YaoGarbleInput;
class ProcessorBase;
class YaoGarbleWire : public YaoWire
{
typedef GC::Secret<YaoGarbleWire> whole_type;
public:
typedef YaoGarbler Party;
typedef YaoGarbleInput Input;
typedef GC::Processor<GC::Secret<YaoGarbleWire>> Processor;
typedef SwitchableOutput out_type;
static string name() { return "YaoGarbleWire"; }
static void andrs(GC::Processor<GC::Secret<YaoGarbleWire>>& processor,
const vector<int>& args)
{
and_(processor, args, true);
}
static void ands(GC::Processor<GC::Secret<YaoGarbleWire>>& processor,
const vector<int>& args)
{
and_(processor, args, false);
}
static void and_(GC::Processor<GC::Secret<YaoGarbleWire>>& processor,
const vector<int>& args, bool repeat);
static void and_multithread(
GC::Processor<GC::Secret<YaoGarbleWire>>& processor,
const vector<int>& args, bool repeat);
static void and_singlethread(
GC::Processor<GC::Secret<YaoGarbleWire>>& processor,
const vector<int>& args, bool repeat);
static void and_(GC::Memory<GC::Secret<YaoGarbleWire>>& S,
const vector<int>& args, size_t start, size_t end,
size_t total_ands, YaoGate* gate, long& counter, PRNG& prng,
map<string, Timer>& timers, bool repeat, YaoGarbler& garbler);
static void inputb(GC::Processor<GC::Secret<YaoGarbleWire>>& processor,
const vector<int>& args);
static void inputbvec(Processor& processor, ProcessorBase& input_processor,
const vector<int>& args);
static void convcbit(Integer& dest, const GC::Clear& source,
GC::Processor<GC::Secret<YaoGarbleWire>>&);
static void reveal_inst(Processor& processor, const vector<int>& args);
static void convcbit2s(GC::Processor<whole_type>& processor,
const BaseInstruction& instruction);
void randomize(PRNG& prng);
void set(Key key, bool mask);
Key full_key() const
{
return key_;
}
void set_full_key(Key key)
{
key_ = key;
}
Key key() const
{
Key res = key_;
res.set_signal(0);
return res;
}
bool mask() const
{
return key_.get_signal();
}
void random();
void public_input(bool value);
void op(const YaoGarbleWire& left, const YaoGarbleWire& right, Function func);
char get_output();
template<class T>
void my_input(T&, bool value, int n_bits)
{
assert(n_bits == 1);
public_input(value);
}
template<class T>
void finalize_input(T& inputter, int from, int n_bits)
{
assert(n_bits == 1);
if (from == 1)
{
set(inputter.garbler.prng.get_doubleword(), 0);
assert(mask() == 0);
inputter.garbler.receiver_input_keys.back().push_back(full_key());
}
}
};
inline void YaoGarbleWire::randomize(PRNG& prng)
{
key_ = prng.get_doubleword();
#ifdef DEBUG
//key = YaoGarbler::s().counter << 1;
#endif
}
inline void YaoGarbleWire::set(Key key, bool mask)
{
key.set_signal(mask);
this->key_ = key;
assert(key.get_signal() == mask);
}
#endif /* YAO_YAOGARBLEWIRE_H_ */