Skip to content

signature: change DigestSigner/DigestVerifier to be ML-DSA "external mu" compatible? #2003

@tarcieri

Description

@tarcieri

Originally signature had DigestSigner/DigestVerifier traits then added hazmat::{PrehashSigner, PrehashVerifier} trait. The original goal of the DigestSigner/DigestVerifier traits was to leverage type safety to ensure that the input is always a hash. We later added the prehash traits out of necessity, especially observing people utilizing hacks like impl'ing pseudo-Digests that emit the hash to work around the constraints of the API in environments where prehashes were being used but computed significantly earlier than the signature function.

The two traits end up being quite similar to the point I've thought about removing DigestSigner/DigestVerifier due to the overlap, which would decouple signature from the digest crate entirely. But instead of that, I think we can do a slight tweak to the API which would make it possible to impl these traits (but not hazmat::{PrehashSigner, PrehashVerifier}), in an ML-DSA external mu-compatible way. Here's a simplified version:

pub trait DigestSigner<D: Digest, S> {
    fn sign_digest<F: Fn(&mut D)>(&self, f: F) -> S;
}

...so instead of DigestSigner and DigestVerifier taking a user-supplied digest instance as they do today, the signer/verifier type which impls this trait instead initializes the provided Digest type themselves, then supply it to a callback function which is expected to perform a series of updates. This means the initialization can include hashing a leading message prefix, which is what's needed to implement an IUF-like API for external mu.

Such an API should work for all existing users of the signature::Digest* traits as well as ML-DSA.

cc @daxpedda

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions