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§
Required Methods§
fn invert(scalar: &Self::Scalar) -> Result<Self::Scalar, FieldError>
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
fn random<R>(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
fn serialize(scalar: &Self::Scalar) -> Self::Serialization
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
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>
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.