Skip to main content

FieldElement

Struct FieldElement 

Source
pub struct FieldElement<const LIMBS: usize> {
    pub limbs: [u64; LIMBS],
}
Expand description

A field element over a prime p, represented as LIMBS x u64 limbs in little-endian order (limbs[0] is least significant).

All arithmetic operations on FieldElement are constant-time and work modulo a per-call prime p supplied as a &[u64; LIMBS] (no implicit field association). The same struct is used by every short-Weierstrass curve in the crate; the LIMBS const tracks the prime size: 4 for P-256 / secp256k1 / brainpoolP256r1, 6 for P-384 / brainpoolP384r1, 8 for brainpoolP512r1, 9 for P-521.

Fields§

§limbs: [u64; LIMBS]

Limb storage in little-endian order (limbs[0] is least significant).

Implementations§

Source§

impl<const LIMBS: usize> FieldElement<LIMBS>

Source

pub const ZERO: Self

The zero element of the field (all limbs set to 0).

Source

pub const fn one() -> Self

The one element of the field (limb 0 = 1, the rest 0).

Source

pub fn is_zero(&self) -> bool

Returns true if every limb is zero. Constant-time across all limbs (no early-exit branch).

Source

pub fn from_bytes_be(bytes: &[u8]) -> Self

Encode from big-endian bytes.

Source

pub fn to_bytes_be(&self) -> Vec<u8>

Encode to big-endian bytes.

Source

pub fn from_bytes_le(bytes: &[u8]) -> Self

Encode from little-endian bytes. Used by X25519 (RFC 7748) which is LE-native throughout, unlike the SEC1-era curves.

Source

pub fn to_bytes_le(&self) -> Vec<u8>

Encode to little-endian bytes (LIMBS*8 bytes).

Trait Implementations§

Source§

impl<const LIMBS: usize> Clone for FieldElement<LIMBS>

Source§

fn clone(&self) -> FieldElement<LIMBS>

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<const LIMBS: usize> Debug for FieldElement<LIMBS>

Source§

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

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

impl<const LIMBS: usize> PartialEq for FieldElement<LIMBS>

Source§

fn eq(&self, other: &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<const LIMBS: usize> Copy for FieldElement<LIMBS>

Source§

impl<const LIMBS: usize> Eq for FieldElement<LIMBS>

Auto Trait Implementations§

§

impl<const LIMBS: usize> Freeze for FieldElement<LIMBS>

§

impl<const LIMBS: usize> RefUnwindSafe for FieldElement<LIMBS>

§

impl<const LIMBS: usize> Send for FieldElement<LIMBS>

§

impl<const LIMBS: usize> Sync for FieldElement<LIMBS>

§

impl<const LIMBS: usize> Unpin for FieldElement<LIMBS>

§

impl<const LIMBS: usize> UnsafeUnpin for FieldElement<LIMBS>

§

impl<const LIMBS: usize> UnwindSafe for FieldElement<LIMBS>

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> 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.