Documentation
¶
Overview ¶
==== Initial package ==== This package implements 128-bit ("double double") floating point using a pair of 64-bit hardware floating point values and standard hardware floating point operations. It is based directly on libqd by Yozo Hida, Xiaoye S. Li, David H. Bailey, Yves Renard and E. Jason Riedy. Source: http://crd.lbl.gov/~dhbailey/mpdist/qd-2.3.13.tar.gz ==== Current package ==== It has been modified and adapted its required use in the BFV. Unused functions have been removed, and some functions simplified to save computation (full precision is not needed).
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 Float128ToUint53(f Float128) uint64
- func Float128ToUint64(f Float128) uint64
- func GaussSampling(sigma float64) int64
- func GenerateNTTPrimes(N, start, n, bitLen uint64, sign bool) ([]uint64, error)
- 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(coeffs_in, coeffs_out []uint64, N uint64, nttPsiInv []uint64, ...)
- func IsPrime(num uint64) bool
- func KYSampling(M [][]uint8, randomBytes []byte, pointer uint8) (uint64, uint64, []byte, uint8)
- 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(coeffs_in, coeffs_out []uint64, N uint64, nttPsi []uint64, ...)
- func PermuteNTT(polIn *Poly, gen uint64, polOut *Poly)
- func PowerOf2(x, n, q, qInv uint64) (r uint64)
- func RandUniform(v uint64) uint64
- func WriteCoeffsTo(pointer, N, numberModuli uint64, coeffs [][]uint64, data []byte) (uint64, error)
- type BasisExtender
- type ComplexScaler
- type Context
- func (context *Context) AND(p1 *Poly, m uint64, p2 *Poly)
- func (context *Context) Add(p1, p2, p3 *Poly)
- func (context *Context) AddNoMod(p1, p2, p3 *Poly)
- func (context *Context) AddScalar(p1 *Poly, scalar uint64, p2 *Poly)
- func (context *Context) BitReverse(p1, p2 *Poly)
- func (context *Context) Copy(p0, p1 *Poly) error
- func (context *Context) Equal(p1, p2 *Poly) bool
- func (context *Context) Exp(p1 *Poly, e uint64, p2 *Poly)
- func (context *Context) GetBredParams() [][]uint64
- func (context *Context) GetCenteredCoefficients(p1 *Poly) [][]int64
- 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) IsValidated() bool
- func (context *Context) MForm(p1, p2 *Poly)
- func (context *Context) MarshalBinary() ([]byte, error)
- func (context *Context) Merge(contextQ, contextP *Context) error
- func (context *Context) Mod(p1 *Poly, m uint64, p2 *Poly)
- func (context *Context) MulByPow2(p1 *Poly, pow2 uint64, p2 *Poly)
- func (context *Context) MulByPow2New(p1 *Poly, pow2 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) MulCoeffsConstantMontgomery(p1, p2, p3 *Poly)
- func (context *Context) MulCoeffsMontgomery(p1, p2, p3 *Poly)
- func (context *Context) MulCoeffsMontgomeryAndAdd(p1, p2, p3 *Poly)
- func (context *Context) MulCoeffsMontgomeryAndAddNoMod(p1, p2, p3 *Poly)
- func (context *Context) MulCoeffsMontgomeryAndSub(p1, p2, p3 *Poly)
- func (context *Context) MulCoeffsMontgomeryAndSubNoMod(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 *Int, 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) Neg(p1, p2 *Poly)
- func (context *Context) NewGaussPoly(sigma float64) *Poly
- func (context *Context) NewKYSampler(sigma float64, bound int) *KYSampler
- func (context *Context) NewPoly() *Poly
- func (context *Context) NewTernaryPoly() *Poly
- func (context *Context) NewTernaryPolyMontgomeryNTT() *Poly
- func (context *Context) NewTernaryPolyNTT() *Poly
- func (context *Context) NewTernarySampler() *TernarySampler
- func (context *Context) NewUniformPoly() (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) []*Int
- func (context *Context) PolyToString(p1 *Poly) []string
- func (context *Context) Reduce(p1, p2 *Poly)
- func (context *Context) Rotate(p1 *Poly, n uint64, p2 *Poly)
- func (context *Context) SetCoefficientsBigint(coeffs []*Int, p1 *Poly) error
- func (context *Context) SetCoefficientsInt64(coeffs []int64, p1 *Poly) error
- func (context *Context) SetCoefficientsString(coeffs []string, p1 *Poly) error
- func (context *Context) SetCoefficientsUint64(coeffs []uint64, p1 *Poly) error
- func (context *Context) SetParameters(N uint64, Modulus []uint64) error
- func (context *Context) Shift(p1 *Poly, n uint64, p2 *Poly)
- func (context *Context) Sub(p1, p2, p3 *Poly)
- func (context *Context) SubNoMod(p1, p2, p3 *Poly)
- func (context *Context) SubScalar(p1 *Poly, scalar uint64, p2 *Poly)
- func (context *Context) UnMarshalBinary(data []byte) error
- func (context *Context) ValidateParameters() error
- func (context *Context) XOR(p1 *Poly, m uint64, p2 *Poly)
- type Float128
- func Float128Add(a, b Float128) (f Float128)
- func Float128Div(a, b Float128) 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 Int
- func (i *Int) Add(a, b *Int) *Int
- func (i *Int) And(a, b *Int) *Int
- func (i *Int) Bits() ([]uint, uint)
- func (i *Int) Center(Q *Int) *Int
- func (i *Int) Compare(i2 *Int) int
- func (i *Int) Div(a, b *Int) *Int
- func (i *Int) DivRound(a, b *Int) *Int
- func (i *Int) EqualTo(i2 *Int) bool
- func (i *Int) Exp(a, b, m *Int) *Int
- func (i *Int) Float64() float64
- func (i *Int) Int64() int64
- func (i *Int) Inv(a, m *Int) *Int
- func (i *Int) IsPrime(n int) bool
- func (i *Int) Lsh(a *Int, m uint64) *Int
- func (i *Int) Mod(a, m *Int) *Int
- func (i *Int) Mul(a, b *Int) *Int
- func (i *Int) Neg(a, m *Int) *Int
- func (i *Int) Rsh(a *Int, m uint64) *Int
- func (i *Int) SetBigInt(v *Int)
- func (i *Int) SetInt(v int64)
- func (i *Int) SetString(s string)
- func (i *Int) SetUint(v uint64)
- func (i *Int) String() string
- func (i *Int) Sub(a, b *Int) *Int
- func (i *Int) Uint32() uint32
- func (i *Int) Uint64() uint64
- type KYSampler
- type Poly
- func (Pol *Poly) Copy(p1 *Poly) error
- func (Pol *Poly) CopyNew() (p1 *Poly)
- func (Pol *Poly) ExtendModulies()
- func (Pol *Poly) GetCoefficients() [][]uint64
- func (Pol *Poly) GetDegree() int
- func (Pol *Poly) GetLenModulies() int
- func (Pol *Poly) MarshalBinary() ([]byte, error)
- func (Pol *Poly) SetCoefficients(coeffs [][]uint64) error
- func (Pol *Poly) UnMarshalBinary(data []byte) (*Poly, error)
- func (Pol *Poly) Zero()
- type SimpleScaler
- type TernarySampler
- func (sampler *TernarySampler) Sample(pol *Poly)
- func (sampler *TernarySampler) SampleMontgomery(pol *Poly)
- func (sampler *TernarySampler) SampleMontgomeryNTT(pol *Poly)
- func (sampler *TernarySampler) SampleMontgomeryNTTNew() (pol *Poly)
- func (sampler *TernarySampler) SampleMontgomeryNew() (pol *Poly)
- func (sampler *TernarySampler) SampleNTT(pol *Poly)
- func (sampler *TernarySampler) SampleNTTNew() (pol *Poly)
- func (sampler *TernarySampler) SampleNew() (pol *Poly)
Constants ¶
This section is empty.
Variables ¶
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}
First hundred (from 0x800000000000000 and upward) 60bit Primes allowing 65536 ǸTT
var Q61u38N4096 = []uint64{0x20000000007c0001, 0x20000000007a6001, 0x200000000071c001, 0x2000000000718001, 0x20000000006b8001, 0x200000000069e001, 0x200000000069a001, 0x2000000000620001, 0x2000000000596001, 0x2000000000578001, 0x200000000052c001, 0x2000000000524001, 0x2000000000518001, 0x2000000000506001, 0x2000000000500001, 0x20000000004c4001, 0x20000000004be001, 0x2000000000460001, 0x2000000000454001, 0x2000000000436001, 0x20000000003aa001, 0x200000000038e001, 0x200000000036e001, 0x2000000000332001, 0x20000000002e4001, 0x20000000002de001, 0x2000000000262001, 0x2000000000208001, 0x20000000001f4001, 0x20000000001ae001, 0x200000000014e001, 0x200000000013c001, 0x2000000000112001, 0x2000000000104001, 0x20000000000e2001, 0x20000000000b0001, 0x200000000003a001, 0x200000000001a001, 0x1ffffffffffde001, 0x1ffffffffffce001, 0x1ffffffffffa4001, 0x1ffffffffff92001, 0x1ffffffffff7a001, 0x1ffffffffff74001, 0x1ffffffffff56001, 0x1ffffffffff0c001, 0x1ffffffffff02001, 0x1fffffffffec4001, 0x1fffffffffe96001, 0x1fffffffffe82001, 0x1fffffffffe5a001, 0x1fffffffffe10001, 0x1fffffffffe00001, 0x1fffffffffdd0001, 0x1fffffffffd08001, 0x1fffffffffcf8001, 0x1fffffffffc9e001, 0x1fffffffffc80001, 0x1fffffffffba6001, 0x1fffffffffb94001, 0x1fffffffffb76001, 0x1fffffffffb72001, 0x1fffffffffb54001, 0x1fffffffffb40001, 0x1ffffffffface001, 0x1fffffffffab0001, 0x1fffffffffa6e001, 0x1fffffffffa6a001, 0x1fffffffffa3e001, 0x1fffffffffa32001, 0x1fffffffffa2e001, 0x1fffffffffa10001, 0x1fffffffffa0a001, 0x1fffffffff9a2001, 0x1fffffffff998001, 0x1fffffffff978001, 0x1fffffffff932001, 0x1fffffffff8c6001, 0x1fffffffff8a8001, 0x1fffffffff89c001, 0x1fffffffff88e001, 0x1fffffffff842001}
var Q61u39N4096 = []uint64{0x20000000003aa001, 0x200000000038e001, 0x200000000036e001, 0x2000000000332001, 0x20000000002e4001, 0x20000000002de001, 0x2000000000262001, 0x2000000000208001, 0x20000000001f4001, 0x20000000001ae001, 0x200000000014e001, 0x200000000013c001, 0x2000000000112001, 0x2000000000104001, 0x20000000000e2001, 0x20000000000b0001, 0x200000000003a001, 0x200000000001a001, 0x1ffffffffffde001, 0x1ffffffffffce001, 0x1ffffffffffa4001, 0x1ffffffffff92001, 0x1ffffffffff7a001, 0x1ffffffffff74001, 0x1ffffffffff56001, 0x1ffffffffff0c001, 0x1ffffffffff02001, 0x1fffffffffec4001, 0x1fffffffffe96001, 0x1fffffffffe82001, 0x1fffffffffe5a001, 0x1fffffffffe10001, 0x1fffffffffe00001, 0x1fffffffffdd0001, 0x1fffffffffd08001, 0x1fffffffffcf8001, 0x1fffffffffc9e001, 0x1fffffffffc80001}
var Q61u40N4096 = []uint64{0x20000000001f4001, 0x20000000001ae001, 0x200000000014e001, 0x200000000013c001, 0x2000000000112001, 0x2000000000104001, 0x20000000000e2001, 0x20000000000b0001, 0x200000000003a001, 0x200000000001a001, 0x1ffffffffffde001, 0x1ffffffffffce001, 0x1ffffffffffa4001, 0x1ffffffffff92001, 0x1ffffffffff7a001, 0x1ffffffffff74001, 0x1ffffffffff56001, 0x1ffffffffff0c001, 0x1ffffffffff02001, 0x1fffffffffec4001, 0x1fffffffffe96001, 0x1fffffffffe82001, 0x1fffffffffe5a001, 0x1fffffffffe10001, 0x1fffffffffe00001}
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}
Last hundred (from 0xfffffffffffffff and downward) 60bit Primes allowing 65536 ǸTT
Functions ¶
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 Barret reduction with a radix of 2^128.
func DecodeCoeffs ¶
DecodeCoeffs converts a byte array to a matrix of coefficients
func Float128ToUint53 ¶
Get 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 ¶
Reconstruct an uint64 integer from a Float128 that was imported with the Float128SetUint64() function. Isolates the integer part from the floatting 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)
func GaussSampling ¶
GaussSampling returns a value sampled from discrete gaussian distribution, originates from Algorithm 11 & 12 in the paper.
func GenerateNTTPrimes ¶
Generates "n" primes of bitlen "bitLen", stuited for NTT with "N", starting from the integer "start" (which must be 1 mod 2N) and increasing (true) / decreasing (false) order
func InvButterfly ¶
func InvMFormConstant ¶
InvMFormConstan is indentical to InvMForm, except that it runs in constant time and returns a value in [0, 2q-1]
func KYSampling ¶
func MFormConstant ¶
MFormConstant is identical to MForm, except that it runs in constant time and returns a value in [0, 2q-1]
func MRed ¶
MRed operates a 64x64 bit multiplication with a montgomery reduction over a radix of 2^64.
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 MontgomeryReduce.
func PermuteNTT ¶
Applies the galois transform on a ring in NTT form TODO : careful, not inplace!
func RandUniform ¶
Types ¶
type BasisExtender ¶
type BasisExtender struct {
// contains filtered or unexported fields
}
Algorithm from https://eprint.iacr.org/2018/117.pdf
func NewBasisExtender ¶
func NewBasisExtender(contextQ, contextP *Context) (*BasisExtender, error)
func (*BasisExtender) ExtendBasis ¶
func (Parameters *BasisExtender) ExtendBasis(p1, p2 *Poly)
Extends the basis of a ring Given a ring with coefficients in basis {Q0,Q1....Qi} Extends its basis from {Q0,Q1....Qi} to {Q0,Q1....Qi,P0,P1...Pj}
func (*BasisExtender) ExtendBasisApproximate ¶
func (Parameters *BasisExtender) ExtendBasisApproximate(p1, p2 *Poly)
Approximate basis extension (returns the value + some multiple of Q (equal to the correction term v) in the basis QP) The algorithm is identical to the ExtendBasis, except it doesn't make use of the correction term v to remove the additional multiplie of Q introduced during the basis extension.
type ComplexScaler ¶
type ComplexScaler struct {
// contains filtered or unexported fields
}
func NewComplexScaler ¶
func NewComplexScaler(t uint64, contextQ, contextP *Context) (*ComplexScaler, error)
func (*ComplexScaler) Scale ¶
func (parameters *ComplexScaler) Scale(p1, p2 *Poly)
Given a ring in basis {Q0,Q1....Qi,P0,P1...Pj} Scales the ring by a factor t/Q and returns the result in basis {Q0,Q1....Qi}
type Context ¶
type Context struct {
// Polynomial nb.Coefficients
N uint64
// Modulies
Modulus []uint64
// Product of the modulies
ModulusBigint *Int
// Parameters for the CRT reconstruction
CrtReconstruction []*Int
// contains filtered or unexported fields
}
func NewContext ¶
func NewContext() *Context
func (*Context) AddNoMod ¶
Adds two polynomials coefficient wise without modular reduction The output range will be [0,2*Qi -1]
func (*Context) AddScalar ¶
Adds to each coefficients of p1 a scalar and applies a modular reduction
func (*Context) BitReverse ¶
Applies a bit reverse permutation on the ring
func (*Context) Equal ¶
Checks if two polynomials are equal in the given context Also applies an exact modular reduction on the two polynomials.
func (*Context) GetBredParams ¶
func (*Context) GetCenteredCoefficients ¶
Returns an array containing the coefficients of Pol centered arount each [-Qi/2, Qi/2]
func (*Context) GetMredParams ¶
func (*Context) GetNttNInv ¶
func (*Context) GetNttPsiInv ¶
func (*Context) InvNTT ¶
InvNTT performes the inverse NTT transformation on the coefficients of a polynomial,
func (*Context) IsValidated ¶
func (*Context) MarshalBinary ¶
func (*Context) Merge ¶
Merge merges two context by appending all the element from contextP to the elements of contextQ Will return an error if contextQ or contextP are not both not validated or both validated
func (*Context) MulByPow2New ¶
func (*Context) MulCoeffsAndAdd ¶
Multiplies p1 by p2 coefficient wise with a modular reduction
func (*Context) MulCoeffsAndAddNoMod ¶
Multiplies p1 by p2 coefficient wise with a modular reduction
func (*Context) MulCoeffsConstant ¶
MulcoeffsConstant multiplies p3 = p1 * p2 The output range of the modular reduction is [0, 2*Qi -1]
func (*Context) MulCoeffsConstantMontgomery ¶
MulcoeffsConstant multiplies p3 = p1 * p2 The output range of the modular reduction is [0, 2*Qi -1]
func (*Context) MulCoeffsMontgomery ¶
Multiplies p1 by p2 coefficient wise with a modular reduction
func (*Context) MulCoeffsMontgomeryAndAdd ¶
Multiplies p1 by p2 coefficient wise and adds the result to p3
func (*Context) MulCoeffsMontgomeryAndAddNoMod ¶
Multiplies p1 by p2 coefficient wise and adds the result to p3
func (*Context) MulCoeffsMontgomeryAndSub ¶
Multiplies p1 by p2 coefficient wise and subss the result to p3
func (*Context) MulCoeffsMontgomeryAndSubNoMod ¶
Multiplies p1 by p2 coefficient wise and subss the result to p3
func (*Context) MulPolyMontgomery ¶
Multiplies p1 by p2
func (*Context) MulPolyNaive ¶
Multiplies p1 by p2 with naive convolution O(n^2)
func (*Context) MulPolyNaiveMontgomery ¶
Multiplies p1 by p2 with naive convolution O(n^2)
func (*Context) MulScalar ¶
Multiplies each coefficients of p1 by a scalar and applies a modular reduction
func (*Context) MulScalarBigint ¶
Multiplies each coefficients of p1 by a bigint variable and applies a modular reduction To be used when the scalar is bigger than 32 bits
func (*Context) MultByMonomial ¶
Given p1 a ring in Z[x]/(X^n + 1), returns p1 * x^d
func (*Context) MultByMonomialNew ¶
func (*Context) NewGaussPoly ¶
Generates a ring with coefficients following a discrete gaussian distribution with derivation sigma
func (*Context) NewKYSampler ¶
func (*Context) NewTernaryPoly ¶
Generates a ring with coefficients following a uniform distribution over [-1,0,1] mod each Qi
func (*Context) NewTernaryPolyMontgomeryNTT ¶
Generates a ring with coefficients following a uniform distribution over [-1,0,1] mod each Qi and applies the NTT and Montgomery form.
func (*Context) NewTernaryPolyNTT ¶
Generates a ring with coefficients following a uniform distribution over [-1,0,1] mod each Qi and applies the NTT.
func (*Context) NewTernarySampler ¶
func (context *Context) NewTernarySampler() *TernarySampler
func (*Context) NewUniformPoly ¶
Generates a ring with coefficients following a uniform distribution over [0, Qi-1]
func (*Context) PolyToBigint ¶
Returns an string array containing the reconstructed coefficients
func (*Context) PolyToString ¶
Returns an string array containing the reconstructed coefficients
func (*Context) Reduce ¶
Modular reduction over the coefficients of the ring Used when several operations can first be done safely without modular reduction
func (*Context) Rotate ¶
Applies a Galoi Automorphism on a ring in NTT form, rotating the coefficients to the right by n. Requirese the data to permuted in bitreversal order before applying NTT.
func (*Context) SetCoefficientsBigint ¶
Sets the coefficients of Pol from a array of strings It will import them as bigint variables and reduce them mod each Qi
func (*Context) SetCoefficientsInt64 ¶
Sets the coefficients of Pol from an int64 array If a coefficient is negative it will instead assay its positive inverse mod each Qi
func (*Context) SetCoefficientsString ¶
Sets the coefficients of Pol from a array of strings It will import them as bigint variables and reduce them mod each Qi.
func (*Context) SetCoefficientsUint64 ¶
Sets the coefficient of Pol from an uint64 array
func (*Context) SetParameters ¶
func (*Context) SubNoMod ¶
Subtract p2 to p1 coefficient wise without modular reduction Since negative values are not allowed, the outupt range will be [0,2*Qi -1]
func (*Context) SubScalar ¶
Subbs to each coefficients of p1 by a scalar and applies a modular reduction
func (*Context) UnMarshalBinary ¶
func (*Context) ValidateParameters ¶
type Float128 ¶
type Float128 [2]float64 // float128 represented by two float64s
A 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 ¶
Set 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.
func Float128SetUint53 ¶
Set 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 ¶
Set 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.
func Float128SetZero ¶
func Float128SetZero() (result Float128)
Set 128-bit floating point object to 0.0
type Int ¶
type Int struct {
Value big.Int // Integer value, theoretically ranging from -infinite to +infinite
}
Int is a generic implementation of natural arithmetic on integers, built using Go's built-in "math/big.Int"
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 (*Int) Bits ¶
Bits returns the bit stream and bit length of i's absolute value. For example, 6=110, this function will return ([0, 1, 1], 3)
func (*Int) Div ¶
Div sets the target i to floor(a / b), which is the closest integer to zero for a/b
type KYSampler ¶
type KYSampler struct {
Matrix [][]uint8
// contains filtered or unexported fields
}
func (*KYSampler) SampleNTTNew ¶
type Poly ¶
type Poly struct {
Coeffs [][]uint64 //Coefficients in CRT representation
}
Poly is the structure containing the coefficients of a ring
func (*Poly) ExtendModulies ¶
func (Pol *Poly) ExtendModulies()
func (*Poly) GetCoefficients ¶
GetCoefficients returns a double slice containing the coefficients of the ring
func (*Poly) GetLenModulies ¶
CetLenModulies returns the number of modulies
func (*Poly) MarshalBinary ¶
func (*Poly) SetCoefficients ¶
SetCoefficients sets the coefficients of ring directly from a CRT format (double slice)
type SimpleScaler ¶
type SimpleScaler struct {
// contains filtered or unexported fields
}
Algorithm from https://eprint.iacr.org/2018/117.pdf
func NewSimpleScaler ¶
func NewSimpleScaler(t uint64, context *Context) (*SimpleScaler, error)
func (*SimpleScaler) Scale ¶
func (parameters *SimpleScaler) Scale(p1, p2 *Poly)
Given a ring in basis Qi Scales its coefficients by a factor t/Q and returns the result mod t Since t is smaller than all Qi, all coefficients will be identical between all Qi
func (*SimpleScaler) ScaleFloat ¶
func (parameters *SimpleScaler) ScaleFloat(p1 *Poly, coeffs []complex128)
type TernarySampler ¶
type TernarySampler struct {
Matrix [][]uint64
MatrixMontgomery [][]uint64
// contains filtered or unexported fields
}
func (*TernarySampler) Sample ¶
func (sampler *TernarySampler) Sample(pol *Poly)
func (*TernarySampler) SampleMontgomery ¶
func (sampler *TernarySampler) SampleMontgomery(pol *Poly)
func (*TernarySampler) SampleMontgomeryNTT ¶
func (sampler *TernarySampler) SampleMontgomeryNTT(pol *Poly)
func (*TernarySampler) SampleMontgomeryNTTNew ¶
func (sampler *TernarySampler) SampleMontgomeryNTTNew() (pol *Poly)
func (*TernarySampler) SampleMontgomeryNew ¶
func (sampler *TernarySampler) SampleMontgomeryNew() (pol *Poly)
func (*TernarySampler) SampleNTT ¶
func (sampler *TernarySampler) SampleNTT(pol *Poly)
func (*TernarySampler) SampleNTTNew ¶
func (sampler *TernarySampler) SampleNTTNew() (pol *Poly)
func (*TernarySampler) SampleNew ¶
func (sampler *TernarySampler) SampleNew() (pol *Poly)