[][src]Struct zerocaf::backend::u64::scalar::Scalar

pub struct Scalar(pub [u64; 5]);

The Scalar struct represents an Scalar over the modulo 2^249 + 14490550575682688738086195780655237219 as 5 52-bit limbs represented in radix 2^52.

Methods

impl Scalar[src]

pub const fn zero() -> Scalar[src]

Return a Scalar with value = 0.

pub const fn one() -> Scalar[src]

Return a Scalar with value = 1.

pub const fn minus_one() -> Scalar[src]

Return a Scalar with value = -1 (mod l).

pub fn is_even(self) -> bool[src]

Evaluate if a Scalar is even or not.

pub fn into_bits(&self) -> [u8; 256][src]

Returns the bit representation of the given Scalar as an array of 256 bits represented as u8.

pub fn compute_NAF(&self) -> [i8; 256][src]

Compute the Non-Adjacent Form of a given Scalar.

pub fn compute_window_NAF(&self, width: u8) -> [i8; 256][src]

Compute the Windowed-Non-Adjacent Form of a given Scalar.

Inputs

  • width => Represents the window-width i.e. width = 2^width.

pub fn mod_2_pow_k(&self, k: u8) -> u8[src]

Compute the result from Scalar (mod 2^k).

Panics

If the given k is > 32 (5 bits) as the value gets greater than the limb.

pub fn mods_2_pow_k(&self, w: u8) -> i8[src]

Compute the result from Scalar (mods k).

Panics

If the given k > 32 (5 bits) || k == 0 as the value gets greater than the limb.

pub fn from_bytes(bytes: &[u8; 32]) -> Scalar[src]

Unpack a 32 byte / 256 bit Scalar into 5 52-bit limbs.

pub fn from_bytes_wide(_bytes: &[u8; 64]) -> Scalar[src]

Reduce a 64 byte / 512 bit scalar mod l

pub fn to_bytes(&self) -> [u8; 32][src]

Pack the limbs of this Scalar into 32 bytes

pub fn two_pow_k(exp: u64) -> Scalar[src]

Given a k: u64, compute 2^k giving the resulting result as a Scalar.

See that the input must be between the range => 0..250.

Panics

If the input is greater than the Sub-group order.

pub fn half_without_mod(self) -> Scalar[src]

Returns the half of an EVEN Scalar.

This function performs almost 4x faster than the Half implementation but SHOULD be used carefully.

Panics

When the Scalar provided is not even.

Trait Implementations

impl<'a, 'b> Add<&'b Scalar> for &'a Scalar[src]

type Output = Scalar

The resulting type after applying the + operator.

