Documentation
¶
Overview ¶
Package ckks implements a RNS-accelerated version of the Homomorphic Encryption for Arithmetic for Approximate Numbers (HEAAN, a.k.a. CKKS) scheme. It provides approximate arithmetic over the complex numbers.
Index ¶
- Constants
- Variables
- func GenModuli(params *Parameters) (Q []uint64, P []uint64)
- func GenSwitchkeysRescalingParams(Q, P []uint64) (params []uint64)
- type ChebyshevInterpolation
- type Ciphertext
- func (el Ciphertext) Ciphertext() *Ciphertext
- func (el Ciphertext) Copy(ctxCopy *ckksElement) (err error)
- func (el Ciphertext) CopyNew() *ckksElement
- func (el Ciphertext) CopyParams(ckkselement *ckksElement)
- func (el Ciphertext) Degree() uint64
- func (el Ciphertext) DivScale(scale float64)
- func (el Ciphertext) Element() *ckksElement
- func (ciphertext *Ciphertext) GetDataLen(WithMetaData bool) (dataLen uint64)
- func (el Ciphertext) InvNTT(context *ring.Context, c *ckksElement) error
- func (el Ciphertext) IsNTT() bool
- func (el Ciphertext) Level() uint64
- func (ciphertext *Ciphertext) MarshalBinary() (data []byte, err error)
- func (el Ciphertext) MulScale(scale float64)
- func (el Ciphertext) NTT(context *ring.Context, c *ckksElement) error
- func (el Ciphertext) Plaintext() *Plaintext
- func (el Ciphertext) Resize(params *Parameters, degree uint64)
- func (el Ciphertext) Scale() float64
- func (el Ciphertext) SetIsNTT(value bool)
- func (el Ciphertext) SetScale(scale float64)
- func (el Ciphertext) SetValue(value []*ring.Poly)
- func (ciphertext *Ciphertext) UnmarshalBinary(data []byte) (err error)
- func (el Ciphertext) Value() []*ring.Poly
- type Context
- type Decryptor
- type Encoder
- type Encryptor
- type EvaluationKey
- func (evk *EvaluationKey) Get() *SwitchingKey
- func (evaluationkey *EvaluationKey) GetDataLen(WithMetaData bool) (dataLen uint64)
- func (evaluationkey *EvaluationKey) MarshalBinary() (data []byte, err error)
- func (evk *EvaluationKey) Set(rlk [][2]*ring.Poly)
- func (evaluationkey *EvaluationKey) UnmarshalBinary(data []byte) (err error)
- type Evaluator
- type KeyGenerator
- type LogModuli
- type Moduli
- type Operand
- type Parameters
- func (p *Parameters) Alpha() uint64
- func (p *Parameters) Beta() uint64
- func (p *Parameters) Copy() (paramsCopy *Parameters)
- func (p *Parameters) Equals(other *Parameters) (res bool)
- func (p *Parameters) GenFromLogModuli()
- func (p *Parameters) GenFromModuli()
- func (p *Parameters) IsValid() bool
- func (p *Parameters) LogQP() uint64
- func (p *Parameters) MarshalBinary() ([]byte, error)
- func (p *Parameters) MaxLevel() uint64
- func (p *Parameters) NewPolyP() *ring.Poly
- func (p *Parameters) NewPolyQ() *ring.Poly
- func (p *Parameters) NewPolyQP() *ring.Poly
- func (p *Parameters) UnmarshalBinary(data []byte) error
- type Plaintext
- func (el Plaintext) Ciphertext() *Ciphertext
- func (el Plaintext) Copy(ctxCopy *ckksElement) (err error)
- func (el Plaintext) CopyNew() *ckksElement
- func (el Plaintext) CopyParams(ckkselement *ckksElement)
- func (el Plaintext) Degree() uint64
- func (el Plaintext) DivScale(scale float64)
- func (el Plaintext) Element() *ckksElement
- func (el Plaintext) InvNTT(context *ring.Context, c *ckksElement) error
- func (el Plaintext) IsNTT() bool
- func (el Plaintext) Level() uint64
- func (el Plaintext) MulScale(scale float64)
- func (el Plaintext) NTT(context *ring.Context, c *ckksElement) error
- func (el Plaintext) Plaintext() *Plaintext
- func (el Plaintext) Resize(params *Parameters, degree uint64)
- func (el Plaintext) Scale() float64
- func (el Plaintext) SetIsNTT(value bool)
- func (el Plaintext) SetScale(scale float64)
- func (el Plaintext) SetValue(value []*ring.Poly)
- func (el Plaintext) Value() []*ring.Poly
- type PublicKey
- type Rotation
- type RotationKeys
- func (rotationkey *RotationKeys) GetDataLen(WithMetaData bool) (dataLen uint64)
- func (rotationkey *RotationKeys) MarshalBinary() (data []byte, err error)
- func (rotKey *RotationKeys) SetRotKey(params *Parameters, evakey [][2]*ring.Poly, rotType Rotation, k uint64)
- func (rotationkey *RotationKeys) UnmarshalBinary(data []byte) (err error)
- type SecretKey
- type SwitchingKey
Constants ¶
const ( RotationRight = iota + 1 RotationLeft Conjugate )
Constants for rotation types
const ( PN12QP109 = iota PN13QP218 PN14QP438 PN15QP880 PN16QP1761 )
const GaloisGen uint64 = 5
GaloisGen is an integer of order N/2 modulo M and that spans Z_M with the integer -1. The j-th ring automorphism takes the root zeta to zeta^(5j). Any other integer or order N/2 modulo M and congruent with 1 modulo 4 could be used instead.
const MaxLogN = 16
MaxLogN is the log2 of the largest supported polynomial modulus degree.
const MaxModuliCount = 34
MaxModuliCount is the largest supported number of moduli in the RNS representation.
const MaxModuliSize = 60
MaxModuliSize is the largest bit-length supported for the moduli in the RNS representation.
Variables ¶
var DefaultParams = []*Parameters{ {LogN: 12, LogSlots: 11, LogModuli: LogModuli{ LogQi: []uint64{37, 32}, LogPi: []uint64{38}, }, Scale: 1 << 32, Sigma: 3.2}, {LogN: 13, LogSlots: 12, LogModuli: LogModuli{ LogQi: []uint64{33, 30, 30, 30, 30, 30}, LogPi: []uint64{35}, }, Scale: 1 << 30, Sigma: 3.2}, {LogN: 14, LogSlots: 13, LogModuli: LogModuli{ LogQi: []uint64{45, 34, 34, 34, 34, 34, 34, 34, 34, 34}, LogPi: []uint64{43, 43}, }, Scale: 1 << 34, Sigma: 3.2}, {LogN: 15, LogSlots: 14, LogModuli: LogModuli{ LogQi: []uint64{50, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40}, LogPi: []uint64{50, 50, 50}, }, Scale: 1 << 40, Sigma: 3.2}, {LogN: 16, LogSlots: 15, LogModuli: LogModuli{ LogQi: []uint64{55, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45}, LogPi: []uint64{55, 55, 55, 55}, }, Scale: 1 << 45, Sigma: 3.2}, }
DefaultParams is a set of default CKKS parameters ensuring 128 bit security.
Functions ¶
func GenModuli ¶ added in v1.3.0
func GenModuli(params *Parameters) (Q []uint64, P []uint64)
GenModuli generates the appropriate primes from the parameters using generateCKKSPrimes, such that all the primes are different.
func GenSwitchkeysRescalingParams ¶ added in v1.3.0
GenSwitchkeysRescalingParams generates the parameters for rescaling the switching keys
Types ¶
type ChebyshevInterpolation ¶
type ChebyshevInterpolation struct {
// contains filtered or unexported fields
}
ChebyshevInterpolation is a struct storing the coefficients, degree and range of a Chebyshev interpolation polynomial.
func Approximate ¶
func Approximate(function func(complex128) complex128, a, b complex128, degree int) (cheby *ChebyshevInterpolation)
Approximate computes a Chebyshev approximation of the input function, for the range [-a, b] of degree degree. To be used in conjunction with the function EvaluateCheby.
type Ciphertext ¶
type Ciphertext struct {
// contains filtered or unexported fields
}
Ciphertext is *ring.Poly array representing a polynomial of degree > 0 with coefficients in R_Q.
func NewCiphertext ¶ added in v1.3.0
func NewCiphertext(params *Parameters, degree uint64, level uint64, scale float64) (ciphertext *Ciphertext)
NewCiphertext creates a new Ciphertext parameterized by degree, level and scale.
func NewCiphertextRandom ¶ added in v1.3.0
func NewCiphertextRandom(params *Parameters, degree, level uint64, scale float64) (ciphertext *Ciphertext)
NewCiphertextRandom generates a new uniformly distributed Ciphertext of degree, level and scale.
func (Ciphertext) Ciphertext ¶ added in v1.1.0
func (el Ciphertext) Ciphertext() *Ciphertext
Ciphertext sets the target element type to Ciphertext.
func (Ciphertext) Copy ¶
func (el Ciphertext) Copy(ctxCopy *ckksElement) (err error)
Copy copies the input element and its parameters on the target element.
func (Ciphertext) CopyNew ¶
func (el Ciphertext) CopyNew() *ckksElement
CopyNew creates a new element as a copy of the target element.
func (Ciphertext) CopyParams ¶
func (el Ciphertext) CopyParams(ckkselement *ckksElement)
CopyParams copies the input element parameters on the target element
func (Ciphertext) Degree ¶
func (el Ciphertext) Degree() uint64
Degree returns the degree of the target element.
func (Ciphertext) DivScale ¶ added in v1.3.0
func (el Ciphertext) DivScale(scale float64)
DivScale divides the scale of the target element by the input scale.
func (Ciphertext) Element ¶ added in v1.1.0
func (el Ciphertext) Element() *ckksElement
Element sets the target element type to Element.
func (*Ciphertext) GetDataLen ¶ added in v1.3.0
func (ciphertext *Ciphertext) GetDataLen(WithMetaData bool) (dataLen uint64)
GetDataLen returns the length in bytes of the target Ciphertext.
func (Ciphertext) InvNTT ¶
InvNTT puts the target element outside of the NTT domain, and sets its isNTT flag to false. If it is not in the NTT domain, it does nothing.
func (Ciphertext) IsNTT ¶
func (el Ciphertext) IsNTT() bool
IsNTT returns the value of the NTT flag of the target element.
func (Ciphertext) Level ¶
func (el Ciphertext) Level() uint64
Level returns the level of the target element.
func (*Ciphertext) MarshalBinary ¶
func (ciphertext *Ciphertext) MarshalBinary() (data []byte, err error)
MarshalBinary encodes a Ciphertext on a byte slice. The total size in byte is 4 + 8* N * numberModuliQ * (degree + 1).
func (Ciphertext) MulScale ¶ added in v1.3.0
func (el Ciphertext) MulScale(scale float64)
MulScale multiplies the scale of the target element with the input scale.
func (Ciphertext) NTT ¶
NTT puts the target element in the NTT domain and sets its isNTT flag to true. If it is already in the NTT domain, it does nothing.
func (Ciphertext) Plaintext ¶ added in v1.1.0
func (el Ciphertext) Plaintext() *Plaintext
Plaintext sets the target element type to Plaintext.
func (Ciphertext) Resize ¶
func (el Ciphertext) Resize(params *Parameters, degree uint64)
Resize resizes the degree of the target element.
func (Ciphertext) Scale ¶
func (el Ciphertext) Scale() float64
Scale returns the scale of the target element.
func (Ciphertext) SetIsNTT ¶
func (el Ciphertext) SetIsNTT(value bool)
SetIsNTT sets the value of the NTT flag of the target element with the input value.
func (Ciphertext) SetScale ¶
func (el Ciphertext) SetScale(scale float64)
SetScale sets the scale of the the target element to the input scale.
func (Ciphertext) SetValue ¶
SetValue sets the input slice of polynomials as the value of the target element.
func (*Ciphertext) UnmarshalBinary ¶
func (ciphertext *Ciphertext) UnmarshalBinary(data []byte) (err error)
UnmarshalBinary decodes a previously marshaled Ciphertext on the target Ciphertext. The target Ciphertext must be of the appropriate format and size, it can be created with the method NewCiphertext(uint64).
type Context ¶ added in v1.3.0
type Context struct {
// contains filtered or unexported fields
}
Context is a struct that contains all the elements required to instantiate the CKKS Scheme. This includes the parameters (polynomial degree, ciphertext modulus, Gaussian sampler, polynomial contexts and other parameters required for the homomorphic operations).
type Decryptor ¶
type Decryptor interface {
// DecryptNew decrypts the ciphertext and returns a newly created
// plaintext. A Horner method is used for evaluating the decryption.
DecryptNew(ciphertext *Ciphertext) (plaintext *Plaintext)
// Decrypt decrypts the ciphertext and returns the result on the provided
// receiver plaintext. A Horner method is used for evaluating the
// decryption.
Decrypt(ciphertext *Ciphertext, plaintext *Plaintext)
}
Decryptor is an interface for decrypting Ciphertexts. A Decryptor stores the secret-key.
func NewDecryptor ¶ added in v1.3.0
func NewDecryptor(params *Parameters, sk *SecretKey) Decryptor
NewDecryptor instantiates a new Decryptor that will be able to decrypt ciphertexts encrypted under the provided secret-key.
type Encoder ¶ added in v1.1.0
type Encoder interface {
Encode(plaintext *Plaintext, values []complex128, slots uint64)
EncodeNew(values []complex128, slots uint64) (plaintext *Plaintext)
Decode(plaintext *Plaintext, slots uint64) (res []complex128)
}
Encoder is an interface implenting the encoding algorithms.
func NewEncoder ¶ added in v1.3.0
func NewEncoder(params *Parameters) Encoder
NewEncoder creates a new Encoder that is used to encode a slice of complex values of size at most N/2 (the number of slots) on a Plaintext.
type Encryptor ¶
type Encryptor interface {
// EncryptNew encrypts the input plaintext using the stored key and returns
// the result on a newly created ciphertext.
EncryptNew(plaintext *Plaintext) *Ciphertext
// Encrypt encrypts the input plaintext using the stored key, and returns
// the result on the reciver ciphertext.
Encrypt(plaintext *Plaintext, ciphertext *Ciphertext)
}
Encryptor in an interface for encryptors
encrypt with pk : ciphertext = [pk[0]*u + m + e_0, pk[1]*u + e_1] encrypt with sk : ciphertext = [-a*sk + m + e, a]
func NewEncryptorFromPk ¶ added in v1.3.0
func NewEncryptorFromPk(params *Parameters, pk *PublicKey) Encryptor
NewEncryptorFromPk creates a new Encryptor with the provided public-key. This Encryptor can be used to encrypt Plaintexts, using the stored key.
func NewEncryptorFromSk ¶ added in v1.3.0
func NewEncryptorFromSk(params *Parameters, sk *SecretKey) Encryptor
NewEncryptorFromSk creates a new Encryptor with the provided secret-key. This Encryptor can be used to encrypt Plaintexts, using the stored key.
type EvaluationKey ¶
type EvaluationKey struct {
// contains filtered or unexported fields
}
EvaluationKey is a structure that stores the switching-keys required during the relinearization.
func NewRelinKey ¶ added in v1.3.0
func NewRelinKey(params *Parameters) (evakey *EvaluationKey)
NewRelinKey returns a new EvaluationKey with zero values.
func (*EvaluationKey) Get ¶ added in v1.3.0
func (evk *EvaluationKey) Get() *SwitchingKey
Get returns the slice of switching keys of the evaluation-key.
func (*EvaluationKey) GetDataLen ¶ added in v1.3.0
func (evaluationkey *EvaluationKey) GetDataLen(WithMetaData bool) (dataLen uint64)
GetDataLen returns the length in bytes of the target EvaluationKey.
func (*EvaluationKey) MarshalBinary ¶ added in v1.1.0
func (evaluationkey *EvaluationKey) MarshalBinary() (data []byte, err error)
MarshalBinary encodes an evaluation key in a byte slice.
func (*EvaluationKey) Set ¶ added in v1.3.0
func (evk *EvaluationKey) Set(rlk [][2]*ring.Poly)
Set sets the target Evaluation key with the input polynomials.
func (*EvaluationKey) UnmarshalBinary ¶ added in v1.3.0
func (evaluationkey *EvaluationKey) UnmarshalBinary(data []byte) (err error)
UnmarshalBinary decodes a previously marshaled evaluation-key in the target evaluation-key.
type Evaluator ¶
type Evaluator interface {
Add(op0, op1 Operand, ctOut *Ciphertext)
AddNoMod(op0, op1 Operand, ctOut *Ciphertext)
AddNew(op0, op1 Operand) (ctOut *Ciphertext)
AddNoModNew(op0, op1 Operand) (ctOut *Ciphertext)
Sub(op0, op1 Operand, ctOut *Ciphertext)
SubNoMod(op0, op1 Operand, ctOut *Ciphertext)
SubNew(op0, op1 Operand) (ctOut *Ciphertext)
SubNoModNew(op0, op1 Operand) (ctOut *Ciphertext)
Neg(ct0 *Ciphertext, ctOut *Ciphertext)
NegNew(ct0 *Ciphertext) (ctOut *Ciphertext)
AddConstNew(ct0 *Ciphertext, constant interface{}) (ctOut *Ciphertext)
AddConst(ct0 *Ciphertext, constant interface{}, ctOut *Ciphertext)
MultByConstAndAdd(ct0 *Ciphertext, constant interface{}, ctOut *Ciphertext)
MultByConstNew(ct0 *Ciphertext, constant interface{}) (ctOut *Ciphertext)
MultByConst(ct0 *Ciphertext, constant interface{}, ctOut *Ciphertext)
MultByiNew(ct0 *Ciphertext) (ctOut *Ciphertext)
MultByi(ct0 *Ciphertext, ct1 *Ciphertext)
DivByiNew(ct0 *Ciphertext) (ctOut *Ciphertext)
DivByi(ct0 *Ciphertext, ct1 *Ciphertext)
ScaleUpNew(ct0 *Ciphertext, scale float64) (ctOut *Ciphertext)
ScaleUp(ct0 *Ciphertext, scale float64, ctOut *Ciphertext)
MulByPow2New(ct0 *Ciphertext, pow2 uint64) (ctOut *Ciphertext)
MulByPow2(ct0 *ckksElement, pow2 uint64, ctOut *ckksElement)
ReduceNew(ct0 *Ciphertext) (ctOut *Ciphertext)
Reduce(ct0 *Ciphertext, ctOut *Ciphertext) error
DropLevelNew(ct0 *Ciphertext, levels uint64) (ctOut *Ciphertext)
DropLevel(ct0 *Ciphertext, levels uint64) (err error)
Rescale(ct0 *Ciphertext, threshold float64, c1 *Ciphertext) (err error)
RescaleMany(ct0 *Ciphertext, nbRescales uint64, c1 *Ciphertext) (err error)
MulRelinNew(op0, op1 Operand, evakey *EvaluationKey) (ctOut *Ciphertext)
MulRelin(op0, op1 Operand, evakey *EvaluationKey, ctOut *Ciphertext)
RelinearizeNew(ct0 *Ciphertext, evakey *EvaluationKey) (ctOut *Ciphertext)
Relinearize(ct0 *Ciphertext, evakey *EvaluationKey, ctOut *Ciphertext)
SwitchKeysNew(ct0 *Ciphertext, switchingKey *SwitchingKey) (ctOut *Ciphertext)
SwitchKeys(ct0 *Ciphertext, switchingKey *SwitchingKey, ctOut *Ciphertext)
RotateColumnsNew(ct0 *Ciphertext, k uint64, evakey *RotationKeys) (ctOut *Ciphertext)
RotateColumns(ct0 *Ciphertext, k uint64, evakey *RotationKeys, ctOut *Ciphertext)
RotateHoisted(ctIn *Ciphertext, rotations []uint64, rotkeys *RotationKeys) (cOut map[uint64]*Ciphertext)
ConjugateNew(ct0 *Ciphertext, evakey *RotationKeys) (ctOut *Ciphertext)
Conjugate(ct0 *Ciphertext, evakey *RotationKeys, ctOut *Ciphertext)
PowerOf2(el0 *Ciphertext, logPow2 uint64, evakey *EvaluationKey, elOut *Ciphertext)
PowerNew(op *Ciphertext, degree uint64, evakey *EvaluationKey) (opOut *Ciphertext)
Power(ct0 *Ciphertext, degree uint64, evakey *EvaluationKey, res *Ciphertext)
InverseNew(ct0 *Ciphertext, steps uint64, evakey *EvaluationKey) (res *Ciphertext)
EvaluatePolyFast(ct *Ciphertext, coeffs interface{}, evakey *EvaluationKey) (res *Ciphertext)
EvaluatePolyEco(ct *Ciphertext, coeffs interface{}, evakey *EvaluationKey) (res *Ciphertext)
EvaluateChebyFast(ct *Ciphertext, cheby *ChebyshevInterpolation, evakey *EvaluationKey) (res *Ciphertext)
EvaluateChebyEco(ct *Ciphertext, cheby *ChebyshevInterpolation, evakey *EvaluationKey) (res *Ciphertext)
}
Evaluator is an interface implementing the methodes to conduct homomorphic operations between ciphertext and/or plaintexts.
func NewEvaluator ¶ added in v1.3.0
func NewEvaluator(params *Parameters) Evaluator
NewEvaluator creates a new Evaluator, that can be used to do homomorphic operations on the Ciphertexts and/or Plaintexts. It stores a small pool of polynomials and Ciphertexts that will be used for intermediate values.
type KeyGenerator ¶
type KeyGenerator interface {
GenSecretKey() (sk *SecretKey)
GenSecretKeyWithDistrib(p float64) (sk *SecretKey)
GenSecretKeySparse(hw uint64) (sk *SecretKey)
GenPublicKey(sk *SecretKey) (pk *PublicKey)
GenKeyPair() (sk *SecretKey, pk *PublicKey)
GenKeyPairSparse(hw uint64) (sk *SecretKey, pk *PublicKey)
GenRelinKey(sk *SecretKey) (evakey *EvaluationKey)
GenSwitchingKey(skInput, skOutput *SecretKey) (newevakey *SwitchingKey)
GenRotationKeysPow2(skOutput *SecretKey) (rotKey *RotationKeys)
GenRot(rotType Rotation, sk *SecretKey, k uint64, rotKey *RotationKeys)
}
KeyGenerator is an interface implementing the methods of the KeyGenerator.
func NewKeyGenerator ¶ added in v1.3.0
func NewKeyGenerator(params *Parameters) KeyGenerator
NewKeyGenerator creates a new KeyGenerator, from which the secret and public keys, as well as the evaluation, rotation and switching keys can be generated.
type LogModuli ¶ added in v1.3.0
type LogModuli struct {
LogQi []uint64 // Ciphertext prime moduli bit-size
LogPi []uint64 // Keys additional prime moduli bit-size
}
LogModuli stores the bit-length of the NTT primes of the RNS representation.
type Moduli ¶ added in v1.3.0
type Moduli struct {
Qi []uint64 // Ciphertext prime moduli
Pi []uint64 // Keys additional prime moduli
}
Moduli stores the NTT primes of the RNS representation.
type Parameters ¶ added in v1.1.0
type Parameters struct {
Moduli
LogModuli
LogN uint64 // Ring degree (power of 2)
LogSlots uint64
Scale float64
Sigma float64 // Gaussian sampling variance
// contains filtered or unexported fields
}
Parameters represents a given parameter set for the BFV cryptosystem.
func NewParametersFromLogModuli ¶ added in v1.3.0
func NewParametersFromLogModuli(LogN, LogSlots uint64, Scale float64, logModuli LogModuli, Sigma float64) (params *Parameters)
NewParametersFromLogModuli generates a new set or bfv parameters from the input parameters.
func NewParametersFromModuli ¶ added in v1.3.0
func NewParametersFromModuli(LogN, LogSlots uint64, Scale float64, moduli Moduli, Sigma float64) (params *Parameters)
NewParametersFromModuli generates a new set or bfv parameters from the input parameters.
func (*Parameters) Beta ¶ added in v1.3.0
func (p *Parameters) Beta() uint64
Beta returns ceil(#Qi/#Pi).
func (*Parameters) Copy ¶ added in v1.3.0
func (p *Parameters) Copy() (paramsCopy *Parameters)
Copy creates a copy of the target parameters.
func (*Parameters) Equals ¶ added in v1.1.0
func (p *Parameters) Equals(other *Parameters) (res bool)
Equals compares two sets of parameters for equality.
func (*Parameters) GenFromLogModuli ¶ added in v1.3.0
func (p *Parameters) GenFromLogModuli()
GenFromLogModuli generates the parameters using the given bit-size for the moduli.
func (*Parameters) GenFromModuli ¶ added in v1.3.0
func (p *Parameters) GenFromModuli()
GenFromModuli generates the parameters using the provided moduli.
func (*Parameters) IsValid ¶ added in v1.3.0
func (p *Parameters) IsValid() bool
IsValid returns a true if the parameters are complete and valid, else false.
func (*Parameters) LogQP ¶ added in v1.3.0
func (p *Parameters) LogQP() uint64
LogQP returns the bitlength of prod(Qi) * prod(Pi)
func (*Parameters) MarshalBinary ¶ added in v1.1.0
func (p *Parameters) MarshalBinary() ([]byte, error)
MarshalBinary returns a []byte representation of the parameter set.
func (*Parameters) MaxLevel ¶ added in v1.3.0
func (p *Parameters) MaxLevel() uint64
MaxLevel returns #Qi -1
func (*Parameters) NewPolyP ¶ added in v1.3.0
func (p *Parameters) NewPolyP() *ring.Poly
NewPolyP returns a new empty polynomial of degree 2^LogN in basis Pi.
func (*Parameters) NewPolyQ ¶ added in v1.3.0
func (p *Parameters) NewPolyQ() *ring.Poly
NewPolyQ returns a new empty polynomial of degree 2^LogN in basis Qi.
func (*Parameters) NewPolyQP ¶ added in v1.3.0
func (p *Parameters) NewPolyQP() *ring.Poly
NewPolyQP returns a new empty polynomial of degree 2^LogN in basis Qi + Pi.
func (*Parameters) UnmarshalBinary ¶ added in v1.3.0
func (p *Parameters) UnmarshalBinary(data []byte) error
UnmarshalBinary decodes a []byte into a parameter set struct
type Plaintext ¶
type Plaintext struct {
// contains filtered or unexported fields
}
Plaintext is is a ckksElement with only one Poly.
func NewPlaintext ¶ added in v1.3.0
func NewPlaintext(params *Parameters, level uint64, scale float64) *Plaintext
NewPlaintext creates a new Plaintext of level level and scale scale.
func (Plaintext) Ciphertext ¶ added in v1.1.0
func (el Plaintext) Ciphertext() *Ciphertext
Ciphertext sets the target element type to Ciphertext.
func (Plaintext) Copy ¶
func (el Plaintext) Copy(ctxCopy *ckksElement) (err error)
Copy copies the input element and its parameters on the target element.
func (Plaintext) CopyNew ¶
func (el Plaintext) CopyNew() *ckksElement
CopyNew creates a new element as a copy of the target element.
func (Plaintext) CopyParams ¶
func (el Plaintext) CopyParams(ckkselement *ckksElement)
CopyParams copies the input element parameters on the target element
func (Plaintext) Degree ¶
func (el Plaintext) Degree() uint64
Degree returns the degree of the target element.
func (Plaintext) DivScale ¶ added in v1.3.0
func (el Plaintext) DivScale(scale float64)
DivScale divides the scale of the target element by the input scale.
func (Plaintext) Element ¶ added in v1.1.0
func (el Plaintext) Element() *ckksElement
Element sets the target element type to Element.
func (Plaintext) InvNTT ¶
InvNTT puts the target element outside of the NTT domain, and sets its isNTT flag to false. If it is not in the NTT domain, it does nothing.
func (Plaintext) IsNTT ¶
func (el Plaintext) IsNTT() bool
IsNTT returns the value of the NTT flag of the target element.
func (Plaintext) Level ¶
func (el Plaintext) Level() uint64
Level returns the level of the target element.
func (Plaintext) MulScale ¶ added in v1.3.0
func (el Plaintext) MulScale(scale float64)
MulScale multiplies the scale of the target element with the input scale.
func (Plaintext) NTT ¶
NTT puts the target element in the NTT domain and sets its isNTT flag to true. If it is already in the NTT domain, it does nothing.
func (Plaintext) Plaintext ¶ added in v1.1.0
func (el Plaintext) Plaintext() *Plaintext
Plaintext sets the target element type to Plaintext.
func (Plaintext) Resize ¶
func (el Plaintext) Resize(params *Parameters, degree uint64)
Resize resizes the degree of the target element.
func (Plaintext) Scale ¶
func (el Plaintext) Scale() float64
Scale returns the scale of the target element.
func (Plaintext) SetIsNTT ¶
func (el Plaintext) SetIsNTT(value bool)
SetIsNTT sets the value of the NTT flag of the target element with the input value.
func (Plaintext) SetScale ¶
func (el Plaintext) SetScale(scale float64)
SetScale sets the scale of the the target element to the input scale.
type PublicKey ¶
type PublicKey struct {
// contains filtered or unexported fields
}
PublicKey is a structure that stores the PublicKey
func NewPublicKey ¶ added in v1.3.0
func NewPublicKey(params *Parameters) (pk *PublicKey)
NewPublicKey returns a new PublicKey with zero values.
func (*PublicKey) GetDataLen ¶ added in v1.3.0
GetDataLen returns the length in bytes of the target PublicKey.
func (*PublicKey) MarshalBinary ¶ added in v1.1.0
MarshalBinary encodes a PublicKey in a byte slice.
func (*PublicKey) UnmarshalBinary ¶ added in v1.3.0
UnmarshalBinary decodes a previously marshaled PublicKey in the target PublicKey.
type Rotation ¶ added in v1.3.0
type Rotation int
Rotation is a type used to represent the rotations types.
type RotationKeys ¶ added in v1.3.0
type RotationKeys struct {
// contains filtered or unexported fields
}
RotationKeys is a structure that stores the switching-keys required during the homomorphic rotations.
func NewRotationKeys ¶ added in v1.3.0
func NewRotationKeys() (rotKey *RotationKeys)
NewRotationKeys generates a new instance of RotationKeys, with the provided rotation to the left, right and conjugation if requested.
func (*RotationKeys) GetDataLen ¶ added in v1.3.0
func (rotationkey *RotationKeys) GetDataLen(WithMetaData bool) (dataLen uint64)
GetDataLen returns the length in bytes of the target RotationKeys.
func (*RotationKeys) MarshalBinary ¶ added in v1.3.0
func (rotationkey *RotationKeys) MarshalBinary() (data []byte, err error)
MarshalBinary encodes a RotationKeys structure in a byte slice.
func (*RotationKeys) SetRotKey ¶ added in v1.3.0
func (rotKey *RotationKeys) SetRotKey(params *Parameters, evakey [][2]*ring.Poly, rotType Rotation, k uint64)
SetRotKey sets the target RotationKeys' SwitchingKey for the specified rotation type and amount with the input polynomials.
func (*RotationKeys) UnmarshalBinary ¶ added in v1.3.0
func (rotationkey *RotationKeys) UnmarshalBinary(data []byte) (err error)
UnmarshalBinary decodes a previously marshaled RotationKeys in the target RotationKeys.
type SecretKey ¶
type SecretKey struct {
// contains filtered or unexported fields
}
SecretKey is a structure that stores the SecretKey
func NewSecretKey ¶ added in v1.3.0
func NewSecretKey(params *Parameters) *SecretKey
NewSecretKey generates a new SecretKey with zero values.
func (*SecretKey) GetDataLen ¶ added in v1.3.0
GetDataLen returns the length in bytes of the target SecretKey.
func (*SecretKey) MarshalBinary ¶ added in v1.1.0
MarshalBinary encodes a SecretKey in a byte slice.
func (*SecretKey) UnmarshalBinary ¶ added in v1.3.0
UnmarshalBinary decodes a previously marshaled SecretKey on the target secret-key.
type SwitchingKey ¶
type SwitchingKey struct {
// contains filtered or unexported fields
}
SwitchingKey is a structure that stores the switching-keys required during the key-switching.
func NewSwitchingKey ¶ added in v1.3.0
func NewSwitchingKey(params *Parameters) (evakey *SwitchingKey)
NewSwitchingKey returns a new SwitchingKey with zero values.
func (*SwitchingKey) Get ¶ added in v1.3.0
func (swk *SwitchingKey) Get() [][2]*ring.Poly
Get returns the switching key backing slice
func (*SwitchingKey) GetDataLen ¶ added in v1.3.0
func (switchkey *SwitchingKey) GetDataLen(WithMetaData bool) (dataLen uint64)
GetDataLen returns the length in bytes of the target SwitchingKey.
func (*SwitchingKey) MarshalBinary ¶ added in v1.1.0
func (switchkey *SwitchingKey) MarshalBinary() (data []byte, err error)
MarshalBinary encodes an SwitchingKey in a byte slice.
func (*SwitchingKey) UnmarshalBinary ¶ added in v1.3.0
func (switchkey *SwitchingKey) UnmarshalBinary(data []byte) (err error)
UnmarshalBinary decode a previously marshaled SwitchingKey in the target SwitchingKey.