diff options
author | Tony Arcieri <bascule@gmail.com> | 2022-01-22 16:49:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-22 16:49:27 -0700 |
commit | fc208141e214d9495585039f64d1911c9de21576 (patch) | |
tree | 021c7e0c9ef55c838d0ea9974e39906c9bf99060 /spake2/src/group.rs | |
parent | 807246b45c9df09c4fab0a36f2148b2b0a0fc992 (diff) | |
download | PAKEs-fc208141e214d9495585039f64d1911c9de21576.tar.xz |
spake2: refactor internals (#91)
Splits the crate apart into multiple modules
Diffstat (limited to 'spake2/src/group.rs')
-rw-r--r-- | spake2/src/group.rs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/spake2/src/group.rs b/spake2/src/group.rs new file mode 100644 index 0000000..2379553 --- /dev/null +++ b/spake2/src/group.rs @@ -0,0 +1,58 @@ +//! Group trait. + +use alloc::vec::Vec; +use rand_core::{CryptoRng, RngCore}; + +/// Group trait. +// TODO(tarcieri): replace with `group` crate? +pub trait Group { + /// Scalar element + type Scalar; + + /// Base field element + type Element; + + /// Transcript hash + type TranscriptHash; + + /// Name + fn name() -> &'static str; + + /// `m` constant + fn const_m() -> Self::Element; + + /// `n` constant + fn const_n() -> Self::Element; + + /// `s` constant + fn const_s() -> Self::Element; + + /// Hash to scalar + fn hash_to_scalar(s: &[u8]) -> Self::Scalar; + + /// Generate a random scalar + fn random_scalar<T>(cspring: &mut T) -> Self::Scalar + where + T: RngCore + CryptoRng; + + /// Scalar negation + fn scalar_neg(s: &Self::Scalar) -> Self::Scalar; + + /// Convert base field element to bytes + fn element_to_bytes(e: &Self::Element) -> Vec<u8>; + + /// Convert bytes to base field element + fn bytes_to_element(b: &[u8]) -> Option<Self::Element>; + + /// Length of a base field element + fn element_length() -> usize; + + /// Fixed-base scalar multiplication + fn basepoint_mult(s: &Self::Scalar) -> Self::Element; + + /// Variable-base scalar multiplication + fn scalarmult(e: &Self::Element, s: &Self::Scalar) -> Self::Element; + + /// Group operation + fn add(a: &Self::Element, b: &Self::Element) -> Self::Element; +} |