Skip to content
This repository has been archived by the owner on Nov 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #55 from dusk-network/revert-54-docs
Browse files Browse the repository at this point in the history
Revert "Implement docs for field and scalar mods."
  • Loading branch information
CPerezz authored Jul 8, 2019
2 parents 0249b92 + 12bcaf2 commit 59326fc
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 144 deletions.
2 changes: 1 addition & 1 deletion src/backend/u64/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ impl FieldElement {
res
}

/// Given a `k`: u64, compute `2^k` giving the result
/// Given a `k`: u64, compute `2^k` giving the resulting result
/// as a `FieldElement`.
/// Note that the input must be between the range => 0..260.
///
Expand Down
54 changes: 0 additions & 54 deletions src/backend/u64/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,33 +359,6 @@ impl Scalar {
]
}

/// Given a `k`: u64, compute `2^k` giving the result
/// as a `Scalar`.
/// Note that the input must be between the range => 0..248.
pub fn two_pow_k(exp: &u64) -> Scalar {
let mut res = Scalar::zero();

debug_assert!(exp < &248u64);
match exp {
0...51 => {
res[0] = 1u64 << exp;
},
52...103 => {
res[1] = 1u64 << (exp - 52);
},
104...155 => {
res[2] = 1u64 << (exp - 104);
},
156...207 => {
res[3] = 1u64 << (exp - 156);
},
_ => {
res[4] = 1u64 << (exp - 208);
}
}
res
}

/// Compute `limbs/R` (mod l), where R is the Montgomery modulus 2^260
#[inline]
pub fn montgomery_reduce(limbs: &[u128; 9]) -> Scalar {
Expand Down Expand Up @@ -507,12 +480,6 @@ mod tests {
/// `X * Y (mod l) = 890263784947025690345271110799906008759402458672628420828189878638015362081`
pub static X_TIMES_Y: Scalar = Scalar([3414372756436001, 1500062170770321, 4341044393209371, 2791496957276064, 2164111380879]);

/// `2^197 (mod l) = 200867255532373784442745261542645325315275374222849104412672`
pub static TWO_POW_197: Scalar = Scalar([0, 0, 0, 2199023255552, 0]);

/// `2^104 (mod l) = 20282409603651670423947251286016`
pub static TWO_POW_104: Scalar = Scalar([0, 0, 1, 0, 0]);

#[test]
fn partial_ord_and_eq() {
assert!(Y.is_even());
Expand Down Expand Up @@ -620,27 +587,6 @@ mod tests {
}
}

#[test]
fn two_pow_k() {
// Check for 0 value
let zero = Scalar::two_pow_k(&0u64);
for i in 0..5 {
assert!(zero[i] == Scalar::one()[i]);
}

// Check for non 52-multiple `k` values
let non_multiple = Scalar::two_pow_k(&197u64);
for i in 0..5 {
assert!(non_multiple[i] == TWO_POW_197[i]);
}

// Check for 52-multiple `k` values
let non_multiple = Scalar::two_pow_k(&104u64);
for i in 0..5 {
assert!(non_multiple[i] == TWO_POW_104[i]);
}
}

#[test]
fn even_scalar() {
assert!(Y.is_even());
Expand Down
49 changes: 0 additions & 49 deletions src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,6 @@
//! here since they will be the samme across all of the different
//! backends.

//! # Examples
//! ```rust
//! use zerocaf::field::FieldElement;
//! use zerocaf::traits::ops::*;
//! use zerocaf::constants::EDWARDS_D;
//!
//! // You can create a FieldElement from a byte-array as follows:
//! let a = FieldElement::from_bytes(&[0u8;32]);
//!
//! // You ca also create a FieldElement from an uint type as follows:
//! let b = FieldElement::from(&86649u128);
//! let c = FieldElement::from(&86650u64);
//!
//! // The last way of creating a FieldElement it by calling the
//! // constructor. THIS IS NOT RECOMMENDED since NO checks about
//! // the correctness of the input will be done at all.
//! // It can be done as follows:
//! let d: FieldElement = FieldElement([0, 1, 0, 0, 0]); // d = 2^52.
//! assert!(d == FieldElement::two_pow_k(&52u64));
//!
//! // All of the basuc modular operations are implemented
//! // for FieldElement type:
//! let mut res = &a + &b; // Performs a + b (mod l).
//! res = &a - &b; // Performs a - b (mod l).
//! res = &a * &b; // Performs a * b (mod l).
//! res = &a.square(); // Performs a^2 (mod l).
//! res = -&a; // Performs Negation over the modulo l.
//!
//! // Division has been also implemented. Remember that when we write
//! // a/b (mod l), we are indeed performing a * inverse_mod(b, l) (mod l).
//! assert!(-&b / &d == EDWARDS_D);
//!
//! // Dividing by two even FieldElements is recommended through the `Half`
//! // trait implmementation since it's much faster.
//! if a.is_even() {
//! let half_a = &a.half(); // This will panic if a isn't even.
//! }
//!
//! We can finally perform inversion modulo l for a FieldElement:
//! let inv_a = &a.inverse(); // Performs a^-1 (mod l).
//! ```
//!
//! `PartialOrd`, `Ord`, `PartialEq` and `Eq` are also implemented for
//! `FieldElement` type.
//!
//! All `std::core::ops traits -> (Add, Sub, Mul, Div)` are implemented
//! for both, `&FieldElement` and `FieldElement`.
use core::cmp::PartialEq;

use subtle::Choice;
Expand Down
40 changes: 0 additions & 40 deletions src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,6 @@
//! which is a type-alias for the curve25519-dalek Scalar Struct.
//!
//! # Examples
//! ```rust
//! use zerocaf::scalar::Scalar;
//! use zerocaf::traits::ops::*;
//!
//! // You can create a Scalar from a byte-array as follows:
//! let a = Scalar::from_bytes(&[0u8;32]);
//!
//! // You ca also create a Scalar from an uint type as follows:
//! let b = Scalar::from(&86649u128);
//! let c = Scalar::from(&86650u64);
//!
//! // The last way of creating a Scalar it by calling the
//! // constructor. THIS IS NOT RECOMMENDED since ANY checks about
//! // the correctness of the input will be done. It can be done as
//! // follows:
//! let d: Scalar = Scalar([0, 1, 0, 0, 0]); // d = 2^52.
//! assert!(d == Scalar::two_pow_k(&52u64));
//!
//! // All of the basuc modular operations are implemented
//! // for Scalar type:
//! let mut res = &a + &b; // Performs a + b (mod l).
//! res = &a - &b; // Performs a - b (mod l).
//! res = &a * &b; // Performs a * b (mod l).
//! res = &a.square(); // Performs a^2 (mod l).
//! res = -&a; // Performs Negation over the modulo l.
//!
//! // Dividing by two even Scalars is recommended through the `Half`
//! // trait implmementation since it's much faster.
//! if a.is_even() {
//! let half_a = &a.half(); // This will panic if a isn't even.
//! }
//! ```
//!
//! `PartialOrd`, `Ord`, `PartialEq` and `Eq` are also implemented for
//! `Scalar` type.
//!
//! All `std::core::ops traits -> (Add, Sub, Mul)` are implemented
//! for both, `&Scalar` and `Scalar`.
use crate::backend;

use subtle::Choice;
Expand Down

0 comments on commit 59326fc

Please sign in to comment.