forked from tuneinsight/lattigo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plaintext.go
64 lines (54 loc) · 1.93 KB
/
plaintext.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
56
57
58
59
60
61
62
63
64
package rlwe
import (
"github.com/tuneinsight/lattigo/v4/ring"
)
// Plaintext is a common base type for RLWE plaintexts.
type Plaintext struct {
MetaData
Value *ring.Poly
}
// NewPlaintext creates a new Plaintext at level `level` from the parameters.
func NewPlaintext(params Parameters, level int) (pt *Plaintext) {
return &Plaintext{Value: ring.NewPoly(params.N(), level), MetaData: MetaData{Scale: params.defaultScale, IsNTT: params.defaultNTTFlag}}
}
// NewPlaintextAtLevelFromPoly constructs a new Plaintext at a specific level
// where the message is set to the passed poly. No checks are performed on poly and
// the returned Plaintext will share its backing array of coefficients.
// Returned plaintext's MetaData is empty.
func NewPlaintextAtLevelFromPoly(level int, poly *ring.Poly) (pt *Plaintext) {
if len(poly.Coeffs) < level+1 {
panic("cannot NewPlaintextAtLevelFromPoly: provided ring.Poly level is too small")
}
v0 := new(ring.Poly)
v0.Coeffs = poly.Coeffs[:level+1]
v0.Buff = poly.Buff[:poly.N()*(level+1)]
return &Plaintext{Value: v0}
}
// Degree returns the degree of the target Plaintext.
func (pt *Plaintext) Degree() int {
return 0
}
// Level returns the level of the target Plaintext.
func (pt *Plaintext) Level() int {
return len(pt.Value.Coeffs) - 1
}
// GetScale gets the scale of the target Plaintext.
func (pt *Plaintext) GetScale() Scale {
return pt.Scale
}
// SetScale sets the scale of the target Plaintext.
func (pt *Plaintext) SetScale(scale Scale) {
pt.Scale = scale
}
// El returns the plaintext as a new `Element` for which the value points
// to the receiver `Value` field.
func (pt *Plaintext) El() *Ciphertext {
return &Ciphertext{Value: []*ring.Poly{pt.Value}, MetaData: pt.MetaData}
}
// Copy copies the `other` plaintext value into the receiver plaintext.
func (pt *Plaintext) Copy(other *Plaintext) {
if other != nil && other.Value != nil {
pt.Value.Copy(other.Value)
pt.MetaData = other.MetaData
}
}