sample

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: BSD-3-Clause Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const KATSchemaV1 = codec.KATSchemaV1

KATSchemaV1 is the canonical bundle schema string.

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 HexDecode added in v1.4.0

func HexDecode(s string) ([]byte, error)

HexDecode is the inverse.

func HexEncode added in v1.4.0

func HexEncode(b []byte) string

HexEncode is the canonical hex encoder shared with codec.

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.

func WriteKATBundleFile added in v1.4.0

func WriteKATBundleFile(path string, b *KATBundle) error

WriteKATBundleFile writes a bundle to disk; thin pass-through.

Types

type KATBundle added in v1.4.0

type KATBundle = codec.KATBundle

KATBundle is an alias for codec.KATBundle.

func ReadKATBundleFile added in v1.4.0

func ReadKATBundleFile(path string) (*KATBundle, error)

ReadKATBundleFile reads a bundle from disk; thin pass-through.

type KATEntry added in v1.4.0

type KATEntry = codec.KATEntry

KATEntry is an alias for codec.KATEntry.

Directories

Path Synopsis
cmd
emit_sample_kat command

Jump to

Keyboard shortcuts

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