hopr_crypto_sphinx::shared_keys

Trait GroupElement

Source
pub trait GroupElement<E: Scalar>: Clone + for<'a> Mul<&'a E, Output = Self> {
    type AlphaLen: ArrayLength<u8>;

    // Required methods
    fn to_alpha(&self) -> Alpha<Self::AlphaLen>;
    fn from_alpha(alpha: Alpha<Self::AlphaLen>) -> Result<Self>;
    fn generate(scalar: &E) -> Self;
    fn is_valid(&self) -> bool;

    // Provided methods
    fn random_pair() -> (Self, E) { ... }
    fn extract_key(&self, salt: &[u8]) -> SharedSecret { ... }
    fn expand_key(&self, salt: &[u8]) -> SharedSecret { ... }
}
Expand description

Generic additive abelian group element with an associated scalar type. It also comes with the associated Alpha value size. A group element is considered valid if it is not neutral or a torsion element of small order.

Required Associated Types§

Source

type AlphaLen: ArrayLength<u8>

Length of the Alpha value - a binary representation of the group element.

Required Methods§

Source

fn to_alpha(&self) -> Alpha<Self::AlphaLen>

Converts the group element to a binary format suitable for representing the Alpha value.

Source

fn from_alpha(alpha: Alpha<Self::AlphaLen>) -> Result<Self>

Converts the group element from the binary format representing an Alpha value.

Source

fn generate(scalar: &E) -> Self

Create a group element using the group generator and the given scalar

Source

fn is_valid(&self) -> bool

Group element is considered valid if it is not a neutral element and also not a torsion element of small order.

Provided Methods§

Source

fn random_pair() -> (Self, E)

Generates a random pair of group element and secret scalar. This is a convenience method that internally calls the random method of the associated Scalar and constructs the group element using generate.

Source

fn extract_key(&self, salt: &[u8]) -> SharedSecret

Extract a keying material from a group element using HKDF extract

Source

fn expand_key(&self, salt: &[u8]) -> SharedSecret

Performs KDF expansion from the given group element using HKDF expand

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl GroupElement<Scalar> for MontgomeryPoint

Source§

type AlphaLen = UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>

Source§

fn to_alpha(&self) -> Alpha<U32>

Source§

fn from_alpha(alpha: Alpha<U32>) -> Result<Self>

Source§

fn generate(scalar: &Scalar) -> Self

Source§

fn is_valid(&self) -> bool

Implementors§