dilithium

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// SeedSize is the number of bytes required for Dilithium seed material.
	SeedSize = 32

	// Public/secret key and signature sizes for the NIST-standardised ML-DSA
	// (Dilithium) parameter sets. These values mirror the definitions in
	// FIPS 204 / ML-DSA round 3.
	PublicKeySize44 = 1312
	SecretKeySize44 = 2528
	SignatureSize44 = 2420
	PublicKeySize65 = 1952
	SecretKeySize65 = 4000
	SignatureSize65 = 3293
	PublicKeySize87 = 2592
	SecretKeySize87 = 4864
	SignatureSize87 = 4595
)

Internal Dilithium constants shared across all parameter sets.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mat

type Mat []Vec

Mat is used to hold the matrix A

type Poly

type Poly [n]int32

Poly represents a polynomial of deg n with coefs in [0, Q)

type PrivateKey

type PrivateKey struct {
	S1  Vec
	S2  Vec
	Rho [SeedSize]byte
	Key [SeedSize]byte
	Tr  [SeedSize]byte
	T0  Vec
}

PrivateKey represents the packed secret key structure.

type PublicKey

type PublicKey struct {
	T1  Vec
	Rho [SeedSize]byte
}

PublicKey holds the expanded public key components (t1, rho).

type Scheme

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

Scheme captures a concrete Dilithium / ML-DSA parameter set together with whether the signer operates in deterministic (false) or randomized (true) mode as defined in FIPS 204.

func NewDilithium2

func NewDilithium2(randomized ...bool) *Scheme

NewDilithium2, NewDilithium3 and NewDilithium5 keep parity with the legacy naming used by the original reference implementations.

func NewDilithium3

func NewDilithium3(randomized ...bool) *Scheme

func NewDilithium5

func NewDilithium5(randomized ...bool) *Scheme

func NewMLDSA44

func NewMLDSA44(randomized ...bool) *Scheme

NewMLDSA44 returns the ML-DSA-44 (Dilithium-2) parameter set. By default the signer operates in randomized mode; pass randomized=false to force the deterministic variant.

func NewMLDSA65

func NewMLDSA65(randomized ...bool) *Scheme

NewMLDSA65 returns the ML-DSA-65 (Dilithium-3) parameter set.

func NewMLDSA87

func NewMLDSA87(randomized ...bool) *Scheme

NewMLDSA87 returns the ML-DSA-87 (Dilithium-5) parameter set.

func (*Scheme) GenerateKey

func (s *Scheme) GenerateKey(seed []byte) ([]byte, []byte, error)

GenerateKey returns packed public/secret key material. When seed is nil a fresh SeedSize-byte seed is sampled from crypto/rand. Providing a custom seed is primarily useful for deterministic test vectors.

func (*Scheme) Name

func (s *Scheme) Name() string

Name returns the human-readable identifier for the scheme (ML-DSA-XX).

func (*Scheme) PackSig

func (d *Scheme) PackSig(z Vec, h Vec, hc []byte) []byte

PackSig packs a dilithium signature into a byte array

func (*Scheme) PublicKeySize

func (s *Scheme) PublicKeySize() int

PublicKeySize returns the packed public key length in bytes.

func (*Scheme) Randomized

func (s *Scheme) Randomized() bool

Randomized returns true if the signer operates in randomized mode.

func (*Scheme) SecretKeySize

func (s *Scheme) SecretKeySize() int

SecretKeySize returns the packed secret key length in bytes.

func (*Scheme) Sign

func (s *Scheme) Sign(sk []byte, msg []byte) ([]byte, error)

Sign produces a packed Dilithium signature over msg using the packed secret key encoded in sk.

func (*Scheme) SignatureSize

func (s *Scheme) SignatureSize() int

SignatureSize returns the packed signature length in bytes.

func (*Scheme) UnpackSig

func (d *Scheme) UnpackSig(sig []byte) (Vec, Vec, []byte)

UnpackSig unpacks a byte array into a signature. If the format is incorrect, nil objects are returned.

func (*Scheme) Verify

func (s *Scheme) Verify(pk []byte, msg []byte, sig []byte) bool

Verify reports whether sig is a valid Dilithium signature on msg under the packed public key pk.

func (*Scheme) WithRandomized

func (s *Scheme) WithRandomized(randomized bool) *Scheme

WithRandomized toggles the signing mode for the receiver and returns the mutated scheme for convenience.

type Vec

type Vec []Poly

Vec holds L or K polynomials

Jump to

Keyboard shortcuts

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