rlwe

package
v3.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2022 License: Apache-2.0 Imports: 9 Imported by: 20

Documentation

Index

Constants

View Source
const DefaultSigma = 3.2

DefaultSigma is the default error distribution standard deviation

View Source
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).

View Source
const MaxLogN = 17

MaxLogN is the log2 of the largest supported polynomial modulus degree.

View Source
const MaxModuliCount = 34

MaxModuliCount is the largest supported number of moduli in the RNS representation.

View Source
const MaxModuliSize = 60

MaxModuliSize is the largest bit-length supported for the moduli in the RNS representation.

View Source
const MinLogN = 4

MinLogN is the log2 of the smallest supported polynomial modulus degree (needed to ensure the NTT correctness).

Variables

View Source
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

func CheckModuli(q, p []uint64) error

CheckModuli checks that the provided q and p correspond to a valid moduli chain.

func GenModuli

func GenModuli(logN int, logQ, logP []int) (q, p []uint64, err error)

GenModuli generates a valid moduli chain from the provided moduli sizes.

func PopulateElementRandom

func PopulateElementRandom(prng utils.PRNG, params Parameters, el *Ciphertext)

PopulateElementRandom creates a new rlwe.Element with random coefficients

func SwitchCiphertextRingDegree

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

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 {
	Value ring.Poly
}

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 {
	Value []*big.Int
}

AdditiveShareBigint is a type for storing additively shared values in Z (positional domain)

func NewAdditiveShareBigint

func NewAdditiveShareBigint(params Parameters, n int) *AdditiveShareBigint

NewAdditiveShareBigint instantiate a new additive share struct composed of "n" big.Int elements

type Ciphertext

type Ciphertext struct {
	Value []*ring.Poly
}

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

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) El

func (el *Ciphertext) El() *Ciphertext

El returns a pointer to this Element

func (*Ciphertext) GetDataLen

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

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

func (ciphertext *Ciphertext) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary decodes a previously marshaled Ciphertext on the target Ciphertext.

type Decryptor

type Decryptor interface {
	Decrypt(ciphertext *Ciphertext, plaintext *Plaintext)
	ShallowCopy() Decryptor
	WithKey(sk *SecretKey) Decryptor
}

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(pt *Plaintext, ct *Ciphertext)
	EncryptFromCRP(pt *Plaintext, crp *ring.Poly, ct *Ciphertext)
	ShallowCopy() Encryptor
	WithKey(key interface{}) Encryptor
}

Encryptor a generic RLWE encryption interface.

func NewEncryptor

func NewEncryptor(params Parameters, key interface{}) Encryptor

NewEncryptor creates a new Encryptor Accepts either a secret-key or a public-key.

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)
	GenSecretKeyWithHammingWeight(hw int) (sk *SecretKey)
	GenPublicKey(sk *SecretKey) (pk *PublicKey)
	GenKeyPair() (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

	BasisExtender *ring.BasisExtender
	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, BuffDecomp []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. BuffDecompQ and BuffDecompQ 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, BuffDecompQP []PolyQP, evakey *SwitchingKey, c0Q, c1Q, c0P, c1P *ring.Poly)

KeyswitchHoisted applies the key-switch to the decomposed polynomial c2 mod QP (BuffDecompQ and BuffDecompP) and divides the result by P, reducing the basis from QP to Q.

Buff2 = dot(BuffDecompQ||BuffDecompP * evakey[0]) mod Q Buff3 = dot(BuffDecompQ||BuffDecompP * evakey[1]) mod Q

func (*KeySwitcher) KeyswitchHoistedNoModDown

func (ks *KeySwitcher) KeyswitchHoistedNoModDown(levelQ int, BuffDecompQP []PolyQP, evakey *SwitchingKey, c0Q, c1Q, c0P, c1P *ring.Poly)

KeyswitchHoistedNoModDown applies the key-switch to the decomposed polynomial c2 mod QP (BuffDecompQ and BuffDecompP)

Buff2 = dot(BuffDecompQ||BuffDecompP * evakey[0]) mod QP Buff3 = dot(BuffDecompQ||BuffDecompP * evakey[1]) mod QP

