Documentation
¶
Overview ¶
Package ntt is the canonical Number-Theoretic-Transform interface for luxfi/math.
LP-107 §"NTT" — the canonical motivation. Production callers (luxfi/lattice, luxfi/pulsar, luxfi/fhe) consume this package's Service abstraction; concrete kernels live behind a Backend interface so AVX2 / NEON / CUDA / Metal / WGSL realizations are interchangeable.
Phase 2 (this file): defines the public surface. The pure-Go reference Backend wraps github.com/luxfi/lattice/v7/ring's SubRing.NTT — the canonical Lattigo-derived Montgomery NTT — so callers see no behavior change. Phase 3 (LP-107) inverts the dependency: lattice/ring imports this package, and the Lattigo kernel body lives here.
Determinism contract: for a fixed (Params, input []uint64), every registered Backend MUST produce byte-equal output. KATs in luxfi/math/ntt/test/kat enforce this across runtimes.
Index ¶
Constants ¶
const KATSchemaV1 = codec.KATSchemaV1
KATSchemaV1 is the canonical bundle schema string.
Variables ¶
var ErrUnsupportedParams = errors.New("ntt: backend does not support these Params")
ErrUnsupportedParams is returned by a Backend that does not support the requested Params (e.g. CUDA backend asked for N=32 when it only implements N >= 256).
Functions ¶
func Register ¶
func Register(b Backend)
Register installs a Backend under its ID. Re-registration replaces. Backends MUST be idempotent — registering the same ID twice with different bodies is a programming error caught at process start when two libraries each try to register the same ID.
func WriteKATBundleFile ¶ added in v1.4.0
WriteKATBundleFile writes a bundle to disk; thin pass-through.
Types ¶
type Backend ¶
type Backend interface {
// ID returns the BackendID for this backend.
ID() params.BackendID
// Supports reports whether this backend can handle p.
Supports(p *Params) bool
// Forward applies the forward NTT in-place. dst must have length
// batch*p.N. Returns ErrUnsupportedParams if Supports returns false.
Forward(dst []uint64, p *Params, batch uint32) error
// Inverse applies the inverse NTT in-place. Same length contract.
Inverse(dst []uint64, p *Params, batch uint32) error
}
Backend is the kernel interface every NTT realization implements. Forward and Inverse operate in-place and MUST produce byte-equal output across all registered backends for the same (Params, input).
func PureGoBackend ¶
func PureGoBackend() Backend
PureGoBackend returns the singleton pure-Go NTT backend. Always available; registered automatically by init().
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.
type Params ¶
type Params struct {
// N is the ring dimension. Must be a power of two.
N uint32
// Q is the prime modulus. Must satisfy (Q - 1) | 2N (NTT-friendly).
Q uint64
// ID is the canonical parameter identifier (e.g. NTTPulsarN256).
ID params.NTTParamID
}
Params identifies one NTT instance: ring degree N, modulus Q, and the canonical parameter ID for KAT lookup.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service binds a Params to a chosen Backend (resolved via dispatch policy) and exposes the public Forward / Inverse methods every downstream caller uses.
func NewService ¶
NewService builds a Service for p under the given dispatch policy. The Backend is resolved at construction time from the registered backends; if no backend supports p, returns an error.
func (*Service) Backend ¶
Backend returns the resolved BackendID. Callers print this in logs to record which path executed.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package canonical owns the canonical Lattigo-derived Montgomery NTT body — SubRing layout, root-table generator, scalar primitives (MRed/MRedLazy/MForm/BRed/CRed/...), the loop-unrolled-by-16 NTT kernel, and the SIMD AVX2 dispatch hooks.
|
Package canonical owns the canonical Lattigo-derived Montgomery NTT body — SubRing layout, root-table generator, scalar primitives (MRed/MRedLazy/MForm/BRed/CRed/...), the loop-unrolled-by-16 NTT kernel, and the SIMD AVX2 dispatch hooks. |
|
cmd
|
|
|
emit_ntt_kat
command
|