util

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2025 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package util implements the generic underlying algorithms from NIST FIPS 204.

This aux.go file contains the auxiliary internal functions needed to implement ML-DSA.

The implementations here have slightly more verbose function prototypes than FIPS-204, due to the need to parametrize the functions based on the actual parameter sets for the ML-DSA algorithm being used. The first parameters to all functions are constants to the specific instantiation of ML-DSA (e.g., k, l, or omega2).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddVector

func AddVector(v, w []ring.Rq) []ring.Rq

func AddVectorNTT

func AddVectorNTT(v, w []ring.Tq) []ring.Tq

Algorithm 46

func BitPack

func BitPack(w ring.Rz, k uint8) []byte

Algorithm 17, for open intervals -2^k < x <= 2^k

func BitPackClosed

func BitPackClosed(w ring.Rz, k uint8) []byte

Algorithm 17, specialized to values in the closed interval -2^k <= x <= 2^k 2^k is called eta in the context of FIPS 204

func BitUnpack

func BitUnpack(b []byte, k uint8) (z ring.Rz)

Algorithm 19, for open intervals -2^k < x <= 2^k

func BitUnpackClosed

func BitUnpackClosed(b []byte, k uint8) (z ring.Rz, err error)

Algorithm 19, specialized to values in -eta <= x <= eta Returns an error if any value is out of range 2^k is called eta in the context of FIPS 204 k is always either 1 or 2. This is only used during sk decoding

func ExpandA

func ExpandA(cfg *params.Cfg, rho []byte) [][]ring.Tq

Algorithm 32

func ExpandMask

func ExpandMask(cfg *params.Cfg, rho []byte, mu uint16) []ring.Rz

Algorithm 34

func ExpandS

func ExpandS(cfg *params.Cfg, rho []byte) ([]ring.Rq, []ring.Rq)

Algorithm 33

func H

func H(out []byte, data []byte)

H(str, l) -> SHAKE256(str, 8l)

func HintBitPack

func HintBitPack(k, omega uint8, h []ring.R2) []byte

Algorithm 20 Does not need to be constant-time, as hints are public This is used during signature encoding

func HintBitUnpack

func HintBitUnpack(k, omega uint8, y []byte) ([]ring.R2, error)

Algorithm 21 This is used by signature verification, which does not need to be constant-time

func IntegerToBits

func IntegerToBits[T ~uint32](x T, a int) []byte

Algorithm 9 Returns a length-`a` []byte with a distinct byte entry for each bit, in lsb order

func InvNttVec

func InvNttVec(w []ring.Tq) []ring.Rq

Helper function for iterating over a vector of k NttElements

func InverseNTT

func InverseNTT(wh ring.Tq) ring.Rq

Algorithm 42

func MakeHint

func MakeHint(cfg *params.Cfg, z, r []ring.Rq) []ring.R2

Algorithm 39 Not constant time - inputs and outputs are public Returns nil when the number of 1s in the hint is greater than omega

func MatrixVectorNTT

func MatrixVectorNTT(M_hat [][]ring.Tq, v_hat []ring.Tq) []ring.Tq

Algorithm 48

func NTT

func NTT(w ring.Rq) (wh ring.Tq)

Algorithm 41 TODO - montgomery multiplication and in-place NTT

func NegateVector

func NegateVector(v []ring.Rq) []ring.Rq

func NttVec

func NttVec(r []ring.Rq) []ring.Tq

Helper function for iterating over a vector of k RingElements

func Power2RoundVec

func Power2RoundVec(x []ring.Rq) ([]ring.Rz, []ring.Rz)

func RejBoundedPoly

func RejBoundedPoly(eta int, seed []byte) (a ring.Rq)

Algorithm 31

func RejNTTPoly

func RejNTTPoly(seed []byte) (ah ring.Tq)

Algorithm 30

func SKEncode

func SKEncode(k, l, log_eta uint8, rho, K, tr []byte, s1, s2, t0 []ring.Rz) []byte

Algorithm 24

func SampleInBall

func SampleInBall(cfg *params.Cfg, seed []byte) (c ring.Rz)

Algorithm 29

func ScalarVector

func ScalarVector(c field.T, v []ring.Rq) []ring.Rq

Multiplies each element of a vector by a scalar

func ScalarVectorNTT

func ScalarVectorNTT(c_hat ring.Tq, v_hat []ring.Tq) []ring.Tq

Algorithm 47

func SigDecode

func SigDecode(cfg *params.Cfg, sig []byte) ([]byte, []ring.Rz, []ring.R2, error)

Algorithm 27

func SigEncode

func SigEncode(cfg *params.Cfg, c []byte, z []ring.Rq, h []ring.R2) []byte

Algorithm 26

func SimpleBitPack

func SimpleBitPack(w ring.Rz, k uint8) []byte

Algorithm 16 Assumes that all coefficients are in the range 0 <= x < 2^k

func SimpleBitUnpack

func SimpleBitUnpack(b []byte, k uint8) (z ring.Rz)

Algorithm 18

func SubVector

func SubVector(v, w []ring.Rq) []ring.Rq

func SubVectorNTT

func SubVectorNTT(v, w []ring.Tq) []ring.Tq

This is implied by Algorithm 46, but needed for Verify_internal()

func UseHint

func UseHint(cfg *params.Cfg, h []ring.R2, r []ring.Rq) []ring.Rz

Algorithm 40 Not constant time - inputs and outputs are public

func W1Encode

func W1Encode(cfg *params.Cfg, w1 []ring.Rz) []byte

Algorithm 28 This is just SimpleBitPack with a precomputed per-paramset length

Types

This section is empty.

Jump to

Keyboard shortcuts

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