pub struct FieldElement(pub(super) U384);Expand description
Element of the secp384r1 base field used for curve coordinates.
Tuple Fields§
§0: U384Implementations§
Source§impl FieldElement
impl FieldElement
Sourcepub fn from_bytes(repr: &FieldBytes) -> CtOption<Self>
pub fn from_bytes(repr: &FieldBytes) -> CtOption<Self>
Create a FieldElement from a canonical big-endian representation.
Sourcepub fn from_slice(slice: &[u8]) -> Result<Self>
pub fn from_slice(slice: &[u8]) -> Result<Self>
Decode FieldElement from a big endian byte slice.
Sourcepub fn from_uint(uint: U384) -> CtOption<Self>
pub fn from_uint(uint: U384) -> CtOption<Self>
Decode FieldElement
from U384 converting it into Montgomery form:
w * R^2 * R^-1 mod p = wR mod pSourcepub(crate) const fn from_hex(hex: &str) -> Self
pub(crate) const fn from_hex(hex: &str) -> Self
Parse a FieldElement from big endian hex-encoded bytes.
Does not perform a check that the field element does not overflow the order.
This method is primarily intended for defining internal constants.
Sourcepub const fn from_u64(w: u64) -> Self
pub const fn from_u64(w: u64) -> Self
Convert a u64 into a FieldElement.
Sourcepub(crate) const fn from_uint_unchecked(w: U384) -> Self
pub(crate) const fn from_uint_unchecked(w: U384) -> Self
Decode FieldElement from U384 converting it into Montgomery form.
Does not perform a check that the field element does not overflow the order.
Used incorrectly this can lead to invalid results!
Sourcepub fn to_bytes(self) -> FieldBytes
pub fn to_bytes(self) -> FieldBytes
Returns the big-endian encoding of this FieldElement.
Sourcepub const fn to_canonical(self) -> U384
pub const fn to_canonical(self) -> U384
Translate FieldElement out of the Montgomery domain, returning a U384 in canonical form.
Sourcepub fn is_odd(&self) -> Choice
pub fn is_odd(&self) -> Choice
Determine if this FieldElement is odd in the SEC1 sense: self mod 2 == 1.
§Returns
If odd, return Choice(1). Otherwise, return Choice(0).
Sourcepub fn is_even(&self) -> Choice
pub fn is_even(&self) -> Choice
Determine if this FieldElement is even in the SEC1 sense: self mod 2 == 0.
§Returns
If even, return Choice(1). Otherwise, return Choice(0).
Sourcepub fn is_zero(&self) -> Choice
pub fn is_zero(&self) -> Choice
Determine if this FieldElement is zero.
§Returns
If zero, return Choice(1). Otherwise, return Choice(0).
Sourcepub const fn pow_vartime(&self, exp: &[u64]) -> Self
pub const fn pow_vartime(&self, exp: &[u64]) -> Self
Returns self^exp, where exp is a little-endian integer exponent.
This operation is variable time with respect to the exponent.
If the exponent is fixed, this operation is effectively constant time.
Source§impl FieldElement
impl FieldElement
Sourcepub fn invert(&self) -> CtOption<Self>
pub fn invert(&self) -> CtOption<Self>
Compute FieldElement inversion: 1 / self.
Sourceconst fn invert_unchecked(&self) -> Self
const fn invert_unchecked(&self) -> Self
Returns the multiplicative inverse of self.
Does not check that self is non-zero.
Trait Implementations§
Source§impl Add<&FieldElement> for &FieldElement
impl Add<&FieldElement> for &FieldElement
Source§type Output = FieldElement
type Output = FieldElement
+ operator.Source§fn add(self, rhs: &FieldElement) -> FieldElement
fn add(self, rhs: &FieldElement) -> FieldElement
+ operation. Read moreSource§impl Add<&FieldElement> for FieldElement
impl Add<&FieldElement> for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
+ operator.Source§fn add(self, rhs: &FieldElement) -> FieldElement
fn add(self, rhs: &FieldElement) -> FieldElement
+ operation. Read moreSource§impl Add for FieldElement
impl Add for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
+ operator.Source§fn add(self, rhs: FieldElement) -> FieldElement
fn add(self, rhs: FieldElement) -> FieldElement
+ operation. Read moreSource§impl AddAssign<&FieldElement> for FieldElement
impl AddAssign<&FieldElement> for FieldElement
Source§fn add_assign(&mut self, other: &FieldElement)
fn add_assign(&mut self, other: &FieldElement)
+= operation. Read moreSource§impl AddAssign for FieldElement
impl AddAssign for FieldElement
Source§fn add_assign(&mut self, other: FieldElement)
fn add_assign(&mut self, other: FieldElement)
+= operation. Read moreSource§impl Clone for FieldElement
impl Clone for FieldElement
Source§fn clone(&self) -> FieldElement
fn clone(&self) -> FieldElement
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl ConditionallySelectable for FieldElement
impl ConditionallySelectable for FieldElement
Source§fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self
Source§fn conditional_assign(&mut self, other: &Self, choice: Choice)
fn conditional_assign(&mut self, other: &Self, choice: Choice)
Source§fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)
self and other if choice == 1; otherwise,
reassign both unto themselves. Read moreSource§impl ConstantTimeEq for FieldElement
impl ConstantTimeEq for FieldElement
Source§impl ConstantTimeGreater for FieldElement
impl ConstantTimeGreater for FieldElement
Source§impl ConstantTimeLess for FieldElement
impl ConstantTimeLess for FieldElement
Source§impl Debug for FieldElement
impl Debug for FieldElement
Source§impl Default for FieldElement
impl Default for FieldElement
Source§impl Field for FieldElement
impl Field for FieldElement
Source§fn random(rng: impl RngCore) -> Self
fn random(rng: impl RngCore) -> Self
Source§fn invert(&self) -> CtOption<Self>
fn invert(&self) -> CtOption<Self>
Source§fn sqrt(&self) -> CtOption<Self>
fn sqrt(&self) -> CtOption<Self>
Source§fn sqrt_ratio(num: &Self, div: &Self) -> (Choice, Self)
fn sqrt_ratio(num: &Self, div: &Self) -> (Choice, Self)
Source§fn is_zero_vartime(&self) -> bool
fn is_zero_vartime(&self) -> bool
Source§impl From<u128> for FieldElement
impl From<u128> for FieldElement
Source§fn from(n: u128) -> FieldElement
fn from(n: u128) -> FieldElement
Source§impl From<u32> for FieldElement
impl From<u32> for FieldElement
Source§fn from(n: u32) -> FieldElement
fn from(n: u32) -> FieldElement
Source§impl From<u64> for FieldElement
impl From<u64> for FieldElement
Source§fn from(n: u64) -> FieldElement
fn from(n: u64) -> FieldElement
Source§impl Mul<&FieldElement> for &FieldElement
impl Mul<&FieldElement> for &FieldElement
Source§type Output = FieldElement
type Output = FieldElement
* operator.Source§fn mul(self, rhs: &FieldElement) -> FieldElement
fn mul(self, rhs: &FieldElement) -> FieldElement
* operation. Read moreSource§impl Mul<&FieldElement> for FieldElement
impl Mul<&FieldElement> for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
* operator.Source§fn mul(self, rhs: &FieldElement) -> FieldElement
fn mul(self, rhs: &FieldElement) -> FieldElement
* operation. Read moreSource§impl Mul for FieldElement
impl Mul for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
* operator.Source§fn mul(self, rhs: FieldElement) -> FieldElement
fn mul(self, rhs: FieldElement) -> FieldElement
* operation. Read moreSource§impl MulAssign<&FieldElement> for FieldElement
impl MulAssign<&FieldElement> for FieldElement
Source§fn mul_assign(&mut self, other: &FieldElement)
fn mul_assign(&mut self, other: &FieldElement)
*= operation. Read moreSource§impl MulAssign for FieldElement
impl MulAssign for FieldElement
Source§fn mul_assign(&mut self, other: FieldElement)
fn mul_assign(&mut self, other: FieldElement)
*= operation. Read moreSource§impl Neg for FieldElement
impl Neg for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
- operator.Source§fn neg(self) -> FieldElement
fn neg(self) -> FieldElement
- operation. Read moreSource§impl PartialEq for FieldElement
impl PartialEq for FieldElement
Source§impl PrimeField for FieldElement
impl PrimeField for FieldElement
Source§const MODULUS: &'static str = "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff"
const MODULUS: &'static str = "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff"
Source§const CAPACITY: u32 = 383u32
const CAPACITY: u32 = 383u32
Source§const MULTIPLICATIVE_GENERATOR: Self
const MULTIPLICATIVE_GENERATOR: Self
modulus - 1 order. This element must also be
a quadratic nonresidue. Read moreSource§const ROOT_OF_UNITY: Self
const ROOT_OF_UNITY: Self
2^s root of unity. Read moreSource§const ROOT_OF_UNITY_INV: Self
const ROOT_OF_UNITY_INV: Self
Self::ROOT_OF_UNITY.Source§type Repr = GenericArray<u8, <NistP384 as Curve>::FieldBytesSize>
type Repr = GenericArray<u8, <NistP384 as Curve>::FieldBytesSize>
Source§fn from_repr(bytes: FieldBytes) -> CtOption<Self>
fn from_repr(bytes: FieldBytes) -> CtOption<Self>
Source§fn to_repr(&self) -> FieldBytes
fn to_repr(&self) -> FieldBytes
Source§fn from_str_vartime(s: &str) -> Option<Self>
fn from_str_vartime(s: &str) -> Option<Self>
Source§impl<'a> Product<&'a FieldElement> for FieldElement
impl<'a> Product<&'a FieldElement> for FieldElement
Source§impl Product for FieldElement
impl Product for FieldElement
Source§impl Sub<&FieldElement> for &FieldElement
impl Sub<&FieldElement> for &FieldElement
Source§type Output = FieldElement
type Output = FieldElement
- operator.Source§fn sub(self, rhs: &FieldElement) -> FieldElement
fn sub(self, rhs: &FieldElement) -> FieldElement
- operation. Read moreSource§impl Sub<&FieldElement> for FieldElement
impl Sub<&FieldElement> for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
- operator.Source§fn sub(self, rhs: &FieldElement) -> FieldElement
fn sub(self, rhs: &FieldElement) -> FieldElement
- operation. Read moreSource§impl Sub for FieldElement
impl Sub for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
- operator.Source§fn sub(self, rhs: FieldElement) -> FieldElement
fn sub(self, rhs: FieldElement) -> FieldElement
- operation. Read moreSource§impl SubAssign<&FieldElement> for FieldElement
impl SubAssign<&FieldElement> for FieldElement
Source§fn sub_assign(&mut self, other: &FieldElement)
fn sub_assign(&mut self, other: &FieldElement)
-= operation. Read moreSource§impl SubAssign for FieldElement
impl SubAssign for FieldElement
Source§fn sub_assign(&mut self, other: FieldElement)
fn sub_assign(&mut self, other: FieldElement)
-= operation. Read moreSource§impl<'a> Sum<&'a FieldElement> for FieldElement
impl<'a> Sum<&'a FieldElement> for FieldElement
Source§fn sum<I: Iterator<Item = &'a FieldElement>>(iter: I) -> Self
fn sum<I: Iterator<Item = &'a FieldElement>>(iter: I) -> Self
Self from the elements by “summing up”
the items.