ringqp

package
v5.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: Apache-2.0 Imports: 9 Imported by: 9

Documentation

Overview

Package ringqp is implements a wrapper for both the ringQ and ringP.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Poly

type Poly struct {
	Q, P ring.Poly
}

Poly 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 NewPoly

func NewPoly(N, levelQ, levelP int) Poly

NewPoly creates a new polynomial at the given levels. If levelQ or levelP are negative, the corresponding polynomial will be nil.

func (Poly) BinarySize

func (p Poly) BinarySize() (dataLen int)

BinarySize returns the serialized size of the object in bytes. It assumes that each coefficient takes 8 bytes.

func (*Poly) Copy

func (p *Poly) Copy(other Poly)

Copy copies the coefficients of other on the target polynomial. This method simply calls the Copy method for each of its sub-polynomials.

func (*Poly) CopyLvl

func (p *Poly) CopyLvl(levelQ, levelP int, other Poly)

CopyLvl copies the values of other on the target polynomial. The operation is performed at levelQ for the ringQ and levelP for the ringP.

func (Poly) CopyNew

func (p Poly) CopyNew() *Poly

CopyNew creates an exact copy of the target polynomial.

func (Poly) Equal

func (p Poly) Equal(other *Poly) (v bool)

Equal returns true if the receiver Poly is equal to the provided other Poly.

func (Poly) LevelP

func (p Poly) LevelP() int

LevelP returns the level of the polynomial modulo P. Returns -1 if the modulus P is absent.

func (Poly) LevelQ

func (p Poly) LevelQ() int

LevelQ returns the level of the polynomial modulo Q. Returns -1 if the modulus Q is absent.

func (Poly) MarshalBinary

func (p Poly) MarshalBinary() (data []byte, err error)

MarshalBinary encodes the object into a binary form on a newly allocated slice of bytes.

func (*Poly) ReadFrom

func (p *Poly) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads on the object from an io.Writer. It implements the io.ReaderFrom interface.

Unless r implements the buffer.Reader interface (see see lattigo/utils/buffer/reader.go), it will be wrapped into a bufio.Reader. Since this requires allocation, it is preferable to pass a buffer.Reader directly:

  • When reading multiple values from a io.Reader, it is preferable to first first wrap io.Reader in a pre-allocated bufio.Reader.
  • When reading from a var b []byte, it is preferable to pass a buffer.NewBuffer(b) as w (see lattigo/utils/buffer/buffer.go).

func (*Poly) Resize

func (p *Poly) Resize(levelQ, levelP int)

Resize resizes the levels of the target polynomial to the provided levels. If the provided level is larger than the current level, then allocates zero coefficients, otherwise dereferences the coefficients above the provided level. Nil polynomials are unaffected.

func (*Poly) UnmarshalBinary

func (p *Poly) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary decodes a slice of bytes generated by MarshalBinary or WriteTo on the object.

func (Poly) WriteTo

func (p Poly) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes the object on an io.Writer. It implements the io.WriterTo interface, and will write exactly object.BinarySize() bytes on w.

Unless w implements the buffer.Writer interface (see lattigo/utils/buffer/writer.go), it will be wrapped into a bufio.Writer. Since this requires allocations, it is preferable to pass a buffer.Writer directly:

  • When writing multiple times to a io.Writer, it is preferable to first wrap the io.Writer in a pre-allocated bufio.Writer.
  • When writing to a pre-allocated var b []byte, it is preferable to pass buffer.NewBuffer(b) as w (see lattigo/utils/buffer/buffer.go).

type Ring

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

Ring 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 (Ring) Add

func (r Ring) Add(p1, p2, p3 Poly)

Add adds p1 to p2 coefficient-wise and writes the result on p3.

func (Ring) AddLazy

func (r Ring) AddLazy(p1, p2, p3 Poly)

AddLazy adds p1 to p2 coefficient-wise and writes the result on p3 without modular reduction.

func (Ring) AtLevel

func (r Ring) AtLevel(levelQ, levelP int) Ring

AtLevel returns a shallow copy of the target ring configured to carry on operations at the specified levels.

func (Ring) Automorphism

func (r Ring) Automorphism(p1 Poly, galEl uint64, p2 Poly)

