modular_frost/curve/
dalek.rs

1use digest::Digest;
2
3use dalek_ff_group::Scalar;
4
5use ciphersuite::Ciphersuite;
6
7use crate::{curve::Curve, algorithm::Hram};
8
9macro_rules! dalek_curve {
10  (
11    $feature: literal,
12
13    $Curve:      ident,
14    $Hram:       ident,
15
16    $CONTEXT: literal,
17    $chal: literal
18  ) => {
19    pub use ciphersuite::$Curve;
20
21    impl Curve for $Curve {
22      const CONTEXT: &'static [u8] = $CONTEXT;
23    }
24
25    /// The challenge function for this ciphersuite.
26    #[derive(Copy, Clone)]
27    pub struct $Hram;
28    impl Hram<$Curve> for $Hram {
29      #[allow(non_snake_case)]
30      fn hram(R: &<$Curve as Ciphersuite>::G, A: &<$Curve as Ciphersuite>::G, m: &[u8]) -> Scalar {
31        let mut hash = <$Curve as Ciphersuite>::H::new();
32        if $chal.len() != 0 {
33          hash.update(&[$CONTEXT.as_ref(), $chal].concat());
34        }
35        Scalar::from_hash(
36          hash.chain_update(&[&R.compress().to_bytes(), &A.compress().to_bytes(), m].concat()),
37        )
38      }
39    }
40  };
41}
42
43#[cfg(feature = "ristretto")]
44dalek_curve!("ristretto", Ristretto, IetfRistrettoHram, b"FROST-RISTRETTO255-SHA512-v1", b"chal");
45
46#[cfg(feature = "ed25519")]
47dalek_curve!("ed25519", Ed25519, IetfEd25519Hram, b"FROST-ED25519-SHA512-v1", b"");