mirror of
https://github.com/tuneinsight/lattigo.git
synced 2025-09-13 03:27:14 +00:00
CHANGELOG: - Update of `PrecisionStats` in `ckks/precision.go`: - precision/error stats computed as log2 of min/max/average/... - fields renamed (`MinPrecision` -> `MINLog2Prec`, `MaxPrecision` -> `MAXLog2Prec`, ...) - `rlwe.Scale` has a `.Log2()` method - Update of `mod1.Parameters` fields (made public, some removed) - Improvement of the relinearization key-generation protocol (reduce the degree of the shares) - Serialisation of bootstrapping keys - Lower noise incurred by `ModUp` - Evaluation keys can be compressed (public element `a` can be generated from a seed) - More doc formatting - Fix various bugs: - `ShallowCopy` of the CKKS bootstrapping evaluator and BFV evaluator not deep enough. - PSI example failing - Incorrect reset of pointer in uniform sampler - Error when doing inverse NTT with small degree - Mod1Evaluator changes the input ciphertext Co-authored-by: Andrea Caforio <andrea.caforio@protonmail.com> Co-authored-by: Jean-Philippe Bossuat <jean-philippe@tuneinsight.com>
72 lines
2.2 KiB
Go
72 lines
2.2 KiB
Go
package rlwe
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/tuneinsight/lattigo/v6/ring"
|
|
"github.com/tuneinsight/lattigo/v6/utils/sampling"
|
|
)
|
|
|
|
// Ciphertext is a generic type for RLWE ciphertexts.
|
|
type Ciphertext struct {
|
|
Element[ring.Poly]
|
|
}
|
|
|
|
// NewCiphertext returns a new [Ciphertext] with zero values and an associated
|
|
// MetaData set to the Parameters default value.
|
|
func NewCiphertext(params ParameterProvider, degree int, level ...int) (ct *Ciphertext) {
|
|
op := *NewElement(params, degree, level...)
|
|
return &Ciphertext{op}
|
|
}
|
|
|
|
// NewCiphertextAtLevelFromPoly constructs a new [Ciphertext] at a specific level
|
|
// where the message is set to the passed poly. No checks are performed on poly and
|
|
// the returned [Ciphertext] will share its backing array of coefficients.
|
|
// Returned [Ciphertext]'s MetaData is allocated but empty.
|
|
func NewCiphertextAtLevelFromPoly(level int, poly []ring.Poly) (*Ciphertext, error) {
|
|
|
|
operand, err := NewElementAtLevelFromPoly(level, poly)
|
|
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot NewCiphertextAtLevelFromPoly: %w", err)
|
|
}
|
|
|
|
operand.MetaData = &MetaData{}
|
|
|
|
return &Ciphertext{*operand}, nil
|
|
}
|
|
|
|
// NewCiphertextRandom generates a new uniformly distributed [Ciphertext] of degree, level.
|
|
func NewCiphertextRandom(prng sampling.PRNG, params ParameterProvider, degree, level int) (ciphertext *Ciphertext) {
|
|
ciphertext = NewCiphertext(params, degree, level)
|
|
PopulateElementRandom(prng, params, ciphertext.El())
|
|
return
|
|
}
|
|
|
|
// Plaintext casts the target ciphertext into a plaintext type.
|
|
// This method is allocation free.
|
|
func (ct Ciphertext) Plaintext() *Plaintext {
|
|
return &Plaintext{
|
|
Element: Element[ring.Poly]{
|
|
Value: ct.Element.Value[:1],
|
|
MetaData: ct.MetaData,
|
|
},
|
|
Value: ct.Element.Value[0],
|
|
}
|
|
}
|
|
|
|
// CopyNew creates a new element as a copy of the target element.
|
|
func (ct Ciphertext) CopyNew() *Ciphertext {
|
|
return &Ciphertext{Element: *ct.Element.CopyNew()}
|
|
}
|
|
|
|
// Copy copies the input element and its parameters on the target element.
|
|
func (ct Ciphertext) Copy(ctxCopy *Ciphertext) {
|
|
ct.Element.Copy(&ctxCopy.Element)
|
|
}
|
|
|
|
// Equal performs a deep equal.
|
|
func (ct Ciphertext) Equal(other *Ciphertext) bool {
|
|
return ct.Element.Equal(&other.Element)
|
|
}
|