sample

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

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

This section is empty.

Variables

This section is empty.

Functions

func CenteredBinomial

func CenteredBinomial(dst []uint64, q uint64, eta int, r io.Reader) error

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

func DiscreteGaussianRejection(q uint64, sigma float64, r io.Reader) (uint64, error)

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

func Ternary(dst []uint64, q uint64, density float64, r io.Reader) error

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

func Uniform(dst []uint64, q uint64, r io.Reader) error

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.

Types

This section is empty.

Jump to

Keyboard shortcuts

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