Struct p256::FieldElement
source · pub struct FieldElement(_);
Expand description
An element in the finite field modulo p = 2^{224}(2^{32} − 1) + 2^{192} + 2^{96} − 1.
The internal representation is in little-endian order. Elements are always in Montgomery form; i.e., FieldElement(a) = aR mod p, with R = 2^256.
Implementations
sourceimpl FieldElement
impl FieldElement
sourcepub fn from_be_bytes(repr: FieldBytes) -> CtOption<Self>
pub fn from_be_bytes(repr: FieldBytes) -> CtOption<Self>
Create a FieldElement
from a canonical big-endian representation.
sourcepub fn from_be_slice(slice: &[u8]) -> Result<Self>
pub fn from_be_slice(slice: &[u8]) -> Result<Self>
Decode FieldElement
from a big endian byte slice.
sourcepub fn from_le_bytes(repr: FieldBytes) -> CtOption<Self>
pub fn from_le_bytes(repr: FieldBytes) -> CtOption<Self>
Create a FieldElement
from a canonical little-endian representation.
sourcepub fn from_le_slice(slice: &[u8]) -> Result<Self>
pub fn from_le_slice(slice: &[u8]) -> Result<Self>
Decode FieldElement
from a little endian byte slice.
sourcepub fn from_uint(uint: U256) -> CtOption<Self>
pub fn from_uint(uint: U256) -> CtOption<Self>
Decode FieldElement
from U256
converting it into Montgomery form:
w * R^2 * R^-1 mod p = wR mod p
sourcepub fn to_be_bytes(self) -> FieldBytes
pub fn to_be_bytes(self) -> FieldBytes
Returns the big-endian encoding of this FieldElement
.
sourcepub fn to_le_bytes(self) -> FieldBytes
pub fn to_le_bytes(self) -> FieldBytes
Returns the little-endian encoding of this FieldElement
.
sourcepub const fn to_canonical(self) -> U256
pub const fn to_canonical(self) -> U256
Translate FieldElement
out of the Montgomery domain, returning a U256
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)
.
sourceimpl FieldElement
impl FieldElement
sourcepub fn from_sec1(bytes: FieldBytes) -> CtOption<Self>
pub fn from_sec1(bytes: FieldBytes) -> CtOption<Self>
Attempts to parse the given byte array as an SEC1-encoded field element.
Returns None if the byte array does not contain a big-endian integer in the range [0, p).
sourcepub fn to_sec1(self) -> FieldBytes
pub fn to_sec1(self) -> FieldBytes
Returns the SEC1 encoding of this field element.
sourcepub fn pow_vartime(&self, by: &[u64; 4]) -> Self
pub fn pow_vartime(&self, by: &[u64; 4]) -> Self
Returns self^by
, where by
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.
Trait Implementations
sourceimpl Add<&FieldElement> for &FieldElement
impl Add<&FieldElement> for &FieldElement
type Output = FieldElement
type Output = FieldElement
+
operator.sourcefn add(self, rhs: &FieldElement) -> FieldElement
fn add(self, rhs: &FieldElement) -> FieldElement
+
operation. Read moresourceimpl Add<&FieldElement> for FieldElement
impl Add<&FieldElement> for FieldElement
type Output = FieldElement
type Output = FieldElement
+
operator.sourcefn add(self, rhs: &FieldElement) -> FieldElement
fn add(self, rhs: &FieldElement) -> FieldElement
+
operation. Read moresourceimpl Add<FieldElement> for FieldElement
impl Add<FieldElement> for FieldElement
type Output = FieldElement
type Output = FieldElement
+
operator.sourcefn add(self, rhs: FieldElement) -> FieldElement
fn add(self, rhs: FieldElement) -> FieldElement
+
operation. Read moresourceimpl AddAssign<&FieldElement> for FieldElement
impl AddAssign<&FieldElement> for FieldElement
sourcefn add_assign(&mut self, other: &FieldElement)
fn add_assign(&mut self, other: &FieldElement)
+=
operation. Read moresourceimpl AddAssign<FieldElement> for FieldElement
impl AddAssign<FieldElement> for FieldElement
sourcefn add_assign(&mut self, other: FieldElement)
fn add_assign(&mut self, other: FieldElement)
+=
operation. Read moresourceimpl AsRef<[u64; 4]> for FieldElement
impl AsRef<[u64; 4]> for FieldElement
sourceimpl Clone for FieldElement
impl Clone for FieldElement
sourcefn clone(&self) -> FieldElement
fn clone(&self) -> FieldElement
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl ConditionallySelectable for FieldElement
impl ConditionallySelectable for FieldElement
sourcefn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self
sourcefn conditional_assign(&mut self, other: &Self, choice: Choice)
fn conditional_assign(&mut self, other: &Self, choice: Choice)
sourceimpl ConstantTimeEq for FieldElement
impl ConstantTimeEq for FieldElement
sourceimpl ConstantTimeGreater for FieldElement
impl ConstantTimeGreater for FieldElement
sourceimpl ConstantTimeLess for FieldElement
impl ConstantTimeLess for FieldElement
sourceimpl Debug for FieldElement
impl Debug for FieldElement
sourceimpl Default for FieldElement
impl Default for FieldElement
sourceimpl Field for FieldElement
impl Field for FieldElement
sourcefn random(rng: impl RngCore) -> Self
fn random(rng: impl RngCore) -> Self
sourcefn invert(&self) -> CtOption<Self>
fn invert(&self) -> CtOption<Self>
sourcefn sqrt(&self) -> CtOption<Self>
fn sqrt(&self) -> CtOption<Self>
fn is_zero_vartime(&self) -> bool
fn is_zero_vartime(&self) -> bool
fn cube(&self) -> Self
fn cube(&self) -> Self
fn pow_vartime<S>(&self, exp: S) -> Selfwhere
S: AsRef<[u64]>,
fn pow_vartime<S>(&self, exp: S) -> Selfwhere
S: AsRef<[u64]>,
sourceimpl From<u64> for FieldElement
impl From<u64> for FieldElement
sourcefn from(n: u64) -> FieldElement
fn from(n: u64) -> FieldElement
sourceimpl FromOkm for FieldElement
impl FromOkm for FieldElement
sourceimpl MapToCurve for FieldElement
impl MapToCurve for FieldElement
type Output = ProjectivePoint<NistP256>
type Output = ProjectivePoint<NistP256>
sourcefn map_to_curve(&self) -> Self::Output
fn map_to_curve(&self) -> Self::Output
sourceimpl Mul<&FieldElement> for &FieldElement
impl Mul<&FieldElement> for &FieldElement
type Output = FieldElement
type Output = FieldElement
*
operator.sourcefn mul(self, rhs: &FieldElement) -> FieldElement
fn mul(self, rhs: &FieldElement) -> FieldElement
*
operation. Read moresourceimpl Mul<&FieldElement> for FieldElement
impl Mul<&FieldElement> for FieldElement
type Output = FieldElement
type Output = FieldElement
*
operator.sourcefn mul(self, rhs: &FieldElement) -> FieldElement
fn mul(self, rhs: &FieldElement) -> FieldElement
*
operation. Read moresourceimpl Mul<FieldElement> for FieldElement
impl Mul<FieldElement> for FieldElement
type Output = FieldElement
type Output = FieldElement
*
operator.sourcefn mul(self, rhs: FieldElement) -> FieldElement
fn mul(self, rhs: FieldElement) -> FieldElement
*
operation. Read moresourceimpl MulAssign<&FieldElement> for FieldElement
impl MulAssign<&FieldElement> for FieldElement
sourcefn mul_assign(&mut self, other: &FieldElement)
fn mul_assign(&mut self, other: &FieldElement)
*=
operation. Read moresourceimpl MulAssign<FieldElement> for FieldElement
impl MulAssign<FieldElement> for FieldElement
sourcefn mul_assign(&mut self, other: FieldElement)
fn mul_assign(&mut self, other: FieldElement)
*=
operation. Read moresourceimpl Neg for FieldElement
impl Neg for FieldElement
type Output = FieldElement
type Output = FieldElement
-
operator.sourcefn neg(self) -> FieldElement
fn neg(self) -> FieldElement
-
operation. Read moresourceimpl OsswuMap for FieldElement
impl OsswuMap for FieldElement
sourceconst PARAMS: OsswuMapParams<Self> = _
const PARAMS: OsswuMapParams<Self> = _
sourcefn osswu(&self) -> (Self, Self)
fn osswu(&self) -> (Self, Self)
sourceimpl PartialEq<FieldElement> for FieldElement
impl PartialEq<FieldElement> for FieldElement
sourceimpl PrimeField for FieldElement
impl PrimeField for FieldElement
type Repr = GenericArray<u8, <<NistP256 as Curve>::UInt as ArrayEncoding>::ByteSize>
type Repr = GenericArray<u8, <<NistP256 as Curve>::UInt as ArrayEncoding>::ByteSize>
sourceconst CAPACITY: u32 = 255u32
const CAPACITY: u32 = 255u32
sourcefn from_repr(bytes: FieldBytes) -> CtOption<Self>
fn from_repr(bytes: FieldBytes) -> CtOption<Self>
sourcefn to_repr(&self) -> FieldBytes
fn to_repr(&self) -> FieldBytes
sourcefn multiplicative_generator() -> Self
fn multiplicative_generator() -> Self
modulus - 1
order. This element must
also be a quadratic nonresidue. Read moresourcefn root_of_unity() -> Self
fn root_of_unity() -> Self
2^s
root of unity. Read morefn from_str_vartime(s: &str) -> Option<Self>
fn from_str_vartime(s: &str) -> Option<Self>
fn from_repr_vartime(repr: Self::Repr) -> Option<Self>
fn from_repr_vartime(repr: Self::Repr) -> Option<Self>
sourceimpl Sgn0 for FieldElement
impl Sgn0 for FieldElement
sourceimpl Sub<&FieldElement> for &FieldElement
impl Sub<&FieldElement> for &FieldElement
type Output = FieldElement
type Output = FieldElement
-
operator.sourcefn sub(self, rhs: &FieldElement) -> FieldElement
fn sub(self, rhs: &FieldElement) -> FieldElement
-
operation. Read moresourceimpl Sub<&FieldElement> for FieldElement
impl Sub<&FieldElement> for FieldElement
type Output = FieldElement
type Output = FieldElement
-
operator.sourcefn sub(self, rhs: &FieldElement) -> FieldElement
fn sub(self, rhs: &FieldElement) -> FieldElement
-
operation. Read moresourceimpl Sub<FieldElement> for FieldElement
impl Sub<FieldElement> for FieldElement
type Output = FieldElement
type Output = FieldElement
-
operator.sourcefn sub(self, rhs: FieldElement) -> FieldElement
fn sub(self, rhs: FieldElement) -> FieldElement
-
operation. Read moresourceimpl SubAssign<&FieldElement> for FieldElement
impl SubAssign<&FieldElement> for FieldElement
sourcefn sub_assign(&mut self, other: &FieldElement)
fn sub_assign(&mut self, other: &FieldElement)
-=
operation. Read moresourceimpl SubAssign<FieldElement> for FieldElement
impl SubAssign<FieldElement> for FieldElement
sourcefn sub_assign(&mut self, other: FieldElement)
fn sub_assign(&mut self, other: FieldElement)
-=
operation. Read moreimpl Copy for FieldElement
impl DefaultIsZeroes for FieldElement
impl Eq for FieldElement
Auto Trait Implementations
impl RefUnwindSafe for FieldElement
impl Send for FieldElement
impl Sync for FieldElement
impl Unpin for FieldElement
impl UnwindSafe for FieldElement
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> FmtForward for T
impl<T> FmtForward for T
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
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 morefn 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 morefn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
self
, then passes self.as_ref()
into the pipe function.fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> Rwhere
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> Rwhere
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
self
, then passes self.deref()
into the pipe function.impl<T> Tap for T
impl<T> Tap for T
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
Borrow<B>
of a value. Read morefn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
BorrowMut<B>
of a value. Read morefn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
AsRef<R>
view of a value. Read morefn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
AsMut<R>
view of a value. Read morefn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
Deref::Target
of a value. Read morefn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
Deref::Target
of a value. Read morefn 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.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. Read morefn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
.tap_borrow()
only in debug builds, and is erased in release
builds. Read morefn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
.tap_borrow_mut()
only in debug builds, and is erased in release
builds. Read morefn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
.tap_ref()
only in debug builds, and is erased in release
builds. Read morefn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
.tap_ref_mut()
only in debug builds, and is erased in release
builds. Read more