forked from tuneinsight/lattigo
/
refresh.go
55 lines (46 loc) · 2.31 KB
/
refresh.go
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
package dbgv
import (
"github.com/tuneinsight/lattigo/v4/bgv"
"github.com/tuneinsight/lattigo/v4/drlwe"
"github.com/tuneinsight/lattigo/v4/ring"
"github.com/tuneinsight/lattigo/v4/rlwe"
)
// RefreshProtocol is a struct storing the relevant parameters for the Refresh protocol.
type RefreshProtocol struct {
MaskedTransformProtocol
}
// ShallowCopy creates a shallow copy of RefreshProtocol in which all the read-only data-structures are
// shared with the receiver and the temporary buffers are reallocated. The receiver and the returned
// RefreshProtocol can be used concurrently.
func (rfp *RefreshProtocol) ShallowCopy() *RefreshProtocol {
return &RefreshProtocol{*rfp.MaskedTransformProtocol.ShallowCopy()}
}
// RefreshShare is a struct storing a party's share in the Refresh protocol.
type RefreshShare struct {
MaskedTransformShare
}
// NewRefreshProtocol creates a new Refresh protocol instance.
func NewRefreshProtocol(params bgv.Parameters, sigmaSmudging float64) (rfp *RefreshProtocol) {
rfp = new(RefreshProtocol)
mt, _ := NewMaskedTransformProtocol(params, params, sigmaSmudging)
rfp.MaskedTransformProtocol = *mt
return
}
// AllocateShare allocates the shares of the PermuteProtocol
func (rfp *RefreshProtocol) AllocateShare(inputLevel, outputLevel int) *RefreshShare {
share := rfp.MaskedTransformProtocol.AllocateShare(inputLevel, outputLevel)
return &RefreshShare{*share}
}
// GenShare generates a share for the Refresh protocol.
// ct1 is degree 1 element of a bgv.Ciphertext, i.e. bgv.Ciphertext.Value[1].
func (rfp *RefreshProtocol) GenShare(sk *rlwe.SecretKey, ct1 *ring.Poly, scale uint64, crp drlwe.CKSCRP, shareOut *RefreshShare) {
rfp.MaskedTransformProtocol.GenShare(sk, sk, ct1, scale, crp, nil, &shareOut.MaskedTransformShare)
}
// AggregateShares aggregates two parties' shares in the Refresh protocol.
func (rfp *RefreshProtocol) AggregateShares(share1, share2, shareOut *RefreshShare) {
rfp.MaskedTransformProtocol.AggregateShares(&share1.MaskedTransformShare, &share2.MaskedTransformShare, &shareOut.MaskedTransformShare)
}
// Finalize applies Decrypt, Recode and Recrypt on the input ciphertext.
func (rfp *RefreshProtocol) Finalize(ctIn *bgv.Ciphertext, crp drlwe.CKSCRP, share *RefreshShare, ctOut *bgv.Ciphertext) {
rfp.MaskedTransformProtocol.Transform(ctIn, nil, crp, &share.MaskedTransformShare, ctOut)
}