11//! Hazardous Materials: low-level APIs which can be insecure if misused.
22//!
3- //! The traits in this module are not generally recommended, and should only be
4- //! used in special cases where they are specifically needed.
3+ //! The traits in this module are not generally recommended, and should only be used in special
4+ //! cases where they are specifically needed.
55//!
6- //! Using them incorrectly can introduce security vulnerabilities. Please
7- //! carefully read the documentation before attempting to use them.
6+ //! <div class = "warning">
7+ //! <b>Security Warning</b>
8+ //!
9+ //! Using these traits incorrectly can introduce security vulnerabilities. Please carefully read the
10+ //! documentation before attempting to use them.
11+ //! </div>
812
913use crate :: Error ;
1014
@@ -13,36 +17,38 @@ use crate::rand_core::TryCryptoRng;
1317
1418/// Sign the provided message prehash, returning a digital signature.
1519pub trait PrehashSigner < S > {
16- /// Attempt to sign the given message digest, returning a digital signature
17- /// on success, or an error if something went wrong.
20+ /// Attempt to sign the given message digest, returning a digital signature on success, or an
21+ /// error if something went wrong.
22+ ///
23+ /// The `prehash` parameter should be the output of a secure cryptographic hash function.
1824 ///
19- /// The `prehash` parameter should be the output of a secure cryptographic
20- /// hash function .
25+ /// This API takes a `prehash` byte slice as there can potentially be many compatible lengths
26+ /// for the message digest for a given concrete signature algorithm .
2127 ///
22- /// This API takes a `prehash` byte slice as there can potentially be many
23- /// compatible lengths for the message digest for a given concrete signature
24- /// algorithm.
28+ /// Allowed lengths are algorithm-dependent and up to a particular implementation to decide.
2529 ///
26- /// Allowed lengths are algorithm-dependent and up to a particular
27- /// implementation to decide .
30+ /// # Errors
31+ /// Returns [`Error`] in the event `prehash` is an invalid length .
2832 fn sign_prehash ( & self , prehash : & [ u8 ] ) -> Result < S , Error > ;
2933}
3034
31- /// Sign the provided message prehash using the provided external randomness source, returning a digital signature.
35+ /// Sign the provided message prehash using the provided external randomness source, returning a
36+ /// digital signature.
3237#[ cfg( feature = "rand_core" ) ]
3338pub trait RandomizedPrehashSigner < S > {
34- /// Attempt to sign the given message digest, returning a digital signature
35- /// on success, or an error if something went wrong.
39+ /// Attempt to sign the given message digest, returning a digital signature on success, or an
40+ /// error if something went wrong.
3641 ///
37- /// The `prehash` parameter should be the output of a secure cryptographic
38- /// hash function.
42+ /// The `prehash` parameter should be the output of a secure cryptographic hash function.
3943 ///
40- /// This API takes a `prehash` byte slice as there can potentially be many
41- /// compatible lengths for the message digest for a given concrete signature
42- /// algorithm.
44+ /// This API takes a `prehash` byte slice as there can potentially be many compatible lengths
45+ /// for the message digest for a given concrete signature algorithm.
4346 ///
44- /// Allowed lengths are algorithm-dependent and up to a particular
45- /// implementation to decide.
47+ /// Allowed lengths are algorithm-dependent and up to a particular implementation to decide.
48+ ///
49+ /// # Errors
50+ /// Returns [`Error`] in the event `prehash` is an invalid length, or if an internal error
51+ /// in the provided `rng` occurs.
4652 fn sign_prehash_with_rng < R : TryCryptoRng + ?Sized > (
4753 & self ,
4854 rng : & mut R ,
@@ -52,57 +58,54 @@ pub trait RandomizedPrehashSigner<S> {
5258
5359/// Verify the provided message prehash using `Self` (e.g. a public key)
5460pub trait PrehashVerifier < S > {
55- /// Use `Self` to verify that the provided signature for a given message
56- /// `prehash` is authentic.
61+ /// Use `Self` to verify that the provided signature for a given message `prehash` is authentic.
62+ ///
63+ /// The `prehash` parameter MUST be the output of a secure cryptographic hash function.
5764 ///
58- /// The `prehash` parameter should be the output of a secure cryptographic
59- /// hash function.
65+ /// <div class="warning">
66+ /// <b>Security Warning</b>
6067 ///
61- /// Returns `Error` if it is inauthentic or some other error occurred, or
62- /// otherwise returns `Ok(())`.
68+ /// If `prehash` is something other than the output of a cryptographically secure hash function,
69+ /// an attacker can potentially forge signatures by e.g. solving a system of linear equations.
70+ /// </div>
6371 ///
64- /// # ⚠️ Security Warning
72+ /// Returns `Ok(())` if the signature verified successfully.
6573 ///
66- /// If `prehash` is something other than the output of a cryptographically
67- /// secure hash function, an attacker can potentially forge signatures by
68- /// solving a system of linear equations .
74+ /// # Errors
75+ /// Returns [`Error`] in the event the signature fails to verify or if `prehash` is an invalid
76+ /// length .
6977 fn verify_prehash ( & self , prehash : & [ u8 ] , signature : & S ) -> Result < ( ) , Error > ;
7078}
7179
7280/// Asynchronously sign the provided message prehash, returning a digital signature.
7381#[ allow( async_fn_in_trait) ]
7482pub trait AsyncPrehashSigner < S > {
75- /// Attempt to sign the given message digest, returning a digital signature
76- /// on success, or an error if something went wrong.
83+ /// Attempt to sign the given message digest, returning a digital signature on success, or an
84+ /// error if something went wrong.
7785 ///
78- /// The `prehash` parameter should be the output of a secure cryptographic
79- /// hash function.
86+ /// The `prehash` parameter should be the output of a secure cryptographic hash function.
8087 ///
81- /// This API takes a `prehash` byte slice as there can potentially be many
82- /// compatible lengths for the message digest for a given concrete signature
83- /// algorithm.
88+ /// This API takes a `prehash` byte slice as there can potentially be many compatible lengths
89+ /// for the message digest for a given concrete signature algorithm.
8490 ///
85- /// Allowed lengths are algorithm-dependent and up to a particular
86- /// implementation to decide.
91+ /// Allowed lengths are algorithm-dependent and up to a particular implementation to decide.
8792 async fn sign_prehash_async ( & self , prehash : & [ u8 ] ) -> Result < S , Error > ;
8893}
8994
90- /// Asynchronously sign the provided message prehash using the provided external randomness source, returning a digital signature.
95+ /// Asynchronously sign the provided message prehash using the provided external randomness source,
96+ /// returning a digital signature.
9197#[ cfg( feature = "rand_core" ) ]
9298#[ allow( async_fn_in_trait) ]
9399pub trait AsyncRandomizedPrehashSigner < S > {
94- /// Attempt to sign the given message digest, returning a digital signature
95- /// on success, or an error if something went wrong.
100+ /// Attempt to sign the given message digest, returning a digital signature on success, or an
101+ /// error if something went wrong.
96102 ///
97- /// The `prehash` parameter should be the output of a secure cryptographic
98- /// hash function.
103+ /// The `prehash` parameter should be the output of a secure cryptographic hash function.
99104 ///
100- /// This API takes a `prehash` byte slice as there can potentially be many
101- /// compatible lengths for the message digest for a given concrete signature
102- /// algorithm.
105+ /// This API takes a `prehash` byte slice as there can potentially be many compatible lengths
106+ /// for the message digest for a given concrete signature algorithm.
103107 ///
104- /// Allowed lengths are algorithm-dependent and up to a particular
105- /// implementation to decide.
108+ /// Allowed lengths are algorithm-dependent and up to a particular implementation to decide.
106109 async fn sign_prehash_with_rng_async < R : TryCryptoRng + ?Sized > (
107110 & self ,
108111 rng : & mut R ,
0 commit comments