spake2/
group.rs

1//! Group trait.
2
3use alloc::vec::Vec;
4use rand_core::{CryptoRng, RngCore};
5
6/// Group trait.
7// TODO(tarcieri): replace with `group` crate?
8pub trait Group {
9    /// Scalar element
10    type Scalar;
11
12    /// Base field element
13    type Element;
14
15    /// Transcript hash
16    type TranscriptHash;
17
18    /// Name
19    fn name() -> &'static str;
20
21    /// `m` constant
22    fn const_m() -> Self::Element;
23
24    /// `n` constant
25    fn const_n() -> Self::Element;
26
27    /// `s` constant
28    fn const_s() -> Self::Element;
29
30    /// Hash to scalar
31    fn hash_to_scalar(s: &[u8]) -> Self::Scalar;
32
33    /// Generate a random scalar
34    fn random_scalar<T>(cspring: &mut T) -> Self::Scalar
35    where
36        T: RngCore + CryptoRng;
37
38    /// Scalar negation
39    fn scalar_neg(s: &Self::Scalar) -> Self::Scalar;
40
41    /// Convert base field element to bytes
42    fn element_to_bytes(e: &Self::Element) -> Vec<u8>;
43
44    /// Convert bytes to base field element
45    fn bytes_to_element(b: &[u8]) -> Option<Self::Element>;
46
47    /// Length of a base field element
48    fn element_length() -> usize;
49
50    /// Fixed-base scalar multiplication
51    fn basepoint_mult(s: &Self::Scalar) -> Self::Element;
52
53    /// Variable-base scalar multiplication
54    fn scalarmult(e: &Self::Element, s: &Self::Scalar) -> Self::Element;
55
56    /// Group operation
57    fn add(a: &Self::Element, b: &Self::Element) -> Self::Element;
58}