lattice

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: BSD-3-Clause Imports: 4 Imported by: 1

Documentation

Overview

Package lattice provides GPU-accelerated lattice cryptography operations.

Used for FHE (Fully Homomorphic Encryption), post-quantum signatures, and other lattice-based cryptographic schemes.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidInput   = errors.New("lattice: invalid input")
	ErrInvalidDegree  = errors.New("lattice: invalid polynomial degree")
	ErrInvalidModulus = errors.New("lattice: invalid modulus")
)

Functions

func BatchNTTForward

func BatchNTTForward(params NTTParams, polys [][]uint64) ([][]uint64, error)

BatchNTTForward performs forward NTT on multiple polynomials in parallel.

func BatchNTTInverse

func BatchNTTInverse(params NTTParams, polys [][]uint64) ([][]uint64, error)

BatchNTTInverse performs inverse NTT on multiple polynomials in parallel.

func MLDSANTTBatch added in v1.2.0

func MLDSANTTBatch(polys [][]int32, inverse bool) error

MLDSANTTBatch performs the in-place forward (inverse=false) or inverse (inverse=true) Number-Theoretic Transform over Z_q[X]/(X^256 + 1) with q = 8380417 (the FIPS 204 ML-DSA prime) on every polynomial in polys.

Each polys[i] MUST have length 256. The transform writes back into the input slice in-place.

Byte-equal to PQCLEAN_MLDSA65_CLEAN_ntt (forward) and PQCLEAN_MLDSA65_CLEAN_invntt_tomont (inverse). The dispatcher engages the GPU substrate when len(polys) >= accel.MLDSABatchThreshold AND the substrate ships an implementation; otherwise this falls through to the per-poly Go oracle below, which is the canonical CPU reference for Pulsar's byte-equality regression test.

func MLDSANTTForward added in v1.2.0

func MLDSANTTForward(coeffs []int32) error

MLDSANTTForward is the single-poly convenience wrapper around MLDSANTTBatch. Returns ErrInvalidDegree if len(coeffs) != 256.

func MLDSANTTInverse added in v1.2.0

func MLDSANTTInverse(coeffs []int32) error

MLDSANTTInverse is the single-poly convenience wrapper around MLDSANTTBatch (inverse direction).

func NTTForward

func NTTForward(params NTTParams, coeffs []uint64) ([]uint64, error)

NTTForward performs forward Number Theoretic Transform. Transforms polynomial from coefficient to evaluation form.

func NTTInverse

func NTTInverse(params NTTParams, evals []uint64) ([]uint64, error)

NTTInverse performs inverse Number Theoretic Transform. Transforms polynomial from evaluation to coefficient form.

func PolyAdd

func PolyAdd(modulus uint64, a, b []uint64) ([]uint64, error)

PolyAdd adds two polynomials coefficient-wise.

func PolyMul

func PolyMul(params NTTParams, a, b []uint64) ([]uint64, error)

PolyMul multiplies two polynomials using NTT. Result is (a * b) mod (X^N + 1) mod modulus.

func PolySub

func PolySub(modulus uint64, a, b []uint64) ([]uint64, error)

PolySub subtracts two polynomials coefficient-wise.

func SampleNTT

func SampleNTT(params NTTParams, seed []byte) ([]uint64, error)

SampleNTT samples a polynomial in NTT domain from a seed. Used for generating random polynomials in lattice schemes.

Types

type NTTParams

type NTTParams struct {
	N       uint32 // Polynomial degree (power of 2)
	Modulus uint64 // Prime modulus
	Root    uint64 // Primitive N-th root of unity
}

NTTParams contains parameters for NTT operations.

Jump to

Keyboard shortcuts

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