ExtElem

Struct ExtElem 

Source
pub struct ExtElem(/* private fields */);
Expand description

Instances of ExtElem are elements of a finite field F_p^4. They are represented as elements of F_p[X] / (X^4 + 11). This large finite field (about 2^128 elements) is used when the security of operations depends on the size of the field. The field extension ExtElem has Elem as a subfield, so operations on elements of each are compatible. The irreducible polynomial x^4 + 11 was chosen because 11 is the simplest choice of BETA for x^4 + BETA that makes this polynomial irreducible.

Implementations§

Source§

impl ExtElem

Source

pub const fn new(x0: Elem, x1: Elem, x2: Elem, x3: Elem) -> Self

Explicitly construct an ExtElem from parts.

Source

pub fn from_fp(x: Elem) -> Self

Create an ExtElem from an Elem.

Source

pub const fn from_u32(x0: u32) -> Self

Create an ExtElem from a raw integer.

Source

pub fn const_part(self) -> Elem

Return the base field term of an Elem.

Source

pub fn elems(&self) -> &[Elem]

Return Elem as a vector of base field values.

Trait Implementations§

Source§

impl Add<Elem> for ExtElem

Source§

fn add(self, rhs: Elem) -> Self

Addition for Baby Bear Elem

Source§

type Output = ExtElem

The resulting type after applying the + operator.
Source§

impl Add<ExtElem> for Elem

Source§

fn add(self, rhs: ExtElem) -> ExtElem

Addition for Baby Bear Elem

Source§

type Output = ExtElem

The resulting type after applying the + operator.
Source§

impl Add for ExtElem

Source§

fn add(self, rhs: Self) -> Self

Addition for Baby Bear ExtElem

Source§

type Output = ExtElem

The resulting type after applying the + operator.
Source§

impl AddAssign<Elem> for ExtElem

Source§

fn add_assign(&mut self, rhs: Elem)

Promoting addition case for BabyBear Elem

Source§

impl AddAssign for ExtElem

Source§

fn add_assign(&mut self, rhs: Self)

Simple addition case for Baby Bear ExtElem

Source§

impl CheckedBitPattern for ExtElem

Source§

fn is_valid_bit_pattern(bits: &[u32; 4]) -> bool

Checks that the u32 array elements are all less than the modulus.

Source§

type Bits = [u32; 4]

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
Source§

impl Clone for ExtElem

Source§

fn clone(&self) -> ExtElem

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ExtElem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for ExtElem

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Elem for ExtElem

Source§

fn random(rng: &mut impl RngCore) -> Self

Generate a random field element uniformly.

Source§

fn pow(self, n: usize) -> Self

Raise a ExtElem to a power of n.

Source§

fn inv(self) -> Self

Compute the multiplicative inverse of an ExtElem.

Source§

fn from_u64(val: u64) -> Self

Convert from a u64 to a base field elem, then cast to the extension field.

Source§

const INVALID: Self

Invalid, a value that is not a member of the field. This should only be used with the “is_valid” or “unwrap_or_zero” methods.
Source§

const ZERO: Self

Zero, the additive identity.
Source§

const ONE: Self

One, the multiplicative identity.
Source§

const WORDS: usize = 4usize

How many u32 words are required to hold a single element
Source§

fn to_u32_words(&self) -> Vec<u32>

Represent a field element as a sequence of u32s
Source§

fn from_u32_words(val: &[u32]) -> Self

Interpret a sequence of u32s as a field element
Source§

fn is_valid(&self) -> bool

Returns true if this element is not INVALID. Unlike most methods, this may be called on an INVALID element.
Source§

fn is_reduced(&self) -> bool

Returns true if this element is represented in reduced/normalized form. Every element has exactly one reduced form. For a field of prime order P, this typically means the underlying data is < P, and for an extension field, this typically means every component is in reduced form.
Source§

fn valid_or_zero(&self) -> Self

