package slhdsa

  1. Overview
  2. Docs

Module Slhdsa.Shake_256sSource

SLH-DSA-SHAKE-256s, as standardized by FIPS 205.

The SHAKE hash family at security level 256, so the security parameter n is 32 bytes. This is the small-signature (s) variant: smaller signatures and slower signing than SLH-DSA-SHAKE-256f.

Operations, randomness contract, and encodings are documented in the shared signature below.

Sourcetype nonrec error =
  1. | Invalid_length of {
    1. what : string;
    2. expected : int;
    3. actual : int;
    }
  2. | Invalid_encoding of string
  3. | Context_too_long of int
Sourceval pp_error : Format.formatter -> error -> unit

pp_error formats an error for humans.

Sourcetype signing_key
Sourcetype verification_key
Sourcetype signature
Sourceval seed_size : int

The size of a key-generation seed: 3 * n bytes.

Sourceval signing_key_size : int

The size of an encoded signing key: 4 * n bytes.

Sourceval verification_key_size : int

The size of an encoded verification key: 2 * n bytes.

Sourceval signature_size : int

The size of an encoded signature, in bytes.

Sourceval generate : random:(int -> string) -> unit -> signing_key * verification_key

generate ~random () creates a key pair from seed_size bytes obtained from random. It builds the top-level Merkle tree, which is markedly slower for the s parameter sets because their trees are taller.

Sourceval signing_key_of_seed : string -> (signing_key, error) result

signing_key_of_seed seed expands a seed_size-byte key-generation seed.

Sourceval signing_key_to_seed : signing_key -> string option

signing_key_to_seed key returns the seed_size-byte seed key was generated from, or None when key was imported with signing_key_of_octets and no seed is recoverable. The result is secret key material.

Sourceval signing_key_of_octets : string -> (signing_key, error) result

signing_key_of_octets octets parses the signing_key_size-byte encoding. It recomputes the top-level Merkle root and returns Invalid_encoding when the embedded root disagrees, so importing a key costs about as much as generating one.

Sourceval signing_key_to_octets : signing_key -> string

signing_key_to_octets key returns the encoded key. The result is secret key material.

Sourceval verification_key_of_signing_key : signing_key -> verification_key

verification_key_of_signing_key key extracts the public half of a key pair.

Sourceval verification_key_of_octets : string -> (verification_key, error) result

verification_key_of_octets octets checks the length only; a verification key carries nothing that can be validated on its own.

Sourceval verification_key_to_octets : verification_key -> string
Sourceval signature_of_octets : string -> (signature, error) result
Sourceval signature_to_octets : signature -> string
Sourceval sign : ?context:string -> random:(int -> string) -> signing_key -> message:string -> (signature, error) result

sign ?context ~random key ~message produces a hedged PureSLH-DSA signature, drawing n fresh bytes from random as the randomizer for this signature. Prefer it over sign_deterministic.

context defaults to "" and identifies the application's use of the signature. It is limited to 255 bytes by FIPS 205, and verification must supply the same value. A longer context returns Context_too_long.

Sourceval sign_deterministic : ?context:string -> signing_key -> message:string -> (signature, error) result

sign_deterministic ?context key ~message signs with the FIPS 205 deterministic variant, using the public key seed as the randomizer instead of fresh entropy. The same key, message, and context always yield the same signature. Key generation still requires secure randomness.

Sourceval verify : ?context:string -> verification_key -> message:string -> signature -> bool

verify ?context key ~message signature returns true only when signature is valid for message under key and the same context used when signing.