algebra

package
v0.0.0-...-b0046da Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SampleSecret

func SampleSecret(rho []byte) (*Vec, *Vec)

Types

type Matrix

type Matrix struct {
	Cs [][]*Poly
}

func NewMatrix

func NewMatrix(Cs [][]*Poly) *Matrix

Constructor for Matrix TODO does it work?

func SampleMatrix

func SampleMatrix(rho []byte) *Matrix

func (*Matrix) MulNTT

func (m *Matrix) MulNTT(vec *Vec) *Vec

MulNTT performs matrix-vector multiplication in the NTT domain

func (*Matrix) SchoolbookMul

func (m *Matrix) SchoolbookMul(vec *Vec) *Vec

SchoolbookMul performs matrix-vector multiplication with InvNTT

func (*Matrix) SchoolbookMulDebug

func (m *Matrix) SchoolbookMulDebug(vec *Vec) (*Vec, *Vec)

SchoolbookMulDebug performs matrix-vector multiplication with debugging

type Poly

type Poly struct {
	Cs [256]int64
}

Poly represents an element of the polynomial ring Z_q[x]/<x^256+1>.

func NewPoly

func NewPoly(Cs []int64) *Poly

NewPoly initializes a new Poly.

func SampleLeqEta

func SampleLeqEta(stream *bytes.Reader) *Poly

func UnpackPoly

func UnpackPoly(bs []byte) *Poly

unpackPoly unpacks a byte array into a Poly structure

func UnpackPolyLeGamma1

func UnpackPolyLeGamma1(bs []byte) *Poly

TODO didnt check

func UnpackPolyLeqEta

func UnpackPolyLeqEta(bs []byte) *Poly

unpackPolyLeqEta unpacks a byte array into a Poly structure considering ETA

func (*Poly) Add

func (p *Poly) Add(other *Poly) *Poly

Add adds two polynomials.

func (*Poly) Decompose

func (p *Poly) Decompose() (*Poly, *Poly)

decompose splits the polynomial into two parts.

func (*Poly) Equal

func (p *Poly) Equal(other *Poly) bool

Equal checks if two polynomials are equal.

func (*Poly) InvNTT

func (p *Poly) InvNTT() *Poly

InvNTT applies the inverse Number Theoretic Transform.

func (*Poly) MulNTT

func (p *Poly) MulNTT(other *Poly) *Poly

MulNTT performs componentwise multiplication in the NTT domain.

func (*Poly) NTT

func (p *Poly) NTT() *Poly

NTT applies the Number Theoretic Transform.

func (*Poly) Neg

func (p *Poly) Neg() *Poly

Neg negates a polynomial.

func (*Poly) Norm

func (p *Poly) Norm() int64

norm calculates the norm of the polynomial.

func (*Poly) Pack

func (p *Poly) Pack() []byte

pack packs the coefficients into bytes.

func (*Poly) PackLeGamma1

func (p *Poly) PackLeGamma1() []byte

packLeGamma1 packs the coefficients with gamma1 constraint. TODO didnt check

func (*Poly) PackLeqEta

func (p *Poly) PackLeqEta() []byte

packLeqEta packs the coefficients with eta constraint. TODO didnt check

func (*Poly) RNorm

func (p *Poly) RNorm() int64

func (*Poly) SchoolbookMul

func (p *Poly) SchoolbookMul(other *Poly) (*Poly, *Poly)

SchoolbookMul performs polynomial multiplication.

func (*Poly) String

func (p *Poly) String() string

String converts the polynomial to a string.

func (*Poly) Sub

func (p *Poly) Sub(other *Poly) *Poly

Sub subtracts two polynomials.

type Vec

type Vec struct {
	Ps []*Poly
}

Vec represents a vector of Polys

func NewVec

func NewVec(Ps []*Poly) *Vec

NewVec creates a new Vec from a slice of Polys

func SampleY

func SampleY(rho []byte, nonce int) *Vec

func UnpackVec

func UnpackVec(bs []byte, l int) *Vec

unpackVec unpacks a byte slice into a Vec of length l.

func UnpackVecLeGamma1

func UnpackVecLeGamma1(bs []byte, l int) *Vec

unpackVecLeGamma1 unpacks a byte slice into a Vec of length l, assuming each Poly is packed with elements bounded by Gamma1.

func UnpackVecLeqEta

func UnpackVecLeqEta(bs []byte, l int) *Vec

unpackVecLeqEta unpacks a byte slice into a Vec of length l, assuming each Poly is packed with elements bounded by Eta.

func (*Vec) Add

func (v *Vec) Add(other *Vec) *Vec

Add adds two Vecs component-wise

func (*Vec) Decompose

func (v *Vec) Decompose() (*Vec, *Vec)

Decompose decomposes each Poly in the Vec into two Vecs

func (*Vec) DotNTT

func (v *Vec) DotNTT(other *Vec) *Poly

DotNTT computes the dot product of two Vecs in the NTT domain

func (*Vec) Equal

func (v *Vec) Equal(other *Vec) bool

Equals checks if two Vecs are equal

func (*Vec) IntArray

func (v *Vec) IntArray() *uint32

func (*Vec) InvNTT

func (v *Vec) InvNTT() *Vec

InvNTT applies Inverse NTT to each Poly in the Vec

func (*Vec) NTT

func (v *Vec) NTT() *Vec

NTT applies NTT to each Poly in the Vec

func (*Vec) Norm

func (v *Vec) Norm() int64

Norm computes the maximum norm of the Polys in the Vec

func (*Vec) Pack

func (v *Vec) Pack() []byte

Pack packs the Vec into a byte slice

func (*Vec) PackLeGamma1

func (v *Vec) PackLeGamma1() []byte

PackLeGamma1 packs the Vec with elements bounded by Gamma1

func (*Vec) PackLeqEta

func (v *Vec) PackLeqEta() []byte

PackLeqEta packs the Vec with elements bounded by Eta

func (*Vec) RNorm

func (v *Vec) RNorm() int64

Norm computes the maximum norm of the Polys in the Vec

func (*Vec) ScalarMulNTT

func (v *Vec) ScalarMulNTT(sc *Poly) *Vec

ScalarMulNTT multiplies each Poly in the Vec by a scalar in the NTT domain

func (*Vec) SchoolbookDot

func (v *Vec) SchoolbookDot(other *Vec) (*Poly, *Poly)

SchoolbookDot computes the dot product of two Vecs using Schoolbook multiplication

func (*Vec) SchoolbookDotDebug

func (v *Vec) SchoolbookDotDebug(other *Vec) (*Poly, *Poly)

SchoolbookDotDebug computes the dot product with debugging??? TODO

func (*Vec) SchoolbookScalarMul

func (v *Vec) SchoolbookScalarMul(sc *Poly) *Vec

SchoolbookScalarMul multiplies each Poly by a scalar using Schoolbook multiplication

func (*Vec) SchoolbookScalarMulDebug

func (v *Vec) SchoolbookScalarMulDebug(sc *Poly) (*Vec, *Vec)

SchoolbookScalarMulDebug is a debug version of SchoolbookScalarMul

func (*Vec) String

func (v *Vec) String() string

String returns a string representation of the Vec

func (*Vec) Sub

func (v *Vec) Sub(other *Vec) *Vec

Sub subtracts two Vecs component-wise

Jump to

Keyboard shortcuts

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