Automorphism applies the automorphism X^{i} -> X^{i*gen} on p1 and writes the result on p2. Method is not in place.

func (Ring) AutomorphismNTT

func (r Ring) AutomorphismNTT(p1 Poly, galEl uint64, p2 Poly)

AutomorphismNTT applies the automorphism X^{i} -> X^{i*gen} on p1 and writes the result on p2. Method is not in place. Inputs are assumed to be in the NTT domain.

func (Ring) AutomorphismNTTWithIndex

func (r Ring) AutomorphismNTTWithIndex(p1 Poly, index []uint64, p2 Poly)

AutomorphismNTTWithIndex applies the automorphism X^{i} -> X^{i*gen} on p1 and writes the result on p2. Index of automorphism must be provided. Method is not in place.

func (Ring) AutomorphismNTTWithIndexThenAddLazy

func (r Ring) AutomorphismNTTWithIndexThenAddLazy(p1 Poly, index []uint64, p2 Poly)

AutomorphismNTTWithIndexThenAddLazy applies the automorphism X^{i} -> X^{i*gen} on p1 and adds the result on p2. Index of automorphism must be provided. Method is not in place.

func (Ring) Equal

func (r Ring) Equal(p1, p2 Poly) (v bool)

func (Ring) EvalPolyScalar

func (r Ring) EvalPolyScalar(pol []Poly, pt uint64, p3 Poly)

EvalPolyScalar evaluate the polynomial pol at pt and writes the result in p3

func (Ring) ExtendBasisSmallNormAndCenter

func (r Ring) 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 (Ring) IMForm

func (r Ring) IMForm(p1, p2 Poly)

IMForm switches back p1 from the Montgomery domain to the conventional domain and writes the result on p2.

func (Ring) INTT

func (r Ring) INTT(p1, p2 Poly)

INTT computes the inverse-NTT of p1 and returns the result on p2.

func (Ring) INTTLazy

func (r Ring) INTTLazy(p1, p2 Poly)

INTTLazy computes the inverse-NTT of p1 and returns the result on p2. Output values are in the range [0, 2q-1].

func (Ring) Inverse

func (r Ring) Inverse(scalar ring.RNSScalar)

Inverse computes the modular inverse of a scalar a expressed in a CRT decomposition. The inversion is done in-place and assumes that a is in Montgomery form.

func (Ring) LevelP

func (r Ring) LevelP() int

LevelP returns the level at which the target ring operates for the modulus P.

func (Ring) LevelQ

func (r Ring) LevelQ() int

LevelQ returns the level at which the target ring operates for the modulus Q.

func (Ring) Log2OfStandardDeviation

func (r Ring) Log2OfStandardDeviation(poly Poly) (std float64)

Log2OfStandardDeviation returns base 2 logarithm of the standard deviation of the coefficients of the polynomial.

func (Ring) MForm

func (r Ring) MForm(p1, p2 Poly)

MForm switches p1 to the Montgomery domain and writes the result on p2.

func (Ring) MulCoeffsMontgomery

func (r Ring) MulCoeffsMontgomery(p1, p2, p3 Poly)

MulCoeffsMontgomery multiplies p1 by p2 coefficient-wise with a Montgomery modular reduction.

func (Ring) MulCoeffsMontgomeryLazy

func (r Ring) MulCoeffsMontgomeryLazy(p1, p2, p3 Poly)

MulCoeffsMontgomeryLazy multiplies p1 by p2 coefficient-wise with a constant-time Montgomery modular reduction. Result is within [0, 2q-1].

func (Ring) MulCoeffsMontgomeryLazyThenAddLazy

func (r Ring) MulCoeffsMontgomeryLazyThenAddLazy(p1, p2, p3 Poly)

MulCoeffsMontgomeryLazyThenAddLazy 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 (Ring) MulCoeffsMontgomeryLazyThenSubLazy

func (r Ring) MulCoeffsMontgomeryLazyThenSubLazy(p1, p2, p3 Poly)

MulCoeffsMontgomeryLazyThenSubLazy multiplies p1 by p2 coefficient-wise with a Montgomery modular reduction and subtracts the result from p3.

func (Ring) MulCoeffsMontgomeryThenAdd

