Struct curve25519_dalek::backend::serial::u32::field::FieldElement2625
source · pub struct FieldElement2625(_);
curve25519_dalek_bits="32"
only.Expand description
A FieldElement2625
represents an element of the field
\( \mathbb Z / (2^{255} - 19)\).
In the 32-bit implementation, a FieldElement
is represented in
radix \(2^{25.5}\) as ten u32
s. This means that a field
element \(x\) is represented as
$$
x = \sum_{i=0}^9 x_i 2^{\lceil i \frac {51} 2 \rceil}
= x_0 + x_1 2^{26} + x_2 2^{51} + x_3 2^{77} + \cdots + x_9 2^{230};
$$
the coefficients are alternately bounded by \(2^{25}\) and
\(2^{26}\). The limbs are allowed to grow between reductions up
to \(2^{25+b}\) or \(2^{26+b}\), where \(b = 1.75\).
Note
The curve25519_dalek::field
module provides a type alias
curve25519_dalek::field::FieldElement
to either FieldElement51
or FieldElement2625
.
The backend-specific type FieldElement2625
should not be used
outside of the curve25519_dalek::field
module.
Implementations§
source§impl FieldElement2625
impl FieldElement2625
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 [FieldElement2625])
Available on crate feature alloc
only.
pub fn batch_invert(inputs: &mut [FieldElement2625])
alloc
only.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) -> FieldElement2625
pub fn invert(&self) -> FieldElement2625
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: &FieldElement2625,
v: &FieldElement2625
) -> (Choice, FieldElement2625)
pub fn sqrt_ratio_i( u: &FieldElement2625, v: &FieldElement2625 ) -> (Choice, FieldElement2625)
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, FieldElement2625)
pub fn invsqrt(&self) -> (Choice, FieldElement2625)
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;
source§impl FieldElement2625
impl FieldElement2625
sourcepub const ZERO: FieldElement2625 = _
pub const ZERO: FieldElement2625 = _
The scalar \( 0 \).
sourcepub const ONE: FieldElement2625 = _
pub const ONE: FieldElement2625 = _
The scalar \( 1 \).
sourcepub const MINUS_ONE: FieldElement2625 = _
pub const MINUS_ONE: FieldElement2625 = _
The scalar \( -1 \).
sourcepub fn pow2k(&self, k: u32) -> FieldElement2625
pub fn pow2k(&self, k: u32) -> FieldElement2625
Given k > 0
, return self^(2^k)
.
sourcepub fn from_bytes(data: &[u8; 32]) -> FieldElement2625
pub fn from_bytes(data: &[u8; 32]) -> FieldElement2625
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 square(&self) -> FieldElement2625
pub fn square(&self) -> FieldElement2625
Compute self^2
.
sourcepub fn square2(&self) -> FieldElement2625
pub fn square2(&self) -> FieldElement2625
Compute 2*self^2
.
Trait Implementations§
source§impl<'a, 'b> Add<&'b FieldElement2625> for &'a FieldElement2625
impl<'a, 'b> Add<&'b FieldElement2625> for &'a FieldElement2625
§type Output = FieldElement2625
type Output = FieldElement2625
+
operator.source§fn add(self, _rhs: &'b FieldElement2625) -> FieldElement2625
fn add(self, _rhs: &'b FieldElement2625) -> FieldElement2625
+
operation. Read moresource§impl<'b> AddAssign<&'b FieldElement2625> for FieldElement2625
impl<'b> AddAssign<&'b FieldElement2625> for FieldElement2625
source§fn add_assign(&mut self, _rhs: &'b FieldElement2625)
fn add_assign(&mut self, _rhs: &'b FieldElement2625)
+=
operation. Read moresource§impl Clone for FieldElement2625
impl Clone for FieldElement2625
source§fn clone(&self) -> FieldElement2625
fn clone(&self) -> FieldElement2625
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl ConditionallySelectable for FieldElement2625
impl ConditionallySelectable for FieldElement2625
source§fn conditional_select(
a: &FieldElement2625,
b: &FieldElement2625,
choice: Choice
) -> FieldElement2625
fn conditional_select( a: &FieldElement2625, b: &FieldElement2625, choice: Choice ) -> FieldElement2625
source§fn conditional_assign(&mut self, other: &FieldElement2625, choice: Choice)
fn conditional_assign(&mut self, other: &FieldElement2625, choice: Choice)
source§fn conditional_swap(
a: &mut FieldElement2625,
b: &mut FieldElement2625,
choice: Choice
)
fn conditional_swap( a: &mut FieldElement2625, b: &mut FieldElement2625, choice: Choice )
self
and other
if choice == 1
; otherwise,
reassign both unto themselves. Read moresource§impl ConstantTimeEq for FieldElement2625
impl ConstantTimeEq for FieldElement2625
source§fn ct_eq(&self, other: &FieldElement2625) -> Choice
fn ct_eq(&self, other: &FieldElement2625) -> Choice
Test equality between two FieldElement
s. Since the
internal representation is not canonical, the field elements
are normalized to wire format before comparison.
source§impl Debug for FieldElement2625
impl Debug for FieldElement2625
source§impl<'a, 'b> Mul<&'b FieldElement2625> for &'a FieldElement2625
impl<'a, 'b> Mul<&'b FieldElement2625> for &'a FieldElement2625
§type Output = FieldElement2625
type Output = FieldElement2625
*
operator.source§fn mul(self, _rhs: &'b FieldElement2625) -> FieldElement2625
fn mul(self, _rhs: &'b FieldElement2625) -> FieldElement2625
*
operation. Read moresource§impl<'b> MulAssign<&'b FieldElement2625> for FieldElement2625
impl<'b> MulAssign<&'b FieldElement2625> for FieldElement2625
source§fn mul_assign(&mut self, _rhs: &'b FieldElement2625)
fn mul_assign(&mut self, _rhs: &'b FieldElement2625)
*=
operation. Read moresource§impl<'a> Neg for &'a FieldElement2625
impl<'a> Neg for &'a FieldElement2625
§type Output = FieldElement2625
type Output = FieldElement2625
-
operator.source§fn neg(self) -> FieldElement2625
fn neg(self) -> FieldElement2625
-
operation. Read moresource§impl PartialEq<FieldElement2625> for FieldElement2625
impl PartialEq<FieldElement2625> for FieldElement2625
source§fn eq(&self, other: &FieldElement2625) -> bool
fn eq(&self, other: &FieldElement2625) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<'a, 'b> Sub<&'b FieldElement2625> for &'a FieldElement2625
impl<'a, 'b> Sub<&'b FieldElement2625> for &'a FieldElement2625
§type Output = FieldElement2625
type Output = FieldElement2625
-
operator.source§fn sub(self, _rhs: &'b FieldElement2625) -> FieldElement2625
fn sub(self, _rhs: &'b FieldElement2625) -> FieldElement2625
-
operation. Read moresource§impl<'b> SubAssign<&'b FieldElement2625> for FieldElement2625
impl<'b> SubAssign<&'b FieldElement2625> for FieldElement2625
source§fn sub_assign(&mut self, _rhs: &'b FieldElement2625)
fn sub_assign(&mut self, _rhs: &'b FieldElement2625)
-=
operation. Read moresource§impl Zeroize for FieldElement2625
Available on crate feature zeroize
only.
impl Zeroize for FieldElement2625
zeroize
only.