Skip to main content

Field

Trait Field 

pub trait Field: Copy {
    type Scalar: Add<Output = Self::Scalar> + Copy + Clone + Eq + Mul<Output = Self::Scalar> + PartialEq + Sub<Output = Self::Scalar> + Send + Sync;
    type Serialization: Clone + AsRef<[u8]> + AsMut<[u8]> + for<'a> TryFrom<&'a [u8]> + Debug;

    // Required methods
    fn zero() -> Self::Scalar;
    fn one() -> Self::Scalar;
    fn invert(scalar: &Self::Scalar) -> Result<Self::Scalar, FieldError>;
    fn random<R>(rng: &mut R) -> Self::Scalar
       where R: RngCore + CryptoRng;
    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§

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

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

type Serialization: Clone + AsRef<[u8]> + AsMut<[u8]> + for<'a> TryFrom<&'a [u8]> + Debug

A unique byte array buf of fixed length N.

Required Methods§

fn zero() -> Self::Scalar

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

fn one() -> Self::Scalar

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

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.

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

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

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

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

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.

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§

Source§

impl Field for PallasScalarField

Source§

type Scalar = <PallasParameters as CurveConfig>::ScalarField

Source§

type Serialization = [u8; 32]