Package mldsa
Overview ▸
Index ▸
Constants
const (
PrivateKeySize = 32
MLDSA44PublicKeySize = 1312
MLDSA65PublicKeySize = 1952
MLDSA87PublicKeySize = 2592
MLDSA44SignatureSize = 2420
MLDSA65SignatureSize = 3309
MLDSA87SignatureSize = 4627
)
func Verify
func Verify(pk *PublicKey, message []byte, signature []byte, opts *Options) error
Verify reports whether signature is a valid signature of message by pk. If opts is nil, it's equivalent to the zero value of Options.
type Options
Options contains additional options for signing and verifying ML-DSA signatures.
type Options struct {
// Context can be used to distinguish signatures created for different
// purposes. It must be at most 255 bytes long, and it is empty by default.
//
// The same context must be used when signing and verifying a signature.
Context string
}
func (*Options) HashFunc
func (opts *Options) HashFunc() crypto.Hash
HashFunc returns zero, to implement the crypto.SignerOpts interface.
type Parameters
Parameters represents one of the fixed parameter sets defined in FIPS 204.
Most applications should use MLDSA44.
Multiple invocations of MLDSA44, MLDSA65, or MLDSA87 will return the same respective value, which can be used for equality checks and switch statements. The returned value is safe for concurrent use.
type Parameters struct {
// contains filtered or unexported fields
}
func MLDSA44
func MLDSA44() Parameters
MLDSA44 returns the ML-DSA-44 parameter set defined in FIPS 204.
func MLDSA65
func MLDSA65() Parameters
MLDSA65 returns the ML-DSA-65 parameter set defined in FIPS 204.
func MLDSA87
func MLDSA87() Parameters
MLDSA87 returns the ML-DSA-87 parameter set defined in FIPS 204.
func (Parameters) PublicKeySize
func (params Parameters) PublicKeySize() int
PublicKeySize returns the size of public keys for this parameter set, in bytes.
func (Parameters) SignatureSize
func (params Parameters) SignatureSize() int
SignatureSize returns the size of signatures for this parameter set, in bytes.
func (Parameters) String
func (params Parameters) String() string
String returns the name of the parameter set, e.g. "ML-DSA-44".
type PrivateKey
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 {
// contains filtered or unexported fields
}
func GenerateKey
func GenerateKey(params Parameters) (*PrivateKey, error)
GenerateKey generates a new random ML-DSA private key.
func NewPrivateKey
func NewPrivateKey(params Parameters, seed []byte) (*PrivateKey, error)
NewPrivateKey decodes an ML-DSA private key from the given seed.
The seed must be exactly PrivateKeySize bytes long.
func (*PrivateKey) Bytes
func (sk *PrivateKey) Bytes() []byte
Bytes returns the private key seed.
func (*PrivateKey) Equal
func (sk *PrivateKey) Equal(x crypto.PrivateKey) bool
Equal reports whether sk and x are the same key (i.e. they are derived from the same seed).
If x is not a *PrivateKey, Equal returns false.
func (*PrivateKey) Public
func (sk *PrivateKey) Public() crypto.PublicKey
Public returns the corresponding PublicKey for this private key.
It implements the crypto.Signer interface.
func (*PrivateKey) PublicKey
func (sk *PrivateKey) PublicKey() *PublicKey
PublicKey returns the corresponding PublicKey for this private key.
func (*PrivateKey) Sign
func (sk *PrivateKey) Sign(_ io.Reader, message []byte, opts crypto.SignerOpts) (signature []byte, err error)
Sign returns a signature of the given message using this private key.
If opts is nil or opts.HashFunc returns zero, the message is signed directly. If opts.HashFunc returns crypto.MLDSAMu, the provided message must be a pre-hashed μ message representative. opts can be of type *Options if a context string is desired along with a directly-signed message. The io.Reader argument is ignored.
func (*PrivateKey) SignDeterministic
func (sk *PrivateKey) SignDeterministic(message []byte, opts crypto.SignerOpts) (signature []byte, err error)
SignDeterministic works like PrivateKey.Sign, but the signature is deterministic.
type PublicKey
PublicKey is an ML-DSA public key. It implements the informal extended crypto.PublicKey interface.
A PublicKey is safe for concurrent use.
type PublicKey struct {
// contains filtered or unexported fields
}
func NewPublicKey
func NewPublicKey(params Parameters, encoding []byte) (*PublicKey, error)
NewPublicKey creates a new ML-DSA public key from the given encoding.
func (*PublicKey) Bytes
func (pk *PublicKey) Bytes() []byte
Bytes returns the public key encoding.
func (*PublicKey) Equal
func (pk *PublicKey) Equal(x crypto.PublicKey) bool
Equal reports whether pk and x are the same key (i.e. they have the same encoding).
If x is not a *PublicKey, Equal returns false.
func (*PublicKey) Parameters
func (pk *PublicKey) Parameters() Parameters
Parameters returns the parameters associated with this public key.