Struct curve25519_dalek::field::FieldElement32
[−]
[src]
pub struct FieldElement32(pub [i32; 10]);
A FieldElement32
represents an element of the field GF(2255 - 19).
In the 32-bit implementation, a FieldElement32
is represented in
radix 225.5 as ten i32
s, so that an element t, entries
t[0],...,t[9], represents the integer t[0]+226 t[1]+251
t[2]+277 t[3]+2102 t[4]+...+2230 t[9].
The coefficients t[i] are allowed to grow between multiplications.
XXX document by how much
Warning
You almost certainly do not want to use FieldElement32
directly. Consider
using curve25519_dalek::field::FieldElement
, which will automatically
select between FieldElement32
and FieldElement64
depending on whether
curve25519-dalek was compiled with --features="nightly"
.
This implementation, FieldElement32
, is intended for platforms that can
multiply 32-bit inputs to produce 64-bit outputs, and is not preferred for
use on x86_64, since the 64-bit implementation is both much simpler and much
faster. However, the FieldElement64
implementation requires Rust's
u128
, which is not yet stable.
Methods
impl FieldElement32
[src]
fn negate(&mut self)
Invert the sign of this field element
fn zero() -> FieldElement32
Construct zero.
fn one() -> FieldElement32
Construct one.
fn minus_one() -> FieldElement32
Construct -1.
fn from_bytes(data: &[u8; 32]) -> FieldElement32
Load a FieldElement64
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 2255 - 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.
XXX the above applies to the 64-bit implementation; check that it applies here too.
fn to_bytes(&self) -> [u8; 32]
Serialize this FieldElement64
to a 32-byte array. The
encoding is canonical.
fn square(&self) -> FieldElement32
Calculates h = f*f. Can overlap h with f.
XXX limbs: better to talk about headroom?
Preconditions
- |f[i]| bounded by 1.1*226, 1.1*225, 1.1*226, 1.1*225, etc.
Postconditions
- |h[i]| bounded by 1.1*225, 1.1*224, 1.1*225, 1.1*224, etc.
fn square2(&self) -> FieldElement32
Square this field element and multiply the result by 2.
XXX explain why square2 exists vs square (overflow)
Preconditions
- |f[i]| bounded by 1.65*226, 1.65*225, 1.65*226, 1.65*225, etc.
Postconditions
- |h[i]| bounded by 1.01*225, 1.01*224, 1.01*225, 1.01*224, etc.
Notes
See fe_mul.c in ref10 implementation for discussion of implementation strategy.
Trait Implementations
impl Copy for FieldElement32
[src]
impl Clone for FieldElement32
[src]
fn clone(&self) -> FieldElement32
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Debug for FieldElement32
[src]
impl<'b> AddAssign<&'b FieldElement32> for FieldElement32
[src]
fn add_assign(&mut self, _rhs: &'b FieldElement32)
The method for the +=
operator
impl<'a, 'b> Add<&'b FieldElement32> for &'a FieldElement32
[src]
type Output = FieldElement32
The resulting type after applying the +
operator
fn add(self, _rhs: &'b FieldElement32) -> FieldElement32
The method for the +
operator
impl<'b> SubAssign<&'b FieldElement32> for FieldElement32
[src]
fn sub_assign(&mut self, _rhs: &'b FieldElement32)
The method for the -=
operator
impl<'a, 'b> Sub<&'b FieldElement32> for &'a FieldElement32
[src]
type Output = FieldElement32
The resulting type after applying the -
operator
fn sub(self, _rhs: &'b FieldElement32) -> FieldElement32
The method for the -
operator
impl<'b> MulAssign<&'b FieldElement32> for FieldElement32
[src]
fn mul_assign(&mut self, _rhs: &'b FieldElement32)
The method for the *=
operator
impl<'a, 'b> Mul<&'b FieldElement32> for &'a FieldElement32
[src]
type Output = FieldElement32
The resulting type after applying the *
operator
fn mul(self, _rhs: &'b FieldElement32) -> FieldElement32
The method for the *
operator
impl<'a> Neg for &'a FieldElement32
[src]
type Output = FieldElement32
The resulting type after applying the -
operator
fn neg(self) -> FieldElement32
The method for the unary -
operator
impl ConditionallyAssignable for FieldElement32
[src]
fn conditional_assign(&mut self, f: &FieldElement32, choice: u8)
Conditionally assign other
to self
in constant time. Read more