pub struct FieldElement(/* private fields */);
Expand description
A constant-time implementation of the Ed25519 field.
Implementations§
Source§impl FieldElement
impl FieldElement
Sourcepub fn from_square(value: [u8; 32]) -> FieldElement
pub fn from_square(value: [u8; 32]) -> FieldElement
Interpret the value as a little-endian integer, square it, and reduce it into a FieldElement.
Sourcepub fn pow(&self, other: FieldElement) -> FieldElement
pub fn pow(&self, other: FieldElement) -> FieldElement
Perform an exponentiation.
Sourcepub fn sqrt_ratio_i(u: FieldElement, v: FieldElement) -> (Choice, FieldElement)
pub fn sqrt_ratio_i(u: FieldElement, v: FieldElement) -> (Choice, FieldElement)
The square root of u/v, as used for Ed25519 point decoding (RFC 8032 5.1.3) and within Ristretto (5.1 Extracting an Inverse Square Root).
The result is only a valid square root if the Choice is true. RFC 8032 simply fails if there isn’t a square root, leaving any return value undefined. Ristretto explicitly returns 0 or sqrt((SQRT_M1 * u) / v).
Trait Implementations§
Source§impl<'a> Add<&'a FieldElement> for FieldElement
impl<'a> Add<&'a FieldElement> for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
+
operator.Source§impl Add for FieldElement
impl Add for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
+
operator.Source§impl<'a> AddAssign<&'a FieldElement> for FieldElement
impl<'a> AddAssign<&'a FieldElement> for FieldElement
Source§fn add_assign(&mut self, other: &'a FieldElement)
fn add_assign(&mut self, other: &'a 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 Debug for FieldElement
impl Debug for FieldElement
Source§impl Default for FieldElement
impl Default for FieldElement
Source§fn default() -> FieldElement
fn default() -> 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(u: &FieldElement, v: &FieldElement) -> (Choice, FieldElement)
fn sqrt_ratio(u: &FieldElement, v: &FieldElement) -> (Choice, FieldElement)
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(a: u128) -> FieldElement
fn from(a: u128) -> FieldElement
Source§impl From<u16> for FieldElement
impl From<u16> for FieldElement
Source§fn from(a: u16) -> FieldElement
fn from(a: u16) -> FieldElement
Source§impl From<u32> for FieldElement
impl From<u32> for FieldElement
Source§fn from(a: u32) -> FieldElement
fn from(a: u32) -> FieldElement
Source§impl From<u64> for FieldElement
impl From<u64> for FieldElement
Source§fn from(a: u64) -> FieldElement
fn from(a: u64) -> FieldElement
Source§impl From<u8> for FieldElement
impl From<u8> for FieldElement
Source§fn from(a: u8) -> FieldElement
fn from(a: u8) -> FieldElement
Source§impl<'a> Mul<&'a FieldElement> for FieldElement
impl<'a> Mul<&'a FieldElement> for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
*
operator.Source§impl Mul for FieldElement
impl Mul for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
*
operator.Source§impl<'a> MulAssign<&'a FieldElement> for FieldElement
impl<'a> MulAssign<&'a FieldElement> for FieldElement
Source§fn mul_assign(&mut self, other: &'a FieldElement)
fn mul_assign(&mut self, other: &'a 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<'a> Neg for &'a FieldElement
impl<'a> Neg for &'a FieldElement
Source§impl Neg for FieldElement
impl Neg for FieldElement
Source§impl PartialEq for FieldElement
impl PartialEq for FieldElement
Source§impl PrimeField for FieldElement
impl PrimeField for FieldElement
Source§const MODULUS: &'static str = "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"
const MODULUS: &'static str = "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"
Source§const CAPACITY: u32 = 254u32
const CAPACITY: u32 = 254u32
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 = [u8; 32]
type Repr = [u8; 32]
Source§fn from_repr(bytes: [u8; 32]) -> CtOption<Self>
fn from_repr(bytes: [u8; 32]) -> CtOption<Self>
Source§fn to_repr(&self) -> [u8; 32]
fn to_repr(&self) -> [u8; 32]
Source§fn from_str_vartime(s: &str) -> Option<Self>
fn from_str_vartime(s: &str) -> Option<Self>
Source§impl PrimeFieldBits for FieldElement
impl PrimeFieldBits for FieldElement
Source§fn to_le_bits(&self) -> FieldBits<Self::ReprBits>
fn to_le_bits(&self) -> FieldBits<Self::ReprBits>
Source§fn char_le_bits() -> FieldBits<Self::ReprBits>
fn char_le_bits() -> FieldBits<Self::ReprBits>
Source§impl<'a> Product<&'a FieldElement> for FieldElement
impl<'a> Product<&'a FieldElement> for FieldElement
Source§fn product<I: Iterator<Item = &'a FieldElement>>(iter: I) -> FieldElement
fn product<I: Iterator<Item = &'a FieldElement>>(iter: I) -> FieldElement
Self
from the elements by multiplying
the items.Source§impl Product for FieldElement
impl Product for FieldElement
Source§fn product<I: Iterator<Item = FieldElement>>(iter: I) -> FieldElement
fn product<I: Iterator<Item = FieldElement>>(iter: I) -> FieldElement
Self
from the elements by multiplying
the items.Source§impl<'a> Sub<&'a FieldElement> for FieldElement
impl<'a> Sub<&'a FieldElement> for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
-
operator.Source§impl Sub for FieldElement
impl Sub for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
-
operator.Source§impl<'a> SubAssign<&'a FieldElement> for FieldElement
impl<'a> SubAssign<&'a FieldElement> for FieldElement
Source§fn sub_assign(&mut self, other: &'a FieldElement)
fn sub_assign(&mut self, other: &'a 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) -> FieldElement
fn sum<I: Iterator<Item = &'a FieldElement>>(iter: I) -> FieldElement
Self
from the elements by “summing up”
the items.Source§impl Sum for FieldElement
impl Sum for FieldElement
Source§fn sum<I: Iterator<Item = FieldElement>>(iter: I) -> FieldElement
fn sum<I: Iterator<Item = FieldElement>>(iter: I) -> FieldElement
Self
from the elements by “summing up”
the items.impl Copy for FieldElement
impl Eq for FieldElement
impl StructuralPartialEq 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> 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> 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.impl<T, Rhs, Output> GroupOps<Rhs, Output> for T
impl<T, Rhs, Output> GroupOpsOwned<Rhs, Output> for T
impl<T, Rhs, Output> ScalarMul<Rhs, Output> for T
impl<T, Rhs, Output> ScalarMulOwned<Rhs, Output> for T
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 32 bytes