Documentation
¶
Overview ¶
Package sample provides primitive samplers — uniform mod q, ternary, centered binomial, discrete Gaussian — used as building blocks by every Lux lattice protocol.
LP-107 §"Sampling" — the canonical motivation. Protocol-specific samplers (e.g. Pulsar's transcript-bound discrete Gaussian for the proof of knowledge) remain in their owning protocol package; this package is the source of the primitive distributions those protocols compose.
Determinism contract: every sampler accepts an io.Reader as its entropy source. Same seed → same samples, byte-identically.
Phase 2 (this file): pure-Go reference implementation. Body uses luxfi/math/modarith for modular reduction.
Index ¶
- Constants
- func CenteredBinomial(dst []uint64, q uint64, eta int, r io.Reader) error
- func DiscreteGaussianRejection(q uint64, sigma float64, r io.Reader) (uint64, error)
- func HexDecode(s string) ([]byte, error)
- func HexEncode(b []byte) string
- func Ternary(dst []uint64, q uint64, density float64, r io.Reader) error
- func Uniform(dst []uint64, q uint64, r io.Reader) error
- func WriteKATBundleFile(path string, b *KATBundle) error
- type KATBundle
- type KATEntry
Constants ¶
const KATSchemaV1 = codec.KATSchemaV1
KATSchemaV1 is the canonical bundle schema string.
Variables ¶
This section is empty.
Functions ¶
func CenteredBinomial ¶
CenteredBinomial fills dst with values from a centered binomial distribution with parameter eta (Bin(2*eta, 0.5) - eta). Standard Module-LWE error distribution.
func DiscreteGaussianRejection ¶
DiscreteGaussianRejection samples one value approximately from the discrete Gaussian D_{Z, sigma}, centered at 0, via rejection sampling with a 6-sigma cutoff. Accepts ~64% of draws on average for sigma in the typical lattice range [3, 50]; exact for the uncentered tail.
This is the same reference path used by lattice/gpu.SampleGaussian (which we're consolidating here under LP-107).
func Ternary ¶
Ternary fills dst with values from {-1 mod q, 0, 1} per the given non-zero density (probability of non-zero coefficient). Standard lattice short-secret distribution.
func Uniform ¶
Uniform fills dst with values uniformly distributed in [0, q). Uses rejection sampling with a per-sample mask up to bits.Len64(q) bits to avoid bias. Reads len(dst) * ceil(log2(q)/8) bytes from r in expectation; rejection rate is at most 2x.
func WriteKATBundleFile ¶ added in v1.4.0
WriteKATBundleFile writes a bundle to disk; thin pass-through.
Types ¶
type KATBundle ¶ added in v1.4.0
KATBundle is an alias for codec.KATBundle.
func ReadKATBundleFile ¶ added in v1.4.0
ReadKATBundleFile reads a bundle from disk; thin pass-through.