[−][src]Struct curve25519_dalek::backend::serial::u64::field::FieldElement51
A FieldElement51
represents an element of the field
.
In the 64-bit implementation, a FieldElement
is represented in
radix as five u64
s; the coefficients are allowed to
grow up to between reductions modulo .
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.
Methods
impl FieldElement51
[src][−]
pub fn is_negative(&self) -> Choice
[src][−]
Determine if this FieldElement
is negative, in the sense
used in the ed25519 paper: x
is negative if the low bit is
set.
Return
If negative, return Choice(1)
. Otherwise, return Choice(0)
.
pub fn is_zero(&self) -> Choice
[src][−]
Determine if this FieldElement
is zero.
Return
If zero, return Choice(1)
. Otherwise, return Choice(0)
.
fn pow22501(&self) -> (FieldElement51, FieldElement51)
[src][−]
Compute (self^(2^250-1), self^11), used as a helper function within invert() and pow22523().
pub fn batch_invert(inputs: &mut [FieldElement51])
[src][−]
Given a slice of public FieldElements
, replace each with its inverse.
All input FieldElements
MUST be nonzero.
pub fn invert(&self) -> FieldElement51
[src][−]
Given a nonzero field element, compute its inverse.
The inverse is computed as self^(p-2), since x^(p-2)x = x^(p-1) = 1 (mod p).
This function returns zero on input zero.
fn pow_p58(&self) -> FieldElement51
[src][−]
Raise this field element to the power (p-5)/8 = 2^252 -3.
pub fn sqrt_ratio_i(
u: &FieldElement51,
v: &FieldElement51
) -> (Choice, FieldElement51)
[src][−]
u: &FieldElement51,
v: &FieldElement51
) -> (Choice, FieldElement51)
Given FieldElements
u
and v
, compute either sqrt(u/v)
or sqrt(i*u/v)
in constant time.
This function always returns the nonnegative square root.
Return
(Choice(1), +sqrt(u/v))
ifv
is nonzero andu/v
is square;(Choice(1), zero)
ifu
is zero;(Choice(0), zero)
ifv
is zero andu
is nonzero;(Choice(0), +sqrt(i*u/v))
ifu/v
is nonsquare (soi*u/v
is square).
pub fn invsqrt(&self) -> (Choice, FieldElement51)
[src][−]
Attempt to compute sqrt(1/self)
in constant time.
Convenience wrapper around sqrt_ratio_i
.
This function always returns the nonnegative square root.
Return
(Choice(1), +sqrt(1/self))
ifself
is a nonzero square;(Choice(0), zero)
ifself
is zero;(Choice(0), +sqrt(i/self))
ifself
is a nonzero nonsquare;
impl FieldElement51
[src][−]
pub fn negate(&mut self)
[src][−]
Invert the sign of this field element
pub fn zero() -> FieldElement51
[src][−]
Construct zero.
pub fn one() -> FieldElement51
[src][−]
Construct one.
pub fn minus_one() -> FieldElement51
[src][−]
Construct -1.
fn reduce(limbs: [u64; 5]) -> FieldElement51
[src][−]
Given 64-bit input limbs, reduce to enforce the bound 2^(51 + epsilon).
pub fn from_bytes(bytes: &[u8; 32]) -> FieldElement51
[src][−]
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.
pub fn to_bytes(&self) -> [u8; 32]
[src][−]
Serialize this FieldElement51
to a 32-byte array. The
encoding is canonical.
pub fn pow2k(&self, k: u32) -> FieldElement51
[src][−]
Given k > 0
, return self^(2^k)
.
pub fn square(&self) -> FieldElement51
[src][−]
Returns the square of this field element.
pub fn square2(&self) -> FieldElement51
[src][−]
Returns 2 times the square of this field element.
Trait Implementations
impl<'a, 'b> Add<&'b FieldElement51> for &'a FieldElement51
[src][+]
impl<'b> AddAssign<&'b FieldElement51> for FieldElement51
[src][+]
impl Clone for FieldElement51
[src][+]
impl ConditionallySelectable for FieldElement51
[src][+]
impl ConstantTimeEq for FieldElement51
[src][+]
impl Copy for FieldElement51
[src]
impl Debug for FieldElement51
[src][+]
impl Eq for FieldElement51
[src][+]
impl<'a, 'b> Mul<&'b FieldElement51> for &'a FieldElement51
[src][+]
impl<'b> MulAssign<&'b FieldElement51> for FieldElement51
[src][+]
impl<'a> Neg for &'a FieldElement51
[src][+]
impl PartialEq<FieldElement51> for FieldElement51
[src][+]
impl<'a, 'b> Sub<&'b FieldElement51> for &'a FieldElement51
[src][+]
impl<'b> SubAssign<&'b FieldElement51> for FieldElement51
[src][+]
impl Zeroize for FieldElement51
[src][+]
Auto Trait Implementations
impl RefUnwindSafe for FieldElement51
impl Send for FieldElement51
impl Sync for FieldElement51
impl Unpin for FieldElement51
impl UnwindSafe for FieldElement51
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src][+]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src][+]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src][+]
T: ?Sized,
impl<T, U> Cast<U> for T where
U: FromCast<T>,
[+]
U: FromCast<T>,
impl<T> ConditionallyNegatable for T where
T: ConditionallySelectable,
&'a T: Neg,
<&'a T as Neg>::Output == T,
[src][+]
T: ConditionallySelectable,
&'a T: Neg,
<&'a T as Neg>::Output == T,
impl<T> From<T> for T
[src][+]
impl<T> FromBits<T> for T
[+]
impl<T> FromCast<T> for T
[+]
impl<T, U> Into<U> for T where
U: From<T>,
[src][+]
U: From<T>,
impl<T, U> IntoBits<U> for T where
U: FromBits<T>,
[+]
U: FromBits<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src][+]
T: Clone,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src][+]
U: Into<T>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src][+]
U: TryFrom<T>,
impl<Z> Zeroize for Z where
Z: DefaultIsZeroes,
[src][+]
Z: DefaultIsZeroes,