golang/go · error
mldsa: invalid parameters
Error message
mldsa: invalid parameters
What it means
Returned by mldsa.GenerateKey (in the real, v1.26 implementation) when params does not match MLDSA44(), MLDSA65(), or MLDSA87(). The switch only handles the three NIST FIPS 204 parameter sets; the default branch returns errInvalidParameters. The Parameters type is comparable via switch, so a zero-value or hand-constructed Parameters falls through to default.
Source
Thrown at src/crypto/mldsa/mldsa_fips140v1.26.go:24
package mldsa
import (
"crypto"
"crypto/internal/fips140/mldsa"
"errors"
"io"
)
// PrivateKey is an in-memory ML-DSA private key. It implements [crypto.Signer]
// and the informal extended [crypto.PrivateKey] interface.
//
// A PrivateKey is safe for concurrent use.
type PrivateKey struct {
k mldsa.PrivateKey
}
var errInvalidParameters = errors.New("mldsa: invalid parameters")
// GenerateKey generates a new random ML-DSA private key.
func GenerateKey(params Parameters) (*PrivateKey, error) {
switch params {
case MLDSA44():
return &PrivateKey{k: *mldsa.GenerateKey44()}, nil
case MLDSA65():
return &PrivateKey{k: *mldsa.GenerateKey65()}, nil
case MLDSA87():
return &PrivateKey{k: *mldsa.GenerateKey87()}, nil
default:
return nil, errInvalidParameters
}
}
// NewPrivateKey decodes an ML-DSA private key from the given seed.
//
// The seed must be exactly [PrivateKeySize] bytes long.View on GitHub (pinned to b6b368adc5)
Solutions
- Always use the package-provided constructors: mldsa.MLDSA44(), mldsa.MLDSA65(), or mldsa.MLDSA87().
- If reading the parameter set from config, map the string ('ML-DSA-44' etc.) to the constructor explicitly and reject unknown values.
- Add a unit test that asserts every code path passes one of the three constants into GenerateKey.
- Validate params before calling GenerateKey (see validationCode below).
Example fix
// before var params mldsa.Parameters // zero value _, err := mldsa.GenerateKey(params) // -> errInvalidParameters // after _, err := mldsa.GenerateKey(mldsa.MLDSA65())
Defensive patterns
Strategy: validation
Validate before calling
func validMLDSAParams(p mldsa.Parameters) bool {
switch p {
case mldsa.MLDSA44(), mldsa.MLDSA65(), mldsa.MLDSA87():
return true
}
return false
}
if !validMLDSAParams(params) {
return errors.New("params must be MLDSA44, MLDSA65, or MLDSA87")
} Prevention
- Always pass a constructor result (MLDSA44/MLDSA65/MLDSA87) — never a zero-value or hand-built Parameters.
- When reading the parameter set from config, map the string to a constructor explicitly.
- Unit-test that every GenerateKey call site uses one of the three constants.
When it happens
Trigger: Calling GenerateKey with the zero value of Parameters (params := mldsa.Parameters{}), with a Parameters value hand-constructed by filling struct fields instead of using a constructor, or with a value returned from a future/extra parameter set not yet supported.
Common situations: Declaring a Parameters variable and forgetting to initialize it; deserializing a Parameters from a config file whose value does not exactly equal one of the three predefined sets; passing a parameter set constant from a different ML-DSA package version.
Related errors
- mldsa: unavailable in FIPS 140-3 Go Cryptographic Module v1.
- mldsa: invalid seed length
- mldsa: invalid public key length
- mldsa: context too long
- mldsa: invalid message hash length
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/2b1b3569a4a3a04e.
Report an issue: GitHub.