poly

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Degree of ML-DSA polynomials.
	N = 256

	// Q is the prime modulus used by ML-DSA.
	Q = 8380417

	// Mont is R mod q with R = 2^32.
	Mont = 4193792
)

Variables

This section is empty.

Functions

func Canonical

func Canonical(x uint32) int32

Canonical returns the representative of x in signed canonical form (-q/2, q/2].

func Freeze

func Freeze(p *Poly)

Freeze normalizes all coefficients of p into [0, q).

func FromMont

func FromMont(x uint32) uint32

FromMont converts a Montgomery-form value back to the canonical representative.

func InvNTT

func InvNTT(p *Poly) error

InvNTT computes the inverse number-theoretic transform of p in place.

func Le2QModQ

func Le2QModQ(x uint32) uint32

Le2QModQ reduces x from [0, 2q) into [0, q).

func ModQ

func ModQ(x uint32) uint32

ModQ returns x mod q for any uint32.

func NTT

func NTT(p *Poly) error

NTT computes the number-theoretic transform of p in place.

func PointwiseAccMontgomery

func PointwiseAccMontgomery(out *Poly, a, b []*Poly)

PointwiseAccMontgomery computes sum_{i}(a_i * b_i) and stores in out.

func PointwiseAccMontgomeryVec

func PointwiseAccMontgomeryVec(out *Poly, a, b *Vec) error

PointwiseAccMontgomery computes the Montgomery inner product of a and b and writes the result to out.

func ReduceLe2Q

func ReduceLe2Q(x uint32) uint32

ReduceLe2Q reduces x into [0, 2q).

func SamplePolyEta

func SamplePolyEta(p *Poly, seed []byte, nonce uint16, eta int) error

SamplePolyEta fills p with coefficients sampled from the centered binomial distribution with parameter eta.

func SamplePolyUniform

func SamplePolyUniform(p *Poly, seed []byte, nonce uint16) error

SamplePolyUniform samples coefficients uniformly at random modulo q using SHAKE256(seed || nonce).

func ToMont

func ToMont(x uint32) uint32

ToMont converts a canonical representative into Montgomery form.

Types

type Poly

type Poly struct {
	Coeffs [N]uint32
}

Poly represents an ML-DSA polynomial with coefficients modulo q.

func (*Poly) Add

func (p *Poly) Add(a, b *Poly)

Add sets p = a + b (mod q).

func (*Poly) PointwiseMontgomery

func (p *Poly) PointwiseMontgomery(a, b *Poly)

PointwiseMontgomery sets p = a * b (coefficient-wise) assuming Montgomery domain inputs.

func (*Poly) Sub

func (p *Poly) Sub(a, b *Poly)

Sub sets p = a - b (mod q).

type Vec

type Vec struct {
	// contains filtered or unexported fields
}

Vec represents a fixed-length vector of polynomials.

func NewVec

func NewVec(length int) *Vec

NewVec constructs a polynomial vector with the specified length. Each entry is initialised to an empty (zero) polynomial.

func (*Vec) Add

func (v *Vec) Add(a, b *Vec) error

Add sets v = a + b.

func (*Vec) At

func (v *Vec) At(i int) (*Poly, error)

At returns the ith polynomial in the vector.

func (*Vec) CopyFrom

func (v *Vec) CopyFrom(src *Vec) error

CopyFrom copies coefficients from src into v. Both vectors must have the same length.

func (*Vec) InfinityNorm

func (v *Vec) InfinityNorm() int32

InfinityNorm computes the maximum absolute coefficient (in canonical representation).

func (*Vec) InvNTT

func (v *Vec) InvNTT() error

InvNTT applies the inverse NTT to each polynomial in the vector.

func (*Vec) Len

func (v *Vec) Len() int

Len returns the number of polynomials in the vector.

func (*Vec) NTT

func (v *Vec) NTT() error

NTT applies the forward NTT to each polynomial in the vector.

func (*Vec) Polys

func (v *Vec) Polys() []*Poly

Polys exposes the underlying slice. Callers must not mutate the slice length.

func (*Vec) Sub

func (v *Vec) Sub(a, b *Vec) error

Sub sets v = a - b.

func (*Vec) Zero

func (v *Vec) Zero()

Zero sets all coefficients in the vector to zero.

Jump to

Keyboard shortcuts

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