pub struct FieldElement(/* private fields */);arithmetic and expose-field only.Expand description
Element of the secp384r1 base field used for curve coordinates.
Implementations§
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]) -> Option<Self>
pub fn from_slice(slice: &[u8]) -> Option<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 const fn from_u64(w: u64) -> Self
pub const fn from_u64(w: u64) -> Self
Convert a u64 into a FieldElement.
Sourcepub fn to_bytes(self) -> FieldBytes
pub fn to_bytes(self) -> FieldBytes
Returns the big-endian encoding of this FieldElement.
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 constant time.
Sourcepub const fn shr(&self, shift: u32) -> Self
pub const fn shr(&self, shift: u32) -> Self
Right shifts the FieldElement.
Sourcepub const fn shr_vartime(&self, shift: u32) -> Self
pub const fn shr_vartime(&self, shift: u32) -> Self
Right shifts the FieldElement.
Note: not constant-time with respect to the shift parameter.
Source§impl FieldElement
impl 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.
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 try_from_rng<R: TryRngCore + ?Sized>(rng: &mut R) -> Result<Self, R::Error>
fn try_from_rng<R: TryRngCore + ?Sized>(rng: &mut R) -> Result<Self, R::Error>
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 random<R>(rng: &mut R) -> Self
fn random<R>(rng: &mut R) -> Self
Source§fn is_zero_vartime(&self) -> bool
fn is_zero_vartime(&self) -> bool
Source§impl From<&FieldElement> for FieldBytes
impl From<&FieldElement> for FieldBytes
Source§fn from(fe: &FieldElement) -> Self
fn from(fe: &FieldElement) -> Self
Source§impl From<&FieldElement> for U384
impl From<&FieldElement> for U384
Source§fn from(fe: &FieldElement) -> U384
fn from(fe: &FieldElement) -> U384
Source§impl From<FieldElement> for FieldBytes
impl From<FieldElement> for FieldBytes
Source§fn from(fe: FieldElement) -> Self
fn from(fe: FieldElement) -> Self
Source§impl From<FieldElement> for U384
impl From<FieldElement> for U384
Source§fn from(fe: FieldElement) -> U384
fn from(fe: FieldElement) -> U384
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 FromOkm for FieldElement
Available on crate feature hash2curve only.
impl FromOkm for FieldElement
hash2curve only.Source§impl Invert for FieldElement
impl Invert for 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 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 OsswuMap for FieldElement
Available on crate feature hash2curve only.
impl OsswuMap for FieldElement
hash2curve only.Source§const PARAMS: OsswuMapParams<Self>
const PARAMS: OsswuMapParams<Self>
Source§fn sqrt_ratio_3mod4(u: Self, v: Self) -> (Choice, Self)
fn sqrt_ratio_3mod4(u: Self, v: Self) -> (Choice, Self)
Source§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 = Array<u8, <NistP384 as Curve>::FieldBytesSize>
type Repr = Array<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 Sgn0 for FieldElement
Available on crate feature hash2curve only.
impl Sgn0 for FieldElement
hash2curve only.Source§impl Shr<u32> for &FieldElement
impl Shr<u32> for &FieldElement
Source§impl Shr<u32> for FieldElement
impl Shr<u32> for FieldElement
Source§impl Shr<usize> for &FieldElement
impl Shr<usize> for &FieldElement
Source§impl Shr<usize> for FieldElement
impl Shr<usize> for FieldElement
Source§impl ShrAssign<u32> for FieldElement
impl ShrAssign<u32> for FieldElement
Source§fn shr_assign(&mut self, rhs: u32)
fn shr_assign(&mut self, rhs: u32)
>>= operation. Read moreSource§impl ShrAssign<usize> for FieldElement
impl ShrAssign<usize> for FieldElement
Source§fn shr_assign(&mut self, rhs: usize)
fn shr_assign(&mut self, rhs: usize)
>>= 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<&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.Source§impl Sum for FieldElement
impl Sum for FieldElement
impl Copy for FieldElement
impl DefaultIsZeroes for FieldElement
impl Eq for FieldElement
Auto Trait Implementations§
impl Freeze for FieldElement
impl RefUnwindSafe for FieldElement
impl Send for FieldElement
impl Sync for FieldElement
impl Unpin for FieldElement
impl UnwindSafe for FieldElement
Blanket Implementations§
Source§impl<T> BatchInvert<&[T]> for Twhere
T: Field,
impl<T> BatchInvert<&[T]> for Twhere
T: Field,
Source§impl<'this, T> BatchInvert<&'this mut [T]> for Twhere
T: Field,
impl<'this, T> BatchInvert<&'this mut [T]> for Twhere
T: Field,
Source§impl<T> BatchInvert<Vec<T>> for Twhere
T: Field,
impl<T> BatchInvert<Vec<T>> for Twhere
T: Field,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ConditionallyNegatable for T
impl<T> ConditionallyNegatable for T
Source§fn conditional_negate(&mut self, choice: Choice)
fn conditional_negate(&mut self, choice: Choice)
Source§impl<T> ConstantTimeSelect for Twhere
T: ConditionallySelectable,
impl<T> ConstantTimeSelect for Twhere
T: ConditionallySelectable,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.