/
decryptor.go
33 lines (27 loc) · 1015 Bytes
/
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
package bfv
import (
"github.com/ldsec/lattigo/v2/rlwe"
)
// Decryptor is an interface wrapping a rlwe.Decryptor.
type Decryptor interface {
DecryptNew(ciphertext *Ciphertext) (plaintext *Plaintext)
Decrypt(ciphertext *Ciphertext, plaintext *Plaintext)
}
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 write 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
}