func (*KeySwitcher) ShallowCopy

func (ks *KeySwitcher) ShallowCopy() *KeySwitcher

ShallowCopy creates a copy of a KeySwitcher, only reallocating the memory Buff.

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 :

Buff2 = dot(decomp(cx) * evakey[0]) mod QP (encrypted input is multiplied by P factor) Buff3 = 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

func NewParameters(logn int, q, p []uint64, h int, sigma float64, ringType ring.Type) (Parameters, error)

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.

If the moduli chain is specified through the LogQ and LogP fields, the method generates a moduli chain matching the specified sizes (see `GenModuli`).

If the secrets' density parameter (H) is left unset, its value is set to 2^(paramDef.LogN-1) to match the standard ternary distribution.

If the error variance is left unset, its value is set to `DefaultSigma`.

If the RingType is left unset, the default value is ring.Standard.

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 deprecated

func (p Parameters) CopyNew() Parameters

CopyNew makes a deep copy of the receiver and returns it.

Deprecated: Parameter is now a read-only struct, except for the UnmarshalBinary method: deep copying should only be required to save a Parameter struct before calling its UnmarshalBinary method and it will be deprecated when transitioning to a immutable serialization interface.

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) HammingWeight added in v3.0.1

func (p Parameters) HammingWeight() int

HammingWeight returns the number of non-zero coefficients in secret-keys.

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) N

func (p Parameters) N() int

N returns the ring degree

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

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) RingP

func (p Parameters) RingP() *ring.Ring

RingP returns a pointer to ringP

func (Parameters) RingQ

func (p Parameters) RingQ() *ring.Ring

RingQ returns a pointer to ringQ

func (Parameters) RingQP

func (p Parameters) RingQP() *RingQP

RingQP returns a pointer to ringQP

func (Parameters) RingType

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

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
	H        int
	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.

Users must set the polynomial degree (LogN) and the coefficient modulus, by either setting the Q and P fields to the desired moduli chain, or by setting the LogQ and LogP fields to the desired moduli sizes.

Optionally, users may specify the error variance (Sigma) and secrets' density (H) and the ring type (RingType). If left unset, standard default values for these field are substituted at parameter creation (see NewParametersFromLiteral).

type Plaintext

type Plaintext struct {
	Value *ring.Poly
}

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) Copy

func (pt *Plaintext) Copy(other *Plaintext)

Copy copies the `other` plaintext value into the reciever plaintext.

func (Plaintext) Degree

func (pt Plaintext) Degree() int

Degree returns the degree of the target element.

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.

func (Plaintext) Level

func (pt Plaintext) Level() int

Level returns the level of the target element.

type PolyQP

type PolyQP struct {
	Q, P *ring.Poly
}

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) Copy

func (p *PolyQP) Copy(polFrom PolyQP)

Copy copies the input polyQP on the target polyQP.

func (*PolyQP) CopyNew

func (p *PolyQP) CopyNew() PolyQP

CopyNew creates an exact copy of the target polynomial.

func (*PolyQP) CopyValues

func (p *PolyQP) CopyValues(other PolyQP)

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

func (p *PolyQP) DecodePolyNew(data []byte) (pt int, err error)

DecodePolyNew decodes the input bytes on the target polyQP.

func (*PolyQP) Equals

func (p *PolyQP) Equals(other PolyQP) (v bool)

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

func (p *PolyQP) GetDataLen(WithMetadata bool) (dataLen int)

GetDataLen returns the length in byte of the target PolyQP

func (*PolyQP) WriteTo

func (p *PolyQP) WriteTo(data []byte) (pt int, err error)

WriteTo writes a polyQP on the inpute data.

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) CopyNew

func (pk *PublicKey) CopyNew() *PublicKey

CopyNew creates a deep copy of the receiver PublicKey and returns it.

func (*PublicKey) Equals

func (pk *PublicKey) Equals(other *PublicKey) bool

Equals checks two PublicKey struct for equality.

func (*PublicKey) GetDataLen

func (pk *PublicKey) GetDataLen(WithMetadata bool) (dataLen int)

