-
Notifications
You must be signed in to change notification settings - Fork 223
Description
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-Digest
s 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 update
s. 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