Field

Trait Field 

Source
pub trait Field: Copy + Clone {
    type Scalar: Add<Output = Self::Scalar> + Copy + Clone + Eq + Mul<Output = Self::Scalar> + PartialEq + Sub<Output = Self::Scalar>;
    type Serialization: AsRef<[u8]> + Debug + TryFrom<Vec<u8>>;

    // Required methods
    fn zero() -> Self::Scalar;
    fn one() -> Self::Scalar;
    fn invert(scalar: &Self::Scalar) -> Result<Self::Scalar, FieldError>;
    fn random<R: RngCore + CryptoRng>(rng: &mut R) -> Self::Scalar;
    fn serialize(scalar: &Self::Scalar) -> Self::Serialization;
    fn little_endian_serialize(scalar: &Self::Scalar) -> Self::Serialization;
    fn deserialize(
        buf: &Self::Serialization,
    ) -> Result<Self::Scalar, FieldError>;
}
Expand description

A prime order finite field GF(q) over which all scalar values for our prime order group can be multiplied are defined.

This trait does not have to be implemented for a finite field scalar itself, it can be a pass-through, implemented for a type just for the ciphersuite, and calls through to another implementation underneath, so that this trait does not have to be implemented for types you don’t own.

Required Associated Types§

Source

type Scalar: Add<Output = Self::Scalar> + Copy + Clone + Eq + Mul<Output = Self::Scalar> + PartialEq + Sub<Output = Self::Scalar>

An element of the scalar field GF(p). The Eq/PartialEq implementation MUST be constant-time.

Source

type Serialization: AsRef<[u8]> + Debug + TryFrom<Vec<u8>>

A unique byte array buf of fixed length N.

Required Methods§

Source

fn zero() -> Self::Scalar

Returns the zero element of the field, the additive identity.

Source

fn one() -> Self::Scalar

Returns the one element of the field, the multiplicative identity.

Source

fn invert(scalar: &Self::Scalar) -> Result<Self::Scalar, FieldError>

Computes the multiplicative inverse of an element of the scalar field, failing if the element is zero.

Source

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

Generate a random scalar from the entire space [0, l-1]

https://datatracker.ietf.org/doc/html/rfc9591#section-3.1-4.6

Source

fn serialize(scalar: &Self::Scalar) -> Self::Serialization

A member function of a Field that maps a Scalar to a unique byte array buf of fixed length Ne.

https://datatracker.ietf.org/doc/html/rfc9591#section-3.1-4.16

Source

fn little_endian_serialize(scalar: &Self::Scalar) -> Self::Serialization

A member function of a Field that maps a Scalar to a unique byte array buf of fixed length Ne, in little-endian order.

This is used internally.

Source

fn deserialize(buf: &Self::Serialization) -> Result<Self::Scalar, FieldError>

A member function of a Field that attempts to map a byte array buf to a Scalar.

Fails if the input is not a valid byte representation of an Scalar of the Field. This function can raise an Error if deserialization fails.

https://datatracker.ietf.org/doc/html/rfc9591#section-3.1-4.18

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§