[−][src]Struct zerocaf::backend::u64::field::FieldElement
A FieldElement
represents an element of the field
which has order of 2^252 + 27742317777372353535851937790883648493
In the 64-bit backend implementation, the FieldElement
is
represented in radix 2^52
Methods
impl FieldElement
[src][−]
pub const fn zero() -> FieldElement
[src][−]
Construct zero.
pub const fn one() -> FieldElement
[src][−]
Construct one.
pub const fn minus_one() -> FieldElement
[src][−]
Construct -1 (mod l).
pub fn is_even(self) -> bool
[src][−]
Evaluate if a FieldElement
is even or not.
pub fn is_positive(&self) -> Choice
[src][−]
Checks if a ´FieldElement` is considered negative following the Decaf paper criteria.
The criteria says: Non-negative field elements.
Let p > 2 be prime. Define a residue x ∈ F =Z/pZ to be
“non-negative” if the least absolute residue for x is in
[0,(p−1)/2]
, and “negative” otherwise.
Returns:
Choice(1)
if pos.Choice(0)
if neg.
pub fn from_bytes(bytes: &[u8; 32]) -> FieldElement
[src][−]
Load a FieldElement
from the low 253b bits of a 256-bit
input. So Little Endian representation in bytes of a FieldElement.
pub fn to_bytes(self) -> [u8; 32]
[src][−]
Serialize this FieldElement
to a 32-byte array. The
encoding is canonical.
pub fn two_pow_k(exp: u64) -> FieldElement
[src][−]
Given a k
: u64, compute 2^k
giving the resulting result
as a FieldElement
.
See that the input must be between the range => 0..253.
NOTE: This function implements an assert!
statement that
checks the correctness of the exponent provided as param.
pub fn half_without_mod(self) -> FieldElement
[src][−]
Returns the half of an EVEN FieldElement
.
This function performs almost 4x faster than the
Half
implementation but SHOULD be used carefully.
Panics
When the FieldElement
provided is not even.
pub fn legendre_symbol(&self) -> Choice
[src][−]
Given a FieldElement, this function evaluates if it is a quadratic residue (mod l).
See: https://en.wikipedia.org/wiki/Legendre_symbol.
Returns:
-1
-> Non-quadratic residue (mod l) == Choice(0).
1
-> Quadratic residue (mod l) == Choice(1).
0
-> Input (mod l) == 0
. Not implemented since you can't pass
an input which is multiple of FIELD_L
.
pub fn inverse(&self) -> FieldElement
[src][−]
Compute a^-1 (mod l)
using the the Savas & Koç modular
inverse algorithm. It's an optimization of the Kalinski
modular inversion algorithm that extends the Binary GCD
algorithm to perform the modular inverse operation.
The PhaseII
it's substituded by 1 or 2 Montgomery Multiplications,
what makes the second part compute in almost ConstTime.
Panics
It is not possible to invert 0
by obvious reasons. So an
the function panics when trying to invert zero.
Special issue on Montgomery arithmetic. Montgomery inversion - Erkay Sava ̧s & Çetin Kaya Koç J Cryptogr Eng (2018) 8:201–210 https://doi.org/10.1007/s13389-017-0161-x.
Trait Implementations
impl<'a, 'b> Add<&'b FieldElement> for &'a FieldElement
[src][+]
impl Add<FieldElement> for FieldElement
[src][+]
impl Clone for FieldElement
[src][+]
impl Copy for FieldElement
[src]
impl Debug for FieldElement
[src][+]
impl Default for FieldElement
[src][+]
impl Display for FieldElement
[src][+]
impl<'a, 'b> Div<&'a FieldElement> for &'b FieldElement
[src][+]
impl Div<FieldElement> for FieldElement
[src][+]
impl Eq for FieldElement
[src]
impl<'a> From<&'a Scalar> for FieldElement
[src][+]
impl From<u128> for FieldElement
[src][+]
impl From<u16> for FieldElement
[src][+]
impl From<u32> for FieldElement
[src][+]
impl From<u64> for FieldElement
[src][+]
impl From<u8> for FieldElement
[src][+]
impl<'a> Half for &'a FieldElement
[src][+]
impl Identity for FieldElement
[src][+]
impl Index<usize> for FieldElement
[src][+]
impl IndexMut<usize> for FieldElement
[src][+]
impl Into<Scalar> for FieldElement
[src][+]
impl<'_> InvSqrt for &'_ FieldElement
[src][+]
impl<'a> ModSqrt for &'a FieldElement
[src][+]
impl<'a, 'b> Mul<&'b FieldElement> for &'a FieldElement
[src][+]
impl Mul<FieldElement> for FieldElement
[src][+]
impl<'a> Neg for &'a FieldElement
[src][+]
impl Neg for FieldElement
[src][+]
impl Ord for FieldElement
[src][+]
impl PartialEq<FieldElement> for FieldElement
[src][+]
impl PartialOrd<FieldElement> for FieldElement
[src][+]
impl<'a, 'b> Pow<&'b FieldElement> for &'a FieldElement
[src][+]
impl<'_> SqrtRatioI<&'_ FieldElement> for FieldElement
[src][+]
impl<'a> Square for &'a FieldElement
[src][+]
impl StructuralEq for FieldElement
[src]
impl<'a, 'b> Sub<&'b FieldElement> for &'a FieldElement
[src][+]
impl Sub<FieldElement> for FieldElement
[src][+]
Auto Trait Implementations
impl RefUnwindSafe for FieldElement
impl Send for FieldElement
impl Sync for FieldElement
impl Unpin for FieldElement
impl UnwindSafe for FieldElement
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> Clear for T where
T: InitializableFromZeroed + ?Sized,
[+]
T: InitializableFromZeroed + ?Sized,
impl<T> ConditionallyNegatable for T where
T: ConditionallySelectable,
&'a T: Neg,
<&'a T as Neg>::Output == T,
[+]
T: ConditionallySelectable,
&'a T: Neg,
<&'a T as Neg>::Output == T,
impl<T> From<T> for T
[src][+]
impl<T> InitializableFromZeroed for T where
T: Default,
[+]
T: Default,
impl<T, U> Into<U> for T where
U: From<T>,
[src][+]
U: From<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> ToString for T where
T: Display + ?Sized,
[src][+]
T: Display + ?Sized,
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<V, T> VZip<V> for T where
V: MultiLane<T>,
[+]
V: MultiLane<T>,