forked from bristolcrypto/SPDZ-2
-
Notifications
You must be signed in to change notification settings - Fork 272
/
VectorInput.h
87 lines (72 loc) · 1.93 KB
/
VectorInput.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
/*
* VectorInput.h
*
*/
#ifndef GC_VECTORINPUT_H_
#define GC_VECTORINPUT_H_
#include "Protocols/ReplicatedInput.h"
namespace GC
{
template<class T>
class VectorInput : public InputBase<T>
{
typename T::part_type::Input part_input;
deque<int> input_lengths;
public:
VectorInput(typename T::MAC_Check& MC, Preprocessing<T>& prep, Player& P) :
part_input(MC.get_part_MC(), prep.get_part(), P)
{
part_input.reset_all(P);
}
VectorInput(SubProcessor<T>& proc, typename T::MAC_Check&) :
part_input(proc.MC, proc.DataF, proc.P)
{
}
void reset(int player)
{
part_input.reset(player);
}
void add_mine(const typename T::open_type& input, int n_bits)
{
if (n_bits == -1)
n_bits = T::default_length;
for (int i = 0; i < n_bits; i++)
part_input.add_mine(input.get_bit(i));
input_lengths.push_back(n_bits);
}
void add_other(int player, int n_bits)
{
if (n_bits == -1)
n_bits = T::default_length;
for (int i = 0; i < n_bits; i++)
part_input.add_other(player);
}
void send_mine()
{
part_input.send_mine();
}
void exchange()
{
part_input.exchange();
}
T finalize_mine()
{
T res;
res.resize_regs(input_lengths.front());
for (int i = 0; i < input_lengths.front(); i++)
res.get_reg(i) = part_input.finalize_mine();
input_lengths.pop_front();
return res;
}
void finalize_other(int player, T& target, octetStream&, int n_bits)
{
if (n_bits == -1)
n_bits = T::default_length;
target.resize_regs(n_bits);
for (int i = 0; i < n_bits; i++)
part_input.finalize_other(player, target.get_reg(i),
part_input.InputBase<typename T::part_type>::os[player]);
}
};
} /* namespace GC */
#endif /* GC_VECTORINPUT_H_ */