Documentation ¶
Index ¶
- Constants
- Variables
- func CheckModuli(q, p []uint64) error
- func GenModuli(logN int, logQ, logP []int) (q, p []uint64, err error)
- func PopulateElementRandom(prng utils.PRNG, params Parameters, el *Ciphertext)
- func SwitchCiphertextRingDegree(ctIn *Ciphertext, ctOut *Ciphertext)
- func SwitchCiphertextRingDegreeNTT(ctIn *Ciphertext, ringQSmallDim, ringQLargeDim *ring.Ring, ctOut *Ciphertext)
- type AdditiveShare
- type AdditiveShareBigint
- type Ciphertext
- func GetSmallestLargest(el0, el1 *Ciphertext) (smallest, largest *Ciphertext, sameDegree bool)
- func NewCiphertext(params Parameters, degree, level int) *Ciphertext
- func NewCiphertextNTT(params Parameters, degree, level int) *Ciphertext
- func NewCiphertextRandom(prng utils.PRNG, params Parameters, degree, level int) (ciphertext *Ciphertext)
- func (el *Ciphertext) Copy(ctxCopy *Ciphertext)
- func (el *Ciphertext) CopyNew() *Ciphertext
- func (el *Ciphertext) Degree() int
- func (el *Ciphertext) El() *Ciphertext
- func (ciphertext *Ciphertext) GetDataLen(WithMetaData bool) (dataLen int)
- func (el *Ciphertext) Level() int
- func (ciphertext *Ciphertext) MarshalBinary() (data []byte, err error)
- func (el *Ciphertext) RLWEElement() *Ciphertext
- func (el *Ciphertext) Resize(params Parameters, degree int)
- func (el *Ciphertext) SetValue(value []*ring.Poly)
- func (ciphertext *Ciphertext) UnmarshalBinary(data []byte) (err error)
- type Decryptor
- type Encryptor
- type EvaluationKey
- type KeyGenerator
- type KeySwitcher
- func (ks *KeySwitcher) DecomposeNTT(levelQ, levelP, alpha int, c2 *ring.Poly, PoolDecomp []PolyQP)
- func (ks *KeySwitcher) DecomposeSingleNTT(levelQ, levelP, alpha, beta int, c2NTT, c2InvNTT, c2QiQ, c2QiP *ring.Poly)
- func (ks *KeySwitcher) KeyswitchHoisted(levelQ int, PoolDecompQP []PolyQP, evakey *SwitchingKey, ...)
- func (ks *KeySwitcher) KeyswitchHoistedNoModDown(levelQ int, PoolDecompQP []PolyQP, evakey *SwitchingKey, ...)
- func (ks *KeySwitcher) ShallowCopy() *KeySwitcher
- func (ks *KeySwitcher) SwitchKeysInPlace(levelQ int, cx *ring.Poly, evakey *SwitchingKey, p0, p1 *ring.Poly)
- func (ks *KeySwitcher) SwitchKeysInPlaceNoModDown(levelQ int, cx *ring.Poly, evakey *SwitchingKey, c0Q, c0P, c1Q, c1P *ring.Poly)
- type Parameters
- func (p Parameters) Alpha() int
- func (p Parameters) Beta() int
- func (p Parameters) CopyNew() Parameters
- func (p Parameters) Equals(other Parameters) bool
- func (p Parameters) GaloisElementForColumnRotationBy(k int) uint64
- func (p Parameters) GaloisElementForRowRotation() uint64
- func (p Parameters) GaloisElementsForRowInnerSum() (galEls []uint64)
- func (p Parameters) InverseGaloisElement(galEl uint64) uint64
- func (p Parameters) LogN() int
- func (p Parameters) LogP() int
- func (p Parameters) LogQ() int
- func (p Parameters) LogQP() int
- func (p Parameters) MarshalBinary() ([]byte, error)
- func (p Parameters) MarshalBinarySize() int
- func (p Parameters) MarshalJSON() ([]byte, error)
- func (p Parameters) MaxLevel() int
- func (p Parameters) N() int
- func (p Parameters) P() []uint64
- func (p Parameters) PBigInt() *big.Int
- func (p Parameters) PCount() int
- func (p *Parameters) PiOverflowMargin(level int) int
- func (p Parameters) Q() []uint64
- func (p Parameters) QBigInt() *big.Int
- func (p Parameters) QCount() int
- func (p Parameters) QP() []uint64
- func (p Parameters) QPBigInt() *big.Int
- func (p Parameters) QPCount() int
- func (p Parameters) QiFloat64(level int) float64
- func (p *Parameters) QiOverflowMargin(level int) int
- func (p Parameters) RingP() *ring.Ring
- func (p Parameters) RingQ() *ring.Ring
- func (p Parameters) RingQP() *RingQP
- func (p Parameters) RingType() ring.Type
- func (p Parameters) Sigma() float64
- func (p Parameters) StandardParameters() (pci Parameters, err error)
- func (p *Parameters) UnmarshalBinary(data []byte) error
- func (p *Parameters) UnmarshalJSON(data []byte) (err error)
- type ParametersLiteral
- type Plaintext
- type PolyQP
- func (p *PolyQP) Copy(polFrom PolyQP)
- func (p *PolyQP) CopyNew() PolyQP
- func (p *PolyQP) CopyValues(other PolyQP)
- func (p *PolyQP) DecodePolyNew(data []byte) (pt int, err error)
- func (p *PolyQP) Equals(other PolyQP) bool
- func (p *PolyQP) GetDataLen(WithMetadata bool) (dataLen int)
- func (p *PolyQP) WriteTo(data []byte) (pt int, err error)
- type PublicKey
- type RelinearizationKey
- func (rlk *RelinearizationKey) CopyNew() *RelinearizationKey
- func (rlk *RelinearizationKey) Equals(other *RelinearizationKey) bool
- func (rlk *RelinearizationKey) GetDataLen(WithMetadata bool) (dataLen int)
- func (rlk *RelinearizationKey) MarshalBinary() (data []byte, err error)
- func (rlk *RelinearizationKey) UnmarshalBinary(data []byte) (err error)
- type RingQP
- func (r *RingQP) AddLvl(levelQ, levelP int, p1, p2, pOut PolyQP)
- func (r *RingQP) AddNoModLvl(levelQ, levelP int, p1, p2, pOut PolyQP)
- func (r *RingQP) CopyValuesLvl(levelQ, levelP int, p1, p2 PolyQP)
- func (r *RingQP) ExtendBasisSmallNormAndCenter(polyInQ *ring.Poly, levelP int, polyOutQ, polyOutP *ring.Poly)
- func (r *RingQP) InvMFormLvl(levelQ, levelP int, p, pOut PolyQP)
- func (r *RingQP) InvNTTLvl(levelQ, levelP int, p, pOut PolyQP)
- func (r *RingQP) MFormLvl(levelQ, levelP int, p, pOut PolyQP)
- func (r *RingQP) MulCoeffsMontgomeryAndAddLvl(levelQ, levelP int, p1, p2, p3 PolyQP)
- func (r *RingQP) MulCoeffsMontgomeryAndSubLvl(levelQ, levelP int, p1, p2, p3 PolyQP)
- func (r *RingQP) MulCoeffsMontgomeryConstantAndAddNoModLvl(levelQ, levelP int, p1, p2, p3 PolyQP)
- func (r *RingQP) MulCoeffsMontgomeryConstantAndSubNoModLvl(levelQ, levelP int, p1, p2, p3 PolyQP)
- func (r *RingQP) MulCoeffsMontgomeryConstantLvl(levelQ, levelP int, p1, p2, p3 PolyQP)
- func (r *RingQP) MulCoeffsMontgomeryLvl(levelQ, levelP int, p1, p2, p3 PolyQP)
- func (r *RingQP) NTTLazyLvl(levelQ, levelP int, p, pOut PolyQP)
- func (r *RingQP) NTTLvl(levelQ, levelP int, p, pOut PolyQP)
- func (r *RingQP) NewPoly() PolyQP
- func (r *RingQP) NewPolyLvl(levelQ, levelP int) PolyQP
- func (r *RingQP) PermuteNTTWithIndexAndAddNoModLvl(levelQ, levelP int, p1 PolyQP, index []uint64, p2 PolyQP)
- func (r *RingQP) PermuteNTTWithIndexLvl(levelQ, levelP int, p1 PolyQP, index []uint64, p2 PolyQP)
- func (r *RingQP) SubLvl(levelQ, levelP int, p1, p2, pOut PolyQP)
- type RotationKeySet
- func (rtks *RotationKeySet) Equals(other *RotationKeySet) bool
- func (rtks *RotationKeySet) GetDataLen(WithMetaData bool) (dataLen int)
- func (rtks *RotationKeySet) GetRotationKey(galoisEl uint64) (*SwitchingKey, bool)
- func (rtks *RotationKeySet) Includes(other *RotationKeySet) bool
- func (rtks *RotationKeySet) MarshalBinary() (data []byte, err error)
- func (rtks *RotationKeySet) UnmarshalBinary(data []byte) (err error)
- type SecretKey
- type SwitchingKey
- func (swk *SwitchingKey) CopyNew() *SwitchingKey
- func (swk *SwitchingKey) Equals(other *SwitchingKey) bool
- func (swk *SwitchingKey) GetDataLen(WithMetadata bool) (dataLen int)
- func (swk *SwitchingKey) MarshalBinary() (data []byte, err error)
- func (swk *SwitchingKey) UnmarshalBinary(data []byte) (err error)
- type UniformSamplerQP
Constants ¶
const DefaultSigma = 3.2
DefaultSigma is the default error distribution standard deviation
const GaloisGen uint64 = 5
GaloisGen is an integer of order N=2^d modulo M=2N and that spans Z_M with the integer -1. The j-th ring automorphism takes the root zeta to zeta^(5j).
const MaxLogN = 17
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.
const MinLogN = 4
MinLogN is the log2 of the smallest supported polynomial modulus degree (needed to ensure the NTT correctness).
Variables ¶
var ( // TestPN12QP109 is a set of default parameters with logN=12 and logQP=109 TestPN12QP109 = ParametersLiteral{ LogN: 12, Q: []uint64{0x7ffffec001, 0x40002001}, P: []uint64{0x8000016001}, Sigma: DefaultSigma, } // TestPN13QP218 is a set of default parameters with logN=13 and logQP=218 TestPN13QP218 = ParametersLiteral{ LogN: 13, Q: []uint64{0x3fffffffef8001, 0x4000000011c001, 0x40000000120001}, P: []uint64{0x7ffffffffb4001}, Sigma: DefaultSigma, } // TestPN14QP438 is a set of default parameters with logN=14 and logQP=438 TestPN14QP438 = ParametersLiteral{ LogN: 14, Q: []uint64{0x100000000060001, 0x80000000068001, 0x80000000080001, 0x3fffffffef8001, 0x40000000120001, 0x3fffffffeb8001}, P: []uint64{0x80000000130001, 0x7fffffffe90001}, Sigma: DefaultSigma, } // TestPN15QP880 is a set of default parameters with logN=15 and logQP=880 TestPN15QP880 = ParametersLiteral{ LogN: 15, Q: []uint64{0x7ffffffffe70001, 0x7ffffffffe10001, 0x7ffffffffcc0001, 0x400000000270001, 0x400000000350001, 0x400000000360001, 0x3ffffffffc10001, 0x3ffffffffbe0001, 0x3ffffffffbd0001, 0x4000000004d0001, 0x400000000570001, 0x400000000660001}, P: []uint64{0xffffffffffc0001, 0x10000000001d0001, 0x10000000006e0001}, Sigma: DefaultSigma, } // TestPN16QP240 is a set of default parameters with logN=16 and logQP=240 TestPN16QP240 = ParametersLiteral{ LogN: 16, LogQ: []int{60, 60, 60}, LogP: []int{60}, Sigma: DefaultSigma, } // TestPN17QP360 is a set of default parameters with logN=17 and logQP=360 TestPN17QP360 = ParametersLiteral{ LogN: 17, LogQ: []int{60, 60, 60, 60}, LogP: []int{60, 60}, Sigma: DefaultSigma, } )
Functions ¶
func CheckModuli ¶
CheckModuli checks that the provided q and p correspond to a valid moduli chain.
func PopulateElementRandom ¶
func PopulateElementRandom(prng utils.PRNG, params Parameters, el *Ciphertext)
PopulateElementRandom creates a new rlwe.Element with random coefficients
func SwitchCiphertextRingDegree ¶ added in v2.3.0
func SwitchCiphertextRingDegree(ctIn *Ciphertext, ctOut *Ciphertext)
SwitchCiphertextRingDegree changes the ring degree of ctIn to the one of ctOut. Maps Y^{N/n} -> X^{N} or X^{N} -> Y^{N/n}. If the ring degree of ctOut is larger than the one of ctIn, then the ringQ of ctIn must be provided (else a nil pointer).
func SwitchCiphertextRingDegreeNTT ¶ added in v2.3.0
func SwitchCiphertextRingDegreeNTT(ctIn *Ciphertext, ringQSmallDim, ringQLargeDim *ring.Ring, ctOut *Ciphertext)
SwitchCiphertextRingDegreeNTT changes the ring degree of ctIn to the one of ctOut. Maps Y^{N/n} -> X^{N} or X^{N} -> Y^{N/n}. If the ring degree of ctOut is larger than the one of ctIn, then the ringQ of ctIn must be provided (else a nil pointer). The ctIn must be in the NTT domain and ctOut will be in the NTT domain.
Types ¶
type AdditiveShare ¶
type AdditiveShare struct {
}AdditiveShare is a type for storing additively shared values in Z_Q[X] (RNS domain)
func NewAdditiveShare ¶
func NewAdditiveShare(params Parameters) *AdditiveShare
NewAdditiveShare instantiate a new additive share struct for the ring defined by the given parameters at maximum level.
func NewAdditiveShareAtLevel ¶
func NewAdditiveShareAtLevel(params Parameters, level int) *AdditiveShare
NewAdditiveShareAtLevel instantiate a new additive share struct for the ring defined by the given parameters at level `level`.
type AdditiveShareBigint ¶
type AdditiveShareBigint struct {
}AdditiveShareBigint is a type for storing additively shared values in Z (positional domain)
func NewAdditiveShareBigint ¶
func NewAdditiveShareBigint(params Parameters) *AdditiveShareBigint
NewAdditiveShareBigint instantiate a new additive share struct composed of big.Int elements
type Ciphertext ¶
Ciphertext is a generic type for RLWE ciphertext.
func GetSmallestLargest ¶
func GetSmallestLargest(el0, el1 *Ciphertext) (smallest, largest *Ciphertext, sameDegree bool)
GetSmallestLargest returns the provided element that has the smallest degree as a first returned value and the largest degree as second return value. If the degree match, the order is the same as for the input.
func NewCiphertext ¶
func NewCiphertext(params Parameters, degree, level int) *Ciphertext
NewCiphertext returns a new Element with zero values.
func NewCiphertextNTT ¶
func NewCiphertextNTT(params Parameters, degree, level int) *Ciphertext
NewCiphertextNTT returns a new Element with zero values and the NTT flags set.
func NewCiphertextRandom ¶ added in v2.4.0
func NewCiphertextRandom(prng utils.PRNG, params Parameters, degree, level int) (ciphertext *Ciphertext)
NewCiphertextRandom generates a new uniformly distributed Ciphertext of degree, level and scale.
func (*Ciphertext) Copy ¶
func (el *Ciphertext) Copy(ctxCopy *Ciphertext)
Copy copies the input element and its parameters on the target element.
func (*Ciphertext) CopyNew ¶
func (el *Ciphertext) CopyNew() *Ciphertext
CopyNew creates a new element as a copy of the target element.
func (*Ciphertext) Degree ¶
func (el *Ciphertext) Degree() int
Degree returns the degree of the target element.
func (*Ciphertext) GetDataLen ¶ added in v2.4.0
func (ciphertext *Ciphertext) GetDataLen(WithMetaData bool) (dataLen int)
GetDataLen returns the length in bytes of the target Ciphertext.
func (*Ciphertext) Level ¶
func (el *Ciphertext) Level() int
Level returns the level of the target element.
func (*Ciphertext) MarshalBinary ¶ added in v2.4.0
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) RLWEElement ¶
func (el *Ciphertext) RLWEElement() *Ciphertext
RLWEElement returns a pointer to this Element
func (*Ciphertext) Resize ¶
func (el *Ciphertext) Resize(params Parameters, degree int)
Resize resizes the degree of the target element. Sets the NTT flag of the added poly equal to the NTT flag to the poly at degree zero.
func (*Ciphertext) SetValue ¶
func (el *Ciphertext) SetValue(value []*ring.Poly)
SetValue sets the input slice of polynomials as the value of the target element.
func (*Ciphertext) UnmarshalBinary ¶ added in v2.4.0
func (ciphertext *Ciphertext) UnmarshalBinary(data []byte) (err error)
UnmarshalBinary decodes a previously marshaled Ciphertext on the target Ciphertext.
type Decryptor ¶
type Decryptor interface { // Decrypt decrypts the ciphertext and write the result in ptOut. // The level of the output plaintext is min(ciphertext.Level(), plaintext.Level()) // Output domain will match plaintext.Value.IsNTT value. Decrypt(ciphertext *Ciphertext, plaintext *Plaintext) }
Decryptor is an interface generic RLWE encryption.
func NewDecryptor ¶
func NewDecryptor(params Parameters, sk *SecretKey) Decryptor
NewDecryptor instantiates a new generic RLWE Decryptor.
type Encryptor ¶
type Encryptor interface { // Encrypt encrypts the input plaintext and write the result on ctOut. // The encryption algorithm depends on the implementor. Encrypt(pt *Plaintext, ctOut *Ciphertext) // EncryptFromCRP encrypts the input plaintext and writes the result in ctOut. // The encryption algorithm depends on the implementor. EncryptFromCRP(pt *Plaintext, crp *ring.Poly, ctOut *Ciphertext) }
Encryptor a generic RLWE encryption interface.
func NewEncryptor ¶
func NewEncryptor(params Parameters, key interface{}) Encryptor
NewEncryptor instatiates a new generic RLWE Encryptor. The key argument can be either a *rlwe.PublicKey or a *rlwe.SecretKey.
func NewFastEncryptor ¶
func NewFastEncryptor(params Parameters, key *PublicKey) Encryptor
NewFastEncryptor instantiates a new generic RLWE Encryptor. This encryptor's Encrypt method first encrypts zero in Q and then adds the plaintext. This method is faster than the normal encryptor but result in a noisier ciphertext.
type EvaluationKey ¶
type EvaluationKey struct { Rlk *RelinearizationKey Rtks *RotationKeySet }
EvaluationKey is a type for storing generic RLWE public evaluation keys. An evaluation key is a union of a relinearization key and a set of rotation keys.
type KeyGenerator ¶
type KeyGenerator interface { GenSecretKey() (sk *SecretKey) GenSecretKeyGaussian() (sk *SecretKey) GenSecretKeyWithDistrib(p float64) (sk *SecretKey) GenSecretKeySparse(hw int) (sk *SecretKey) GenPublicKey(sk *SecretKey) (pk *PublicKey) GenKeyPair() (sk *SecretKey, pk *PublicKey) GenKeyPairSparse(hw int) (sk *SecretKey, pk *PublicKey) GenRelinearizationKey(sk *SecretKey, maxDegree int) (evk *RelinearizationKey) GenSwitchingKey(skInput, skOutput *SecretKey) (newevakey *SwitchingKey) GenSwitchingKeyForGalois(galEl uint64, sk *SecretKey) (swk *SwitchingKey) GenRotationKeys(galEls []uint64, sk *SecretKey) (rks *RotationKeySet) GenSwitchingKeyForRotationBy(k int, sk *SecretKey) (swk *SwitchingKey) GenRotationKeysForRotations(ks []int, inclueSwapRows bool, sk *SecretKey) (rks *RotationKeySet) GenSwitchingKeyForRowRotation(sk *SecretKey) (swk *SwitchingKey) GenRotationKeysForInnerSum(sk *SecretKey) (rks *RotationKeySet) GenSwitchingKeysForRingSwap(skCKKS, skCI *SecretKey) (swkStdToConjugateInvariant, swkConjugateInvariantToStd *SwitchingKey) }
KeyGenerator is an interface implementing the methods of the KeyGenerator.
func NewKeyGenerator ¶
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 KeySwitcher ¶
type KeySwitcher struct { *Parameters Baseconverter *ring.FastBasisExtender Decomposer *ring.Decomposer // contains filtered or unexported fields }
KeySwitcher is a struct for RLWE key-switching.
func NewKeySwitcher ¶
func NewKeySwitcher(params Parameters) *KeySwitcher
NewKeySwitcher creates a new KeySwitcher.
func (*KeySwitcher) DecomposeNTT ¶
func (ks *KeySwitcher) DecomposeNTT(levelQ, levelP, alpha int, c2 *ring.Poly, PoolDecomp []PolyQP)
DecomposeNTT applies the full RNS basis decomposition for all q_alpha_i on c2. Expects the IsNTT flag of c2 to correctly reflect the domain of c2. PoolDecompQ and PoolDecompQ are vectors of polynomials (mod Q and mod P) that store the special RNS decomposition of c2 (in the NTT domain)
func (*KeySwitcher) DecomposeSingleNTT ¶
func (ks *KeySwitcher) DecomposeSingleNTT(levelQ, levelP, alpha, beta int, c2NTT, c2InvNTT, c2QiQ, c2QiP *ring.Poly)
DecomposeSingleNTT takes the input polynomial c2 (c2NTT and c2InvNTT, respectively in the NTT and out of the NTT domain) modulo q_alpha_beta, and returns the result on c2QiQ are c2QiP the receiver polynomials respectively mod Q and mod P (in the NTT domain)
func (*KeySwitcher) KeyswitchHoisted ¶
func (ks *KeySwitcher) KeyswitchHoisted(levelQ int, PoolDecompQP []PolyQP, evakey *SwitchingKey, c0Q, c1Q, c0P, c1P *ring.Poly)
KeyswitchHoisted applies the key-switch to the decomposed polynomial c2 mod QP (PoolDecompQ and PoolDecompP) and divides the result by P, reducing the basis from QP to Q.
pool2 = dot(PoolDecompQ||PoolDecompP * evakey[0]) mod Q pool3 = dot(PoolDecompQ||PoolDecompP * evakey[1]) mod Q
func (*KeySwitcher) KeyswitchHoistedNoModDown ¶
func (ks *KeySwitcher) KeyswitchHoistedNoModDown(levelQ int, PoolDecompQP []PolyQP, evakey *SwitchingKey, c0Q, c1Q, c0P, c1P *ring.Poly)
KeyswitchHoistedNoModDown applies the key-switch to the decomposed polynomial c2 mod QP (PoolDecompQ and PoolDecompP)
pool2 = dot(PoolDecompQ||PoolDecompP * evakey[0]) mod QP pool3 = dot(PoolDecompQ||PoolDecompP * evakey[1]) mod QP
func (*KeySwitcher) ShallowCopy ¶
func (ks *KeySwitcher) ShallowCopy() *KeySwitcher
ShallowCopy creates a copy of a KeySwitcher, only reallocating the memory pool.
func (*KeySwitcher) SwitchKeysInPlace ¶
func (ks *KeySwitcher) SwitchKeysInPlace(levelQ int, cx *ring.Poly, evakey *SwitchingKey, p0, p1 *ring.Poly)
SwitchKeysInPlace applies the general key-switching procedure of the form [c0 + cx*evakey[0], c1 + cx*evakey[1]] Will return the result in the same NTT domain as the input cx.
func (*KeySwitcher) SwitchKeysInPlaceNoModDown ¶
func (ks *KeySwitcher) SwitchKeysInPlaceNoModDown(levelQ int, cx *ring.Poly, evakey *SwitchingKey, c0Q, c0P, c1Q, c1P *ring.Poly)
SwitchKeysInPlaceNoModDown applies the key-switch to the polynomial cx :
pool2 = dot(decomp(cx) * evakey[0]) mod QP (encrypted input is multiplied by P factor) pool3 = dot(decomp(cx) * evakey[1]) mod QP (encrypted input is multiplied by P factor)
Expects the flag IsNTT of cx to correctly reflect the domain of cx.
type Parameters ¶
type Parameters struct {
// contains filtered or unexported fields
}
Parameters represents a set of generic RLWE parameters. Its fields are private and immutable. See ParametersLiteral for user-specified parameters.
func NewParameters ¶
NewParameters returns a new set of generic RLWE parameters from the given ring degree logn, moduli q and p, and error distribution parameter sigma. It returns the empty parameters Parameters{} and a non-nil error if the specified parameters are invalid.
func NewParametersFromLiteral ¶
func NewParametersFromLiteral(paramDef ParametersLiteral) (Parameters, error)
NewParametersFromLiteral instantiate a set of generic RLWE parameters from a ParametersLiteral specification. It returns the empty parameters Parameters{} and a non-nil error if the specified parameters are invalid.
func (Parameters) Alpha ¶
func (p Parameters) Alpha() int
Alpha returns the number of moduli in in P
func (Parameters) Beta ¶
func (p Parameters) Beta() int
Beta returns the number of element in the RNS decomposition basis: Ceil(lenQi / lenPi)
func (Parameters) CopyNew ¶
func (p Parameters) CopyNew() Parameters
CopyNew makes a deep copy of the receiver and returns it.
func (Parameters) Equals ¶
func (p Parameters) Equals(other Parameters) bool
Equals checks two Parameter structs for equality.
func (Parameters) GaloisElementForColumnRotationBy ¶
func (p Parameters) GaloisElementForColumnRotationBy(k int) uint64
GaloisElementForColumnRotationBy returns the galois element for plaintext column rotations by k position to the left. Providing a negative k is equivalent to a right rotation.
func (Parameters) GaloisElementForRowRotation ¶
func (p Parameters) GaloisElementForRowRotation() uint64
GaloisElementForRowRotation returns the galois element for generating the row rotation automorphism
func (Parameters) GaloisElementsForRowInnerSum ¶
func (p Parameters) GaloisElementsForRowInnerSum() (galEls []uint64)
GaloisElementsForRowInnerSum returns a list of all galois elements required to perform an InnerSum operation. This corresponds to all the left rotations by k-positions where k is a power of two and the row-rotation element.
func (Parameters) InverseGaloisElement ¶
func (p Parameters) InverseGaloisElement(galEl uint64) uint64
InverseGaloisElement takes a galois element and returns the galois element
corresponding to the inverse automorphism
func (Parameters) LogN ¶
func (p Parameters) LogN() int
LogN returns the log of the degree of the polynomial ring
func (Parameters) LogP ¶
func (p Parameters) LogP() int
LogP returns the size of the extended modulus P in bits
func (Parameters) LogQ ¶
func (p Parameters) LogQ() int
LogQ returns the size of the extended modulus Q in bits
func (Parameters) LogQP ¶
func (p Parameters) LogQP() int
LogQP returns the size of the extended modulus QP in bits
func (Parameters) MarshalBinary ¶
func (p Parameters) MarshalBinary() ([]byte, error)
MarshalBinary returns a []byte representation of the parameter set.
func (Parameters) MarshalBinarySize ¶
func (p Parameters) MarshalBinarySize() int
MarshalBinarySize returns the length of the []byte encoding of the reciever.
func (Parameters) MarshalJSON ¶
func (p Parameters) MarshalJSON() ([]byte, error)
MarshalJSON returns a JSON representation of this parameter set. See `Marshal` from the `encoding/json` package.
func (Parameters) MaxLevel ¶
func (p Parameters) MaxLevel() int
MaxLevel returns the maximum level of a ciphertext
func (Parameters) P ¶
func (p Parameters) P() []uint64
P returns a new slice with the factors of the ciphertext modulus extension P
func (Parameters) PBigInt ¶
func (p Parameters) PBigInt() *big.Int
PBigInt return the ciphertext-space extention modulus P in big.Integer, reconstructed, representation.
func (Parameters) PCount ¶
func (p Parameters) PCount() int
PCount returns the number of factors of the ciphertext modulus extension P
func (*Parameters) PiOverflowMargin ¶
func (p *Parameters) PiOverflowMargin(level int) int
PiOverflowMargin returns floor(2^64 / max(Pi)), i.e. the number of times elements of Z_max{Pi} can be added together before overflowing 2^64.
func (Parameters) Q ¶
func (p Parameters) Q() []uint64
Q returns a new slice with the factors of the ciphertext modulus q
func (Parameters) QBigInt ¶
func (p Parameters) QBigInt() *big.Int
QBigInt return the ciphertext-space modulus Q in big.Integer, reconstructed, representation.
func (Parameters) QCount ¶
func (p Parameters) QCount() int
QCount returns the number of factors of the ciphertext modulus Q
func (Parameters) QP ¶
func (p Parameters) QP() []uint64
QP return the extended ciphertext-space modulus QP in RNS representation.
func (Parameters) QPBigInt ¶
func (p Parameters) QPBigInt() *big.Int
QPBigInt return the extended ciphertext-space modulus QP in big.Integer, reconstructed, representation.
func (Parameters) QPCount ¶
func (p Parameters) QPCount() int
QPCount returns the number of factors of the ciphertext modulus + the modulus extension P
func (Parameters) QiFloat64 ¶ added in v2.3.0
func (p Parameters) QiFloat64(level int) float64
QiFloat64 returns the float64 value of the Qi at position level in the modulus chain.
func (*Parameters) QiOverflowMargin ¶
func (p *Parameters) QiOverflowMargin(level int) int
QiOverflowMargin returns floor(2^64 / max(Qi)), i.e. the number of times elements of Z_max{Qi} can be added together before overflowing 2^64.
func (Parameters) RingType ¶ added in v2.4.0
func (p Parameters) RingType() ring.Type
RingType returns the type of the underlying ring.
func (Parameters) Sigma ¶
func (p Parameters) Sigma() float64
Sigma returns standard deviation of the noise distribution
func (Parameters) StandardParameters ¶ added in v2.4.0
func (p Parameters) StandardParameters() (pci Parameters, err error)
StandardParameters returns a RLWE parameter set that corresponds to the standard dual of a conjugate invariant parameter set. If the receiver is already a standard set, then the method returns the receiver.
func (*Parameters) UnmarshalBinary ¶
func (p *Parameters) UnmarshalBinary(data []byte) error
UnmarshalBinary decodes a []byte into a parameter set struct.
func (*Parameters) UnmarshalJSON ¶
func (p *Parameters) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON reads a JSON representation of a parameter set into the receiver Parameter. See `Unmarshal` from the `encoding/json` package.
type ParametersLiteral ¶
type ParametersLiteral struct { LogN int Q []uint64 P []uint64 LogQ []int `json:",omitempty"` LogP []int `json:",omitempty"` Sigma float64 RingType ring.Type }
ParametersLiteral is a literal representation of BFV parameters. It has public fields and is used to express unchecked user-defined parameters literally into Go programs. The NewParametersFromLiteral function is used to generate the actual checked parameters from the literal representation.
type Plaintext ¶
Plaintext is a common base type for RLWE plaintexts.
func NewPlaintext ¶
func NewPlaintext(params Parameters, level int) *Plaintext
NewPlaintext creates a new Plaintext at level `level` from the parameters.
func (Plaintext) El ¶
func (pt Plaintext) El() *Ciphertext
El returns the plaintext as a new `Element` for which the value points to the receiver `Value` field.
type PolyQP ¶ added in v2.3.0
PolyQP represents a polynomial in the ring of polynomial modulo Q*P. This type is simply the union type between two ring.Poly, each one containing the modulus Q and P coefficients of that polynomial. The modulus Q represent the ciphertext modulus and the modulus P the special primes for the RNS decomposition during homomorphic operations involving keys.
func (*PolyQP) CopyValues ¶ added in v2.3.0
CopyValues copies the coefficients of p1 on the target polynomial. This method simply calls the CopyValues method for each of its sub-polynomials.
func (*PolyQP) DecodePolyNew ¶ added in v2.3.0
DecodePolyNew decodes the input bytes on the target polyQP.
func (*PolyQP) Equals ¶ added in v2.3.0
Equals returns true if the receiver PolyQP is equal to the provided other PolyQP. This method checks for equality of its two sub-polynomials.
func (*PolyQP) GetDataLen ¶ added in v2.3.0
GetDataLen returns the length in byte of the target PolyQP
type PublicKey ¶
type PublicKey struct {
Value [2]PolyQP
}
PublicKey is a type for generic RLWE public keys.
func NewPublicKey ¶
func NewPublicKey(params Parameters) (pk *PublicKey)
NewPublicKey returns a new PublicKey with zero values.
func (*PublicKey) GetDataLen ¶
GetDataLen returns the length in bytes of the target PublicKey.
func (*PublicKey) MarshalBinary ¶
MarshalBinary encodes a PublicKey in a byte slice.
func (*PublicKey) UnmarshalBinary ¶
UnmarshalBinary decodes a previously marshaled PublicKey in the target PublicKey.
type RelinearizationKey ¶
type RelinearizationKey struct {
Keys []*SwitchingKey
}
RelinearizationKey is a type for generic RLWE public relinearization keys. It stores a slice with a switching key per relinearizable degree. The switching key at index i is used to relinearize a degree i+2 ciphertexts back to a degree i + 1 one.
func NewRelinKey ¶
func NewRelinKey(params Parameters, maxRelinDegree int) (evakey *RelinearizationKey)
NewRelinKey creates a new EvaluationKey with zero values.
func (*RelinearizationKey) CopyNew ¶
func (rlk *RelinearizationKey) CopyNew() *RelinearizationKey
CopyNew creates a deep copy of the receiver RelinearizationKey and returns it.
func (*RelinearizationKey) Equals ¶
func (rlk *RelinearizationKey) Equals(other *RelinearizationKey) bool
Equals checks two RelinearizationKeys for equality.
func (*RelinearizationKey) GetDataLen ¶
func (rlk *RelinearizationKey) GetDataLen(WithMetadata bool) (dataLen int)
GetDataLen returns the length in bytes of the target EvaluationKey.
func (*RelinearizationKey) MarshalBinary ¶
func (rlk *RelinearizationKey) MarshalBinary() (data []byte, err error)
MarshalBinary encodes an EvaluationKey key in a byte slice.
func (*RelinearizationKey) UnmarshalBinary ¶
func (rlk *RelinearizationKey) UnmarshalBinary(data []byte) (err error)
UnmarshalBinary decodes a previously marshaled EvaluationKey in the target EvaluationKey.
type RingQP ¶ added in v2.3.0
RingQP is a structure that implements the operation in the ring R_QP. This type is simply a union type between the two Ring types representing R_Q and R_P.
func (*RingQP) AddLvl ¶ added in v2.3.0
AddLvl adds p1 to p2 coefficient-wise and writes the result on p3. The operation is performed at levelQ for the ringQ and levelP for the ringP.
func (*RingQP) AddNoModLvl ¶ added in v2.3.0
AddNoModLvl adds p1 to p2 coefficient-wise and writes the result on p3 without modular reduction. The operation is performed at levelQ for the ringQ and levelP for the ringP.
func (*RingQP) CopyValuesLvl ¶ added in v2.3.0
CopyValuesLvl copies the values of p1 on p2. The operation is performed at levelQ for the ringQ and levelP for the ringP.
func (*RingQP) ExtendBasisSmallNormAndCenter ¶ added in v2.3.0
func (r *RingQP) ExtendBasisSmallNormAndCenter(polyInQ *ring.Poly, levelP int, polyOutQ, polyOutP *ring.Poly)
ExtendBasisSmallNormAndCenter extends a small-norm polynomial polQ in R_Q to a polynomial polQP in R_QP.
func (*RingQP) InvMFormLvl ¶ added in v2.3.0
InvMFormLvl switches back p1 from the Montgomery domain to the conventional domain and writes the result on p2. The operation is performed at levelQ for the ringQ and levelP for the ringP.
func (*RingQP) InvNTTLvl ¶ added in v2.3.0
InvNTTLvl computes the inverse-NTT of p1 and returns the result on p2. The operation is performed at levelQ for the ringQ and levelP for the ringP.
func (*RingQP) MFormLvl ¶ added in v2.3.0
MFormLvl switches p1 to the Montgomery domain and writes the result on p2. The operation is performed at levelQ for the ringQ and levelP for the ringP.
func (*RingQP) MulCoeffsMontgomeryAndAddLvl ¶ added in v2.3.0
MulCoeffsMontgomeryAndAddLvl multiplies p1 by p2 coefficient-wise with a Montgomery modular reduction and adds the result to p3. The operation is performed at levelQ for the ringQ and levelP for the ringP.
func (*RingQP) MulCoeffsMontgomeryAndSubLvl ¶ added in v2.3.0
MulCoeffsMontgomeryAndSubLvl multiplies p1 by p2 coefficient-wise with a Montgomery modular reduction and subtracts the result from p3. The operation is performed at levelQ for the ringQ and levelP for the ringP.
func (*RingQP) MulCoeffsMontgomeryConstantAndAddNoModLvl ¶ added in v2.3.0
MulCoeffsMontgomeryConstantAndAddNoModLvl multiplies p1 by p2 coefficient-wise with a constant-time Montgomery modular reduction and adds the result on p3. Result is within [0, 2q-1]
func (*RingQP) MulCoeffsMontgomeryConstantAndSubNoModLvl ¶ added in v2.4.0
MulCoeffsMontgomeryConstantAndSubNoModLvl multiplies p1 by p2 coefficient-wise with a Montgomery modular reduction and subtracts the result from p3. The operation is performed at levelQ for the ringQ and levelP for the ringP.
func (*RingQP) MulCoeffsMontgomeryConstantLvl ¶ added in v2.3.0
MulCoeffsMontgomeryConstantLvl multiplies p1 by p2 coefficient-wise with a constant-time Montgomery modular reduction. The operation is performed at levelQ for the ringQ and levelP for the ringP. Result is within [0, 2q-1].
func (*RingQP) MulCoeffsMontgomeryLvl ¶ added in v2.3.0
MulCoeffsMontgomeryLvl multiplies p1 by p2 coefficient-wise with a Montgomery modular reduction. The operation is performed at levelQ for the ringQ and levelP for the ringP.
func (*RingQP) NTTLazyLvl ¶ added in v2.3.0
NTTLazyLvl computes the NTT of p1 and returns the result on p2. The operation is performed at levelQ for the ringQ and levelP for the ringP. Output values are in the range [0, 2q-1].
func (*RingQP) NTTLvl ¶ added in v2.3.0
NTTLvl computes the NTT of p1 and returns the result on p2. The operation is performed at levelQ for the ringQ and levelP for the ringP.
func (*RingQP) NewPoly ¶ added in v2.3.0
NewPoly creates a new polynomial with all coefficients set to 0.
func (*RingQP) NewPolyLvl ¶ added in v2.3.0
NewPolyLvl creates a new polynomial with all coefficients set to 0.
func (*RingQP) PermuteNTTWithIndexAndAddNoModLvl ¶ added in v2.3.0
func (r *RingQP) PermuteNTTWithIndexAndAddNoModLvl(levelQ, levelP int, p1 PolyQP, index []uint64, p2 PolyQP)
PermuteNTTWithIndexAndAddNoModLvl applies the automorphism X^{5^j} on p1 and adds the result on p2. Index of automorphism must be provided. Method is not in place. The operation is performed at levelQ for the ringQ and levelP for the ringP.
func (*RingQP) PermuteNTTWithIndexLvl ¶ added in v2.3.0
PermuteNTTWithIndexLvl applies the automorphism X^{5^j} on p1 and writes the result on p2. Index of automorphism must be provided. Method is not in place. The operation is performed at levelQ for the ringQ and levelP for the ringP.
type RotationKeySet ¶
type RotationKeySet struct {
Keys map[uint64]*SwitchingKey
}
RotationKeySet is a type for storing generic RLWE public rotation keys. It stores a map indexed by the galois element defining the automorphism.
func NewRotationKeySet ¶
func NewRotationKeySet(params Parameters, galoisElement []uint64) (rotKey *RotationKeySet)
NewRotationKeySet returns a new RotationKeySet with pre-allocated switching keys for each distinct galoisElement value.
func (*RotationKeySet) Equals ¶
func (rtks *RotationKeySet) Equals(other *RotationKeySet) bool
Equals checks to RotationKeySets for equality.
func (*RotationKeySet) GetDataLen ¶
func (rtks *RotationKeySet) GetDataLen(WithMetaData bool) (dataLen int)
GetDataLen returns the length in bytes of the target RotationKeys.
func (*RotationKeySet) GetRotationKey ¶
func (rtks *RotationKeySet) GetRotationKey(galoisEl uint64) (*SwitchingKey, bool)
GetRotationKey return the rotation key for the given galois element or nil if such key is not in the set. The second argument is true iff the first one is non-nil.
func (*RotationKeySet) Includes ¶
func (rtks *RotationKeySet) Includes(other *RotationKeySet) bool
Includes checks whether the receiver RotationKeySet includes the given other RotationKeySet.
func (*RotationKeySet) MarshalBinary ¶
func (rtks *RotationKeySet) MarshalBinary() (data []byte, err error)
MarshalBinary encodes a RotationKeys struct in a byte slice.
func (*RotationKeySet) UnmarshalBinary ¶
func (rtks *RotationKeySet) UnmarshalBinary(data []byte) (err error)
UnmarshalBinary decodes a previously marshaled RotationKeys in the target RotationKeys.
type SecretKey ¶
type SecretKey struct {
Value PolyQP
}
SecretKey is a type for generic RLWE secret keys.
func NewSecretKey ¶
func NewSecretKey(params Parameters) *SecretKey
NewSecretKey generates a new SecretKey with zero values.
func (*SecretKey) GetDataLen ¶
GetDataLen returns the length in bytes of the target SecretKey.
func (*SecretKey) MarshalBinary ¶
MarshalBinary encodes a secret key in a byte slice.
func (*SecretKey) UnmarshalBinary ¶
UnmarshalBinary decodes a previously marshaled SecretKey in the target SecretKey.
type SwitchingKey ¶
type SwitchingKey struct {
Value [][2]PolyQP
}
SwitchingKey is a type for generic RLWE public switching keys.
func NewSwitchingKey ¶
func NewSwitchingKey(params Parameters, levelQ, levelP int) *SwitchingKey
NewSwitchingKey returns a new public switching key with pre-allocated zero-value
func (*SwitchingKey) CopyNew ¶
func (swk *SwitchingKey) CopyNew() *SwitchingKey
CopyNew creates a deep copy of the receiver SwitchingKey and returns it.
func (*SwitchingKey) Equals ¶
func (swk *SwitchingKey) Equals(other *SwitchingKey) bool
Equals checks two SwitchingKeys for equality.
func (*SwitchingKey) GetDataLen ¶
func (swk *SwitchingKey) GetDataLen(WithMetadata bool) (dataLen int)
GetDataLen returns the length in bytes of the target SwitchingKey.
func (*SwitchingKey) MarshalBinary ¶
func (swk *SwitchingKey) MarshalBinary() (data []byte, err error)
MarshalBinary encodes an SwitchingKey in a byte slice.
func (*SwitchingKey) UnmarshalBinary ¶
func (swk *SwitchingKey) UnmarshalBinary(data []byte) (err error)
UnmarshalBinary decode a previously marshaled SwitchingKey in the target SwitchingKey.
type UniformSamplerQP ¶ added in v2.3.0
type UniformSamplerQP struct {
// contains filtered or unexported fields
}
UniformSamplerQP is a type for sampling polynomials in RingQP.
func NewUniformSamplerQP ¶ added in v2.3.0
func NewUniformSamplerQP(params Parameters, prng utils.PRNG, baseRing *RingQP) (s UniformSamplerQP)
NewUniformSamplerQP instantiates a new UniformSamplerQP from a given PRNG.
func (UniformSamplerQP) Read ¶ added in v2.3.0
func (s UniformSamplerQP) Read(p *PolyQP)
Read samples a new polynomial in RingQP and stores it into p.