func (r Ring) MulCoeffsMontgomeryThenAdd(p1, p2, p3 Poly)

MulCoeffsMontgomeryThenAdd multiplies p1 by p2 coefficient-wise with a Montgomery modular reduction and adds the result to p3.

func (Ring) MulCoeffsMontgomeryThenSub

func (r Ring) MulCoeffsMontgomeryThenSub(p1, p2, p3 Poly)

MulCoeffsMontgomeryThenSub multiplies p1 by p2 coefficient-wise with a Montgomery modular reduction and subtracts the result from p3.

func (Ring) MulRNSScalar

func (r Ring) MulRNSScalar(s1, s2, sout ring.RNSScalar)

MulRNSScalar multiplies s1 and s2 and stores the result in sout.

func (Ring) MulRNSScalarMontgomery

func (r Ring) MulRNSScalarMontgomery(p Poly, scalar []uint64, pOut Poly)

MulRNSScalarMontgomery multiplies p with a scalar value expressed in the CRT decomposition. It assumes the scalar decomposition to be in Montgomery form.

func (Ring) MulScalar

func (r Ring) MulScalar(p1 Poly, scalar uint64, p2 Poly)

MulScalar multiplies p1 by scalar and returns the result in p2.

func (Ring) N

func (r Ring) N() int

func (Ring) NTT

func (r Ring) NTT(p1, p2 Poly)

NTT computes the NTT of p1 and returns the result on p2.

func (Ring) NTTLazy

func (r Ring) NTTLazy(p1, p2 Poly)

NTTLazy computes the NTT of p1 and returns the result on p2. Output values are in the range [0, 2q-1].

func (Ring) Neg

func (r Ring) Neg(p1, p2 Poly)

Neg negates p1 coefficient-wise and writes the result on p2.

func (Ring) NewPoly

func (r Ring) NewPoly() Poly

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

func (Ring) NewRNSScalar

func (r Ring) NewRNSScalar() ring.RNSScalar

NewRNSScalar creates a new Scalar value (i.e., a degree-0 polynomial) in the RingQP.

func (Ring) NewRNSScalarFromUInt64

func (r Ring) NewRNSScalarFromUInt64(v uint64) ring.RNSScalar

NewRNSScalarFromUInt64 creates a new Scalar in the RingQP initialized with value v.

func (Ring) PolyToBigintCentered

func (r Ring) PolyToBigintCentered(p1 Poly, gap int, coeffsBigint []*big.Int)

PolyToBigintCentered reconstructs p1 and returns the result in an array of Int. Coefficients are centered around Q/2 gap defines coefficients X^{i*gap} that will be reconstructed. For example, if gap = 1, then all coefficients are reconstructed, while if gap = 2 then only coefficients X^{2*i} are reconstructed.

func (Ring) Reduce

func (r Ring) Reduce(p1, p2 Poly)

Reduce applies the modular reduction on the coefficients of p1 and returns the result on p2.

func (Ring) Sub

func (r Ring) Sub(p1, p2, p3 Poly)

Sub subtracts p2 to p1 coefficient-wise and writes the result on p3.

func (Ring) SubRNSScalar

func (r Ring) SubRNSScalar(s1, s2, sout ring.RNSScalar)

SubRNSScalar subtracts s2 to s1 and stores the result in sout.

type UniformSampler

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

UniformSampler is a type for sampling polynomials in Ring.

func NewUniformSampler

func NewUniformSampler(prng sampling.PRNG, r Ring) (s UniformSampler)

NewUniformSampler instantiates a new UniformSampler from a given PRNG.

func (UniformSampler) AtLevel

func (s UniformSampler) AtLevel(levelQ, levelP int) UniformSampler

AtLevel returns a shallow copy of the target sampler that operates at the specified levels.

func (UniformSampler) Read

func (s UniformSampler) Read(p Poly)

Read samples a new polynomial with uniform distribution and stores it into p.

func (UniformSampler) ReadNew

func (s UniformSampler) ReadNew() (p Poly)

ReadNew samples a new polynomial with uniform distribution and returns it.

func (UniformSampler) WithPRNG

func (s UniformSampler) WithPRNG(prng sampling.PRNG) UniformSampler

Jump to

Keyboard shortcuts

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