Skip to content

Commit

Permalink
async-signature: adds hazmat::AsyncPrehashSigner
Browse files Browse the repository at this point in the history
  • Loading branch information
baloo committed Dec 2, 2024
1 parent 8bb3381 commit 7eec720
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
53 changes: 53 additions & 0 deletions async-signature/src/hazmat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//! Hazardous Materials: low-level APIs which can be insecure if misused.
//!
//! The traits in this module are not generally recommended, and should only be
//! used in special cases where they are specifically needed.
//!
//! Using them incorrectly can introduce security vulnerabilities. Please
//! carefully read the documentation before attempting to use them.
use signature::Error;

#[cfg(feature = "rand_core")]
use signature::rand_core::CryptoRngCore;

/// Asynchronously sign the provided message prehash, returning a digital signature.
#[allow(async_fn_in_trait)]
pub trait AsyncPrehashSigner<S> {
/// Attempt to sign the given message digest, returning a digital signature
/// on success, or an error if something went wrong.
///
/// The `prehash` parameter should be the output of a secure cryptographic
/// hash function.
///
/// This API takes a `prehash` byte slice as there can potentially be many
/// compatible lengths for the message digest for a given concrete signature
/// algorithm.
///
/// Allowed lengths are algorithm-dependent and up to a particular
/// implementation to decide.
async fn sign_prehash_async(&self, prehash: &[u8]) -> Result<S, Error>;
}

/// Asynchronously sign the provided message prehash using the provided external randomness source, returning a digital signature.
#[cfg(feature = "rand_core")]
#[allow(async_fn_in_trait)]
pub trait AsyncRandomizedPrehashSigner<S> {
/// Attempt to sign the given message digest, returning a digital signature
/// on success, or an error if something went wrong.
///
/// The `prehash` parameter should be the output of a secure cryptographic
/// hash function.
///
/// This API takes a `prehash` byte slice as there can potentially be many
/// compatible lengths for the message digest for a given concrete signature
/// algorithm.
///
/// Allowed lengths are algorithm-dependent and up to a particular
/// implementation to decide.
async fn sign_prehash_with_rng_async(
&self,
rng: &mut impl CryptoRngCore,
prehash: &[u8],
) -> Result<S, Error>;
}
2 changes: 2 additions & 0 deletions async-signature/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
missing_debug_implementations
)]

pub mod hazmat;

pub use signature::{self, Error};

#[cfg(feature = "digest")]
Expand Down

0 comments on commit 7eec720

Please sign in to comment.