pub struct FieldElement51(/* private fields */);docsrs and curve25519_dalek_bits=64 only.Expand description
A FieldElement51 represents an element of the field
\( \mathbb Z / (2^{255} - 19)\).
In the 64-bit implementation, a FieldElement is represented in
radix \(2^{51}\) as five u64s; the coefficients are allowed to
grow up to \(2^{54}\) between reductions modulo \(p\).
§Note
The curve25519_dalek::field module provides a type alias
curve25519_dalek::field::FieldElement to either FieldElement51
or FieldElement2625.
The backend-specific type FieldElement51 should not be used
outside of the curve25519_dalek::field module.
Implementations§
Source§impl FieldElement51
impl FieldElement51
Sourcepub const ZERO: FieldElement51
pub const ZERO: FieldElement51
The scalar \( 0 \).
Sourcepub const ONE: FieldElement51
pub const ONE: FieldElement51
The scalar \( 1 \).
Sourcepub const MINUS_ONE: FieldElement51
pub const MINUS_ONE: FieldElement51
The scalar \( -1 \).
Sourcepub fn from_bytes(bytes: &[u8; 32]) -> FieldElement51
pub fn from_bytes(bytes: &[u8; 32]) -> FieldElement51
Load a FieldElement51 from the low 255 bits of a 256-bit
input.
§Warning
This function does not check that the input used the canonical representative. It masks the high bit, but it will happily decode 2^255 - 18 to 1. Applications that require a canonical encoding of every field element should decode, re-encode to the canonical encoding, and check that the input was canonical.
Sourcepub fn as_bytes(&self) -> [u8; 32]
pub fn as_bytes(&self) -> [u8; 32]
Serialize this FieldElement51 to a 32-byte array. The
encoding is canonical.
Sourcepub fn pow2k(&self, k: u32) -> FieldElement51
pub fn pow2k(&self, k: u32) -> FieldElement51
Given k > 0, return self^(2^k).
Sourcepub fn square(&self) -> FieldElement51
pub fn square(&self) -> FieldElement51
Returns the square of this field element.
Sourcepub fn square2(&self) -> FieldElement51
pub fn square2(&self) -> FieldElement51
Returns 2 times the square of this field element.
Trait Implementations§
Source§impl<'a, 'b> Add<&'b FieldElement51> for &'a FieldElement51
impl<'a, 'b> Add<&'b FieldElement51> for &'a FieldElement51
Source§type Output = FieldElement51
type Output = FieldElement51
+ operator.Source§fn add(self, _rhs: &'b FieldElement51) -> FieldElement51
fn add(self, _rhs: &'b FieldElement51) -> FieldElement51
+ operation. Read moreSource§impl<'b> AddAssign<&'b FieldElement51> for FieldElement51
impl<'b> AddAssign<&'b FieldElement51> for FieldElement51
Source§fn add_assign(&mut self, _rhs: &'b FieldElement51)
fn add_assign(&mut self, _rhs: &'b FieldElement51)
+= operation. Read moreSource§impl Clone for FieldElement51
impl Clone for FieldElement51
Source§fn clone(&self) -> FieldElement51
fn clone(&self) -> FieldElement51
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl ConditionallySelectable for FieldElement51
impl ConditionallySelectable for FieldElement51
Source§fn conditional_select(
a: &FieldElement51,
b: &FieldElement51,
choice: Choice,
) -> FieldElement51
fn conditional_select( a: &FieldElement51, b: &FieldElement51, choice: Choice, ) -> FieldElement51
Source§fn conditional_swap(
a: &mut FieldElement51,
b: &mut FieldElement51,
choice: Choice,
)
fn conditional_swap( a: &mut FieldElement51, b: &mut FieldElement51, choice: Choice, )
self and other if choice == 1; otherwise,
reassign both unto themselves. Read moreSource§fn conditional_assign(&mut self, other: &FieldElement51, choice: Choice)
fn conditional_assign(&mut self, other: &FieldElement51, choice: Choice)
Source§impl ConstantTimeEq for FieldElement51
impl ConstantTimeEq for FieldElement51
Source§fn ct_eq(&self, other: &FieldElement51) -> Choice
fn ct_eq(&self, other: &FieldElement51) -> Choice
Test equality between two FieldElements. Since the
internal representation is not canonical, the field elements
are normalized to wire format before comparison.
Source§impl Debug for FieldElement51
impl Debug for FieldElement51
Source§impl Eq for FieldElement51
impl Eq for FieldElement51
#[doc(hidden)] fn assert_receiver_is_total_eq(&self)
Source§impl<'a, 'b> Mul<&'b FieldElement51> for &'a FieldElement51
impl<'a, 'b> Mul<&'b FieldElement51> for &'a FieldElement51
Source§type Output = FieldElement51
type Output = FieldElement51
* operator.Source§fn mul(self, _rhs: &'b FieldElement51) -> FieldElement51
fn mul(self, _rhs: &'b FieldElement51) -> FieldElement51
* operation. Read moreSource§impl<'b> MulAssign<&'b FieldElement51> for FieldElement51
impl<'b> MulAssign<&'b FieldElement51> for FieldElement51
Source§fn mul_assign(&mut self, _rhs: &'b FieldElement51)
fn mul_assign(&mut self, _rhs: &'b FieldElement51)
*= operation. Read moreSource§impl<'a> Neg for &'a FieldElement51
impl<'a> Neg for &'a FieldElement51
Source§type Output = FieldElement51
type Output = FieldElement51
- operator.Source§fn neg(self) -> FieldElement51
fn neg(self) -> FieldElement51
- operation. Read moreSource§impl PartialEq for FieldElement51
impl PartialEq for FieldElement51
Source§impl<'a, 'b> Sub<&'b FieldElement51> for &'a FieldElement51
impl<'a, 'b> Sub<&'b FieldElement51> for &'a FieldElement51
Source§type Output = FieldElement51
type Output = FieldElement51
- operator.Source§fn sub(self, _rhs: &'b FieldElement51) -> FieldElement51
fn sub(self, _rhs: &'b FieldElement51) -> FieldElement51
- operation. Read moreSource§impl<'b> SubAssign<&'b FieldElement51> for FieldElement51
impl<'b> SubAssign<&'b FieldElement51> for FieldElement51
Source§fn sub_assign(&mut self, _rhs: &'b FieldElement51)
fn sub_assign(&mut self, _rhs: &'b FieldElement51)
-= operation. Read moreSource§impl Zeroize for FieldElement51
Available on crate feature zeroize only.
impl Zeroize for FieldElement51
zeroize only.impl Copy for FieldElement51
impl TrivialClone for FieldElement51
Auto Trait Implementations§
impl Freeze for FieldElement51
impl RefUnwindSafe for FieldElement51
impl Send for FieldElement51
impl Sync for FieldElement51
impl Unpin for FieldElement51
impl UnwindSafe for FieldElement51
Blanket Implementations§
Source§impl<T> AssertZeroize for T
impl<T> AssertZeroize for T
fn zeroize_or_on_drop(&mut self)
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<A, B> IsEqualPrivate<B, Equal> for A
impl<A, B> IsEqualPrivate<B, Equal> for A
Source§impl<A, B> IsEqualPrivate<B, Greater> for A
impl<A, B> IsEqualPrivate<B, Greater> for A
Source§impl<A, B> IsEqualPrivate<B, Less> for A
impl<A, B> IsEqualPrivate<B, Less> for A
Source§impl<A, B> IsGreaterOrEqualPrivate<B, Equal> for A
impl<A, B> IsGreaterOrEqualPrivate<B, Equal> for A
Source§impl<A, B> IsGreaterOrEqualPrivate<B, Greater> for A
impl<A, B> IsGreaterOrEqualPrivate<B, Greater> for A
Source§impl<A, B> IsGreaterOrEqualPrivate<B, Less> for A
impl<A, B> IsGreaterOrEqualPrivate<B, Less> for A
Source§impl<A, B> IsGreaterPrivate<B, Equal> for A
impl<A, B> IsGreaterPrivate<B, Equal> for A
Source§impl<A, B> IsGreaterPrivate<B, Greater> for A
impl<A, B> IsGreaterPrivate<B, Greater> for A
Source§impl<A, B> IsGreaterPrivate<B, Less> for A
impl<A, B> IsGreaterPrivate<B, Less> for A
Source§impl<A, B> IsLessOrEqualPrivate<B, Equal> for A
impl<A, B> IsLessOrEqualPrivate<B, Equal> for A
Source§impl<A, B> IsLessOrEqualPrivate<B, Greater> for A
impl<A, B> IsLessOrEqualPrivate<B, Greater> for A
Source§impl<A, B> IsLessOrEqualPrivate<B, Less> for A
impl<A, B> IsLessOrEqualPrivate<B, Less> for A
Source§impl<A, B> IsLessPrivate<B, Equal> for A
impl<A, B> IsLessPrivate<B, Equal> for A
Source§impl<A, B> IsLessPrivate<B, Greater> for A
impl<A, B> IsLessPrivate<B, Greater> for A
Source§impl<A, B> IsLessPrivate<B, Less> for A
impl<A, B> IsLessPrivate<B, Less> for A
Source§impl<A, B> IsNotEqualPrivate<B, Equal> for A
impl<A, B> IsNotEqualPrivate<B, Equal> for A
Source§impl<A, B> IsNotEqualPrivate<B, Greater> for A
impl<A, B> IsNotEqualPrivate<B, Greater> for A
Source§impl<A, B> IsNotEqualPrivate<B, Less> for A
impl<A, B> IsNotEqualPrivate<B, Less> for A
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> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)] const SIZE: usize = _
#[doc(hidden)] const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)] const ALIGN: usize = _
#[doc(hidden)] const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)] const IS_ZST: bool = _
#[doc(hidden)] const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)] const LAYOUT: Layout = _
#[doc(hidden)] const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)] const MAX_SLICE_LEN: usize = _
#[doc(hidden)] const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read moreSource§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.