GetDataLen returns the length in bytes of the target PublicKey.

func (*PublicKey) MarshalBinary

func (pk *PublicKey) MarshalBinary() (data []byte, err error)

MarshalBinary encodes a PublicKey in a byte slice.

func (*PublicKey) UnmarshalBinary

func (pk *PublicKey) UnmarshalBinary(data []byte) (err error)

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

type RingQP struct {
	RingQ, RingP *ring.Ring
}

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

func (r *RingQP) AddLvl(levelQ, levelP int, p1, p2, pOut PolyQP)

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

func (r *RingQP) AddNoModLvl(levelQ, levelP int, p1, p2, pOut PolyQP)

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

func (r *RingQP) CopyValuesLvl(levelQ, levelP int, p1, p2 PolyQP)

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

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

func (r *RingQP) InvMFormLvl(levelQ, levelP int, p, pOut PolyQP)

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

func (r *RingQP) InvNTTLvl(levelQ, levelP int, p, pOut PolyQP)

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

func (r *RingQP) MFormLvl(levelQ, levelP int, p, pOut PolyQP)

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

func (r *RingQP) MulCoeffsMontgomeryAndAddLvl(levelQ, levelP int, p1, p2, p3 PolyQP)

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

func (r *RingQP) MulCoeffsMontgomeryAndSubLvl(levelQ, levelP int, p1, p2, p3 PolyQP)

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

func (r *RingQP) MulCoeffsMontgomeryConstantAndAddNoModLvl(levelQ, levelP int, p1, p2, p3 PolyQP)

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

func (r *RingQP) MulCoeffsMontgomeryConstantAndSubNoModLvl(levelQ, levelP int, p1, p2, p3 PolyQP)

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

func (r *RingQP) MulCoeffsMontgomeryConstantLvl(levelQ, levelP int, p1, p2, p3 PolyQP)

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

func (r *RingQP) MulCoeffsMontgomeryLvl(levelQ, levelP int, p1, p2, p3 PolyQP)

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

func (r *RingQP) NTTLazyLvl(levelQ, levelP int, p, pOut PolyQP)

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

func (r *RingQP) NTTLvl(levelQ, levelP int, p, pOut PolyQP)

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

func (r *RingQP) NewPoly() PolyQP

NewPoly creates a new polynomial with all coefficients set to 0.

func (*RingQP) NewPolyLvl

func (r *RingQP) NewPolyLvl(levelQ, levelP int) PolyQP

NewPolyLvl creates a new polynomial with all coefficients set to 0.

func (*RingQP) PermuteNTTWithIndexAndAddNoModLvl

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

func (r *RingQP) PermuteNTTWithIndexLvl(levelQ, levelP int, p1 PolyQP, index []uint64, p2 PolyQP)

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.

func (*RingQP) SubLvl

func (r *RingQP) SubLvl(levelQ, levelP int, p1, p2, pOut PolyQP)

SubLvl subtracts p2 to p1 coefficient-wise and writes the result on p3. 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) CopyNew

func (sk *SecretKey) CopyNew() *SecretKey

CopyNew creates a deep copy of the receiver secret key and returns it.

func (*SecretKey) GetDataLen

func (sk *SecretKey) GetDataLen(WithMetadata bool) (dataLen int)

GetDataLen returns the length in bytes of the target SecretKey.

func (*SecretKey) MarshalBinary

func (sk *SecretKey) MarshalBinary() (data []byte, err error)

MarshalBinary encodes a secret key in a byte slice.

func (*SecretKey) UnmarshalBinary

func (sk *SecretKey) UnmarshalBinary(data []byte) (err error)

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

type UniformSamplerQP struct {
	// contains filtered or unexported fields
}

UniformSamplerQP is a type for sampling polynomials in RingQP.

func NewUniformSamplerQP

func NewUniformSamplerQP(params Parameters, prng utils.PRNG) (s UniformSamplerQP)

NewUniformSamplerQP instantiates a new UniformSamplerQP from a given PRNG.

func (UniformSamplerQP) Read

func (s UniformSamplerQP) Read(p *PolyQP)

Read samples a new polynomial in RingQP and stores it into p.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL