Struct p256::FieldElement
source · pub struct FieldElement(_);
arithmetic
and expose-field
only.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§
source§impl 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)
.
source§impl 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§
source§impl Add<&FieldElement> for &FieldElement
impl Add<&FieldElement> for &FieldElement
§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
§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
§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<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 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§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>
§fn is_zero_vartime(&self) -> bool
fn is_zero_vartime(&self) -> bool
§fn pow_vartime<S>(&self, exp: S) -> Selfwhere
S: AsRef<[u64]>,
fn pow_vartime<S>(&self, exp: S) -> Selfwhere
S: AsRef<[u64]>,
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 MapToCurve for FieldElement
Available on crate feature hash2curve
only.
impl MapToCurve for FieldElement
hash2curve
only.§type Output = ProjectivePoint<NistP256>
type Output = ProjectivePoint<NistP256>
source§fn map_to_curve(&self) -> Self::Output
fn map_to_curve(&self) -> Self::Output
source§impl Mul<&FieldElement> for &FieldElement
impl Mul<&FieldElement> for &FieldElement
§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
§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
§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<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 Neg for FieldElement
impl Neg for FieldElement
§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 osswu(&self) -> (Self, Self)
fn osswu(&self) -> (Self, Self)
source§impl PartialEq<FieldElement> for FieldElement
impl PartialEq<FieldElement> for FieldElement
source§impl 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>
source§const CAPACITY: u32 = 255u32
const CAPACITY: u32 = 255u32
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 multiplicative_generator() -> Self
fn multiplicative_generator() -> Self
modulus - 1
order. This element must
also be a quadratic nonresidue. Read moresource§fn root_of_unity() -> Self
fn root_of_unity() -> Self
2^s
root of unity. Read more§fn 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>
source§impl Sgn0 for FieldElement
Available on crate feature hash2curve
only.
impl Sgn0 for FieldElement
hash2curve
only.source§impl Sub<&FieldElement> for &FieldElement
impl Sub<&FieldElement> for &FieldElement
§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
§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
§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<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 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§
§impl<T> Conv for T
impl<T> Conv for 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,
self
to use its Binary
implementation when Debug
-formatted.§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.§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.§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.§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.§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.§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.§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.§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 more§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 more§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<'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,
self
, then passes self.as_mut()
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 more§fn 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 more§fn 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 more§fn 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 more§fn 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 more§fn 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 more§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.§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.§fn 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.§fn 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.§fn 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.§fn 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.