Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/signature/src/hazmat.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / signature / src / hazmat.rs` 70 lines · 2818 bytes Raw Blame History 1 //! Hazardous Materials: low-level APIs which can be insecure if misused. 2 //! 3 //! The traits in this module are not generally recommended, and should only be 4 //! used in special cases where they are specifically needed. 5 //! 6 //! Using them incorrectly can introduce security vulnerabilities. Please 7 //! carefully read the documentation before attempting to use them. 8 9 use crate::Error; 10 11 #[cfg(feature = "rand_core")] 12 use crate::rand_core::CryptoRngCore; 13 14 /// Sign the provided message prehash, returning a digital signature. 15 pub trait PrehashSigner { 16 /// Attempt to sign the given message digest, returning a digital signature 17 /// on success, or an error if something went wrong. 18 /// 19 /// The `prehash` parameter should be the output of a secure cryptographic 20 /// hash function. 21 /// 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. 25 /// 26 /// Allowed lengths are algorithm-dependent and up to a particular 27 /// implementation to decide. 28 fn sign_prehash(&self, prehash: &[u8]) -> Result; 29 } 30 31 /// Sign the provided message prehash using the provided external randomness source, returning a digital signature. 32 #[cfg(feature = "rand_core")] 33 pub trait RandomizedPrehashSigner { 34 /// Attempt to sign the given message digest, returning a digital signature 35 /// on success, or an error if something went wrong. 36 /// 37 /// The `prehash` parameter should be the output of a secure cryptographic 38 /// hash function. 39 /// 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. 43 /// 44 /// Allowed lengths are algorithm-dependent and up to a particular 45 /// implementation to decide. 46 fn sign_prehash_with_rng( 47 &self, 48 rng: &mut impl CryptoRngCore, 49 prehash: &[u8], 50 ) -> Result; 51 } 52 53 /// Verify the provided message prehash using `Self` (e.g. a public key) 54 pub trait PrehashVerifier { 55 /// Use `Self` to verify that the provided signature for a given message 56 /// `prehash` is authentic. 57 /// 58 /// The `prehash` parameter should be the output of a secure cryptographic 59 /// hash function. 60 /// 61 /// Returns `Error` if it is inauthentic or some other error occurred, or 62 /// otherwise returns `Ok(())`. 63 /// 64 /// # ⚠️ Security Warning 65 /// 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. 69 fn verify_prehash(&self, prehash: &[u8], signature: &S) -> Result<(), Error>; 70 }