Struct test_dalek_docs::backend::serial::u64::field::FieldElement51
source · pub struct FieldElement51(_);
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 u64
s; 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
sourceimpl FieldElement51
impl FieldElement51
sourcepub fn is_negative(&self) -> Choice
pub fn is_negative(&self) -> Choice
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)
.
sourcepub fn is_zero(&self) -> Choice
pub fn is_zero(&self) -> Choice
Determine if this FieldElement
is zero.
Return
If zero, return Choice(1)
. Otherwise, return Choice(0)
.
sourcepub fn batch_invert(inputs: &mut [FieldElement51])
pub fn batch_invert(inputs: &mut [FieldElement51])
Given a slice of public FieldElements
, replace each with its inverse.
When an input FieldElement
is zero, its value is unchanged.
sourcepub fn invert(&self) -> FieldElement51
pub fn invert(&self) -> FieldElement51
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.
sourcepub fn sqrt_ratio_i(
u: &FieldElement51,
v: &FieldElement51
) -> (Choice, FieldElement51)
pub fn sqrt_ratio_i(
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).
sourcepub fn invsqrt(&self) -> (Choice, FieldElement51)
pub fn invsqrt(&self) -> (Choice, FieldElement51)
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;
sourceimpl FieldElement51
impl FieldElement51
sourcepub fn zero() -> FieldElement51
pub fn zero() -> FieldElement51
Construct zero.
sourcepub fn one() -> FieldElement51
pub fn one() -> FieldElement51
Construct one.
sourcepub fn minus_one() -> FieldElement51
pub fn minus_one() -> FieldElement51
Construct -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 to_bytes(&self) -> [u8; 32]
pub fn to_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
sourceimpl<'a, 'b> Add<&'b FieldElement51> for &'a FieldElement51
impl<'a, 'b> Add<&'b FieldElement51> for &'a FieldElement51
type Output = FieldElement51
type Output = FieldElement51
+
operator.sourcefn add(self, _rhs: &'b FieldElement51) -> FieldElement51
fn add(self, _rhs: &'b FieldElement51) -> FieldElement51
+
operation. Read moresourceimpl<'b> AddAssign<&'b FieldElement51> for FieldElement51
impl<'b> AddAssign<&'b FieldElement51> for FieldElement51
sourcefn add_assign(&mut self, _rhs: &'b FieldElement51)
fn add_assign(&mut self, _rhs: &'b FieldElement51)
+=
operation. Read moresourceimpl Clone for FieldElement51
impl Clone for FieldElement51
sourcefn clone(&self) -> FieldElement51
fn clone(&self) -> FieldElement51
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl ConditionallySelectable for FieldElement51
impl ConditionallySelectable for FieldElement51
sourcefn conditional_select(
a: &FieldElement51,
b: &FieldElement51,
choice: Choice
) -> FieldElement51
fn conditional_select(
a: &FieldElement51,
b: &FieldElement51,
choice: Choice
) -> FieldElement51
sourcefn 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 moresourcefn conditional_assign(&mut self, other: &FieldElement51, choice: Choice)
fn conditional_assign(&mut self, other: &FieldElement51, choice: Choice)
sourceimpl ConstantTimeEq for FieldElement51
impl ConstantTimeEq for FieldElement51
sourcefn ct_eq(&self, other: &FieldElement51) -> Choice
fn ct_eq(&self, other: &FieldElement51) -> Choice
Test equality between two FieldElement
s. Since the
internal representation is not canonical, the field elements
are normalized to wire format before comparison.
sourceimpl Debug for FieldElement51
impl Debug for FieldElement51
sourceimpl<'a, 'b> Mul<&'b FieldElement51> for &'a FieldElement51
impl<'a, 'b> Mul<&'b FieldElement51> for &'a FieldElement51
type Output = FieldElement51
type Output = FieldElement51
*
operator.sourcefn mul(self, _rhs: &'b FieldElement51) -> FieldElement51
fn mul(self, _rhs: &'b FieldElement51) -> FieldElement51
*
operation. Read moresourceimpl<'b> MulAssign<&'b FieldElement51> for FieldElement51
impl<'b> MulAssign<&'b FieldElement51> for FieldElement51
sourcefn mul_assign(&mut self, _rhs: &'b FieldElement51)
fn mul_assign(&mut self, _rhs: &'b FieldElement51)
*=
operation. Read moresourceimpl<'a> Neg for &'a FieldElement51
impl<'a> Neg for &'a FieldElement51
type Output = FieldElement51
type Output = FieldElement51
-
operator.sourcefn neg(self) -> FieldElement51
fn neg(self) -> FieldElement51
-
operation. Read moresourceimpl PartialEq<FieldElement51> for FieldElement51
impl PartialEq<FieldElement51> for FieldElement51
sourcefn eq(&self, other: &FieldElement51) -> bool
fn eq(&self, other: &FieldElement51) -> bool
sourceimpl<'a, 'b> Sub<&'b FieldElement51> for &'a FieldElement51
impl<'a, 'b> Sub<&'b FieldElement51> for &'a FieldElement51
type Output = FieldElement51
type Output = FieldElement51
-
operator.sourcefn sub(self, _rhs: &'b FieldElement51) -> FieldElement51
fn sub(self, _rhs: &'b FieldElement51) -> FieldElement51
-
operation. Read moresourceimpl<'b> SubAssign<&'b FieldElement51> for FieldElement51
impl<'b> SubAssign<&'b FieldElement51> for FieldElement51
sourcefn sub_assign(&mut self, _rhs: &'b FieldElement51)
fn sub_assign(&mut self, _rhs: &'b FieldElement51)
-=
operation. Read more