fn add(self, b: &'b Scalar) -> Scalar[src]

Compute a + b (mod l).

impl Add<Scalar> for Scalar[src]

type Output = Scalar

The resulting type after applying the + operator.

fn add(self, b: Scalar) -> Scalar[src]

Compute a + b (mod l).

impl Clone for Scalar[src]

impl Copy for Scalar[src]

impl Debug for Scalar[src]

impl From<i8> for Scalar[src]

fn from(_inp: i8) -> Scalar[src]

Performs the conversion.

impl From<u128> for Scalar[src]

fn from(_inp: u128) -> Scalar[src]

Performs the conversion.

impl From<u16> for Scalar[src]

fn from(_inp: u16) -> Scalar[src]

Performs the conversion.

impl From<u32> for Scalar[src]

fn from(_inp: u32) -> Scalar[src]

Performs the conversion.

impl From<u64> for Scalar[src]

fn from(_inp: u64) -> Scalar[src]

Performs the conversion.

impl From<u8> for Scalar[src]

fn from(_inp: u8) -> Scalar[src]

Performs the conversion.

impl<'a> Half for &'a Scalar[src]

type Output = Scalar

fn half(self) -> Scalar[src]

Give the half of the Scalar value (mod l).

impl Identity for Scalar[src]

fn identity() -> Scalar[src]

Returns the Identity element for Scalar which equals 1 (mod l).

impl Index<usize> for Scalar[src]

type Output = u64

The returned type after indexing.

impl IndexMut<usize> for Scalar[src]

impl<'a, 'b> Mul<&'a Scalar> for &'b Scalar[src]

type Output = Scalar

The resulting type after applying the * operator.

fn mul(self, b: &'a Scalar) -> Scalar[src]

This Mul implementation returns a double precision result. The result of the standard mul is stored on a [u128; 9].

Then, we apply the Montgomery Reduction function to perform the modulo and the reduction to the Scalar format: [u64; 5].

impl<'a, 'b> Mul<&'a Scalar> for &'b ProjectivePoint[src]

type Output = ProjectivePoint

The resulting type after applying the * operator.

fn mul(self, scalar: &'a Scalar) -> ProjectivePoint[src]

Scalar multiplication: compute Scalar * self. This implementation uses the algorithm: add_and_doubling which is the standard one for this operations and also adds less constraints on R1CS.

Hankerson, Darrel; Vanstone, Scott; Menezes, Alfred (2004). Guide to Elliptic Curve Cryptography. Springer Professional Computing. New York: Springer-Verlag.

impl<'a, 'b> Mul<&'b Scalar> for &'a EdwardsPoint[src]

type Output = EdwardsPoint

The resulting type after applying the * operator.

fn mul(self, scalar: &'b Scalar) -> EdwardsPoint[src]

Scalar multiplication: compute self * Scalar. This implementation uses the algorithm: add_and_doubling which is the standard one for this operations and also adds less constraints on R1CS.

Hankerson, Darrel; Vanstone, Scott; Menezes, Alfred (2004). Guide to Elliptic Curve Cryptography. Springer Professional Computing. New York: Springer-Verlag.

impl<'a, 'b> Mul<&'b Scalar> for &'a RistrettoPoint[src]

type Output = RistrettoPoint

The resulting type after applying the * operator.

fn mul(self, scalar: &'b Scalar) -> RistrettoPoint[src]

Scalar multiplication: compute self * Scalar. This implementation uses the algorithm: add_and_doubling which is the standard one for this operations and also adds less constraints on R1CS.

Hankerson, Darrel; Vanstone, Scott; Menezes, Alfred (2004). Guide to Elliptic Curve Cryptography. Springer Professional Computing. New York: Springer-Verlag.

impl Mul<Scalar> for Scalar[src]

type Output = Scalar

The resulting type after applying the * operator.

fn mul(self, b: Scalar) -> Scalar[src]

This Mul implementation returns a double precision result. The result of the standard mul is stored on a [u128; 9].

Then, we apply the Montgomery Reduction function to perform the modulo and the reduction to the Scalar format: [u64; 5].

impl Mul<Scalar> for EdwardsPoint[src]

type Output = EdwardsPoint

The resulting type after applying the * operator.

fn mul(self, scalar: Scalar) -> EdwardsPoint[src]

Scalar multiplication: compute Scalar * self. This implementation uses the algorithm: add_and_doubling which is the standard one for this operations and also adds less constraints on R1CS.

Hankerson, Darrel; Vanstone, Scott; Menezes, Alfred (2004). Guide to Elliptic Curve Cryptography. Springer Professional Computing. New York: Springer-Verlag.

impl Mul<Scalar> for ProjectivePoint[src]

type Output = ProjectivePoint

The resulting type after applying the * operator.

fn mul(self, scalar: Scalar) -> ProjectivePoint[src]

Scalar multiplication: compute Scalar * self. This implementation uses the algorithm: add_and_doubling which is the standard one for this operations and also adds less constraints on R1CS.

Hankerson, Darrel; Vanstone, Scott; Menezes, Alfred (2004). Guide to Elliptic Curve Cryptography. Springer Professional Computing. New York: Springer-Verlag.

impl Mul<Scalar> for RistrettoPoint[src]

type Output = RistrettoPoint

The resulting type after applying the * operator.

fn mul(self, scalar: Scalar) -> RistrettoPoint[src]

Scalar multiplication: compute self * Scalar. This implementation uses the algorithm: add_and_doubling which is the standard one for this operations and also adds less constraints on R1CS.

Hankerson, Darrel; Vanstone, Scott; Menezes, Alfred (2004). Guide to Elliptic Curve Cryptography. Springer Professional Computing. New York: Springer-Verlag.

impl<'a> Neg for &'a Scalar[src]

type Output = Scalar

The resulting type after applying the - operator.

fn neg(self) -> Scalar[src]

Performs the negate operation over the sub-group modulo l.

impl Neg for Scalar[src]

type Output = Scalar

The resulting type after applying the - operator.

fn neg(self) -> Scalar[src]

Performs the negate operation over the sub-group modulo l.

impl Ord for Scalar[src]

impl PartialEq<Scalar> for Scalar[src]

impl PartialOrd<Scalar> for Scalar[src]

impl<'a, 'b> Pow<&'b Scalar> for &'a Scalar[src]

Performs the op: a^b (mod l).

Exponentiation by squaring classical algorithm implementation for Scalar.

Schneier, Bruce (1996). Applied Cryptography: Protocols, Algorithms, and Source Code in C, Second Edition (2nd ed.).

type Output = Scalar

impl Shr<u8> for Scalar[src]

type Output = Scalar

The resulting type after applying the >> operator.

impl<'a> Square for &'a Scalar[src]

type Output = Scalar

fn square(self) -> Scalar[src]

This Square implementation returns a double precision result. The result of the standard mul is stored on a [u128; 9].

Then, we apply the Montgomery Reduction function to perform the modulo and the reduction to the Scalar format: [u64; 5].

impl<'a, 'b> Sub<&'b Scalar> for &'a Scalar[src]

type Output = Scalar

The resulting type after applying the - operator.

fn sub(self, b: &'b Scalar) -> Scalar[src]

Compute a - b (mod l).

impl Sub<Scalar> for Scalar[src]

type Output = Scalar

The resulting type after applying the - operator.

fn sub(self, b: Scalar) -> Scalar[src]

Compute a - b (mod l).

Auto Trait Implementations

impl RefUnwindSafe for Scalar

impl Send for Scalar

impl Sync for Scalar

impl Unpin for Scalar

impl UnwindSafe for Scalar

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,