Skip to content

signature: add MultipartSigner and MultipartVerifier #1880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions signature/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ pub trait Signer<S> {
fn try_sign(&self, msg: &[u8]) -> Result<S, Error>;
}

/// Equivalent of [`Signer`] but the message is provided in non-contiguous byte slices.
pub trait MultiPartSigner<S> {
/// See [`Signer::sign()`].
fn multi_part_sign(&self, msg: &[&[u8]]) -> S {
self.try_multi_part_sign(msg)
.expect("signature operation failed")
}

/// See [`Signer::try_sign()`].
fn try_multi_part_sign(&self, msg: &[&[u8]]) -> Result<S, Error>;
}

/// Sign the provided message bytestring using `&mut Self` (e.g. an evolving
/// cryptographic key such as a stateful hash-based signature), returning a
/// digital signature.
Expand Down Expand Up @@ -103,6 +115,23 @@ pub trait RandomizedSigner<S> {
) -> Result<S, Error>;
}

/// Equivalent of [`RandomizedSigner`] but the message is provided in non-contiguous byte slices.
#[cfg(feature = "rand_core")]
pub trait RandomizedMultiPartSigner<S> {
/// See [`RandomizedSigner::sign_with_rng()`].
fn multi_part_sign_with_rng<R: CryptoRng + ?Sized>(&self, rng: &mut R, msg: &[&[u8]]) -> S {
self.try_multi_part_sign_with_rng(rng, msg)
.expect("signature operation failed")
}

/// See [`RandomizedSigner::try_sign_with_rng()`].
fn try_multi_part_sign_with_rng<R: TryCryptoRng + ?Sized>(
&self,
rng: &mut R,
msg: &[&[u8]],
) -> Result<S, Error>;
}

/// Combination of [`DigestSigner`] and [`RandomizedSigner`] with support for
/// computing a signature over a digest which requires entropy from an RNG.
#[cfg(all(feature = "digest", feature = "rand_core"))]
Expand Down
6 changes: 6 additions & 0 deletions signature/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ pub trait Verifier<S> {
fn verify(&self, msg: &[u8], signature: &S) -> Result<(), Error>;
}

/// Equivalent of [`Verifier`] but the message is provided in non-contiguous byte slices.
pub trait MultiPartVerifier<S> {
/// See [`Verifier::verify()`].
fn multi_part_verify(&self, msg: &[&[u8]], signature: &S) -> Result<(), Error>;
}

/// Verify the provided signature for the given prehashed message [`Digest`]
/// is authentic.
///
Expand Down