Trait Group

Source
pub trait Group {
    type Elem: ConstantTimeEq + Copy + Zeroize + for<'a> Add<&'a Self::Elem, Output = Self::Elem> + for<'a> Mul<&'a Self::Scalar, Output = Self::Elem>;
    type ElemLen: ArrayLength<u8> + 'static;
    type Scalar: ConstantTimeEq + Copy + Zeroize + for<'a> Add<&'a Self::Scalar, Output = Self::Scalar> + for<'a> Mul<&'a Self::Scalar, Output = Self::Scalar> + for<'a> Sub<&'a Self::Scalar, Output = Self::Scalar>;
    type ScalarLen: ArrayLength<u8> + 'static;

    // Required methods
    fn hash_to_curve<H>(
        input: &[&[u8]],
        dst: &[&[u8]],
    ) -> Result<Self::Elem, InternalError>
       where H: BlockSizeUser + Default + FixedOutput + HashMarker,
             H::OutputSize: IsLess<U256> + IsLessOrEqual<H::BlockSize>;
    fn hash_to_scalar<H>(
        input: &[&[u8]],
        dst: &[&[u8]],
    ) -> Result<Self::Scalar, InternalError>
       where H: BlockSizeUser + Default + FixedOutput + HashMarker,
             H::OutputSize: IsLess<U256> + IsLessOrEqual<H::BlockSize>;
    fn base_elem() -> Self::Elem;
    fn identity_elem() -> Self::Elem;
    fn serialize_elem(elem: Self::Elem) -> GenericArray<u8, Self::ElemLen>;
    fn deserialize_elem(element_bits: &[u8]) -> Result<Self::Elem>;
    fn random_scalar<R: RngCore + CryptoRng>(rng: &mut R) -> Self::Scalar;
    fn invert_scalar(scalar: Self::Scalar) -> Self::Scalar;
    fn is_zero_scalar(scalar: Self::Scalar) -> Choice;
    fn serialize_scalar(
        scalar: Self::Scalar,
    ) -> GenericArray<u8, Self::ScalarLen>;
    fn deserialize_scalar(scalar_bits: &[u8]) -> Result<Self::Scalar>;

    // Provided method
    fn is_identity_elem(elem: Self::Elem) -> Choice { ... }
}
Expand description

A prime-order subgroup of a base field (EC, prime-order field …). This subgroup is noted additively — as in the RFC — in this trait.

Required Associated Types§

Source

type Elem: ConstantTimeEq + Copy + Zeroize + for<'a> Add<&'a Self::Elem, Output = Self::Elem> + for<'a> Mul<&'a Self::Scalar, Output = Self::Elem>

The type of group elements

Source

type ElemLen: ArrayLength<u8> + 'static

The byte length necessary to represent group elements

Source

type Scalar: ConstantTimeEq + Copy + Zeroize + for<'a> Add<&'a Self::Scalar, Output = Self::Scalar> + for<'a> Mul<&'a Self::Scalar, Output = Self::Scalar> + for<'a> Sub<&'a Self::Scalar, Output = Self::Scalar>

The type of base field scalars

Source

type ScalarLen: ArrayLength<u8> + 'static

The byte length necessary to represent scalars

Required Methods§

Source

fn hash_to_curve<H>( input: &[&[u8]], dst: &[&[u8]], ) -> Result<Self::Elem, InternalError>

Transforms a password and domain separation tag (DST) into a curve point

§Errors

Error::Input if the input is empty or longer then u16::MAX.

Source

fn hash_to_scalar<H>( input: &[&[u8]], dst: &[&[u8]], ) -> Result<Self::Scalar, InternalError>

Hashes a slice of pseudo-random bytes to a scalar

§Errors

Error::Input if the input is empty or longer then u16::MAX.

Source

fn base_elem() -> Self::Elem

Get the base point for the group

Source

fn identity_elem() -> Self::Elem

Returns the identity group element

Source

fn serialize_elem(elem: Self::Elem) -> GenericArray<u8, Self::ElemLen>

Serializes the self group element

Source

fn deserialize_elem(element_bits: &[u8]) -> Result<Self::Elem>

Return an element from its fixed-length bytes representation. If the element is the identity element, return an error.

§Errors

Error::Deserialization if the element is not a valid point on the group or the identity element.

Source

fn random_scalar<R: RngCore + CryptoRng>(rng: &mut R) -> Self::Scalar

picks a scalar at random

Source

fn invert_scalar(scalar: Self::Scalar) -> Self::Scalar

The multiplicative inverse of this scalar

Source

fn is_zero_scalar(scalar: Self::Scalar) -> Choice

Returns true if the scalar is zero.

Source

fn serialize_scalar(scalar: Self::Scalar) -> GenericArray<u8, Self::ScalarLen>

Serializes a scalar to bytes

Source

fn deserialize_scalar(scalar_bits: &[u8]) -> Result<Self::Scalar>

Return a scalar from its fixed-length bytes representation. If the scalar is zero or invalid, then return an error.

§Errors

Error::Deserialization if the scalar is not a valid point on the group or zero.

Provided Methods§

Source

fn is_identity_elem(elem: Self::Elem) -> Choice

Returns true if the element is equal to the identity element

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.

Implementors§