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§
Required Methods§
Sourcefn 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.
Sourcefn random<R: RngCore + CryptoRng>(rng: &mut R) -> Self::Scalar
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
Sourcefn 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
Sourcefn little_endian_serialize(scalar: &Self::Scalar) -> Self::Serialization
fn little_endian_serialize(scalar: &Self::Scalar) -> Self::Serialization
Sourcefn deserialize(buf: &Self::Serialization) -> Result<Self::Scalar, FieldError>
fn deserialize(buf: &Self::Serialization) -> Result<Self::Scalar, FieldError>
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.