Skip to main content

defuse_crypto/
curve.rs

1/// Digital Signature Algorithm.
2pub trait Curve {
3    /// Public key
4    type PublicKey;
5
6    /// Signature
7    type Signature;
8
9    /// Verify the signature over the message for given public key
10    ///
11    /// NOTE: implementations MAY require `msg` to be prehash (i.e. output
12    /// of cryptographic hash function) of a fixed length and reject
13    /// the signature otherwise. Check corresponding docs before using.
14    fn verify(public_key: &Self::PublicKey, msg: &[u8], signature: &Self::Signature) -> bool;
15}
16
17/// A recoverable [curve](Curve).
18pub trait RecoverableCurve: Curve {
19    /// An additional information required to [recover](Self::recover)
20    /// the public key.
21    type RecoveryId;
22
23    /// Try to recover [public key](Curve::PublicKey) which signed given
24    /// message and produced given signature along with a
25    /// [recovery id](Self::RecoveryId)
26    ///
27    /// NOTE: implementations MAY require `msg` to be prehash (i.e. output
28    /// of cryptographic hash function) of a fixed length and reject
29    /// the signature otherwise. Check corresponding docs before using.
30    fn recover(
31        msg: &[u8],
32        signature: &Self::Signature,
33        recovery_id: Self::RecoveryId,
34    ) -> Option<Self::PublicKey>;
35}