forked from WeDPR-Team/MP-SPDZ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Reshare.cpp
86 lines (67 loc) · 2.59 KB
/
Reshare.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
#include "FHEOffline/Reshare.h"
#include "FHEOffline/DistDecrypt.h"
#include "FHE/P2Data.h"
#include "Tools/random.h"
#include "Math/modp.hpp"
template<class T,class FD,class S>
void Reshare(Plaintext<T,FD,S>& m,Ciphertext& cc,
const Ciphertext& cm,bool NewCiphertext,
const Player& P,EncCommitBase<T,FD,S>& EC,
const FHE_PK& pk,const FHE_SK& share)
{
DistDecrypt<FD> dd(P, share, pk, m.get_field());
Reshare(m, cc, cm, NewCiphertext, P, EC, pk, dd);
}
template<class T,class FD,class S>
void Reshare(Plaintext<T,FD,S>& m,Ciphertext& cc,
const Ciphertext& cm,bool NewCiphertext,
const Player& P,EncCommitBase<T,FD,S>& EC,
const FHE_PK& pk,DistDecrypt<FD>& dd)
{
const FHE_Params& params=pk.get_params();
// Step 1
Ciphertext cf(params);
Plaintext_<FD>& f = dd.f;
EC.next(f,cf);
// Step 2
// We could be resharing a level 0 ciphertext so adjust if we are
if (cm.level()==0) { cf.Scale(m.get_field().get_prime()); }
Ciphertext cmf(params);
add(cmf,cf,cm);
// Step 3
Plaintext_<FD>& mf = dd.mf;
dd.run(cmf, NewCiphertext);
// Step 4
if (P.my_num()==0)
{ sub(m,mf,f); }
else
{ m=f; m.negate(); }
// Step 5
if (NewCiphertext)
{ unsigned char sd[SEED_SIZE] = { 0 };
PRNG G;
G.SetSeed(sd);
Random_Coins rc(params);
rc.generate(G);
pk.encrypt(cc,mf,rc);
// And again
if (cf.level()==0) { cc.Scale(m.get_field().get_prime()); }
sub(cc,cc,cf);
}
}
template void Reshare(Plaintext<gfp,FFT_Data,bigint>& m,Ciphertext& cc,
const Ciphertext& cm,bool NewCiphertext,
const Player& P,EncCommitBase<gfp,FFT_Data,bigint>& EC,
const FHE_PK& pk,DistDecrypt<FFT_Data>& dd);
template void Reshare(Plaintext<gf2n_short,P2Data,int>& m,Ciphertext& cc,
const Ciphertext& cm,bool NewCiphertext,
const Player& P,EncCommitBase<gf2n_short,P2Data,int>& EC,
const FHE_PK& pk,DistDecrypt<P2Data>& dd);
template void Reshare(Plaintext<gfp,FFT_Data,bigint>& m,Ciphertext& cc,
const Ciphertext& cm,bool NewCiphertext,
const Player& P,EncCommitBase<gfp,FFT_Data,bigint>& EC,
const FHE_PK& pk,const FHE_SK& share);
template void Reshare(Plaintext<gf2n_short,P2Data,int>& m,Ciphertext& cc,
const Ciphertext& cm,bool NewCiphertext,
const Player& P,EncCommitBase<gf2n_short,P2Data,int>& EC,
const FHE_PK& pk,const FHE_SK& share);