Documentation ¶
Index ¶
- Constants
- Variables
- func BaseSampler(randomBytes [RCDTprecLen]byte) int
- func Compress(v []int16, slen int) ([]byte, error)
- func Decompress(x []byte, slen int, n int) ([]int, error)
- func FfnpFFT(t [][]complex128, T []interface{}) [][]complex128
- func GenPoly(n uint16) []int16
- func Gram(B [][][]float64) [][][]float64
- func GsNorm(f, g []float64, q float64) float64
- func Karatsuba(a, b []*big.Int, n int) []*big.Int
- func LdlFFT(G [][][]complex128) [][][][]complex128
- func NtruGen(n uint16) (f, g, F, G []int16)
- func NtruSolve(f, g []*big.Int) ([]*big.Int, []*big.Int, error)
- func Samplerz(mu, sigma, sigmin float64) int8
- type CoeffTree
- type FFTtree
Constants ¶
const RCDTprec uint8 = 72
Precision of RCDT
const RCDTprecLen uint8 = (RCDTprec >> 3)
Variables ¶
var ( ErrEncodingTooLong = errors.New("encoding is too long") ErrInvalidEncoding = errors.New("invalid encoding") )
var C = [13]uint64{
0x00000004741183A3,
0x00000036548CFC06,
0x0000024FDCBF140A,
0x0000171D939DE045,
0x0000D00CF58F6F84,
0x000680681CF796E3,
0x002D82D8305B0FEA,
0x011111110E066FD0,
0x0555555555070F00,
0x155555555581FF00,
0x400000000002B400,
0x7FFFFFFFFFFF4800,
0x8000000000000000,
}
C contains the coefficients of a polynomial that approximates exp(-x) More precisely, the value: (2 ** -63) * sum(C[12 - i] * (x ** i) for i in range(i)) Should be very close to exp(-x). This polynomial is lifted from FACCT: https://doi.org/10.1109/TC.2019.2940949
var (
ErrEquation = errors.New("NTRU equation has no solution")
)
var ILN2 float64 = 1.44269504089
var LN2 float64 = 0.69314718056
ln(2) and 1 / ln(2), with ln the natural logarithm
var RCDT = [18]*big.Int{ types.NewBigIntFromString("3024686241123004913666"), types.NewBigIntFromString("1564742784480091954050"), types.NewBigIntFromString("636254429462080897535"), types.NewBigIntFromString("199560484645026482916"), types.NewBigIntFromString("47667343854657281903"), types.NewBigIntFromString("8595902006365044063"), types.NewBigIntFromString("1163297957344668388"), types.NewBigIntFromString("117656387352093658"), types.NewBigIntFromString("8867391802663976"), types.NewBigIntFromString("496969357462633"), types.NewBigIntFromString("20680885154299"), types.NewBigIntFromString("638331848991"), types.NewBigIntFromString("14602316184"), types.NewBigIntFromString("247426747"), types.NewBigIntFromString("3104126"), types.NewBigIntFromString("28824"), types.NewBigIntFromString("198"), types.NewBigIntFromString("1"), }
RCDT is the reverse cumulative distribution table of a distribution that is very close to a half-Gaussian of parameter MAX_SIGMA.
Functions ¶
func BaseSampler ¶
func BaseSampler(randomBytes [RCDTprecLen]byte) int
func Compress ¶
Take as input an array of integers v and a bytelength slen, and return a bytestring of length slen that encode/compress v. If this is not possible, return False.
For each coefficient of v: - the sign is encoded on 1 bit - the 7 lower bits are encoded naively (binary) - the high bits are encoded in unary encoding
func Decompress ¶
Take as input an encoding x, a bytelength slen and a length n, and return a list of integers v of length n such that x encode v. If such a list does not exist, the encoding is invalid and we output (nil, ErrInvalidEncoding).
func FfnpFFT ¶
func FfnpFFT(t [][]complex128, T []interface{}) [][]complex128
func Karatsuba ¶
Karatsuba multiplication between polynomials. The coefficients may be either integer or real.
func LdlFFT ¶
func LdlFFT(G [][][]complex128) [][][][]complex128
func NtruSolve ¶
Solve the NTRU equation for f and g. Corresponds to NTRUSolve in Falcon's documentation.
func Samplerz ¶
Given floating-point values mu, sigma (and sigmin), output an integer z according to the discrete Gaussian distribution D_{Z, mu, sigma}.
Input: - the center mu - the standard deviation sigma - a scaling factor sigmin The inputs MUST verify 1 < sigmin < sigma < MAX_SIGMA.
Output: - a sample z from the distribution D_{Z, mu, sigma}. https://falcon-sign.info/falcon.pdf#58
Types ¶
type FFTtree ¶
type FFTtree struct { Value []complex128 Leftchild []complex128 Rightchild []complex128 }
func (*FFTtree) AllChild ¶
func (t *FFTtree) AllChild() [][]complex128
func (*FFTtree) FfSamplingFFT ¶
func (T *FFTtree) FfSamplingFFT(t [][]complex128, sigmin float64) [][]complex128
func (*FFTtree) FfldlFFT ¶
func (T *FFTtree) FfldlFFT(G [][][]complex128) FFTtree