Documentation ¶
Overview ¶
Package ring implelents a RNS-accelerated modular arithmetic operations for polynomials, including: RNS basis extension; RNS rescaling; number theoretic transform (NTT); uniform, Gaussian and ternary sampling.
Index ¶
- Variables
- func BRed(x, y, q uint64, u []uint64) (r uint64)
- func BRedAdd(x, q uint64, u []uint64) (r uint64)
- func BRedAddConstant(x, q uint64, u []uint64) uint64
- func BRedConstant(x, y, q uint64, u []uint64) (r uint64)
- func BRedParams(q uint64) (params []uint64)
- func Butterfly(U, V, Psi, Q, Qinv uint64) (X, Y uint64)
- func CRed(a, q uint64) uint64
- func DecodeCoeffs(pointer, N, numberModuli uint64, coeffs [][]uint64, data []byte) (uint64, error)
- func DecodeCoeffsNew(pointer, N, numberModuli uint64, coeffs [][]uint64, data []byte) (uint64, error)
- func DivRound(a, b, i *big.Int)
- func Float128ToUint53(f Float128) uint64
- func Float128ToUint64(f Float128) uint64
- func GenGaloisParams(n, gen uint64) (galElRotCol []uint64)
- func GenerateNTTPrimes(logQ, logN, levels uint64) (primes []uint64)
- func InvButterfly(U, V, Psi, Q, Qinv uint64) (X, Y uint64)
- func InvMForm(a, q, qInv uint64) (r uint64)
- func InvMFormConstant(a, q, qInv uint64) (r uint64)
- func InvNTT(coeffsIn, coeffsOut []uint64, N uint64, nttPsiInv []uint64, ...)
- func IsPrime(num uint64) bool
- func MForm(a, q uint64, u []uint64) (r uint64)
- func MFormConstant(a, q uint64, u []uint64) (r uint64)
- func MRed(x, y, q, qInv uint64) (r uint64)
- func MRedConstant(x, y, q, qInv uint64) (r uint64)
- func MRedParams(q uint64) (qInv uint64)
- func ModExp(x, e, p uint64) (result uint64)
- func NTT(coeffsIn, coeffsOut []uint64, N uint64, nttPsi []uint64, Q, mredParams uint64, ...)
- func NewInt(v int64) *big.Int
- func NewIntFromString(s string) *big.Int
- func NewUint(v uint64) *big.Int
- func PermuteNTT(polIn *Poly, gen uint64, polOut *Poly)
- func PermuteNTTIndex(gen, power, N uint64) (index []uint64)
- func PermuteNTTWithIndex(polIn *Poly, index []uint64, polOut *Poly)
- func PowerOf2(x, n, q, qInv uint64) (r uint64)
- func RandInt(max *big.Int) (n *big.Int)
- func RandUniform(v uint64, mask uint64) (randomInt uint64)
- func WriteCoeffsTo(pointer, N, numberModuli uint64, coeffs [][]uint64, data []byte) (uint64, error)
- type CRPGenerator
- func (crpgenerator *CRPGenerator) Clock(crp *Poly)
- func (crpgenerator *CRPGenerator) ClockNew() (crp *Poly)
- func (crpgenerator *CRPGenerator) GetClock() uint64
- func (crpgenerator *CRPGenerator) GetSeed() []byte
- func (crpgenerator *CRPGenerator) Seed(seed []byte)
- func (crpgenerator *CRPGenerator) SetClock(n uint64)
- type Context
- func (context *Context) AND(p1 *Poly, m uint64, p2 *Poly)
- func (context *Context) Add(p1, p2, p3 *Poly)
- func (context *Context) AddLvl(level uint64, p1, p2, p3 *Poly)
- func (context *Context) AddNoMod(p1, p2, p3 *Poly)
- func (context *Context) AddNoModLvl(level uint64, p1, p2, p3 *Poly)
- func (context *Context) AddScalar(p1 *Poly, scalar uint64, p2 *Poly)
- func (context *Context) AddScalarBigint(p1 *Poly, scalar *big.Int, p2 *Poly)
- func (context *Context) AllowsNTT() bool
- func (context *Context) BitReverse(p1, p2 *Poly)
- func (context *Context) Copy(p0, p1 *Poly)
- func (context *Context) CopyLvl(level uint64, p0, p1 *Poly)
- func (context *Context) DivFloorByLastModulus(p0 *Poly)
- func (context *Context) DivFloorByLastModulusMany(p0 *Poly, nbRescales uint64)
- func (context *Context) DivFloorByLastModulusManyNTT(p0 *Poly, nbRescales uint64)
- func (context *Context) DivFloorByLastModulusNTT(p0 *Poly)
- func (context *Context) DivRoundByLastModulus(p0 *Poly)
- func (context *Context) DivRoundByLastModulusMany(p0 *Poly, nbRescales uint64)
- func (context *Context) DivRoundByLastModulusManyNTT(p0 *Poly, nbRescales uint64)
- func (context *Context) DivRoundByLastModulusNTT(p0 *Poly)
- func (context *Context) Equal(p1, p2 *Poly) bool
- func (context *Context) EqualLvl(level uint64, p1, p2 *Poly) bool
- func (context *Context) Exp(p1 *Poly, e uint64, p2 *Poly)
- func (context *Context) GenNTTParams() error
- func (context *Context) GetBredParams() [][]uint64
- func (context *Context) GetMredParams() []uint64
- func (context *Context) GetNttNInv() []uint64
- func (context *Context) GetNttPsi() [][]uint64
- func (context *Context) GetNttPsiInv() [][]uint64
- func (context *Context) GetPsi() []uint64
- func (context *Context) GetPsiInv() []uint64
- func (context *Context) InvMForm(p1, p2 *Poly)
- func (context *Context) InvNTT(p1, p2 *Poly)
- func (context *Context) InvNTTLvl(level uint64, p1, p2 *Poly)
- func (context *Context) MForm(p1, p2 *Poly)
- func (context *Context) MFormLvl(level uint64, p1, p2 *Poly)
- func (context *Context) MarshalBinary() ([]byte, error)
- func (context *Context) Mod(p1 *Poly, m uint64, p2 *Poly)
- func (context *Context) MulByPow2(p1 *Poly, pow2 uint64, p2 *Poly)
- func (context *Context) MulByPow2Lvl(level uint64, p1 *Poly, pow2 uint64, p2 *Poly)
- func (context *Context) MulByPow2New(p1 *Poly, pow2 uint64) (p2 *Poly)
- func (context *Context) MulByVectorMontgomery(p1 *Poly, vector []uint64, p2 *Poly)
- func (context *Context) MulByVectorMontgomeryAndAddNoMod(p1 *Poly, vector []uint64, p2 *Poly)
- func (context *Context) MulCoeffs(p1, p2, p3 *Poly)
- func (context *Context) MulCoeffsAndAdd(p1, p2, p3 *Poly)
- func (context *Context) MulCoeffsAndAddNoMod(p1, p2, p3 *Poly)
- func (context *Context) MulCoeffsConstant(p1, p2, p3 *Poly)
- func (context *Context) MulCoeffsMontgomery(p1, p2, p3 *Poly)
- func (context *Context) MulCoeffsMontgomeryAndAdd(p1, p2, p3 *Poly)
- func (context *Context) MulCoeffsMontgomeryAndAddLvl(level uint64, p1, p2, p3 *Poly)
- func (context *Context) MulCoeffsMontgomeryAndAddNoMod(p1, p2, p3 *Poly)
- func (context *Context) MulCoeffsMontgomeryAndAddNoModLvl(level uint64, p1, p2, p3 *Poly)
- func (context *Context) MulCoeffsMontgomeryAndSub(p1, p2, p3 *Poly)
- func (context *Context) MulCoeffsMontgomeryAndSubNoMod(p1, p2, p3 *Poly)
- func (context *Context) MulCoeffsMontgomeryConstant(p1, p2, p3 *Poly)
- func (context *Context) MulCoeffsMontgomeryLvl(level uint64, p1, p2, p3 *Poly)
- func (context *Context) MulPoly(p1, p2, p3 *Poly)
- func (context *Context) MulPolyMontgomery(p1, p2, p3 *Poly)
- func (context *Context) MulPolyNaive(p1, p2, p3 *Poly)
- func (context *Context) MulPolyNaiveMontgomery(p1, p2, p3 *Poly)
- func (context *Context) MulScalar(p1 *Poly, scalar uint64, p2 *Poly)
- func (context *Context) MulScalarBigint(p1 *Poly, scalar *big.Int, p2 *Poly)
- func (context *Context) MulScalarBigintLvl(level uint64, p1 *Poly, scalar *big.Int, p2 *Poly)
- func (context *Context) MulScalarLvl(level uint64, p1 *Poly, scalar uint64, p2 *Poly)
- func (context *Context) MultByMonomial(p1 *Poly, monomialDeg uint64, p2 *Poly)
- func (context *Context) MultByMonomialNew(p1 *Poly, monomialDeg uint64) (p2 *Poly)
- func (context *Context) NTT(p1, p2 *Poly)
- func (context *Context) NTTLvl(level uint64, p1, p2 *Poly)
- func (context *Context) Neg(p1, p2 *Poly)
- func (context *Context) NegLvl(level uint64, p1, p2 *Poly)
- func (context *Context) NewKYSampler(sigma float64, bound int) *KYSampler
- func (context *Context) NewPoly() *Poly
- func (context *Context) NewPolyLvl(level uint64) *Poly
- func (context *Context) NewUniformPoly() (Pol *Poly)
- func (context *Context) NewUniformPolyLvl(level uint64) (Pol *Poly)
- func (context *Context) OR(p1 *Poly, m uint64, p2 *Poly)
- func (context *Context) Permute(polIn *Poly, gen uint64, polOut *Poly)
- func (context *Context) PolyToBigint(p1 *Poly, coeffsBigint []*big.Int)
- func (context *Context) PolyToString(p1 *Poly) []string
- func (context *Context) Reduce(p1, p2 *Poly)
- func (context *Context) ReduceLvl(level uint64, p1, p2 *Poly)
- func (context *Context) Rotate(p1 *Poly, n uint64, p2 *Poly)
- func (context *Context) SampleGaussian(pol *Poly, sigma float64, bound uint64)
- func (context *Context) SampleGaussianNTT(pol *Poly, sigma float64, bound uint64)
- func (context *Context) SampleGaussianNTTNew(sigma float64, bound uint64) (pol *Poly)
- func (context *Context) SampleGaussianNew(sigma float64, bound uint64) (pol *Poly)
- func (context *Context) SampleSparseMontgomeryNew(hw uint64) (pol *Poly)
- func (context *Context) SampleTernary(pol *Poly, p float64)
- func (context *Context) SampleTernaryMontgomery(pol *Poly, p float64)
- func (context *Context) SampleTernaryMontgomeryNTT(pol *Poly, p float64)
- func (context *Context) SampleTernaryMontgomeryNTTNew(p float64) (pol *Poly)
- func (context *Context) SampleTernaryMontgomeryNew(p float64) (pol *Poly)
- func (context *Context) SampleTernaryNTT(pol *Poly, p float64)
- func (context *Context) SampleTernaryNTTNew(p float64) (pol *Poly)
- func (context *Context) SampleTernaryNew(p float64) (pol *Poly)
- func (context *Context) SampleTernarySparse(pol *Poly, hw uint64)
- func (context *Context) SampleTernarySparseMontgomery(pol *Poly, hw uint64)
- func (context *Context) SampleTernarySparseMontgomeryNTT(pol *Poly, hw uint64)
- func (context *Context) SampleTernarySparseMontgomeryNTTNew(hw uint64) (pol *Poly)
- func (context *Context) SampleTernarySparseNTT(pol *Poly, hw uint64)
- func (context *Context) SampleTernarySparseNTTNew(hw uint64) (pol *Poly)
- func (context *Context) SampleTernarySparseNew(hw uint64) (pol *Poly)
- func (context *Context) SampleTernaryUniform(pol *Poly)
- func (context *Context) SetCoefficientsBigint(coeffs []*big.Int, p1 *Poly)
- func (context *Context) SetCoefficientsBigintLvl(level uint64, coeffs []*big.Int, p1 *Poly)
- func (context *Context) SetCoefficientsInt64(coeffs []int64, p1 *Poly)
- func (context *Context) SetCoefficientsString(coeffs []string, p1 *Poly)
- func (context *Context) SetCoefficientsUint64(coeffs []uint64, p1 *Poly)
- func (context *Context) SetParameters(N uint64, Modulus []uint64)
- func (context *Context) Shift(p1 *Poly, n uint64, p2 *Poly)
- func (context *Context) Sub(p1, p2, p3 *Poly)
- func (context *Context) SubLvl(level uint64, p1, p2, p3 *Poly)
- func (context *Context) SubNoMod(p1, p2, p3 *Poly)
- func (context *Context) SubNoModLvl(level uint64, p1, p2, p3 *Poly)
- func (context *Context) SubScalar(p1 *Poly, scalar uint64, p2 *Poly)
- func (context *Context) SubScalarBigint(p1 *Poly, scalar *big.Int, p2 *Poly)
- func (context *Context) UniformPoly(Pol *Poly)
- func (context *Context) UnmarshalBinary(data []byte) error
- func (context *Context) XOR(p1 *Poly, m uint64, p2 *Poly)
- type Decomposer
- type FastBasisExtender
- func (basisextender *FastBasisExtender) ModDownNTTPQ(level uint64, p1, p2 *Poly)
- func (basisextender *FastBasisExtender) ModDownPQ(level uint64, p1, p2 *Poly)
- func (basisextender *FastBasisExtender) ModDownSplitedNTTPQ(level uint64, p1Q, p1P, p2 *Poly)
- func (basisextender *FastBasisExtender) ModDownSplitedPQ(level uint64, p1Q, p1P, p2 *Poly)
- func (basisextender *FastBasisExtender) ModDownSplitedQP(level uint64, p1Q, p1P, p2 *Poly)
- func (basisextender *FastBasisExtender) ModUpSplitPQ(level uint64, p1, p2 *Poly)
- func (basisextender *FastBasisExtender) ModUpSplitQP(level uint64, p1, p2 *Poly)
- type Float128
- func Float128Add(a, b Float128) (f Float128)
- func Float128Div(a, b Float128) (f Float128)
- func Float128Mul(a, b Float128) (f Float128)
- func Float128SetInt64(i int64) (result Float128)
- func Float128SetUint53(i uint64) (result Float128)
- func Float128SetUint64(i uint64) (result Float128)
- func Float128SetZero() (result Float128)
- func Float128Sub(a, b Float128) (f Float128)
- type KYSampler
- type Parameters
- type Poly
- func (pol *Poly) Copy(p1 *Poly)
- func (pol *Poly) CopyNew() (p1 *Poly)
- func (pol *Poly) DecodePolyNew(data []byte) (pointer uint64, err error)
- func (pol *Poly) GetCoefficients() [][]uint64
- func (pol *Poly) GetDataLen(WithMetadata bool) uint64
- func (pol *Poly) GetDegree() int
- func (pol *Poly) GetLenModuli() int
- func (pol *Poly) MarshalBinary() ([]byte, error)
- func (pol *Poly) SetCoefficients(coeffs [][]uint64)
- func (pol *Poly) UnmarshalBinary(data []byte) (err error)
- func (pol *Poly) WriteCoeffs(data []byte) (uint64, error)
- func (pol *Poly) WriteTo(data []byte) (uint64, error)
- func (pol *Poly) Zero()
- type SimpleScaler
Constants ¶
This section is empty.
Variables ¶
var DefaultParamsPi = map[uint64]*Parameters{ 12: {1 << 12, Pi60[len(Pi60)-2:]}, 13: {1 << 13, Pi60[len(Pi60)-4:]}, 14: {1 << 14, Pi60[len(Pi60)-8:]}, 15: {1 << 15, Pi60[len(Pi60)-16:]}, 16: {1 << 16, Pi60[len(Pi60)-32:]}, }
DefaultParamsPi is a struct storing default test parameters for the package Ring.
var DefaultParamsQi = map[uint64]*Parameters{ 12: {1 << 12, Qi60[len(Qi60)-2:]}, 13: {1 << 13, Qi60[len(Qi60)-4:]}, 14: {1 << 14, Qi60[len(Qi60)-8:]}, 15: {1 << 15, Qi60[len(Qi60)-16:]}, 16: {1 << 16, Qi60[len(Qi60)-32:]}, }
DefaultParamsQi is a struct storing default test parameters for the package Ring.
var Pi60 = []uint64{576460752308273153, 576460752315482113, 576460752319021057, 576460752319414273, 576460752321642497,
576460752325705729, 576460752328327169, 576460752329113601, 576460752329506817, 576460752329900033,
576460752331210753, 576460752337502209, 576460752340123649, 576460752342876161, 576460752347201537,
576460752347332609, 576460752352837633, 576460752354017281, 576460752355065857, 576460752355459073,
576460752358604801, 576460752364240897, 576460752368435201, 576460752371187713, 576460752373547009,
576460752374333441, 576460752376692737, 576460752378003457, 576460752378396673, 576460752380755969,
576460752381411329, 576460752386129921, 576460752395173889, 576460752395960321, 576460752396091393,
576460752396484609, 576460752399106049, 576460752405135361, 576460752405921793, 576460752409722881,
576460752410116097, 576460752411033601, 576460752412082177, 576460752416145409, 576460752416931841,
576460752421257217, 576460752427548673, 576460752429514753, 576460752435281921, 576460752437248001,
576460752438558721, 576460752441966593, 576460752449044481, 576460752451141633, 576460752451534849,
576460752462938113, 576460752465952769, 576460752468705281, 576460752469491713, 576460752472375297,
576460752473948161, 576460752475389953, 576460752480894977, 576460752483254273, 576460752484827137,
576460752486793217, 576460752486924289, 576460752492691457, 576460752498589697, 576460752498720769,
576460752499507201, 576460752504225793, 576460752505405441, 576460752507240449, 576460752507764737,
576460752509206529, 576460752510124033, 576460752510779393, 576460752511959041, 576460752514449409,
576460752516284417, 576460752519168001, 576460752520347649, 576460752520609793, 576460752522969089,
576460752523100161, 576460752524279809, 576460752525852673, 576460752526245889, 576460752526508033,
576460752532013057, 576460752545120257, 576460752550100993, 576460752551804929, 576460752567402497,
576460752568975361, 576460752573431809, 576460752580902913, 576460752585490433, 576460752586407937}
Pi60 are the first hundred (from 0x800000000000000 and upward) 60bit Primes allowing ǸTT for N = 65536
var Qi60 = []uint64{1152921504606584833, 1152921504598720513, 1152921504592429057, 1152921504581419009, 1152921504580894721,
1152921504578273281, 1152921504577748993, 1152921504577486849, 1152921504568836097, 1152921504565166081,
1152921504563331073, 1152921504556515329, 1152921504555466753, 1152921504554156033, 1152921504552583169,
1152921504542883841, 1152921504538951681, 1152921504537378817, 1152921504531873793, 1152921504521650177,
1152921504509853697, 1152921504508280833, 1152921504506970113, 1152921504495697921, 1152921504491241473,
1152921504488620033, 1152921504479444993, 1152921504470794241, 1152921504468172801, 1152921504462929921,
1152921504462667777, 1152921504455589889, 1152921504447987713, 1152921504442482689, 1152921504436191233,
1152921504427278337, 1152921504419414017, 1152921504409190401, 1152921504403947521, 1152921504396869633,
1152921504395821057, 1152921504373014529, 1152921504369344513, 1152921504368558081, 1152921504364625921,
1152921504362790913, 1152921504361218049, 1152921504353615873, 1152921504337887233, 1152921504337625089,
1152921504321372161, 1152921504314032129, 1152921504303022081, 1152921504301449217, 1152921504288342017,
1152921504287293441, 1152921504286769153, 1152921504282836993, 1152921504274972673, 1152921504266321921,
1152921504256622593, 1152921504253739009, 1152921504245088257, 1152921504241942529, 1152921504240107521,
1152921504239583233, 1152921504238010369, 1152921504234078209, 1152921504231718913, 1152921504230670337,
1152921504227524609, 1152921504214417409, 1152921504207339521, 1152921504205504513, 1152921504204193793,
1152921504190824449, 1152921504179552257, 1152921504177192961, 1152921504176668673, 1152921504174309377,
1152921504172474369, 1152921504164872193, 1152921504162512897, 1152921504139706369, 1152921504134987777,
1152921504132628481, 1152921504122142721, 1152921504120832001, 1152921504116899841, 1152921504105627649,
1152921504101957633, 1152921504100384769, 1152921504096452609, 1152921504093306881, 1152921504078364673,
1152921504067092481, 1152921504066306049, 1152921504057917441, 1152921504053723137, 1152921504050839553}
Qi60 are the last hundred (from 0xfffffffffffffff and downward) 60bit Primes allowing ǸTT for N = 65536
Functions ¶
func BRed ¶
BRed compute x*y mod q for arbitrary x,y uint64. To be used when both x,y can not be pre-computed. However applying a Montgomery transform on either a or b might be faster depending on the computation to do, especially if either x or y needs to be multiplied with several other values.
func BRedAdd ¶
BRedAdd reduces a 64 bit integer by q. Assumes that x <= 64bits. Useful when several additions are performed before a modular reduction, as it is faster than applying a conditional reduction after each addition.
func BRedAddConstant ¶
BRedAddConstant is indentical to BReAdd, except it runs in constant time and returns a value in [0, 2q-1].
func BRedConstant ¶
BRedConstant is indentical to BRed, except it runs in constant time and returns a value in [0, 2q-1].
func BRedParams ¶
BRedParams computes the parameters required for the BRed with a radix of 2^128.
func DecodeCoeffs ¶
DecodeCoeffs converts a byte array to a matrix of coefficients.
func DecodeCoeffsNew ¶
func DecodeCoeffsNew(pointer, N, numberModuli uint64, coeffs [][]uint64, data []byte) (uint64, error)
DecodeCoeffsNew converts a byte array to a matrix of coefficients.
func Float128ToUint53 ¶
Float128ToUint53 returns the uint64 value from 128-bit floating point object rounded down. To be used if the result of the computation is under 53 bits.
func Float128ToUint64 ¶
Float128ToUint64 reconstructs an uint64 integer from a Float128 that was imported with the Float128SetUint64() function. Isolates the integer part from the floating point part, then adds the rounded floating point part to the integer part (this prevents occasional rounding errors when the second floating element is negative). The value needs to be scaled by 1/4096 to be reconstructed correctly.
func GenGaloisParams ¶
GenGaloisParams generates the generators for the galois endomorphisms.
func GenerateNTTPrimes ¶
GenerateNTTPrimes generates primes given logQ = size of the primes, logN = size of N and level, the number of levels required. Will return all the appropriate primes, up to the number of level, with the best avaliable deviation from the base power of 2 for the given level.
func InvButterfly ¶
InvButterfly computes X, Y = U + V, (U - V) * Psi mod Q.
func InvMForm ¶
InvMForm returns a*(1/2^64) mod q. It takes the input a in Montgomery form mod q with a radix of 2^64 and returns r which is the normal form of a mod q.
func InvMFormConstant ¶
InvMFormConstant is indentical to InvMForm, except that it runs in constant time and returns a value in [0, 2q-1].
func InvNTT ¶
func InvNTT(coeffsIn, coeffsOut []uint64, N uint64, nttPsiInv []uint64, nttNInv, Q, mredParams uint64)
InvNTT computes the InvNTT transformation on the input coefficients given the provided params.
func IsPrime ¶
IsPrime applies a Miller-Rabin test on the given uint64 variable, returning true if num is probably prime, else false.
func MForm ¶
MForm returns a*2^64 mod q. It takes the input a in conventional form and returns r which is the the Montgomery form of a of a mod q with a radix of 2^64.
func MFormConstant ¶
MFormConstant is identical to MForm, except that it runs in constant time and returns a value in [0, 2q-1] (it omits the conditional reduction).
func MRed ¶
MRed computes x * y * (1/2^64) mod q. Requires that at least one of the inputs is in Montgomery form. If only one of the inputs is in Montgomery form (ex : a pre-computed constant), the result will be in normal form. If both inputs are in Montgomery form, then the result will be in Montgomery form.
func MRedConstant ¶
MRedConstant is identical to MRed except it runs in constant time and returns a value in [0, 2q-1].
func MRedParams ¶
MRedParams computes the parameter qInv = (q^-1) mod 2^64, required for MRed.
func ModExp ¶
ModExp performes the modular exponentiation x^e mod p, x and p are required to be a most 64 bits to avoid an overflow.
func NTT ¶
func NTT(coeffsIn, coeffsOut []uint64, N uint64, nttPsi []uint64, Q, mredParams uint64, bredParams []uint64)
NTT computes the NTT transformation on the input coefficients given the provided params.
func NewIntFromString ¶
NewIntFromString creates a new Int from a string. A prefix of “0x” or “0X” selects base 16; the “0” prefix selects base 8, and a “0b” or “0B” prefix selects base 2. Otherwise the selected base is 10.
func PermuteNTT ¶
PermuteNTT applies the galois transform on a polynomial in the NTT domain. It maps the coefficients x^i to x^(gen*i) Careful, not inplace!
func PermuteNTTIndex ¶
PermuteNTTIndex computes the index table for PermuteNTT.
func PermuteNTTWithIndex ¶
PermuteNTTWithIndex applies the galois transform on a polynomial in the NTT domain. It maps the coefficients x^i to x^(gen*i) using the PermuteNTTIndex table. Careful, not inplace!
func RandUniform ¶
RandUniform samples a uniform randomInt variable in the range [0, mask] until randomInt is in the range [0, v-1]. mask needs to be of the form 2^n -1.
Types ¶
type CRPGenerator ¶
type CRPGenerator struct {
// contains filtered or unexported fields
}
CRPGenerator is the structure storing the parameters for deterministicaly securely generating random polynomials using the structure PRNG.
func NewCRPGenerator ¶
func NewCRPGenerator(key []byte, context *Context) *CRPGenerator
NewCRPGenerator creates a new CRPGenerator, that will deterministically and securely generate uniform polynomials in the input context using the hash function blake2b. The PRNG can be instantiated with a key on top of the public seed. If no key is used, set key=nil.
func (*CRPGenerator) Clock ¶
func (crpgenerator *CRPGenerator) Clock(crp *Poly)
Clock generates and returns a uniform polynomial. Also increases the clock cycle by 1.
func (*CRPGenerator) ClockNew ¶
func (crpgenerator *CRPGenerator) ClockNew() (crp *Poly)
ClockNew generates and returns a new uniform polynomial. Also increases the clock cycle by 1.
func (*CRPGenerator) GetClock ¶
func (crpgenerator *CRPGenerator) GetClock() uint64
GetClock returns the current clock of the CRPGenerator.
func (*CRPGenerator) GetSeed ¶
func (crpgenerator *CRPGenerator) GetSeed() []byte
GetSeed returns the seed of the CRPGenerator.
func (*CRPGenerator) Seed ¶
func (crpgenerator *CRPGenerator) Seed(seed []byte)
Seed resets the CRPGenerator and instantiates it with a new seed. Does not change the key.
func (*CRPGenerator) SetClock ¶
func (crpgenerator *CRPGenerator) SetClock(n uint64)
SetClock sets the clock of the CRPGenerator to the given input by clocking it until the clock cycle reaches the desired number. If the given input is smaller than the current clock, it will panic.
type Context ¶
type Context struct { // Polynomial nb.Coefficients N uint64 // Moduli Modulus []uint64 // Product of the Moduli ModulusBigint *big.Int // contains filtered or unexported fields }
Context is a structure keeping all the variables required to operate on a polynomial represented in this context.
func NewContextWithParams ¶
NewContextWithParams creates a new ringContex with the given parameters. Returns an error if the moduli are not NTT compliants.
func (*Context) AND ¶
AND applies a logical AND of m to the coefficients of p1, returning the result on p2.
func (*Context) Add ¶
Add adds p1 to p2 coefficient wise and applies a modular reduction, returning the result on p3.
func (*Context) AddLvl ¶
AddLvl adds p1 to p2 coefficient wise and applies a modular reduction, returning the result on p3.
func (*Context) AddNoMod ¶
AddNoMod adds p1 to p2 coefficient wise without modular reduction, returning the result on p3. The output range will be [0,2*Qi -1].
func (*Context) AddNoModLvl ¶
AddNoModLvl adds p1 to p2 coefficient wise without modular reduction, returning the result on p3. The output range will be [0,2*Qi -1].
func (*Context) AddScalar ¶
AddScalar adds to each coefficient of p1 a scalar and applies a modular reduction, returing the result on p2.
func (*Context) AddScalarBigint ¶
AddScalarBigint adds to each coefficient of p1 a big.Int scalar and applies a modular reduction, returing the result on p2.
func (*Context) BitReverse ¶
BitReverse applies a bit reverse permutation on the coefficients of the input polynomial and returns the result on the receiver polynomial. Can safely be used for inplace permutation.
func (*Context) Copy ¶
Copy copies the coefficients of p0 on p1 within the given context. Requires p1 to be as big as the target context.
func (*Context) CopyLvl ¶
CopyLvl copies the coefficients of p0 on p1 within the given context. Requiers p1 to be as big as the target context.
func (*Context) DivFloorByLastModulus ¶
DivFloorByLastModulus divides floor the polynomial by its last modulus.
func (*Context) DivFloorByLastModulusMany ¶
DivFloorByLastModulusMany divides floor sequentially nbRescales times the polynmial by its last modulus.
func (*Context) DivFloorByLastModulusManyNTT ¶
DivFloorByLastModulusManyNTT divides floor sequentially nbRescales times the polynmial by its last modulus. Input must be in the NTT domain.
func (*Context) DivFloorByLastModulusNTT ¶
DivFloorByLastModulusNTT divides floor the polynomial by its last modulus. Input must be in the NTT domain.
func (*Context) DivRoundByLastModulus ¶
DivRoundByLastModulus divides round the polynomial by its last modulus. Input must be in the NTT domain.
func (*Context) DivRoundByLastModulusMany ¶
DivRoundByLastModulusMany divides round sequentially nbRescales times the polynmial by its last modulus.
func (*Context) DivRoundByLastModulusManyNTT ¶
DivRoundByLastModulusManyNTT divides round sequentially nbRescales times the polynmial by its last modulus. Input must be in the NTT domain.
func (*Context) DivRoundByLastModulusNTT ¶
DivRoundByLastModulusNTT divides round the polynomial by its last modulus. Input must be in the NTT domain.
func (*Context) Exp ¶
Exp raises p1 to p1^e, returning the result on p2. TODO : implement Montgomery ladder
func (*Context) GenNTTParams ¶
GenNTTParams checks that N has been correctly initialized, and checks that each moduli is a prime congruent to 1 mod 2N (i.e. allowing NTT). Then it computes the variables required for the NTT. ValidateParameters purpose is to validate that the moduli allow the NTT and compute the NTT parameters.
func (*Context) GetBredParams ¶
GetBredParams returns the Barret reduction parameters of the context.
func (*Context) GetMredParams ¶
GetMredParams returns the Montgomery reduction parameters of the context.
func (*Context) GetNttNInv ¶
GetNttNInv returns 1/N mod each moduli.
func (*Context) GetNttPsiInv ¶
GetNttPsiInv returns the InvNTT parameters of the context.
func (*Context) GetPsi ¶
GetPsi returns the primitive root used to compute the NTT parameters of the context.
func (*Context) GetPsiInv ¶
GetPsiInv returns the primitive root used to compute the InvNTT parameters of the context.
func (*Context) InvMForm ¶
InvMForm setss p1 in Montgomeryform to its conventional form, returning the result on p2.
func (*Context) InvNTT ¶
InvNTT performs the inverse NTT transformation on the CRT coefficients of of a Polynomial, based on the target context.
func (*Context) InvNTTLvl ¶
InvNTTLvl performs the NTT transformation on the CRT coefficients of a Polynomial, based on the target context.
func (*Context) MForm ¶
MForm setss p1 in conventional form to its Montgomeryform, returning the result on p2.
func (*Context) MFormLvl ¶
MFormLvl setss p1 in conventional form to its Montgomeryform, returning the result on p2.
func (*Context) MarshalBinary ¶
MarshalBinary encodes the target ring context on a slice of bytes.
func (*Context) Mod ¶
Mod applies a modular reduction by m over the coefficients of p1, returning the result on p2.
func (*Context) MulByPow2 ¶
MulByPow2 multiplies the input polynomial by 2^pow2 and returns the result on the receiver polynomial.
func (*Context) MulByPow2Lvl ¶
MulByPow2Lvl multiplies the input polynomial by 2^pow2 and returns the result on the receiver polynomial.
func (*Context) MulByPow2New ¶
MulByPow2New multiplies the input polynomial by 2^pow2 and returns the result on a new polynomial.
func (*Context) MulByVectorMontgomery ¶
MulByVectorMontgomery multiplies p1 by a vector of uint64 coefficients and returns the result on p2.
func (*Context) MulByVectorMontgomeryAndAddNoMod ¶
MulByVectorMontgomeryAndAddNoMod multiplies p1 by a vector of uint64 coefficients and adds the result on p2 without modular reduction.
func (*Context) MulCoeffs ¶
MulCoeffs multiplies p1 by p2 coefficient wise with a Barrett modular reduction, returning the result on p3.
func (*Context) MulCoeffsAndAdd ¶
MulCoeffsAndAdd multiplies p1 by p2 coefficient wise with a Barret modular reduction, adding the result to p3 with modular reduction.
func (*Context) MulCoeffsAndAddNoMod ¶
MulCoeffsAndAddNoMod multiplies p1 by p2 coefficient wise with a Barrett modular reduction, adding the result to p3 without modular reduction.
func (*Context) MulCoeffsConstant ¶
MulCoeffsConstant multiplies p1 by p2 coefficient wise with a constant time Barrett modular reduction, returning the result on p3. The output range of the modular reduction is [0, 2*Qi -1].
func (*Context) MulCoeffsMontgomery ¶
MulCoeffsMontgomery multiplies p1 by p2 coefficient wise with a Montgomery modular reduction, returning the result on p3. Expects p1 and/or p2 to be in Montgomery form for correctness (see MRed).
func (*Context) MulCoeffsMontgomeryAndAdd ¶
MulCoeffsMontgomeryAndAdd multiplies p1 by p2 coefficient wise with a Montgomery modular reduction, adding the result to p3. Expects p1 and/or p2 to be in Montgomery form for correctness (see MRed).
func (*Context) MulCoeffsMontgomeryAndAddLvl ¶
MulCoeffsMontgomeryAndAddLvl multiplies p1 by p2 coefficient wise with a Montgomery modular reduction, adding the result to p3. Expects p1 and/or p2 to be in Montgomery form for correctness (see MRed).
func (*Context) MulCoeffsMontgomeryAndAddNoMod ¶
MulCoeffsMontgomeryAndAddNoMod multiplies p1 by p2 coefficient wise with a Montgomery modular reduction, adding the result to p3 without modular reduction. Expects p1 and/or p2 to be in Montgomery form for correctness (see MRed).
func (*Context) MulCoeffsMontgomeryAndAddNoModLvl ¶
MulCoeffsMontgomeryAndAddNoModLvl multiplies p1 by p2 coefficient wise with a Montgomery modular reduction, adding the result to p3 without modular reduction. Expects p1 and/or p2 to be in Montgomery form for correctness (see MRed).
func (*Context) MulCoeffsMontgomeryAndSub ¶
MulCoeffsMontgomeryAndSub multiplies p1 by p2 coefficient wise with a Montgomery modular reduction, subtractsing the result to p3 with modular reduction. Expects p1 and/or p2 to be in Montgomery form for correctness (see MRed).
func (*Context) MulCoeffsMontgomeryAndSubNoMod ¶
MulCoeffsMontgomeryAndSubNoMod multiplies p1 by p2 coefficient wise with a Montgomery modular reduction, subtractsing the result to p3 without modular reduction. Expects p1 and/or p2 to be in Montgomery form for correctness (see MRed).
func (*Context) MulCoeffsMontgomeryConstant ¶
MulCoeffsMontgomeryConstant multiplies p1 by p2 coefficient wise with a constant time Montgomery modular reduction, returning the result on p3. The output range of the modular reduction is [0, 2*Qi -1].
func (*Context) MulCoeffsMontgomeryLvl ¶
MulCoeffsMontgomeryLvl multiplies p1 by p2 coefficient wise with a Montgomery modular reduction, returning the result on p3. Expects p1 and/or p2 to be in Montgomery form for correctness (see MRed).
func (*Context) MulPolyMontgomery ¶
MulPolyMontgomery multiplies p1 by p2 and returns the result on p3. Expect wither p1 or p2 to be in Montgomery form for correctness.
func (*Context) MulPolyNaive ¶
MulPolyNaive multiplies p1 by p2 with a naive convolution, returning the result on p3.
func (*Context) MulPolyNaiveMontgomery ¶
MulPolyNaiveMontgomery multiplies p1 by p2 with a naive convolution, returning the result on p3. Much faster than MulPolyNaive.
func (*Context) MulScalar ¶
MulScalar multiplies each coefficient of p1 by a scalar and applies a modular reduction, returning the result on p2.
func (*Context) MulScalarBigint ¶
MulScalarBigint multiplies each coefficientsof p1 by a big.Int scalar and applies a modular reduction, returning the result on p2. To be used when the scalar is bigger than 64 bits.
func (*Context) MulScalarBigintLvl ¶
MulScalarBigintLvl multiplies each coefficientsof p1 by a big.Int scalar and applies a modular reduction, returning the result on p2. To be used when the scalar is bigger than 64 bits.
func (*Context) MulScalarLvl ¶
MulScalarLvl multiplies each coefficient of p1 by a scalar and applies a modular reduction, returning the result on p2.
func (*Context) MultByMonomial ¶
MultByMonomial multiplies the input polynomial by x^monomialDeg and returns the result on the receiver polynomial.
func (*Context) MultByMonomialNew ¶
MultByMonomialNew multiplies the input polynomial by x^monomialDeg and returns the result on a new polynomial.
func (*Context) NTT ¶
NTT performs the NTT transformation on the CRT coefficients of a Polynomial, based on the target context.
func (*Context) NTTLvl ¶
NTTLvl performs the NTT transformation on the CRT coefficients of a Polynomial, based on the target context.
func (*Context) Neg ¶
Neg sets all coefficients of p1 to there additive inverse, returning the result on p2.
func (*Context) NegLvl ¶
NegLvl sets all coefficients of p1 to there additive inverse, returning the result on p2.
func (*Context) NewKYSampler ¶
NewKYSampler creates a new KYSampler with sigma and bound that will be used to sample polynomial within the provided discret gaussian distribution.
func (*Context) NewPolyLvl ¶
NewPolyLvl create a new polynomial with all coefficients set to 0.
func (*Context) NewUniformPoly ¶
NewUniformPoly generates a new polynomial with coefficients following a uniform distribution over [0, Qi-1].
func (*Context) NewUniformPolyLvl ¶
NewUniformPolyLvl generates a new polynomial with coefficients following a uniform distribution over [0, Qi-1].
func (*Context) OR ¶
OR applies a logical OR of m to the coefficients of p1, returning the result on p2.
func (*Context) Permute ¶
Permute applies the galois transform on a polynonial outside of the NTT domain. It maps the coefficients x^i to x^(gen*i) Careful, not inplace!
func (*Context) PolyToBigint ¶
PolyToBigint reconstructs p1 and returns the result in an array of Int.
func (*Context) PolyToString ¶
PolyToString reconstructs p1 and returns the result in an array of string.
func (*Context) Reduce ¶
Reduce applies a modular reduction over the coefficients of p1 returning the result on p2.
func (*Context) ReduceLvl ¶
ReduceLvl applies a modular reduction over the coefficients of p1 returning the result on p2.
func (*Context) Rotate ¶
Rotate applies a Galoi Automorphism on p1 in NTT form, rotating the coefficients to the right by n, returning the result on p2. Requires the data to permuted in bitreversal order before applying NTT.
func (*Context) SampleGaussian ¶
SampleGaussian samples a truncated gaussian polynomial with variance sigma within the given bound using the Ziggurat algorithm.
func (*Context) SampleGaussianNTT ¶
SampleGaussianNTT samples a trucated gaussian polynomial in the NTT domain with variance sigma within the given bound using the Ziggurat algorithm.
func (*Context) SampleGaussianNTTNew ¶
SampleGaussianNTTNew samples a new trucated gaussian polynomial in the NTT domain with variance sigma within the given bound using the Ziggurat algorithm
func (*Context) SampleGaussianNew ¶
SampleGaussianNew samples a new truncated gaussian polynomial with variance sigma within the given bound using the Ziggurat algorithm.
func (*Context) SampleSparseMontgomeryNew ¶
SampleSparseMontgomeryNew samples a new polynomial with distribution [-1, 1] = [1/2, 1/2] with exactly hw non zero coefficients in Montgomery form.
func (*Context) SampleTernary ¶
SampleTernary samples a ternary polynomial with distribution [(1-p)/2, p, (1-p)/2].
func (*Context) SampleTernaryMontgomery ¶
SampleTernaryMontgomery samples a ternary polynomial with distribution [(1-p)/2, p, (1-p)/2] in Montgomery form.
func (*Context) SampleTernaryMontgomeryNTT ¶
SampleTernaryMontgomeryNTT samples a ternary polynomial with distribution [(1-p)/2, p, (1-p)/2] in NTT and Montgomery form.
func (*Context) SampleTernaryMontgomeryNTTNew ¶
SampleTernaryMontgomeryNTTNew samples a new ternary polynomial with distribution [(1-p)/2, p, (1-p)/2] in NTT and Montgomery form.
func (*Context) SampleTernaryMontgomeryNew ¶
SampleTernaryMontgomeryNew samples a nes ternary polynomial with distribution [(1-p)/2, p, (1-p)/2] in Montgomery form.
func (*Context) SampleTernaryNTT ¶
SampleTernaryNTT samples a ternary polynomial with distribution [(1-p)/2, p, (1-p)/2] in NTT form.
func (*Context) SampleTernaryNTTNew ¶
SampleTernaryNTTNew samples a new ternary polynomial with distribution [(1-p)/2, p, (1-p)/2] in NTT form.
func (*Context) SampleTernaryNew ¶
SampleTernaryNew samples a new ternary polynomial with distribution [(1-p)/2, p, (1-p)/2].
func (*Context) SampleTernarySparse ¶
SampleTernarySparse samples a polynomial with distribution [-1, 1] = [1/2, 1/2] with exactly hw non zero coefficients.
func (*Context) SampleTernarySparseMontgomery ¶
SampleTernarySparseMontgomery samples a polynomial with distribution [-1, 1] = [1/2, 1/2] with exactly hw non zero coefficients in Montgomery form.
func (*Context) SampleTernarySparseMontgomeryNTT ¶
SampleTernarySparseMontgomeryNTT samples a polynomial with distribution [-1, 1] = [1/2, 1/2] with exactly hw non zero coefficients in NTT and Montgomery form.
func (*Context) SampleTernarySparseMontgomeryNTTNew ¶
SampleTernarySparseMontgomeryNTTNew samples a new polynomial with distribution [-1, 1] = [1/2, 1/2] with exactly hw non zero coefficients in NTT and Montgomery form.
func (*Context) SampleTernarySparseNTT ¶
SampleTernarySparseNTT samples a polynomial with distribution [-1, 1] = [1/2, 1/2] with exactly hw non zero coefficients in NTT form.
func (*Context) SampleTernarySparseNTTNew ¶
SampleTernarySparseNTTNew samples a new polynomial with distribution [-1, 1] = [1/2, 1/2] with exactly hw non zero coefficients in NTT form.
func (*Context) SampleTernarySparseNew ¶
SampleTernarySparseNew samples a new polynomial with distribution [-1, 1] = [1/2, 1/2] with exactly hw non zero coefficients.
func (*Context) SampleTernaryUniform ¶
SampleTernaryUniform samples a ternary polynomial with distribution [1/3, 1/3, 1/3].
func (*Context) SetCoefficientsBigint ¶
SetCoefficientsBigint sets the coefficients of p1 from an array of Int variables.
func (*Context) SetCoefficientsBigintLvl ¶
SetCoefficientsBigintLvl sets the coefficients of p1 from an array of Int variables.
func (*Context) SetCoefficientsInt64 ¶
SetCoefficientsInt64 sets the coefficients of p1 from an int64 array.
func (*Context) SetCoefficientsString ¶
SetCoefficientsString parses an array of string as Int variables, and sets the coefficients of p1 with this Int variables.
func (*Context) SetCoefficientsUint64 ¶
SetCoefficientsUint64 sets the coefficients of p1 from an uint64 array.
func (*Context) SetParameters ¶
SetParameters initializes the parameters of an empty context with N and the provided moduli. Only checks that N is a power of 2 and computes all the variables that aren't used for the NTT.
func (*Context) Shift ¶
Shift circulary shifts the coefficients of the polynomial p1 by n to the left and returns the result on the receiver polynomial.
func (*Context) Sub ¶
Sub subtracts p2 to p1 coefficient wise and applies a modular reduction, returning the result on p3.
func (*Context) SubLvl ¶
SubLvl subtracts p2 to p1 coefficient wise and applies a modular reduction, returning the result on p3.
func (*Context) SubNoMod ¶
SubNoMod subtracts p2 to p1 coefficient wise without modular reduction, returning the result on p3. The output range will be [0,2*Qi -1].
func (*Context) SubNoModLvl ¶
SubNoModLvl subtracts p2 to p1 coefficient wise without modular reduction, returning the result on p3. The output range will be [0,2*Qi -1].
func (*Context) SubScalar ¶
SubScalar subtractss to each coefficient of p1 a scalar and applies a modular reduction, returing the result on p2.
func (*Context) SubScalarBigint ¶
SubScalarBigint subtractss to each coefficient of p1 a big.Int scalar and applies a modular reduction, returing the result on p2.
func (*Context) UniformPoly ¶
UniformPoly generates a new polynomial with coefficients following a uniform distribution over [0, Qi-1]
func (*Context) UnmarshalBinary ¶
UnmarshalBinary decodes slice of bytes on the target ring context.
type Decomposer ¶
Decomposer is a structure storing the parameters of the arbitrary decomposer. This decomposer takes a p(x)_Q (in basis Q) and returns p(x) mod qi in basis QP. Where qi = prod(Q_i) for 0<=i<=L where L is the number of factors in P.
func NewDecomposer ¶
func NewDecomposer(Q, P []uint64) (decomposer *Decomposer)
NewDecomposer creates a new Decomposer.
func (*Decomposer) Decompose ¶
func (decomposer *Decomposer) Decompose(level, crtDecompLevel uint64, p0, p1 *Poly)
Decompose decomposes takes a polynomial p(x) in basis Q, reduces it modulo qi, and returns the result in basis QP.
func (*Decomposer) DecomposeAndSplit ¶
func (decomposer *Decomposer) DecomposeAndSplit(level, crtDecompLevel uint64, p0, p1Q, p1P *Poly)
DecomposeAndSplit decomposes takes a polynomial p(x) in basis Q, reduces it modulo qi, and returns the result in basis QP separately.
func (*Decomposer) Xalpha ¶
func (decomposer *Decomposer) Xalpha() (xalpha []uint64)
Xalpha returns a slice containing all the values of #Qi/#Pi.
type FastBasisExtender ¶
type FastBasisExtender struct {
// contains filtered or unexported fields
}
FastBasisExtender Algorithm from https://eprint.iacr.org/2018/117.pdf
func NewFastBasisExtender ¶
func NewFastBasisExtender(contextQ, contextP *Context) *FastBasisExtender
NewFastBasisExtender is a struct storing all the pre-computed parameters to apply modUp from a basis Q to P and modDown from a basis QP to Q.
func (*FastBasisExtender) ModDownNTTPQ ¶
func (basisextender *FastBasisExtender) ModDownNTTPQ(level uint64, p1, p2 *Poly)
ModDownNTTPQ reduces the basis of a polynomial. Given a polynomial with coefficients in basis {Q0,Q1....Qi,P0,P1...Pj} Reduces its basis from {Q0,Q1....Qi,P0,P1...Pj} to {Q0,Q1....Qi} and does a runded integer division of the result by P. Inputs must be in the NTT domain.
func (*FastBasisExtender) ModDownPQ ¶
func (basisextender *FastBasisExtender) ModDownPQ(level uint64, p1, p2 *Poly)
ModDownPQ reduces the basis of a polynomial. Given a polynomial with coefficients in basis {Q0,Q1....Qi,P0,P1...Pj} Reduces its basis from {Q0,Q1....Qi,P0,P1...Pj} to {Q0,Q1....Qi} and does a runded integer division of the result by P.
func (*FastBasisExtender) ModDownSplitedNTTPQ ¶
func (basisextender *FastBasisExtender) ModDownSplitedNTTPQ(level uint64, p1Q, p1P, p2 *Poly)
ModDownSplitedNTTPQ reduces the basis of a polynomial. Given a polynomial with coefficients in basis {Q0,Q1....Qi} and {P0,P1...Pj} Reduces its basis from {Q0,Q1....Qi} and {P0,P1...Pj} to {Q0,Q1....Qi} and does a runded integer division of the result by P. Inputs must be in the NTT domain.
func (*FastBasisExtender) ModDownSplitedPQ ¶
func (basisextender *FastBasisExtender) ModDownSplitedPQ(level uint64, p1Q, p1P, p2 *Poly)
ModDownSplitedPQ reduces the basis of a polynomial. Given a polynomial with coefficients in basis {Q0,Q1....Qi} and {P0,P1...Pj} Reduces its basis from {Q0,Q1....Qi} and {P0,P1...Pj} to {Q0,Q1....Qi} and does a runded integer division of the result by P.
func (*FastBasisExtender) ModDownSplitedQP ¶
func (basisextender *FastBasisExtender) ModDownSplitedQP(level uint64, p1Q, p1P, p2 *Poly)
ModDownSplitedQP reduces the basis of a polynomial. Given a polynomial with coefficients in basis {Q0,Q1....Qi} and {P0,P1...Pj} Reduces its basis from {Q0,Q1....Qi} and {P0,P1...Pj} to {P0,P1...Pj} and does a runded integer division of the result by Q.
func (*FastBasisExtender) ModUpSplitPQ ¶
func (basisextender *FastBasisExtender) ModUpSplitPQ(level uint64, p1, p2 *Poly)
ModUpSplitPQ extends the basis of a polynomial Given a polynomial with coefficients in basis {P0,P1....Pi} Extends its basis from {P0,P1....Pi} to {Q0,Q1...Qj}
func (*FastBasisExtender) ModUpSplitQP ¶
func (basisextender *FastBasisExtender) ModUpSplitQP(level uint64, p1, p2 *Poly)
ModUpSplitQP extends the basis of a polynomial Given a polynomial with coefficients in basis {Q0,Q1....Qi} Extends its basis from {Q0,Q1....Qi} to {Q0,Q1....Qi,P0,P1...Pj}
type Float128 ¶
type Float128 [2]float64 // float128 represented by two float64s
Float128 represents a double-double floating point number with 106 bits of mantissa, or about 32 decimal digits. The zero value for a Float128 represents the value 0.
func Float128SetInt64 ¶
Float128SetInt64 sets 128-bit floating point object from int64 Allows to import integers bigger than 53 bits and do computation with a result of up to 64 bits. However the variable will be scaled by a 1/4096 factor that has to be taken into account when doing computation. Unsafe to use for values below 2^64/4096 since it will set the first element to zero.
func Float128SetUint53 ¶
Float128SetUint53 sets 128-bit floating point object from an uint64. To be used only if the integer is 53 or less bits and if the computation will stay under 54 bits.
func Float128SetUint64 ¶
Float128SetUint64 sets 128-bit floating point object from uint64 Allows to import integers bigger than 53 bits and do computation with result of up to 64 bits. However the variable will be scaled by a 1/4096 factor that has to be taken into account when doing computation. Unsafe to use for values below 2^64/4096 since it will set the first element to zero.
func Float128SetZero ¶
func Float128SetZero() (result Float128)
Float128SetZero sets a 128-bit floating point object to 0.0
type KYSampler ¶
type KYSampler struct { Matrix [][]uint8 // contains filtered or unexported fields }
KYSampler is the structure holding the parameters for the gaussian sampling.
func (*KYSampler) Sample ¶
Sample samples on the target polynomial coefficients with gaussian distribution given the target kys parameters.
func (*KYSampler) SampleAndAdd ¶
SampleAndAdd samples a gaussian polynomial and adds it on the int polynomial.
func (*KYSampler) SampleAndAddLvl ¶
SampleAndAddLvl samples on the target polynomial coefficients with gaussian distribution given the target kys parameters.
func (*KYSampler) SampleNTT ¶
SampleNTT samples on the target polynomial coefficients with gaussian distribution given the target kys parameters,and applies the NTT.
func (*KYSampler) SampleNTTNew ¶
SampleNTTNew samples a polynomial with gaussian distribution given the target kys context and apply the NTT.
type Parameters ¶
Parameters is a struct storing test parameters for the package Ring.
type Poly ¶
type Poly struct {
Coeffs [][]uint64 //Coefficients in CRT representation
}
Poly is the structure containing the coefficients of a polynomial.
func NewPolyUniform ¶
NewPolyUniform ... [FIXME]
func (*Poly) CopyNew ¶
CopyNew creates a new polynomial p1 which is a copy of the target polynomial.
func (*Poly) DecodePolyNew ¶
DecodePolyNew decodes a slice of bytes in the target polynomial returns the number of bytes decoded.
func (*Poly) GetCoefficients ¶
GetCoefficients returns a double slice containing the coefficients of the polynomial.
func (*Poly) GetDataLen ¶
GetDataLen returns the lenght the poly will take when written to data. Can take into account meta data if necessary.
func (*Poly) GetLenModuli ¶
GetLenModuli returns the number of modulie.
func (*Poly) MarshalBinary ¶
MarshalBinary encodes the target polynomial on a slice of bytes.
func (*Poly) SetCoefficients ¶
SetCoefficients sets the coefficients of polynomial directly from a CRT format (double slice).
func (*Poly) UnmarshalBinary ¶
UnmarshalBinary decodes a slice of byte on the target polynomial.
func (*Poly) WriteCoeffs ¶
WriteCoeffs write the coefficient to the given data array. Fails if the data array is not big enough to contain the ring.Poly
type SimpleScaler ¶
type SimpleScaler struct {
// contains filtered or unexported fields
}
SimpleScaler is the structure storing the parameters to reconstruct a polynomial, scale it by t/Q and return the results modulo t. Algorithm from https://eprint.iacr.org/2018/117.pdf
func NewSimpleScaler ¶
func NewSimpleScaler(t uint64, context *Context) (newParams *SimpleScaler)
NewSimpleScaler creates a new SimpleScaler from t (the modulus under which the reconstruction is returned) and context (the context in which the polynomial to reconstruct will be represented).
func (*SimpleScaler) Scale ¶
func (parameters *SimpleScaler) Scale(p1, p2 *Poly)
Scale returns the reconstruction of p1 scaled by a factor t/Q and mod t on the reciever p2.