Documentation
¶
Overview ¶
Package slhdsa provides Stateless Hash-based Digital Signature Algorithm.
This package is compliant with FIPS 205 and the ID represents the following parameter sets:
Category 1
- Based on SHA2: SHA2_128s and SHA2_128f.
- Based on SHAKE: SHAKE_128s and SHAKE_128f.
Category 3
- Based on SHA2: SHA2_192s and SHA2_192f
- Based on SHAKE: SHAKE_192s and SHAKE_192f
Category 5
- Based on SHA2: SHA2_256s and SHA2_256f.
- Based on SHAKE: SHAKE_256s and SHAKE_256f.
Index ¶
- Variables
- func GenerateKey(random io.Reader, id ID) (pub PublicKey, priv PrivateKey, err error)
- func SignDeterministic(priv *PrivateKey, message *Message, context []byte) (signature []byte, err error)
- func SignRandomized(priv *PrivateKey, random io.Reader, message *Message, context []byte) (signature []byte, err error)
- func Verify(key *PublicKey, message *Message, signature, context []byte) bool
- type ID
- type Message
- type PreHash
- type PrivateKey
- func (k PrivateKey) Equal(x crypto.PrivateKey) bool
- func (k PrivateKey) Marshal(b *cryptobyte.Builder) error
- func (k PrivateKey) MarshalBinary() ([]byte, error)
- func (k PrivateKey) Public() crypto.PublicKey
- func (k PrivateKey) PublicKey() (pub PublicKey)
- func (k PrivateKey) Sign(random io.Reader, message []byte, _ crypto.SignerOpts) (signature []byte, err error)
- func (k *PrivateKey) Unmarshal(s *cryptobyte.String) bool
- func (k *PrivateKey) UnmarshalBinary(b []byte) error
- type PublicKey
Constants ¶
This section is empty.
Variables ¶
var ( ErrContext = errors.New("sign/slhdsa: context is larger than 255 bytes") ErrMsgLen = errors.New("sign/slhdsa: invalid message length") ErrParam = errors.New("sign/slhdsa: invalid SLH-DSA parameter") ErrPreHash = errors.New("sign/slhdsa: invalid prehash function") ErrSigParse = errors.New("sign/slhdsa: failed to decode the signature") ErrTree = errors.New("sign/slhdsa: invalid tree height or tree index") ErrWriting = errors.New("sign/slhdsa: failed to write to a hash function") )
Functions ¶
func GenerateKey ¶
GenerateKey returns a pair of keys using the parameter set specified. It returns an error if it fails reading from the random source.
func SignDeterministic ¶
func SignDeterministic( priv *PrivateKey, message *Message, context []byte, ) (signature []byte, err error)
SignDeterministic returns the signature of the message with the specified context.
func SignRandomized ¶
func SignRandomized( priv *PrivateKey, random io.Reader, message *Message, context []byte, ) (signature []byte, err error)
SignRandomized returns a random signature of the message with the specified context. It returns an error if it fails reading from the random source.
Types ¶
type ID ¶
type ID byte
ID identifies the supported parameter sets of SLH-DSA. Note that the zero value is not a valid identifier.
const ( SHA2_128s ID = iota + 1 // SLH-DSA-SHA2-128s SHAKE_128s // SLH-DSA-SHAKE-128s SHA2_128f // SLH-DSA-SHA2-128f SHAKE_128f // SLH-DSA-SHAKE-128f SHA2_192s // SLH-DSA-SHA2-192s SHAKE_192s // SLH-DSA-SHAKE-192s SHA2_192f // SLH-DSA-SHA2-192f SHAKE_192f // SLH-DSA-SHAKE-192f SHA2_256s // SLH-DSA-SHA2-256s SHAKE_256s // SLH-DSA-SHAKE-256s SHA2_256f // SLH-DSA-SHA2-256f SHAKE_256f // SLH-DSA-SHAKE-256f )
func IDByName ¶
IDByName returns the ID that corresponds to the given name, or an error if no parameter set was found. See ID documentation for the specific names of each parameter set. Names are case insensitive.
Example:
IDByName("SLH-DSA-SHAKE-256s") // returns (SHAKESmall256, nil)
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
Message wraps a message for signing.
func NewMessage ¶
For pure signatures, use NewMessage to pass the message to be signed. For pre-hashed signatures, use PreHash to hash the message first, and then use PreHash.BuildMessage to get a Message to be signed.
type PreHash ¶
type PreHash struct {
// contains filtered or unexported fields
}
PreHash is a helper for hashing a message before signing. It implements the io.Writer interface, so the message can be provided in chunks before calling the SignDeterministic, SignRandomized, or Verify functions. Pre-hash must not be used for generating pure signatures.
func NewPreHashWithHash ¶
NewPreHashWithHash is used to prehash messages using either the SHA2 or SHA3 hash functions. Returns ErrPreHash if the function is not supported.
func NewPreHashWithXof ¶
NewPreHashWithXof is used to prehash messages using either SHAKE-128 or SHAKE-256. Returns ErrPreHash if the function is not supported.
func (*PreHash) BuildMessage ¶
BuildMessage returns a Message for signing, and resets the writer.
type PrivateKey ¶
type PrivateKey struct {
ID
// contains filtered or unexported fields
}
PrivateKey stores a private key of the SLH-DSA scheme. It implements the crypto.Signer and crypto.PrivateKey interfaces. For serialization, it also implements cryptobyte.MarshalingValue, encoding.BinaryMarshaler, and encoding.BinaryUnmarshaler.
func (PrivateKey) Equal ¶
func (k PrivateKey) Equal(x crypto.PrivateKey) bool
func (PrivateKey) Marshal ¶
func (k PrivateKey) Marshal(b *cryptobyte.Builder) error
Marshal serializes the key using a cryptobyte.Builder.
func (PrivateKey) MarshalBinary ¶
func (k PrivateKey) MarshalBinary() ([]byte, error)
func (PrivateKey) Public ¶
func (k PrivateKey) Public() crypto.PublicKey
func (PrivateKey) PublicKey ¶
func (k PrivateKey) PublicKey() (pub PublicKey)
func (PrivateKey) Sign ¶
func (k PrivateKey) Sign( random io.Reader, message []byte, _ crypto.SignerOpts, ) (signature []byte, err error)
PrivateKey.Sign returns a randomized signature of the message with an empty context. Any parameter passed in crypto.SignerOpts is discarded. It returns an error if it fails reading from the random source.
func (*PrivateKey) Unmarshal ¶
func (k *PrivateKey) Unmarshal(s *cryptobyte.String) bool
Unmarshal recovers a PrivateKey from a cryptobyte.String. Caller must specify the private key's ID in advance. Example:
key := PrivateKey{ID: SHA2Small192}
key.Unmarshal(str) // returns true
func (*PrivateKey) UnmarshalBinary ¶
func (k *PrivateKey) UnmarshalBinary(b []byte) error
UnmarshalBinary recovers a PrivateKey from a slice of bytes. Caller must specify the private key's ID in advance. Example:
key := PrivateKey{ID: SHA2Small192}
key.UnmarshalBinary(bytes) // returns nil
type PublicKey ¶
type PublicKey struct {
ID
// contains filtered or unexported fields
}
PublicKey stores a public key of the SLH-DSA scheme. It implements the crypto.PublicKey interface. For serialization, it also implements cryptobyte.MarshalingValue, encoding.BinaryMarshaler, and encoding.BinaryUnmarshaler.
func (PublicKey) Marshal ¶
func (k PublicKey) Marshal(b *cryptobyte.Builder) error
Marshal serializes the key using a cryptobyte.Builder.
func (PublicKey) MarshalBinary ¶
func (*PublicKey) Unmarshal ¶
func (k *PublicKey) Unmarshal(s *cryptobyte.String) bool
Unmarshal recovers a PublicKey from a cryptobyte.String. Caller must specify the public key's ID in advance. Example:
key := PublicKey{ID: SHA2Small192}
key.Unmarshal(str) // returns true