Struct dalek_ff_group::FieldElement
source · 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
§type Output = FieldElement
type Output = FieldElement
The resulting type after applying the
+
operator.source§impl Add for FieldElement
impl Add for FieldElement
§type Output = FieldElement
type Output = FieldElement
The resulting type after applying the
+
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)
Performs the
+=
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)
Performs the
+=
operation. Read moresource§impl Clone for FieldElement
impl Clone for FieldElement
source§fn clone(&self) -> FieldElement
fn clone(&self) -> FieldElement
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl ConditionallySelectable for FieldElement
impl ConditionallySelectable for FieldElement
source§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
Returns the “default value” for a type. Read more
source§impl Field for FieldElement
impl Field for FieldElement
source§fn random(rng: impl RngCore) -> Self
fn random(rng: impl RngCore) -> Self
Returns an element chosen uniformly at random using a user-provided RNG.
source§fn invert(&self) -> CtOption<Self>
fn invert(&self) -> CtOption<Self>
Computes the multiplicative inverse of this element,
failing if the element is zero.
source§fn sqrt(&self) -> CtOption<Self>
fn sqrt(&self) -> CtOption<Self>
Returns the square root of the field element, if it is
quadratic residue. Read more
source§fn sqrt_ratio(u: &FieldElement, v: &FieldElement) -> (Choice, FieldElement)
fn sqrt_ratio(u: &FieldElement, v: &FieldElement) -> (Choice, FieldElement)
Computes: Read more
source§fn is_zero_vartime(&self) -> bool
fn is_zero_vartime(&self) -> bool
Returns true iff this element is zero. Read more
source§impl From<u128> for FieldElement
impl From<u128> for FieldElement
source§fn from(a: u128) -> FieldElement
fn from(a: u128) -> FieldElement
Converts to this type from the input type.
source§impl From<u16> for FieldElement
impl From<u16> for FieldElement
source§fn from(a: u16) -> FieldElement
fn from(a: u16) -> FieldElement
Converts to this type from the input type.
source§impl From<u32> for FieldElement
impl From<u32> for FieldElement
source§fn from(a: u32) -> FieldElement
fn from(a: u32) -> FieldElement
Converts to this type from the input type.
source§impl From<u64> for FieldElement
impl From<u64> for FieldElement
source§fn from(a: u64) -> FieldElement
fn from(a: u64) -> FieldElement
Converts to this type from the input type.
source§impl From<u8> for FieldElement
impl From<u8> for FieldElement
source§fn from(a: u8) -> FieldElement
fn from(a: u8) -> FieldElement
Converts to this type from the input type.
source§impl<'a> Mul<&'a FieldElement> for FieldElement
impl<'a> Mul<&'a FieldElement> for FieldElement
§type Output = FieldElement
type Output = FieldElement
The resulting type after applying the
*
operator.source§impl Mul for FieldElement
impl Mul for FieldElement
§type Output = FieldElement
type Output = FieldElement
The resulting type after applying the
*
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)
Performs the
*=
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)
Performs the
*=
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§fn eq(&self, other: &FieldElement) -> bool
fn eq(&self, other: &FieldElement) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PrimeField for FieldElement
impl PrimeField for FieldElement
§type Repr = [u8; 32]
type Repr = [u8; 32]
The prime field can be converted back and forth into this binary
representation.
source§const MODULUS: &'static str = "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"
const MODULUS: &'static str = "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"
Modulus of the field written as a string for debugging purposes. Read more
source§const CAPACITY: u32 = 254u32
const CAPACITY: u32 = 254u32
How many bits of information can be reliably stored in the field element. Read more
source§const MULTIPLICATIVE_GENERATOR: Self = _
const MULTIPLICATIVE_GENERATOR: Self = _
A fixed multiplicative generator of
modulus - 1
order. This element must also be
a quadratic nonresidue. Read moresource§const ROOT_OF_UNITY: Self = _
const ROOT_OF_UNITY: Self = _
The
2^s
root of unity. Read moresource§const ROOT_OF_UNITY_INV: Self = _
const ROOT_OF_UNITY_INV: Self = _
Inverse of
Self::ROOT_OF_UNITY
.source§fn from_repr(bytes: [u8; 32]) -> CtOption<Self>
fn from_repr(bytes: [u8; 32]) -> CtOption<Self>
Attempts to convert a byte representation of a field element into an element of
this prime field, failing if the input is not canonical (is not smaller than the
field’s modulus). Read more
source§fn to_repr(&self) -> [u8; 32]
fn to_repr(&self) -> [u8; 32]
Converts an element of the prime field into the standard byte representation for
this field. Read more
source§fn from_str_vartime(s: &str) -> Option<Self>
fn from_str_vartime(s: &str) -> Option<Self>
Interpret a string of numbers as a (congruent) prime field element.
Does not accept unnecessary leading zeroes or a blank string. Read more
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>
Converts an element of the prime field into a little-endian sequence of bits.
source§fn char_le_bits() -> FieldBits<Self::ReprBits>
fn char_le_bits() -> FieldBits<Self::ReprBits>
Returns the bits of the field characteristic (the modulus) in little-endian order.
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
Method which takes an iterator and generates
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
Method which takes an iterator and generates
Self
from the elements by
multiplying the items.source§impl<'a> Sub<&'a FieldElement> for FieldElement
impl<'a> Sub<&'a FieldElement> for FieldElement
§type Output = FieldElement
type Output = FieldElement
The resulting type after applying the
-
operator.source§impl Sub for FieldElement
impl Sub for FieldElement
§type Output = FieldElement
type Output = FieldElement
The resulting type after applying the
-
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)
Performs the
-=
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)
Performs the
-=
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
Method which takes an iterator and generates
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
Method which takes an iterator and generates
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
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)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,
Causes
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,
Causes
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,
Causes
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,
Causes
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,
Causes
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,
Causes
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,
Causes
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,
Causes
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,
Pipes by value. This is generally the method you want to use. Read more
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,
Borrows
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,
Mutably borrows
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
Borrows
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
Mutably borrows
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
Borrows
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
Immutable access to the
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
Mutable access to the
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
Immutable access to the
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
Mutable access to the
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
Immutable access to the
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
Mutable access to the
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
Calls
.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
Calls
.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
Calls
.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
Calls
.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
Calls
.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
Calls
.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
Calls
.tap_deref()
only in debug builds, and is erased in release
builds.