Skip to main content

FieldElement

Struct FieldElement 

Source
#[repr(align(16))]
pub struct FieldElement([u8; 16]);
Expand description

An element in POLYVAL’s field.

This type represents an element of the binary field GF(2^128) modulo the irreducible polynomial x^128 + x^127 + x^126 + x^121 + 1 as described in RFC8452 §3.

Arithmetic in POLYVAL’s field has the following properties:

  • All arithmetic operations are performed modulo the polynomial above.
  • Addition is equivalent to the XOR operation applied to the two field elements
  • Multiplication is carryless

Tuple Fields§

§0: [u8; 16]

Implementations§

Source§

impl FieldElement

Source

unsafe fn from_m128i(reg: __m128i) -> Self

Source

unsafe fn to_m128i(self) -> __m128i

Source§

impl FieldElement

Source

pub(crate) fn karatsuba_mul(self, rhs: Self) -> Product

Compute the unreduced 256-bit carryless product of two 128-bit field elements.

Uses a Karatsuba decomposition in which the 128x128 multiplication is reduced to three 64x64 multiplications together with a bit-reversal trick to efficiently recover the high half.

Source

fn to_u64x2(self) -> (u64, u64)

Splits into (lo, hi).

Source§

impl FieldElement

Source

pub fn mulx(self) -> Self

The mulX_POLYVAL() function as defined in RFC 8452 Appendix A.

Performs a doubling (a.k.a. “multiply by x”) over GF(2^128). This is useful for implementing GHASH in terms of POLYVAL.

Source§

impl FieldElement

Source

pub fn reverse(self) -> Self

Reverse this field element at a byte-level of granularity.

This is useful when implementing GHASH in terms of POLYVAL.

Trait Implementations§

Source§

impl Add for FieldElement

Source§

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

Adds two POLYVAL field elements.

In POLYVAL’s field, addition is the equivalent operation to XOR.

Source§

type Output = FieldElement

The resulting type after applying the + operator.
Source§

impl Clone for FieldElement

Source§

fn clone(&self) -> FieldElement

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for FieldElement

Source§

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

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

impl Default for FieldElement

Source§

fn default() -> FieldElement

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

impl From<&Array<u8, <Polyval as BlockSizeUser>::BlockSize>> for FieldElement

Source§

fn from(block: &Block) -> Self

Converts to this type from the input type.
Source§

impl From<&FieldElement> for Block

Source§

fn from(fe: &FieldElement) -> Self

Converts to this type from the input type.
Source§

impl From<[u8; 16]> for FieldElement

Source§

fn from(bytes: [u8; 16]) -> Self

Converts to this type from the input type.
Source§

impl From<Array<u8, <Polyval as BlockSizeUser>::BlockSize>> for FieldElement

Source§

fn from(block: Block) -> Self

Converts to this type from the input type.
Source§

impl From<FieldElement> for [u8; 16]

Source§

fn from(fe: FieldElement) -> [u8; 16]

Converts to this type from the input type.
Source§

impl From<FieldElement> for Block

Source§

fn from(fe: FieldElement) -> Self

Converts to this type from the input type.
Source§

impl From<FieldElement> for u128

Source§

fn from(fe: FieldElement) -> Self

Converts to this type from the input type.
Source§

impl From<u128> for FieldElement

Source§

fn from(x: u128) -> Self

Converts to this type from the input type.
Source§

impl Mul for FieldElement

Source§

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

Perform carryless multiplication within POLYVAL’s field modulo its polynomial.

Source§

type Output = FieldElement

The resulting type after applying the * operator.
Source§

impl MulAssign for FieldElement

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl Zeroize for FieldElement

Available on crate feature zeroize only.
Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
Source§

impl Copy for FieldElement

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> Same for T

Source§

type Output = T

Should always be Self
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.