forked from data61/MP-SPDZ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleEncCommit.h
193 lines (156 loc) · 5.88 KB
/
SimpleEncCommit.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
* SimpleEncCommit.h
*
*/
#ifndef FHEOFFLINE_SIMPLEENCCOMMIT_H_
#define FHEOFFLINE_SIMPLEENCCOMMIT_H_
#include "FHEOffline/EncCommit.h"
#include "FHEOffline/Proof.h"
#include "FHEOffline/Prover.h"
#include "FHEOffline/Verifier.h"
#include "Tools/MemoryUsage.h"
class MachineBase;
typedef map<string, Timer> TimerMap;
template<class T,class FD,class S>
class SimpleEncCommitBase : public EncCommitBase<T,FD,S>
{
protected:
int extra_slack;
int n_rounds;
void generate_ciphertexts(AddableVector<Ciphertext>& c,
const vector<Plaintext_<FD> >& m, Proof::Randomness& r,
const FHE_PK& pk, map<string, Timer>& timers, Proof& proof);
virtual void prepare_plaintext(PRNG& G) = 0;
public:
MemoryUsage memory_usage;
SimpleEncCommitBase(const MachineBase& machine);
virtual ~SimpleEncCommitBase() {}
void report_size(ReportType type, MemoryUsage& res) { (void)type; res += memory_usage; }
};
template <class FD>
using SimpleEncCommitBase_ = SimpleEncCommitBase<typename FD::T, FD, typename FD::S>;
template <class FD>
class NonInteractiveProofSimpleEncCommit : public SimpleEncCommitBase_<FD>
{
protected:
const PlayerBase& P;
const FHE_PK& pk;
const FD& FTD;
virtual const FHE_PK& get_pk_for_verification(int offset) = 0;
virtual void add_ciphertexts(vector<Ciphertext>& ciphertexts, int offset) = 0;
public:
NonInteractiveProof proof;
#ifdef LESS_ALLOC_MORE_MEM
Proof::Randomness r;
Prover<FD, Plaintext_<FD> > prover;
Verifier<FD> verifier;
#endif
map<string, Timer>& timers;
NonInteractiveProofSimpleEncCommit(const PlayerBase& P, const FHE_PK& pk,
const FD& FTD, map<string, Timer>& timers,
const MachineBase& machine, bool diagonal = false);
virtual ~NonInteractiveProofSimpleEncCommit() {}
size_t generate_proof(AddableVector<Ciphertext>& c,
vector<Plaintext_<FD> >& m, octetStream& ciphertexts,
octetStream& cleartexts);
size_t create_more(octetStream& my_ciphertext, octetStream& my_cleartext);
virtual size_t report_size(ReportType type);
using SimpleEncCommitBase_<FD>::report_size;
Proof& get_proof() { return proof; }
};
template <class FD>
class SimpleEncCommitFactory
{
protected:
int cnt;
AddableVector<Ciphertext> c;
AddableVector< Plaintext_<FD> > m;
int n_calls;
const FHE_PK& pk;
void prepare_plaintext(PRNG& G);
virtual void create_more() = 0;
public:
SimpleEncCommitFactory(const FHE_PK& pk);
virtual ~SimpleEncCommitFactory();
void init(const Proof& proof, const FD& FTD);
bool has_left() { return cnt >= 0; }
void next(Plaintext_<FD>& mess, Ciphertext& C);
virtual size_t report_size(ReportType type);
void report_size(ReportType type, MemoryUsage& res);
virtual Proof& get_proof() = 0;
};
template<class T,class FD,class S>
class SimpleEncCommit: public NonInteractiveProofSimpleEncCommit<FD>,
public SimpleEncCommitFactory<FD>
{
protected:
const FHE_PK& get_pk_for_verification(int)
{ return NonInteractiveProofSimpleEncCommit<FD>::pk; }
void prepare_plaintext(PRNG& G)
{ SimpleEncCommitFactory<FD>::prepare_plaintext(G); }
void add_ciphertexts(vector<Ciphertext>& ciphertexts, int offset);
public:
SimpleEncCommit(const PlayerBase& P, const FHE_PK& pk, const FD& FTD,
map<string, Timer>& timers, const MachineBase& machine,
int thread_num, bool diagonal = false);
void next(Plaintext_<FD>& mess, Ciphertext& C) { SimpleEncCommitFactory<FD>::next(mess, C); }
void create_more();
size_t report_size(ReportType type)
{ return SimpleEncCommitFactory<FD>::report_size(type) + EncCommitBase_<FD>::report_size(type); }
void report_size(ReportType type, MemoryUsage& res)
{ SimpleEncCommitFactory<FD>::report_size(type, res); SimpleEncCommitBase_<FD>::report_size(type, res); }
Proof& get_proof() { return NonInteractiveProofSimpleEncCommit<FD>::get_proof(); }
};
template <class FD>
using SimpleEncCommit_ = SimpleEncCommit<typename FD::T, FD, typename FD::S>;
template <class FD>
class SummingEncCommit: public SimpleEncCommitFactory<FD>,
public SimpleEncCommitBase_<FD>
{
InteractiveProof proof;
const FHE_PK& pk;
const FD& FTD;
const Player& P;
int thread_num;
#ifdef LESS_ALLOC_MORE_MEM
Prover<FD, Plaintext_<FD> > prover;
Verifier<FD> verifier;
Proof::Preimages preimages;
#endif
void prepare_plaintext(PRNG& G)
{ SimpleEncCommitFactory<FD>::prepare_plaintext(G); }
public:
map<string, Timer>& timers;
SummingEncCommit(const Player& P, const FHE_PK& pk, const FD& FTD,
map<string, Timer>& timers, const MachineBase& machine,
int thread_num, bool diagonal = false);
void next(Plaintext_<FD>& mess, Ciphertext& C) { SimpleEncCommitFactory<FD>::next(mess, C); }
void create_more();
size_t report_size(ReportType type);
void report_size(ReportType type, MemoryUsage& res)
{ SimpleEncCommitFactory<FD>::report_size(type, res); SimpleEncCommitBase_<FD>::report_size(type, res); }
Proof& get_proof() { return proof; }
};
template <class FD>
class Multiplier;
template <class FD>
class PairwiseGenerator;
template <class FD>
class MultiEncCommit : public NonInteractiveProofSimpleEncCommit<FD>
{
friend PairwiseGenerator<FD>;
protected:
const vector<FHE_PK>& pks;
const Player& P;
PairwiseGenerator<FD>& generator;
void prepare_plaintext(PRNG& G) { (void)G; }
const FHE_PK& get_pk_for_verification(int offset)
{ return pks[(P.my_num() - offset + P.num_players()) % P.num_players()]; }
void add_ciphertexts(vector<Ciphertext>& ciphertexts, int offset);
public:
MultiEncCommit(const Player& P, const vector<FHE_PK>& pks,
const FD& FTD,
map<string, Timer>& timers, MachineBase& machine,
PairwiseGenerator<FD>& generator, bool diagonal = false);
};
#endif /* FHEOFFLINE_SIMPLEENCCOMMIT_H_ */