Returns 0 if this element is INVALID, else the value of this element. Unlike most methods, this may be called on an INVALID element.
Source§

fn ensure_valid(&self) -> &Self

Returns this element, but checks to make sure it’s valid.
Source§

fn ensure_reduced(&self) -> &Self

Returns this element, but checks to make sure it’s in reduced form.
Source§

fn as_u32_slice(elems: &[Self]) -> &[u32]

Interprets a slice of these elements as u32s. These elements may not be INVALID.
Source§

fn as_u32_slice_unchecked(elems: &[Self]) -> &[u32]

Interprets a slice of these elements as u32s. These elements may potentially be INVALID.
Source§

fn from_u32_slice(u32s: &[u32]) -> &[Self]

Interprets a slice of u32s as a slice of these elements. These elements may not be INVALID.
Source§

impl ExtElem for ExtElem

Source§

fn subelems(&self) -> &[Elem]

Returns the subelements of a Elem.

Source§

const EXT_SIZE: usize = 4usize

The degree of the field extension Read more
Source§

type SubElem = Elem

An element of the base field Read more
Source§

fn from_subfield(elem: &Elem) -> Self

Interpret a base field element as an extension field element Read more
Source§

fn from_subelems(elems: impl IntoIterator<Item = Self::SubElem>) -> Self

Construct an extension field element Read more
Source§

impl From<[Elem; 4]> for ExtElem

Source§

fn from(val: [Elem; 4]) -> Self

Converts to this type from the input type.
Source§

impl From<Elem> for ExtElem

Source§

fn from(x: Elem) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for ExtElem

Source§

fn from(x: u32) -> Self

Converts to this type from the input type.
Source§

impl Mul<Elem> for ExtElem

Source§

fn mul(self, rhs: Elem) -> Self

Multiplication by a Baby Bear Elem

Source§

type Output = ExtElem

The resulting type after applying the * operator.
Source§

impl Mul<ExtElem> for Elem

Source§

fn mul(self, rhs: ExtElem) -> ExtElem

Multiplication for a subfield Elem by an ExtElem

Source§

type Output = ExtElem

The resulting type after applying the * operator.
Source§

impl Mul for ExtElem

Source§

type Output = ExtElem

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: ExtElem) -> ExtElem

Performs the * operation. Read more
Source§

impl MulAssign<Elem> for ExtElem

Source§

fn mul_assign(&mut self, rhs: Elem)

Simple multiplication case by a Baby Bear Elem

Source§

impl MulAssign for ExtElem

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl Neg for ExtElem

Source§

type Output = ExtElem

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl PartialEq for ExtElem

Source§

fn eq(&self, rhs: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub<Elem> for ExtElem

Source§

fn sub(self, rhs: Elem) -> Self

Subtraction for Baby Bear ExtElem

Source§

type Output = ExtElem

The resulting type after applying the - operator.
Source§

impl Sub<ExtElem> for Elem

Source§

fn sub(self, rhs: ExtElem) -> ExtElem

Subtraction for Baby Bear ExtElem

Source§

type Output = ExtElem

The resulting type after applying the - operator.
Source§

impl Sub for ExtElem

Source§

fn sub(self, rhs: Self) -> Self

Subtraction for Baby Bear ExtElem

Source§

type Output = ExtElem

The resulting type after applying the - operator.
Source§

impl SubAssign<Elem> for ExtElem

Source§

fn sub_assign(&mut self, rhs: Elem)

Promoting subtraction case for BabyBear Elem

Source§

impl SubAssign for ExtElem

Source§

fn sub_assign(&mut self, rhs: Self)

Simple subtraction case for Baby Bear ExtElem

Source§

impl Zeroable for ExtElem

Source§

fn zeroed() -> Self

Source§

impl Copy for ExtElem

Source§

impl Eq for ExtElem

Source§

impl NoUninit for ExtElem

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.