forked from tuneinsight/lattigo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
decryptor.go
49 lines (41 loc) · 1.78 KB
/
decryptor.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
package bfv
import (
"github.com/tuneinsight/lattigo/v4/rlwe"
)
// Decryptor is an interface wrapping a rlwe.Decryptor.
type Decryptor interface {
DecryptNew(ciphertext *Ciphertext) (plaintext *Plaintext)
Decrypt(ciphertext *Ciphertext, plaintext *Plaintext)
ShallowCopy() Decryptor
WithKey(sk *rlwe.SecretKey) Decryptor
}
type decryptor struct {
rlwe.Decryptor
params Parameters
}
// NewDecryptor instantiates a Decryptor for the BFV scheme.
func NewDecryptor(params Parameters, sk *rlwe.SecretKey) Decryptor {
return &decryptor{rlwe.NewDecryptor(params.Parameters, sk), params}
}
// Decrypt decrypts the ciphertext and writes the result in ptOut.
func (dec *decryptor) Decrypt(ct *Ciphertext, ptOut *Plaintext) {
dec.Decryptor.Decrypt(&rlwe.Ciphertext{Value: ct.Value}, &rlwe.Plaintext{Value: ptOut.Value})
}
// DecryptNew decrypts the ciphertext and returns the result in a newly allocated Plaintext.
func (dec *decryptor) DecryptNew(ct *Ciphertext) (ptOut *Plaintext) {
pt := NewPlaintext(dec.params)
dec.Decryptor.Decrypt(ct.Ciphertext, pt.Plaintext)
return pt
}
// ShallowCopy creates a shallow copy of Decryptor in which all the read-only data-structures are
// shared with the receiver and the temporary buffers are reallocated. The receiver and the returned
// Decryptor can be used concurrently.
func (dec *decryptor) ShallowCopy() Decryptor {
return &decryptor{dec.Decryptor.ShallowCopy(), dec.params}
}
// WithKey creates a shallow copy of Decryptor with a new decryption key, in which all the
// read-only data-structures are shared with the receiver and the temporary buffers
// are reallocated. The receiver and the returned Decryptor can be used concurrently.
func (dec *decryptor) WithKey(sk *rlwe.SecretKey) Decryptor {
return &decryptor{dec.Decryptor.WithKey(sk), dec.params}
}