You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@milagro.apache.org by km...@apache.org on 2020/03/31 08:54:21 UTC
[incubator-milagro-crypto-rust] 06/31: Massive reformatting and
style changes
This is an automated email from the ASF dual-hosted git repository.
kmccusker pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-milagro-crypto-rust.git
commit ddb0937f5d182b72a70ae01b2c6bd02bf12cb718
Author: Kirk Baird <ba...@outlook.com>
AuthorDate: Thu Aug 8 14:32:49 2019 +1000
Massive reformatting and style changes
---
BenchtestALL.rs | 16 +-
readme.md | 37 ++--
src/aes.rs | 79 +++++----
src/big.rs | 182 +++++++++-----------
src/bls.rs | 28 +--
src/bls192.rs | 26 +--
src/bls256.rs | 24 +--
src/dbig.rs | 57 ++++---
src/ecdh.rs | 121 ++++++-------
src/ecp.rs | 129 +++++++-------
src/ecp2.rs | 111 ++++++------
src/ecp4.rs | 28 +--
src/ecp8.rs | 38 ++---
src/ff.rs | 4 +-
src/fp.rs | 144 ++++++++--------
src/fp12.rs | 385 ++++++++++++++++++++++++------------------
src/fp16.rs | 24 +--
src/fp2.rs | 30 ++--
src/fp24.rs | 350 ++++++++++++++++++++++----------------
src/fp4.rs | 34 ++--
src/fp48.rs | 352 ++++++++++++++++++++++----------------
src/fp8.rs | 25 ++-
src/hash256.rs | 16 +-
src/lib.rs | 182 ++++++++++----------
src/mpin.rs | 109 ++++++------
src/mpin192.rs | 9 +-
src/mpin256.rs | 6 +-
src/nhs.rs | 10 +-
src/pair.rs | 197 +++++++++++----------
src/pair192.rs | 95 ++++++-----
src/pair256.rs | 117 +++++++------
src/rand.rs | 2 +-
src/roms/rom_anssi_32.rs | 14 +-
src/roms/rom_anssi_64.rs | 14 +-
src/roms/rom_bls24_32.rs | 14 +-
src/roms/rom_bls24_64.rs | 14 +-
src/roms/rom_bls381_32.rs | 14 +-
src/roms/rom_bls381_64.rs | 14 +-
src/roms/rom_bls383_32.rs | 14 +-
src/roms/rom_bls383_64.rs | 14 +-
src/roms/rom_bls461_32.rs | 14 +-
src/roms/rom_bls461_64.rs | 14 +-
src/roms/rom_bls48_32.rs | 14 +-
src/roms/rom_bls48_64.rs | 14 +-
src/roms/rom_bn254CX_32.rs | 14 +-
src/roms/rom_bn254CX_64.rs | 15 +-
src/roms/rom_bn254_32.rs | 14 +-
src/roms/rom_bn254_64.rs | 16 +-
src/roms/rom_brainpool_32.rs | 14 +-
src/roms/rom_brainpool_64.rs | 14 +-
src/roms/rom_c25519_32.rs | 14 +-
src/roms/rom_c25519_64.rs | 14 +-
src/roms/rom_c41417_32.rs | 14 +-
src/roms/rom_c41417_64.rs | 14 +-
src/roms/rom_ed25519_32.rs | 14 +-
src/roms/rom_ed25519_64.rs | 14 +-
src/roms/rom_fp256bn_32.rs | 15 +-
src/roms/rom_fp256bn_64.rs | 14 +-
src/roms/rom_fp512bn_32.rs | 14 +-
src/roms/rom_fp512bn_64.rs | 14 +-
src/roms/rom_goldilocks_32.rs | 14 +-
src/roms/rom_goldilocks_64.rs | 14 +-
src/roms/rom_hifive_32.rs | 14 +-
src/roms/rom_hifive_64.rs | 14 +-
src/roms/rom_nist256_32.rs | 17 +-
src/roms/rom_nist256_64.rs | 14 +-
src/roms/rom_nist384_32.rs | 14 +-
src/roms/rom_nist384_64.rs | 15 +-
src/roms/rom_nist521_32.rs | 14 +-
src/roms/rom_nist521_64.rs | 14 +-
src/roms/rom_nums256e_32.rs | 15 +-
src/roms/rom_nums256e_64.rs | 15 +-
src/roms/rom_nums256w_32.rs | 14 +-
src/roms/rom_nums256w_64.rs | 14 +-
src/roms/rom_nums384e_32.rs | 15 +-
src/roms/rom_nums384e_64.rs | 15 +-
src/roms/rom_nums384w_32.rs | 15 +-
src/roms/rom_nums384w_64.rs | 15 +-
src/roms/rom_nums512e_32.rs | 14 +-
src/roms/rom_nums512e_64.rs | 14 +-
src/roms/rom_nums512w_32.rs | 14 +-
src/roms/rom_nums512w_64.rs | 14 +-
src/roms/rom_rsa2048_32.rs | 2 +-
src/roms/rom_rsa2048_64.rs | 2 +-
src/roms/rom_rsa3072_32.rs | 2 +-
src/roms/rom_rsa3072_64.rs | 2 +-
src/roms/rom_rsa4096_32.rs | 2 +-
src/roms/rom_rsa4096_64.rs | 2 +-
src/roms/rom_secp256k1_32.rs | 14 +-
src/roms/rom_secp256k1_64.rs | 14 +-
src/sha3.rs | 2 +-
src/types.rs | 39 +++--
92 files changed, 1955 insertions(+), 1807 deletions(-)
diff --git a/BenchtestALL.rs b/BenchtestALL.rs
index 55961be..ff8fb92 100644
--- a/BenchtestALL.rs
+++ b/BenchtestALL.rs
@@ -231,10 +231,10 @@ fn bn254(mut rng: &mut RAND) {
let mut fail = false;
println!("\nTesting/Timing BN254 Pairings");
- if ecp::CURVE_PAIRING_TYPE == CurvePairingType::BN {
+ if ecp::CURVE_PAIRING_TYPE == CurvePairingType::Bn {
println!("BN Pairing-Friendly Curve");
}
- if ecp::CURVE_PAIRING_TYPE == CurvePairingType::BLS {
+ if ecp::CURVE_PAIRING_TYPE == CurvePairingType::Bls {
println!("BLS Pairing-Friendly Curve");
}
@@ -391,10 +391,10 @@ fn bls383(mut rng: &mut RAND) {
let mut fail = false;
println!("\nTesting/Timing BLS383 Pairings");
- if ecp::CURVE_PAIRING_TYPE == CurvePairingType::BN {
+ if ecp::CURVE_PAIRING_TYPE == CurvePairingType::Bn {
println!("BN Pairing-Friendly Curve");
}
- if ecp::CURVE_PAIRING_TYPE == CurvePairingType::BLS {
+ if ecp::CURVE_PAIRING_TYPE == CurvePairingType::Bls {
println!("BLS Pairing-Friendly Curve");
}
@@ -551,10 +551,10 @@ fn bls24(mut rng: &mut RAND) {
let mut fail = false;
println!("\nTesting/Timing BLS24 Pairings");
- if ecp::CURVE_PAIRING_TYPE == CurvePairingType::BN {
+ if ecp::CURVE_PAIRING_TYPE == CurvePairingType::Bn {
println!("BN Pairing-Friendly Curve");
}
- if ecp::CURVE_PAIRING_TYPE == CurvePairingType::BLS {
+ if ecp::CURVE_PAIRING_TYPE == CurvePairingType::Bls {
println!("BLS24 Pairing-Friendly Curve");
}
@@ -711,10 +711,10 @@ fn bls48(mut rng: &mut RAND) {
let mut fail = false;
println!("\nTesting/Timing BLS48 Pairings");
- if ecp::CURVE_PAIRING_TYPE == CurvePairingType::BN {
+ if ecp::CURVE_PAIRING_TYPE == CurvePairingType::Bn {
println!("BN Pairing-Friendly Curve");
}
- if ecp::CURVE_PAIRING_TYPE == CurvePairingType::BLS {
+ if ecp::CURVE_PAIRING_TYPE == CurvePairingType::Bls {
println!("BLS48 Pairing-Friendly Curve");
}
diff --git a/readme.md b/readme.md
index da805e0..98f7d20 100644
--- a/readme.md
+++ b/readme.md
@@ -1,26 +1,28 @@
+# Apache Milagro Crypto Library - Rust Version
+
NOTE: Updated to Rust 2018
-NOTE: This version of the library requires Version 1.31+ of Rust for 64-bit
-integer support and for Rust 2018.
+NOTE: This version of the library requires Version 1.31+ of Rust for 64-bit
+integer support and for Rust 2018.
Now AMCL version 3 is distributed as a cargo crate.
Namespaces are used to separate different curves.
-To build the library and see it in action, copy all of the files in this
-directory and its subdirectories to a fresh root directory.
+To build the library and see it in action, copy all of the files in this
+directory and its subdirectories to a fresh root directory.
Then for example execute
-
+```
cargo rustc --release --features "bn254 bls383 bls24 bls48 ed25519 nist256 goldilocks rsa2048"
-
-This will create a build of the library for the current default target (be it 32 or 64 bits).
+```
+This will create a build of the library for the current default target (be it 32 or 64 bits).
(To test a 32-bit environment you can follow the Web Assembly (wasm) readme instructions for rust)
-Next copy the library from target/release/libamcl.rlib into the root
+Next copy the library from `target/release/libamcl.rlib` into the root
directory and execute
-
+```
rustc TestALL.rs --extern amcl=libamcl.rlib
rustc TestBLS.rs --extern amcl=libamcl.rlib
@@ -28,23 +30,29 @@ rustc TestBLS.rs --extern amcl=libamcl.rlib
rustc BenchtestALL.rs --extern amcl=libamcl.rlib
rustc TestNHS.rs --extern amcl=libamcl.rlib
+```
Finally execute these programs.
-To add amcl functionality to your own programs, add a dependency to your
-Cargo.toml file. For example to use the curve bls48, add this dependency
+To add amcl functionality to your own programs, add a dependency to your
+`Cargo.toml` file. For example to use the curve bls48, add this dependency
+```
[dependencies]
-
amcl = { version = "0.2.0", optional = true, default-features = false, features = ["bls48"]}
+```
-if published to crates.io, or
+If published to crates.io, or
+```
amcl = { version = "0.2.0", optional = true, default-features = false, features = ["bls48"], path="your_amcl_location" }
+```
And to use primitives of the needed curve in your source code:
-use amcl::bls48::{ECP, ECP8}; //any primitive you need
+```
+use amcl::bls48::{ECP, ECP8}; // any primitive you need
+```
Full list of features:
@@ -76,7 +84,6 @@ Full list of features:
* bls461
* bls24
* bls48
-
* RSA
* rsa2048
* rsa3072
diff --git a/src/aes.rs b/src/aes.rs
index 32a0f86..265cdec 100644
--- a/src/aes.rs
+++ b/src/aes.rs
@@ -184,34 +184,33 @@ pub struct AES {
impl AES {
fn rotl8(x: u32) -> u32 {
- return ((x) << 8) | ((x) >> 24);
+ ((x) << 8) | ((x) >> 24)
}
fn rotl16(x: u32) -> u32 {
- return ((x) << 16) | ((x) >> 16);
+ ((x) << 16) | ((x) >> 16)
}
fn rotl24(x: u32) -> u32 {
- return ((x) << 24) | ((x) >> 8);
+ ((x) << 24) | ((x) >> 8)
}
fn pack(b: [u8; 4]) -> u32 {
// pack bytes into a 32-bit Word
- return ((((b[3]) & 0xff) as u32) << 24)
+ ((((b[3]) & 0xff) as u32) << 24)
| ((((b[2]) & 0xff) as u32) << 16)
| ((((b[1]) & 0xff) as u32) << 8)
- | (((b[0]) & 0xff) as u32);
+ | (((b[0]) & 0xff) as u32)
}
fn unpack(a: u32) -> [u8; 4] {
// unpack bytes from a word
- let b: [u8; 4] = [
+ [
(a & 0xff) as u8,
((a >> 8) & 0xff) as u8,
((a >> 16) & 0xff) as u8,
((a >> 24) & 0xff) as u8,
- ];
- return b;
+ ]
}
fn bmul(x: u8, y: u8) -> u8 {
@@ -234,7 +233,7 @@ impl AES {
b[1] = FBSUB[b[1] as usize];
b[2] = FBSUB[b[2] as usize];
b[3] = FBSUB[b[3] as usize];
- return AES::pack(b);
+ AES::pack(b)
}
fn product(x: u32, y: u32) -> u8 {
@@ -242,10 +241,10 @@ impl AES {
let xb = AES::unpack(x);
let yb = AES::unpack(y);
- return AES::bmul(xb[0], yb[0])
+ AES::bmul(xb[0], yb[0])
^ AES::bmul(xb[1], yb[1])
^ AES::bmul(xb[2], yb[2])
- ^ AES::bmul(xb[3], yb[3]);
+ ^ AES::bmul(xb[3], yb[3])
}
fn invmixcol(x: u32) -> u32 {
@@ -260,7 +259,7 @@ impl AES {
m = AES::rotl24(m);
b[0] = AES::product(m, x);
let y = AES::pack(b);
- return y;
+ y
}
fn increment(f: &mut [u8; 16]) {
@@ -283,7 +282,7 @@ impl AES {
}
}
- // reset cipher
+ /// Reset cipher.
pub fn reset(&mut self, m: usize, iv: Option<[u8; 16]>) {
// reset mode, or reset iv
self.mode = m;
@@ -331,31 +330,31 @@ impl AES {
while j < n {
self.fkey[j] =
self.fkey[j - nk] ^ AES::subbyte(AES::rotl24(self.fkey[j - 1])) ^ (RCO[k] as u32);
- if nk<=6 {
- for i in 1..nk {
- if (i + j) >= n {
- break;
- }
- self.fkey[i + j] = self.fkey[i + j - nk] ^ self.fkey[i + j - 1];
- }
- } else {
- for i in 1..4 {
- if (i + j) >= n {
- break;
- }
- self.fkey[i + j] = self.fkey[i + j - nk] ^ self.fkey[i + j - 1];
- }
-
- if (j + 4) < n {
- self.fkey[j + 4] = self.fkey[j + 4 - nk] ^ AES::subbyte(self.fkey[j + 3]);
- }
- for i in 5..nk {
- if (i + j) >= n {
- break;
- }
- self.fkey[i + j] = self.fkey[i + j - nk] ^ self.fkey[i + j - 1];
- }
- }
+ if nk <= 6 {
+ for i in 1..nk {
+ if (i + j) >= n {
+ break;
+ }
+ self.fkey[i + j] = self.fkey[i + j - nk] ^ self.fkey[i + j - 1];
+ }
+ } else {
+ for i in 1..4 {
+ if (i + j) >= n {
+ break;
+ }
+ self.fkey[i + j] = self.fkey[i + j - nk] ^ self.fkey[i + j - 1];
+ }
+
+ if (j + 4) < n {
+ self.fkey[j + 4] = self.fkey[j + 4 - nk] ^ AES::subbyte(self.fkey[j + 3]);
+ }
+ for i in 5..nk {
+ if (i + j) >= n {
+ break;
+ }
+ self.fkey[i + j] = self.fkey[i + j - nk] ^ self.fkey[i + j - 1];
+ }
+ }
j += nk;
k += 1;
}
@@ -376,7 +375,7 @@ impl AES {
for j in n - 4..n {
self.rkey[j + 4 - n] = self.fkey[j]
}
- return true;
+ true
}
pub fn getreg(&mut self) -> [u8; 16] {
@@ -384,7 +383,7 @@ impl AES {
for i in 0..16 {
ir[i] = self.f[i]
}
- return ir;
+ ir
}
// Encrypt a single block
diff --git a/src/big.rs b/src/big.rs
index 99342f4..a5424b2 100644
--- a/src/big.rs
+++ b/src/big.rs
@@ -25,8 +25,8 @@ use super::super::arch::DChunk;
use super::dbig::DBig;
use rand::RAND;
-pub use super::rom::MODBYTES;
pub use super::rom::BASEBITS;
+pub use super::rom::MODBYTES;
use std::cmp::Ordering;
use std::fmt;
@@ -44,30 +44,26 @@ pub struct Big {
}
impl Clone for Big {
- fn clone(&self) -> Big { *self }
+ fn clone(&self) -> Big {
+ *self
+ }
}
impl fmt::Display for Big {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- let mut big = self.clone();
- write!(f, "Big: [ {} ]", big.tostring())
+ write!(f, "Big: [ {} ]", self.tostring())
}
}
impl fmt::Debug for Big {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- let mut big = self.clone();
- write!(f, "Big: [ {} ]", big.tostring())
+ write!(f, "Big: [ {} ]", self.tostring())
}
}
impl PartialEq for Big {
fn eq(&self, other: &Big) -> bool {
- if Big::comp(self,other)==0 {
- return true;
- } else {
- return false;
- }
+ Big::comp(self, other) == 0
}
}
@@ -80,11 +76,11 @@ impl Ord for Big {
if r < 0 {
return Ordering::Less;
}
- return Ordering::Equal;
+ Ordering::Equal
}
}
-impl Eq for Big { }
+impl Eq for Big {}
impl PartialOrd for Big {
fn partial_cmp(&self, other: &Big) -> Option<Ordering> {
@@ -97,34 +93,29 @@ impl Big {
Big { w: [0; NLEN] }
}
+ /// Convert a integer to a Big
pub fn new_int(x: isize) -> Big {
let mut s = Big::new();
s.w[0] = x as Chunk;
- return s;
+ s
}
+ /// Takes an array of integers and converts to a Big
pub fn new_ints(a: &[Chunk]) -> Big {
let mut s = Big::new();
for i in 0..NLEN {
s.w[i] = a[i]
}
- return s;
+ s
}
+ /// Creates a copy of the Big
pub fn new_copy(y: &Big) -> Big {
let mut s = Big::new();
for i in 0..NLEN {
s.w[i] = y.w[i]
}
- return s;
- }
-
- pub fn new_big(y: &Big) -> Big {
- let mut s = Big::new();
- for i in 0..NLEN {
- s.w[i] = y.w[i]
- }
- return s;
+ s
}
pub fn new_dcopy(y: &DBig) -> Big {
@@ -132,11 +123,11 @@ impl Big {
for i in 0..NLEN {
s.w[i] = y.w[i]
}
- return s;
+ s
}
pub fn get(&self, i: usize) -> Chunk {
- return self.w[i];
+ self.w[i]
}
pub fn set(&mut self, i: usize, x: Chunk) {
@@ -151,24 +142,24 @@ impl Big {
self.w[NLEN - 1] |= x;
}
- // test for zero
+ /// test for zero
pub fn iszilch(&self) -> bool {
for i in 0..NLEN {
if self.w[i] != 0 {
return false;
}
}
- return true;
+ true
}
- // set to zero
+ /// set to zero
pub fn zero(&mut self) {
for i in 0..NLEN {
self.w[i] = 0
}
}
- // Test for equal to one
+ /// Test for equal to one
pub fn isunity(&self) -> bool {
for i in 1..NLEN {
if self.w[i] != 0 {
@@ -178,7 +169,7 @@ impl Big {
if self.w[0] != 1 {
return false;
}
- return true;
+ true
}
/// Set to one
@@ -208,7 +199,7 @@ impl Big {
let prod: DChunk = (a as DChunk) * (b as DChunk) + (c as DChunk) + (r as DChunk);
let bot = (prod & (BMASK as DChunk)) as Chunk;
let top = (prod >> BASEBITS) as Chunk;
- return (top, bot);
+ (top, bot)
}
/// normalise Big - force all digits < 2^BASEBITS
@@ -220,7 +211,7 @@ impl Big {
carry = d >> BASEBITS;
}
self.w[NLEN - 1] += carry;
- return (self.w[NLEN - 1] >> ((8 * MODBYTES) % BASEBITS)) as Chunk;
+ (self.w[NLEN - 1] >> ((8 * MODBYTES) % BASEBITS)) as Chunk
}
/// Conditional swap of two bigs depending on d using XOR - no branches
@@ -273,10 +264,11 @@ impl Big {
self.w[i] = ((self.w[i] << k) & BMASK) | (self.w[i - 1] >> (BASEBITS - n));
}
self.w[0] = (self.w[0] << n) & BMASK;
- return (self.w[NLEN - 1] >> ((8 * MODBYTES) % BASEBITS)) as isize; // return excess - only used in ff.c
+ // return excess - only used in ff.c
+ (self.w[NLEN - 1] >> ((8 * MODBYTES) % BASEBITS)) as isize
}
- /// general shift left
+ /// General shift left
pub fn shl(&mut self, k: usize) {
let n = k % BASEBITS;
let m = k / BASEBITS;
@@ -294,7 +286,7 @@ impl Big {
}
}
- // return number of bits
+ /// Return number of bits
pub fn nbits(&self) -> usize {
let mut k = NLEN - 1;
let mut s = Big::new_copy(&self);
@@ -311,11 +303,11 @@ impl Big {
c /= 2;
bts += 1;
}
- return bts;
+ bts
}
// Convert to Hex String
- pub fn tostring(&mut self) -> String {
+ pub fn tostring(&self) -> String {
let mut s = String::new();
let mut len = self.nbits();
@@ -335,9 +327,10 @@ impl Big {
b.shr(i * 4);
s = s + &format!("{:X}", b.w[0] & 15);
}
- return s;
+ s
}
+ /// From Hex String
pub fn fromstring(val: String) -> Big {
let mut res = Big::new();
let len = val.len();
@@ -346,63 +339,59 @@ impl Big {
res.w[0] += n as Chunk;
for i in 1..len {
res.shl(4);
- let op = &val[i..i+1];
+ let op = &val[i..=i];
let n = u8::from_str_radix(op, 16).unwrap();
res.w[0] += n as Chunk;
}
- return res;
- }
-
- pub fn from_hex(val: String) -> Big {
- Big::fromstring(val)
- }
-
- pub fn to_hex(&mut self) -> String {
- self.tostring()
+ res
}
+ // Self += r
pub fn add(&mut self, r: &Big) {
for i in 0..NLEN {
self.w[i] += r.w[i]
}
}
+ //? Bitwise OR
pub fn or(&mut self, r: &Big) {
for i in 0..NLEN {
self.w[i] |= r.w[i]
}
}
+ /// Self * 2
pub fn dbl(&mut self) {
for i in 0..NLEN {
self.w[i] += self.w[i]
}
}
- // return this+x
+ /// Return self + x
pub fn plus(&self, x: &Big) -> Big {
let mut s = Big::new();
for i in 0..NLEN {
s.w[i] = self.w[i] + x.w[i];
}
- return s;
+ s
}
+ /// Return self + 1
pub fn inc(&mut self, x: isize) {
self.norm();
self.w[0] += x as Chunk;
}
- // return self-x
+ /// Return self - x
pub fn minus(&self, x: &Big) -> Big {
let mut d = Big::new();
for i in 0..NLEN {
d.w[i] = self.w[i] - x.w[i];
}
- return d;
+ d
}
- // self-=x
+ // self -= x
pub fn sub(&mut self, x: &Big) {
for i in 0..NLEN {
self.w[i] -= x.w[i];
@@ -410,7 +399,6 @@ impl Big {
}
// reverse subtract this=x-this
-
pub fn rsub(&mut self, x: &Big) {
for i in 0..NLEN {
self.w[i] = x.w[i] - self.w[i]
@@ -448,7 +436,7 @@ impl Big {
m.fshl(8);
m.w[0] += (b[i + n] & 0xff) as Chunk;
}
- return m;
+ m
}
pub fn tobytes(&mut self, b: &mut [u8]) {
@@ -456,7 +444,7 @@ impl Big {
}
pub fn frombytes(b: &[u8]) -> Big {
- return Big::frombytearray(b, 0);
+ Big::frombytearray(b, 0)
}
// self*=x, where x is >NEXCESS
@@ -468,7 +456,7 @@ impl Big {
carry = tuple.0;
self.w[i] = tuple.1;
}
- return carry;
+ carry
}
// self*=c and catch overflow in DBig
@@ -481,7 +469,7 @@ impl Big {
m.w[j] = tuple.1;
}
m.w[NLEN] = carry;
- return m;
+ m
}
// divide by 3
@@ -494,7 +482,7 @@ impl Big {
self.w[i] = ak / 3;
carry = ak % 3;
}
- return carry;
+ carry
}
// return a*b where result fits in a Big
@@ -510,7 +498,7 @@ impl Big {
}
}
}
- return c;
+ c
}
// Compare a and b, return 0 if a==b, -1 if a<b, +1 if a>b. Inputs must be normalised
@@ -525,7 +513,7 @@ impl Big {
return -1;
}
}
- return 0;
+ 0
}
// set x = x mod 2^m
@@ -575,31 +563,30 @@ impl Big {
t1 <<= 4;
u += t1;
- return u;
+ u
}
- // return parity
+ /// Return parity
pub fn parity(&self) -> isize {
- return (self.w[0] % 2) as isize;
+ (self.w[0] % 2) as isize
}
- // return n-th bit
+ // Return n-th bit
pub fn bit(&self, n: usize) -> isize {
if (self.w[n / (BASEBITS as usize)] & (1 << (n % BASEBITS))) > 0 {
return 1;
- } else {
- return 0;
}
+ 0
}
- // return n last bits
+ /// Return n last bits
pub fn lastbits(&mut self, n: usize) -> isize {
let msk = ((1 << n) - 1) as Chunk;
self.norm();
- return (self.w[0] & msk) as isize;
+ (self.w[0] & msk) as isize
}
- // a=1/a mod 2^256. This is very fast!
+ /// a = 1/a mod 2^256. This is very fast!
pub fn invmod2m(&mut self) {
let mut u = Big::new();
let mut b = Big::new();
@@ -639,7 +626,7 @@ impl Big {
self.norm();
}
- // reduce self mod m
+ /// reduce self mod m
pub fn rmod(&mut self, n: &Big) {
let mut k = 0;
let mut m = Big::new_copy(n);
@@ -670,7 +657,7 @@ impl Big {
}
}
- // divide self by m
+ /// Divide self by m
pub fn div(&mut self, n: &Big) {
let mut k = 0;
self.norm();
@@ -703,7 +690,7 @@ impl Big {
}
}
- // get 8*MODBYTES size random number
+ /// Get 8*MODBYTES size random number
pub fn random(rng: &mut RAND) -> Big {
let mut m = Big::new();
let mut j = 0;
@@ -723,10 +710,10 @@ impl Big {
j += 1;
j &= 7;
}
- return m;
+ m
}
- // Create random Big in portable way, one bit at a time
+ /// Create random Big in portable way, one bit at a time
pub fn randomnum(q: &Big, rng: &mut RAND) -> Big {
let mut d = DBig::new();
let mut j = 0;
@@ -746,10 +733,10 @@ impl Big {
j &= 7;
}
let m = d.dmod(q);
- return m;
+ m
}
- // Jacobi Symbol (this/p). Returns 0, 1 or -1
+ /// Jacobi Symbol (this/p). Returns 0, 1 or -1
pub fn jacobi(&mut self, p: &Big) -> isize {
let mut m: usize = 0;
let mut t = Big::new();
@@ -788,12 +775,11 @@ impl Big {
}
if m == 0 {
return 1;
- } else {
- return -1;
}
+ -1
}
- // self=1/self mod p. Binary method
+ /// self = 1/self mod p. Binary method
pub fn invmodp(&mut self, p: &Big) {
self.rmod(p);
let mut u = Big::new_copy(self);
@@ -851,8 +837,7 @@ impl Big {
}
}
- // return a*b as DBig
-
+ /// return a*b as DBig
pub fn mul(a: &Big, b: &Big) -> DBig {
let mut c = DBig::new();
let rm = BMASK as DChunk;
@@ -869,7 +854,7 @@ impl Big {
for k in 1..NLEN {
s += d[k];
t = co + s;
- for i in 1 + k / 2..k + 1 {
+ for i in 1 + k / 2..=k {
t += ((a.w[i] - a.w[k - i]) as DChunk) * ((b.w[k - i] - b.w[i]) as DChunk)
}
c.w[k] = (t & rm) as Chunk;
@@ -888,10 +873,10 @@ impl Big {
co = t >> rb;
}
c.w[2 * NLEN - 1] = co as Chunk;
- return c;
+ c
}
- // return a^2 as DBig
+ /// return a^2 as DBig
pub fn sqr(a: &Big) -> DBig {
let mut c = DBig::new();
let rm = BMASK as DChunk;
@@ -958,9 +943,10 @@ impl Big {
co = t >> rb;
c.w[DNLEN - 1] = co as Chunk;
- return c;
+ c
}
+ /// Montegomery Reduction
pub fn monty(md: &Big, mc: Chunk, d: &mut DBig) -> Big {
let mut b = Big::new();
let rm = BMASK as DChunk;
@@ -1002,7 +988,7 @@ impl Big {
s -= dd[k + 1 - NLEN];
}
b.w[NLEN - 1] = (c & rm) as Chunk;
- return b;
+ b
}
pub fn ssn(r: &mut Big, a: &Big, m: &mut Big) -> isize {
@@ -1019,35 +1005,35 @@ impl Big {
}
m.w[n] >>= 1;
r.w[n] = a.w[n] - m.w[n] + carry;
- return ((r.w[n] >> (arch::CHUNK - 1)) & 1) as isize;
+ ((r.w[n] >> (arch::CHUNK - 1)) & 1) as isize
}
- // return a*b mod m
+ /// return a*b mod m
pub fn modmul(a1: &Big, b1: &Big, m: &Big) -> Big {
let mut a = Big::new_copy(a1);
let mut b = Big::new_copy(b1);
a.rmod(m);
b.rmod(m);
let mut d = Big::mul(&a, &b);
- return d.dmod(m);
+ d.dmod(m)
}
- // return a^2 mod m
+ /// return a^2 mod m
pub fn modsqr(a1: &Big, m: &Big) -> Big {
let mut a = Big::new_copy(a1);
a.rmod(m);
let mut d = Big::sqr(&a);
- return d.dmod(m);
+ d.dmod(m)
}
- // return -a mod m
+ /// return -a mod m
pub fn modneg(a1: &Big, m: &Big) -> Big {
let mut a = Big::new_copy(a1);
a.rmod(m);
- return m.minus(&a);
+ m.minus(&a)
}
- // return this^e mod m
+ /// return this^e mod m
pub fn powmod(&mut self, e1: &Big, m: &Big) -> Big {
self.norm();
let mut e = Big::new_copy(e1);
@@ -1064,8 +1050,8 @@ impl Big {
if z.iszilch() {
break;
}
- s = Big::modsqr(&mut s, m);
+ s = Big::modsqr(&s, m);
}
- return a;
+ a
}
}
diff --git a/src/bls.rs b/src/bls.rs
index 2ef80a4..07b8353 100644
--- a/src/bls.rs
+++ b/src/bls.rs
@@ -17,13 +17,13 @@ specific language governing permissions and limitations
under the License.
*/
-use std::str;
use super::ecp::ECP;
use super::ecp2::ECP2;
+use std::str;
//use super::fp12::FP12;
+use super::big;
use super::big::Big;
use super::pair;
-use super::big;
use super::rom;
use rand::RAND;
@@ -47,28 +47,28 @@ fn bls_hashit(m: &str) -> ECP {
}
sh.shake(&mut hm, BFS);
let P = ECP::mapit(&hm);
- return P;
+ P
}
-// generate key pair, private key s, public key w
+/// Generate key pair, private key s, public key w
pub fn key_pair_generate(mut rng: &mut RAND, s: &mut [u8], w: &mut [u8]) -> isize {
let q = Big::new_ints(&rom::CURVE_ORDER);
let g = ECP2::generator();
let mut sc = Big::randomnum(&q, &mut rng);
sc.tobytes(s);
- pair::g2mul(&g, &mut sc).tobytes(w);
- return BLS_OK;
+ pair::g2mul(&g, &sc).tobytes(w);
+ BLS_OK
}
-// Sign message m using private key s to produce signature sig
+/// Sign message m using private key s to produce signature sig.
pub fn sign(sig: &mut [u8], m: &str, s: &[u8]) -> isize {
let d = bls_hashit(m);
let mut sc = Big::frombytes(&s);
pair::g1mul(&d, &mut sc).tobytes(sig, true);
- return BLS_OK;
+ BLS_OK
}
-// Verify signature given message m, the signature sig, and the public key w
+/// Verify signature given message m, the signature sig, and the public key w
pub fn verify(sig: &[u8], m: &str, w: &[u8]) -> isize {
let hm = bls_hashit(m);
let mut d = ECP::frombytes(&sig);
@@ -77,10 +77,10 @@ pub fn verify(sig: &[u8], m: &str, w: &[u8]) -> isize {
d.neg();
// Use new multi-pairing mechanism
- let mut r=pair::initmp();
- pair::another(&mut r,&g,&d);
- pair::another(&mut r,&pk,&hm);
- let mut v=pair::miller(&r);
+ let mut r = pair::initmp();
+ pair::another(&mut r, &g, &d);
+ pair::another(&mut r, &pk, &hm);
+ let mut v = pair::miller(&r);
//.. or alternatively
// let mut v = pair::ate2(&g, &d, &pk, &hm);
@@ -89,5 +89,5 @@ pub fn verify(sig: &[u8], m: &str, w: &[u8]) -> isize {
if v.isunity() {
return BLS_OK;
}
- return BLS_FAIL;
+ BLS_FAIL
}
diff --git a/src/bls192.rs b/src/bls192.rs
index b2c7e97..3654452 100644
--- a/src/bls192.rs
+++ b/src/bls192.rs
@@ -17,13 +17,13 @@ specific language governing permissions and limitations
under the License.
*/
-use std::str;
use super::ecp::ECP;
use super::ecp4::ECP4;
+use std::str;
//use super::fp24::FP24;
+use super::big;
use super::big::Big;
use super::pair192;
-use super::big;
use super::rom;
use rand::RAND;
@@ -49,28 +49,28 @@ fn bls_hashit(m: &str) -> ECP {
}
sh.shake(&mut hm, BFS);
let P = ECP::mapit(&hm);
- return P;
+ P
}
-// generate key pair, private key s, public key w
+/// Generate key pair, private key s, public key w
pub fn key_pair_generate(mut rng: &mut RAND, s: &mut [u8], w: &mut [u8]) -> isize {
let q = Big::new_ints(&rom::CURVE_ORDER);
let g = ECP4::generator();
let mut sc = Big::randomnum(&q, &mut rng);
sc.tobytes(s);
pair192::g2mul(&g, &mut sc).tobytes(w);
- return BLS_OK;
+ BLS_OK
}
-// Sign message m using private key s to produce signature sig
+/// Sign message m using private key s to produce signature sig
pub fn sign(sig: &mut [u8], m: &str, s: &[u8]) -> isize {
let d = bls_hashit(m);
let mut sc = Big::frombytes(&s);
pair192::g1mul(&d, &mut sc).tobytes(sig, true);
- return BLS_OK;
+ BLS_OK
}
-// Verify signature given message m, the signature sig, and the public key w
+/// Verify signature given message m, the signature sig, and the public key w
pub fn verify(sig: &[u8], m: &str, w: &[u8]) -> isize {
let hm = bls_hashit(m);
let mut d = ECP::frombytes(&sig);
@@ -79,10 +79,10 @@ pub fn verify(sig: &[u8], m: &str, w: &[u8]) -> isize {
d.neg();
// Use new multi-pairing mechanism
- let mut r=pair192::initmp();
- pair192::another(&mut r,&g,&d);
- pair192::another(&mut r,&pk,&hm);
- let mut v=pair192::miller(&r);
+ let mut r = pair192::initmp();
+ pair192::another(&mut r, &g, &d);
+ pair192::another(&mut r, &pk, &hm);
+ let mut v = pair192::miller(&r);
//.. or alternatively
// let mut v = pair192::ate2(&g, &d, &pk, &hm);
@@ -91,5 +91,5 @@ pub fn verify(sig: &[u8], m: &str, w: &[u8]) -> isize {
if v.isunity() {
return BLS_OK;
}
- return BLS_FAIL;
+ BLS_FAIL
}
diff --git a/src/bls256.rs b/src/bls256.rs
index a0ac094..c3722f3 100644
--- a/src/bls256.rs
+++ b/src/bls256.rs
@@ -17,13 +17,13 @@ specific language governing permissions and limitations
under the License.
*/
-use std::str;
use super::ecp::ECP;
use super::ecp8::ECP8;
+use std::str;
//use super::fp48::FP48;
+use super::big;
use super::big::Big;
use super::pair256;
-use super::big;
use super::rom;
use rand::RAND;
@@ -47,17 +47,17 @@ fn bls_hashit(m: &str) -> ECP {
}
sh.shake(&mut hm, BFS);
let P = ECP::mapit(&hm);
- return P;
+ P
}
-// generate key pair, private key s, public key w
+/// Generate key pair, private key s, public key w
pub fn key_pair_generate(mut rng: &mut RAND, s: &mut [u8], w: &mut [u8]) -> isize {
let q = Big::new_ints(&rom::CURVE_ORDER);
let g = ECP8::generator();
let mut sc = Big::randomnum(&q, &mut rng);
sc.tobytes(s);
pair256::g2mul(&g, &mut sc).tobytes(w);
- return BLS_OK;
+ BLS_OK
}
// Sign message m using private key s to produce signature sig
@@ -65,10 +65,10 @@ pub fn sign(sig: &mut [u8], m: &str, s: &[u8]) -> isize {
let d = bls_hashit(m);
let mut sc = Big::frombytes(&s);
pair256::g1mul(&d, &mut sc).tobytes(sig, true);
- return BLS_OK;
+ BLS_OK
}
-// Verify signature given message m, the signature sig, and the public key w
+/// Verify signature given message m, the signature sig, and the public key w
pub fn verify(sig: &[u8], m: &str, w: &[u8]) -> isize {
let hm = bls_hashit(m);
let mut d = ECP::frombytes(&sig);
@@ -77,10 +77,10 @@ pub fn verify(sig: &[u8], m: &str, w: &[u8]) -> isize {
d.neg();
// Use new multi-pairing mechanism
- let mut r=pair256::initmp();
- pair256::another(&mut r,&g,&d);
- pair256::another(&mut r,&pk,&hm);
- let mut v=pair256::miller(&r);
+ let mut r = pair256::initmp();
+ pair256::another(&mut r, &g, &d);
+ pair256::another(&mut r, &pk, &hm);
+ let mut v = pair256::miller(&r);
//.. or alternatively
// let mut v = pair256::ate2(&g, &d, &pk, &hm);
@@ -89,5 +89,5 @@ pub fn verify(sig: &[u8], m: &str, w: &[u8]) -> isize {
if v.isunity() {
return BLS_OK;
}
- return BLS_FAIL;
+ BLS_FAIL
}
diff --git a/src/dbig.rs b/src/dbig.rs
index 31cf402..2479637 100644
--- a/src/dbig.rs
+++ b/src/dbig.rs
@@ -18,9 +18,9 @@ under the License.
*/
use super::super::arch;
+use super::super::arch::Chunk;
use super::big;
use super::big::Big;
-use super::super::arch::Chunk;
#[derive(Copy)]
pub struct DBig {
@@ -28,7 +28,9 @@ pub struct DBig {
}
impl Clone for DBig {
- fn clone(&self) -> DBig { *self }
+ fn clone(&self) -> DBig {
+ *self
+ }
}
impl DBig {
@@ -43,7 +45,7 @@ impl DBig {
for i in 0..big::DNLEN {
s.w[i] = y.w[i]
}
- return s;
+ s
}
pub fn new_scopy(x: &Big) -> DBig {
@@ -51,16 +53,16 @@ impl DBig {
for i in 0..big::NLEN {
b.w[i] = x.w[i];
}
- b.w[big::NLEN - 1] = x.get(big::NLEN - 1) & big::BMASK; /* top word normalized */
+ b.w[big::NLEN - 1] = x.get(big::NLEN - 1) & big::BMASK; // top word normalized
b.w[big::NLEN] = x.get(big::NLEN - 1) >> big::BASEBITS;
for i in big::NLEN + 1..big::DNLEN {
b.w[i] = 0
}
- return b;
+ b
}
- /* split DBig at position n, return higher half, keep lower half */
+ /// split DBig at position n, return higher half, keep lower half
pub fn split(&mut self, n: usize) -> Big {
let mut t = Big::new();
let m = n % big::BASEBITS;
@@ -72,10 +74,10 @@ impl DBig {
t.set(i + 1 - big::NLEN, nw);
}
self.w[big::NLEN - 1] &= ((1 as Chunk) << m) - 1;
- return t;
+ t
}
- /* general shift left */
+ /// General shift left
pub fn shl(&mut self, k: usize) {
let n = k % big::BASEBITS;
let m = k / big::BASEBITS;
@@ -92,7 +94,7 @@ impl DBig {
}
}
- /* general shift right */
+ /// General shift right
pub fn shr(&mut self, k: usize) {
let n = k % big::BASEBITS;
let m = k / big::BASEBITS;
@@ -106,13 +108,14 @@ impl DBig {
}
}
- /* Copy from another DBig */
+ /// Copy from another DBig
pub fn copy(&mut self, x: &DBig) {
for i in 0..big::DNLEN {
self.w[i] = x.w[i];
}
}
+ /// Copy from a Big
pub fn ucopy(&mut self, x: &Big) {
for i in 0..big::NLEN {
self.w[i] = 0;
@@ -129,28 +132,28 @@ impl DBig {
}
}
- /* self+=x */
+ /// self += x
pub fn add(&mut self, x: &DBig) {
for i in 0..big::DNLEN {
self.w[i] += x.w[i];
}
}
- /* self-=x */
+ /// self -= x
pub fn sub(&mut self, x: &DBig) {
for i in 0..big::DNLEN {
self.w[i] -= x.w[i];
}
}
- /* self=x-self */
+ /// self = x - self
pub fn rsub(&mut self, x: &DBig) {
for i in 0..big::DNLEN {
self.w[i] = x.w[i] - self.w[i];
}
}
- /* Compare a and b, return 0 if a==b, -1 if a<b, +1 if a>b. Inputs must be normalised */
+ /// Compare a and b, return 0 if a==b, -1 if a<b, +1 if a>b. Inputs must be normalised
pub fn comp(a: &DBig, b: &DBig) -> isize {
for i in (0..big::DNLEN).rev() {
if a.w[i] == b.w[i] {
@@ -162,10 +165,10 @@ impl DBig {
return -1;
}
}
- return 0;
+ 0
}
- /* normalise Big - force all digits < 2^big::BASEBITS */
+ /// Normalise Big - force all digits < 2^big::BASEBITS
pub fn norm(&mut self) {
let mut carry = 0 as Chunk;
for i in 0..big::DNLEN - 1 {
@@ -176,7 +179,7 @@ impl DBig {
self.w[big::DNLEN - 1] += carry
}
- /* reduces self DBig mod a Big, and returns the Big */
+ /// Reduces self DBig mod a Big, and returns the Big
pub fn dmod(&mut self, c: &Big) -> Big {
let mut k = 0;
self.norm();
@@ -210,10 +213,10 @@ impl DBig {
k -= 1;
}
let r = Big::new_dcopy(self);
- return r;
+ r
}
- /* return this/c */
+ /// return self / c
pub fn div(&mut self, c: &Big) -> Big {
let mut k = 0;
let mut m = DBig::new_scopy(c);
@@ -245,10 +248,10 @@ impl DBig {
k -= 1;
}
- return a;
+ a
}
- /* set x = x mod 2^m */
+ /// set x = x mod 2^m
pub fn mod2m(&mut self, m: usize) {
let wd = m / big::BASEBITS;
let bt = m % big::BASEBITS;
@@ -259,8 +262,8 @@ impl DBig {
}
}
- /* return number of bits */
- pub fn nbits(&mut self) -> usize {
+ /// Return number of bits
+ pub fn nbits(&self) -> usize {
let mut k = big::DNLEN - 1;
let mut s = DBig::new_copy(&self);
s.norm();
@@ -276,11 +279,11 @@ impl DBig {
c /= 2;
bts += 1;
}
- return bts;
+ bts
}
- /* Convert to Hex String */
- pub fn to_string(&mut self) -> String {
+ /// Convert to Hex String
+ pub fn to_string(&self) -> String {
let mut s = String::new();
let mut len = self.nbits();
@@ -296,6 +299,6 @@ impl DBig {
b.shr(i * 4);
s = s + &format!("{:X}", b.w[0] & 15);
}
- return s;
+ s
}
}
diff --git a/src/ecdh.rs b/src/ecdh.rs
index 1df8446..12aa34e 100644
--- a/src/ecdh.rs
+++ b/src/ecdh.rs
@@ -17,19 +17,18 @@ specific language governing permissions and limitations
under the License.
*/
+use super::big;
+use super::big::Big;
use super::ecp;
use super::ecp::ECP;
-use super::big::Big;
use super::rom;
-use super::big;
-use rand::RAND;
+use aes;
+use aes::AES;
use hash256::HASH256;
use hash384::HASH384;
use hash512::HASH512;
-use aes;
-use aes::AES;
-
+use rand::RAND;
pub const INVALID_PUBLIC_KEY: isize = -2;
pub const ERROR: isize = -3;
@@ -52,6 +51,7 @@ fn inttobytes(n: usize, b: &mut [u8]) {
}
}
+/// Hash to curve function using Hash and Test on SHA256, 384 or 512
fn hashit(sha: usize, a: &[u8], n: usize, b: Option<&[u8]>, pad: usize, w: &mut [u8]) {
let mut r: [u8; 64] = [0; 64];
if sha == SHA256 {
@@ -117,11 +117,11 @@ fn hashit(sha: usize, a: &[u8], n: usize, b: Option<&[u8]>, pad: usize, w: &mut
}
}
-/* Key Derivation Functions */
-/* Input octet Z */
-/* Output key of length olen */
+// Key Derivation Function 1
+// Input octet Z
+// Output key of length olen
pub fn kdf1(sha: usize, z: &[u8], olen: usize, k: &mut [u8]) {
- /* NOTE: the parameter olen is the length of the output K in bytes */
+ // NOTE: the parameter olen is the length of the output K in bytes
let hlen = sha;
let mut lk = 0;
@@ -147,8 +147,11 @@ pub fn kdf1(sha: usize, z: &[u8], olen: usize, k: &mut [u8]) {
}
}
+// Key Derivation Function 2
+// Input octet Z
+// Output key of length olen
pub fn kdf2(sha: usize, z: &[u8], p: Option<&[u8]>, olen: usize, k: &mut [u8]) {
- /* NOTE: the parameter olen is the length of the output K in bytes */
+ // NOTE: the parameter olen is the length of the output K in bytes
let hlen = sha;
let mut lk = 0;
@@ -157,7 +160,7 @@ pub fn kdf2(sha: usize, z: &[u8], p: Option<&[u8]>, olen: usize, k: &mut [u8]) {
cthreshold += 1
}
- for counter in 1..cthreshold + 1 {
+ for counter in 1..=cthreshold {
let mut b: [u8; 64] = [0; 64];
hashit(sha, z, counter, p, 0, &mut b);
if lk + hlen > olen {
@@ -174,9 +177,9 @@ pub fn kdf2(sha: usize, z: &[u8], p: Option<&[u8]>, olen: usize, k: &mut [u8]) {
}
}
-/* Password based Key Derivation Function */
-/* Input password p, salt s, and repeat count */
-/* Output key of length olen */
+/// Password based Key Derivation Function
+/// Input password p, salt s, and repeat count
+/// Output key of length olen
pub fn pbkdf2(sha: usize, pass: &[u8], salt: &[u8], rep: usize, olen: usize, k: &mut [u8]) {
let mut d = olen / sha;
if olen % sha != 0 {
@@ -205,7 +208,7 @@ pub fn pbkdf2(sha: usize, pass: &[u8], salt: &[u8], rep: usize, olen: usize, k:
u[j] = f[j]
}
for _ in 1..rep {
- hmac(sha, &mut u, pass, sha, &mut ku);
+ hmac(sha, &u, pass, sha, &mut ku);
for k in 0..sha {
u[k] = ku[k];
f[k] ^= u[k]
@@ -220,7 +223,7 @@ pub fn pbkdf2(sha: usize, pass: &[u8], salt: &[u8], rep: usize, olen: usize, k:
}
}
-/* Calculate HMAC of m using key k. HMAC is tag of length olen (which is length of tag) */
+/// Calculate HMAC of m using key k. HMAC is tag of length olen (which is length of tag)
pub fn hmac(sha: usize, m: &[u8], k: &[u8], olen: usize, tag: &mut [u8]) -> bool {
/* Input is from an octet m *
* olen is requested output length in bytes. k is the key *
@@ -255,17 +258,17 @@ pub fn hmac(sha: usize, m: &[u8], k: &[u8], olen: usize, tag: &mut [u8]) -> bool
for i in 0..lb {
k0[i] ^= 0x36
}
- hashit(sha, &mut k0[0..lb], 0, Some(m), 0, &mut b);
+ hashit(sha, &k0[0..lb], 0, Some(m), 0, &mut b);
for i in 0..lb {
k0[i] ^= 0x6a
}
- hashit(sha, &mut k0[0..lb], 0, Some(&b[0..sha]), olen, tag);
+ hashit(sha, &k0[0..lb], 0, Some(&b[0..sha]), olen, tag);
return true;
}
-/* AES encryption/decryption. Encrypt byte array m using key k and returns ciphertext c */
+/// AES encryption/decryption. Encrypt byte array m using key k and returns ciphertext c
pub fn cbc_iv0_encrypt(k: &[u8], m: &[u8]) -> Vec<u8> {
/* AES CBC encryption, with Null IV and key K */
/* Input is from an octet string m, output is to an octet string c */
@@ -314,10 +317,10 @@ pub fn cbc_iv0_encrypt(k: &[u8], m: &[u8]) -> Vec<u8> {
c.push(buff[j]);
}
a.end();
- return c;
+ c
}
-/* returns plaintext if all consistent, else returns null string */
+/// Returns plaintext if all consistent, else returns null string
pub fn cbc_iv0_decrypt(k: &[u8], c: &[u8]) -> Option<Vec<u8>> {
/* padding is removed */
let mut a = AES::new();
@@ -382,14 +385,14 @@ pub fn cbc_iv0_decrypt(k: &[u8], c: &[u8]) -> Option<Vec<u8>> {
if bad {
return None;
}
- return Some(m);
+ Some(m)
}
-/* Calculate a public/private EC GF(p) key pair w,s where W=s.G mod EC(p),
- * where s is the secret key and W is the public key
- * and G is fixed generator.
- * If RNG is NULL then the private key is provided externally in s
- * otherwise it is generated randomly internally */
+/// Calculate a public/private EC GF(p) key pair w,s where W=s.G mod EC(p),
+/// where s is the secret key and W is the public key
+/// and G is fixed generator.
+/// If RNG is NULL then the private key is provided externally in s
+/// otherwise it is generated randomly internally
#[allow(non_snake_case)]
pub fn key_pair_generate(rng: Option<&mut RAND>, s: &mut [u8], w: &mut [u8]) -> isize {
let res = 0;
@@ -407,14 +410,14 @@ pub fn key_pair_generate(rng: Option<&mut RAND>, s: &mut [u8], w: &mut [u8]) ->
sc.tobytes(s);
- let WP = G.mul(&mut sc);
+ let WP = G.mul(&sc);
WP.tobytes(w, false); // To use point compression on public keys, change to true
- return res;
+ res
}
-/* validate public key */
+/// Validate public key
#[allow(non_snake_case)]
pub fn public_key_validate(w: &[u8]) -> isize {
let mut WP = ECP::frombytes(w);
@@ -440,16 +443,16 @@ pub fn public_key_validate(w: &[u8]) -> isize {
}
if !k.isunity() {
- WP = WP.mul(&mut k)
+ WP = WP.mul(&k)
}
if WP.is_infinity() {
res = INVALID_PUBLIC_KEY
}
}
- return res;
+ res
}
-/* IEEE-1363 Diffie-Hellman online calculation Z=S.WD */
+/// IEEE-1363 Diffie-Hellman online calculation Z=S.WD
#[allow(non_snake_case)]
pub fn ecpsvdp_dh(s: &[u8], wd: &[u8], z: &mut [u8]) -> isize {
let mut res = 0;
@@ -465,7 +468,7 @@ pub fn ecpsvdp_dh(s: &[u8], wd: &[u8], z: &mut [u8]) -> isize {
if res == 0 {
let r = Big::new_ints(&rom::CURVE_ORDER);
sc.rmod(&r);
- W = W.mul(&mut sc);
+ W = W.mul(&sc);
if W.is_infinity() {
res = ERROR;
} else {
@@ -475,10 +478,10 @@ pub fn ecpsvdp_dh(s: &[u8], wd: &[u8], z: &mut [u8]) -> isize {
}
}
}
- return res;
+ res
}
-/* IEEE ECDSA Signature, C and D are signature on F using private key S */
+/// IEEE ECDSA Signature, C and D are signature on F using private key S
#[allow(non_snake_case)]
pub fn ecpsp_dsa(
sha: usize,
@@ -497,7 +500,7 @@ pub fn ecpsp_dsa(
let r = Big::new_ints(&rom::CURVE_ORDER);
- let mut sc = Big::frombytes(s); /* s or &s? */
+ let sc = Big::frombytes(s); /* s or &s? */
let fb = Big::frombytes(&b);
let mut cb = Big::new();
@@ -507,10 +510,10 @@ pub fn ecpsp_dsa(
while db.iszilch() {
let mut u = Big::randomnum(&r, rng);
- let mut w = Big::randomnum(&r, rng); /* side channel masking */
+ let w = Big::randomnum(&r, rng); /* side channel masking */
V.copy(&G);
- V = V.mul(&mut u);
+ V = V.mul(&u);
let vx = V.getx();
cb.copy(&vx);
cb.rmod(&r);
@@ -518,17 +521,17 @@ pub fn ecpsp_dsa(
continue;
}
- tb.copy(&Big::modmul(&mut u, &mut w, &r));
+ tb.copy(&Big::modmul(&u, &w, &r));
u.copy(&tb);
u.invmodp(&r);
- db.copy(&Big::modmul(&mut sc, &mut cb, &r));
+ db.copy(&Big::modmul(&sc, &cb, &r));
db.add(&fb);
- tb.copy(&Big::modmul(&mut db, &mut w, &r));
+ tb.copy(&Big::modmul(&db, &w, &r));
db.copy(&tb);
- tb.copy(&Big::modmul(&mut u, &mut db, &r));
+ tb.copy(&Big::modmul(&u, &db, &r));
db.copy(&tb);
}
@@ -540,10 +543,10 @@ pub fn ecpsp_dsa(
for i in 0..EFS {
d[i] = t[i]
}
- return 0;
+ 0
}
-/* IEEE1363 ECDSA Signature Verification. Signature C and D on F is verified using public key W */
+/// IEEE1363 ECDSA Signature Verification. Signature C and D on F is verified using public key W
#[allow(non_snake_case)]
pub fn ecpvp_dsa(sha: usize, w: &[u8], f: &[u8], c: &[u8], d: &[u8]) -> isize {
let mut res = 0;
@@ -552,11 +555,11 @@ pub fn ecpvp_dsa(sha: usize, w: &[u8], f: &[u8], c: &[u8], d: &[u8]) -> isize {
hashit(sha, f, 0, None, big::MODBYTES as usize, &mut b);
- let mut G = ECP::generator();
+ let G = ECP::generator();
let r = Big::new_ints(&rom::CURVE_ORDER);
- let mut cb = Big::frombytes(c); /* c or &c ? */
+ let cb = Big::frombytes(c); /* c or &c ? */
let mut db = Big::frombytes(d); /* d or &d ? */
let mut fb = Big::frombytes(&b);
let mut tb = Big::new();
@@ -567,9 +570,9 @@ pub fn ecpvp_dsa(sha: usize, w: &[u8], f: &[u8], c: &[u8], d: &[u8]) -> isize {
if res == 0 {
db.invmodp(&r);
- tb.copy(&Big::modmul(&mut fb, &mut db, &r));
+ tb.copy(&Big::modmul(&fb, &db, &r));
fb.copy(&tb);
- let h2 = Big::modmul(&mut cb, &mut db, &r);
+ let h2 = Big::modmul(&cb, &db, &r);
let WP = ECP::frombytes(&w);
if WP.is_infinity() {
@@ -578,7 +581,7 @@ pub fn ecpvp_dsa(sha: usize, w: &[u8], f: &[u8], c: &[u8], d: &[u8]) -> isize {
let mut P = ECP::new();
P.copy(&WP);
- P = P.mul2(&h2, &mut G, &fb);
+ P = P.mul2(&h2, &G, &fb);
if P.is_infinity() {
res = INVALID;
@@ -593,10 +596,10 @@ pub fn ecpvp_dsa(sha: usize, w: &[u8], f: &[u8], c: &[u8], d: &[u8]) -> isize {
}
}
- return res;
+ res
}
-/* IEEE1363 ECIES encryption. Encryption of plaintext M uses public key W and produces ciphertext V,C,T */
+/// IEEE1363 ECIES encryption. Encryption of plaintext M uses public key W and produces ciphertext V,C,T
#[allow(non_snake_case)]
pub fn ecies_encrypt(
sha: usize,
@@ -622,7 +625,7 @@ pub fn ecies_encrypt(
return None;
}
- for i in 0..2 * EFS + 1 {
+ for i in 0..=2 * EFS {
vz[i] = v[i]
}
for i in 0..EFS {
@@ -656,10 +659,10 @@ pub fn ecies_encrypt(
c.pop();
}
- return Some(c);
+ Some(c)
}
-/* constant time n-byte compare */
+/// constant time n-byte compare
fn ncomp(t1: &[u8], t2: &[u8], n: usize) -> bool {
let mut res = 0;
for i in 0..n {
@@ -668,10 +671,10 @@ fn ncomp(t1: &[u8], t2: &[u8], n: usize) -> bool {
if res == 0 {
return true;
}
- return false;
+ false
}
-/* IEEE1363 ECIES decryption. Decryption of ciphertext V,C,T using private key U outputs plaintext M */
+/// IEEE1363 ECIES decryption. Decryption of ciphertext V,C,T using private key U outputs plaintext M
#[allow(non_snake_case)]
pub fn ecies_decrypt(
sha: usize,
@@ -740,5 +743,5 @@ pub fn ecies_decrypt(
return None;
}
- return m;
+ m
}
diff --git a/src/ecp.rs b/src/ecp.rs
index 0e27f32..b779e2d 100644
--- a/src/ecp.rs
+++ b/src/ecp.rs
@@ -17,15 +17,15 @@ specific language governing permissions and limitations
under the License.
*/
-use super::fp::FP;
-use super::big::Big;
use super::big;
+use super::big::Big;
+use super::fp::FP;
use super::rom;
-pub use super::rom::{CURVETYPE, CURVE_PAIRING_TYPE, SEXTIC_TWIST, SIGN_OF_X, HASH_TYPE, AESKEY};
-pub use types::CurveType;
-use std::str::SplitWhitespace;
+pub use super::rom::{AESKEY, CURVETYPE, CURVE_PAIRING_TYPE, HASH_TYPE, SEXTIC_TWIST, SIGN_OF_X};
use std::fmt;
+use std::str::SplitWhitespace;
+pub use types::CurveType;
#[derive(Copy, Clone)]
pub struct ECP {
@@ -41,15 +41,15 @@ impl PartialEq for ECP {
}
impl fmt::Display for ECP {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "ECP: [ {}, {}, {} ]", self.x, self.y, self.z)
- }
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "ECP: [ {}, {}, {} ]", self.x, self.y, self.z)
+ }
}
impl fmt::Debug for ECP {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "ECP: [ {}, {}, {} ]", self.x, self.y, self.z)
- }
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "ECP: [ {}, {}, {} ]", self.x, self.y, self.z)
+ }
}
#[allow(non_snake_case)]
@@ -64,7 +64,7 @@ impl ECP {
pub fn new() -> ECP {
let mut E = ECP::pnew();
- if CURVETYPE == CurveType::EDWARDS {
+ if CURVETYPE == CurveType::Edwards {
E.z.one();
}
return E;
@@ -78,14 +78,14 @@ impl ECP {
E.z.one();
E.x.norm();
let mut rhs = ECP::rhs(&E.x);
- if CURVETYPE == CurveType::MONTGOMERY {
+ if CURVETYPE == CurveType::Montgomery {
if rhs.jacobi() != 1 {
E.inf();
}
} else {
let mut y2 = FP::new_copy(&E.y);
y2.sqr();
- if !y2.equals(&mut rhs) {
+ if !y2.equals(&rhs) {
E.inf();
}
}
@@ -122,7 +122,7 @@ impl ECP {
E.z.one();
let mut rhs = ECP::rhs(&E.x);
if rhs.jacobi() == 1 {
- if CURVETYPE != CurveType::MONTGOMERY {
+ if CURVETYPE != CurveType::Montgomery {
E.y.copy(&rhs.sqrt())
}
} else {
@@ -134,10 +134,10 @@ impl ECP {
/* set this=O */
pub fn inf(&mut self) {
self.x.zero();
- if CURVETYPE != CurveType::MONTGOMERY {
+ if CURVETYPE != CurveType::Montgomery {
self.y.one();
}
- if CURVETYPE != CurveType::EDWARDS {
+ if CURVETYPE != CurveType::Edwards {
self.z.zero();
} else {
self.z.one()
@@ -149,7 +149,7 @@ impl ECP {
let mut r = FP::new_copy(x);
r.sqr();
- if CURVETYPE == CurveType::WEIERSTRASS {
+ if CURVETYPE == CurveType::Weierstrass {
// x^3+Ax+B
let b = FP::new_big(&Big::new_ints(&rom::CURVE_B));
r.mul(x);
@@ -162,7 +162,7 @@ impl ECP {
}
r.add(&b);
}
- if CURVETYPE == CurveType::EDWARDS {
+ if CURVETYPE == CurveType::Edwards {
// (Ax^2-1)/(Bx^2-1)
let mut b = FP::new_big(&Big::new_ints(&rom::CURVE_B));
let one = FP::new_int(1);
@@ -177,7 +177,7 @@ impl ECP {
b.inverse();
r.mul(&b);
}
- if CURVETYPE == CurveType::MONTGOMERY {
+ if CURVETYPE == CurveType::Montgomery {
// x^3+Ax^2+x
let mut x3 = FP::new();
x3.copy(&r);
@@ -193,16 +193,16 @@ impl ECP {
/* test for O point-at-infinity */
pub fn is_infinity(&self) -> bool {
match CURVETYPE {
- CurveType::EDWARDS=> self.x.iszilch() && self.y.equals(&self.z),
- CurveType::WEIERSTRASS => self.x.iszilch() && self.z.iszilch(),
- CurveType::MONTGOMERY => self.z.iszilch(),
+ CurveType::Edwards => self.x.iszilch() && self.y.equals(&self.z),
+ CurveType::Weierstrass => self.x.iszilch() && self.z.iszilch(),
+ CurveType::Montgomery => self.z.iszilch(),
}
}
/* Conditional swap of P and Q dependant on d */
pub fn cswap(&mut self, Q: &mut ECP, d: isize) {
self.x.cswap(&mut Q.x, d);
- if CURVETYPE != CurveType::MONTGOMERY {
+ if CURVETYPE != CurveType::Montgomery {
self.y.cswap(&mut Q.y, d)
}
self.z.cswap(&mut Q.z, d);
@@ -211,7 +211,7 @@ impl ECP {
/* Conditional move of Q to P dependant on d */
pub fn cmove(&mut self, Q: &ECP, d: isize) {
self.x.cmove(&Q.x, d);
- if CURVETYPE != CurveType::MONTGOMERY {
+ if CURVETYPE != CurveType::Montgomery {
self.y.cmove(&Q.y, d)
}
self.z.cmove(&Q.z, d);
@@ -227,7 +227,7 @@ impl ECP {
/* this=P */
pub fn copy(&mut self, P: &ECP) {
self.x.copy(&P.x);
- if CURVETYPE != CurveType::MONTGOMERY {
+ if CURVETYPE != CurveType::Montgomery {
self.y.copy(&P.y)
}
self.z.copy(&P.z);
@@ -235,11 +235,11 @@ impl ECP {
/* this=-this */
pub fn neg(&mut self) {
- if CURVETYPE == CurveType::WEIERSTRASS {
+ if CURVETYPE == CurveType::Weierstrass {
self.y.neg();
self.y.norm();
}
- if CURVETYPE == CurveType::EDWARDS {
+ if CURVETYPE == CurveType::Edwards {
self.x.neg();
self.x.norm();
}
@@ -281,15 +281,15 @@ impl ECP {
a.mul(&Q.z);
b.copy(&Q.x);
b.mul(&self.z);
- if !a.equals(&mut b) {
+ if !a.equals(&b) {
return false;
}
- if CURVETYPE != CurveType::MONTGOMERY {
+ if CURVETYPE != CurveType::Montgomery {
a.copy(&self.y);
a.mul(&Q.z);
b.copy(&Q.y);
b.mul(&self.z);
- if !a.equals(&mut b) {
+ if !a.equals(&b) {
return false;
}
}
@@ -301,15 +301,15 @@ impl ECP {
if self.is_infinity() {
return;
}
- let mut one = FP::new_int(1);
- if self.z.equals(&mut one) {
+ let one = FP::new_int(1);
+ if self.z.equals(&one) {
return;
}
self.z.inverse();
self.x.mul(&self.z);
self.x.reduce();
- if CURVETYPE != CurveType::MONTGOMERY {
+ if CURVETYPE != CurveType::Montgomery {
self.y.mul(&self.z);
self.y.reduce();
}
@@ -368,7 +368,7 @@ impl ECP {
b[i + 1] = t[i]
}
- if CURVETYPE == CurveType::MONTGOMERY {
+ if CURVETYPE == CurveType::Montgomery {
b[0] = 0x06;
return;
}
@@ -403,7 +403,7 @@ impl ECP {
return ECP::new();
}
- if CURVETYPE == CurveType::MONTGOMERY {
+ if CURVETYPE == CurveType::Montgomery {
return ECP::new_big(&px);
}
@@ -432,7 +432,7 @@ impl ECP {
if W.is_infinity() {
return String::from("infinity");
}
- if CURVETYPE == CurveType::MONTGOMERY {
+ if CURVETYPE == CurveType::Montgomery {
return format!("({})", W.x.redc().tostring());
} else {
return format!("({},{})", W.x.redc().tostring(), W.y.redc().tostring());
@@ -440,7 +440,12 @@ impl ECP {
}
pub fn to_hex(&self) -> String {
- format!("{} {} {}", self.x.to_hex(), self.y.to_hex(), self.z.to_hex())
+ format!(
+ "{} {} {}",
+ self.x.to_hex(),
+ self.y.to_hex(),
+ self.z.to_hex()
+ )
}
pub fn from_hex_iter(iter: &mut SplitWhitespace) -> ECP {
@@ -458,7 +463,7 @@ impl ECP {
/* this*=2 */
pub fn dbl(&mut self) {
- if CURVETYPE == CurveType::WEIERSTRASS {
+ if CURVETYPE == CurveType::Weierstrass {
if rom::CURVE_A == 0 {
let mut t0 = FP::new_copy(&self.y);
t0.sqr();
@@ -590,7 +595,7 @@ impl ECP {
self.z.norm();
}
}
- if CURVETYPE == CurveType::EDWARDS {
+ if CURVETYPE == CurveType::Edwards {
let mut c = FP::new_copy(&self.x);
let mut d = FP::new_copy(&self.y);
let mut h = FP::new_copy(&self.z);
@@ -619,7 +624,7 @@ impl ECP {
self.y.mul(&c);
self.z.mul(&j);
}
- if CURVETYPE == CurveType::MONTGOMERY {
+ if CURVETYPE == CurveType::Montgomery {
let mut a = FP::new_copy(&self.x);
let mut b = FP::new_copy(&self.x);
let mut aa = FP::new();
@@ -654,7 +659,7 @@ impl ECP {
/* self+=Q */
pub fn add(&mut self, Q: &ECP) {
- if CURVETYPE == CurveType::WEIERSTRASS {
+ if CURVETYPE == CurveType::Weierstrass {
if rom::CURVE_A == 0 {
let b = 3 * rom::CURVE_B_I;
let mut t0 = FP::new_copy(&self.x);
@@ -847,7 +852,7 @@ impl ECP {
self.z.norm();
}
}
- if CURVETYPE == CurveType::EDWARDS {
+ if CURVETYPE == CurveType::Edwards {
let bb = FP::new_big(&Big::new_ints(&rom::CURVE_B));
let mut a = FP::new_copy(&self.z);
let mut b = FP::new();
@@ -959,7 +964,7 @@ impl ECP {
/* constant time multiply by small integer of length bts - use ladder */
pub fn pinmul(&self, e: i32, bts: i32) -> ECP {
- if CURVETYPE == CurveType::MONTGOMERY {
+ if CURVETYPE == CurveType::Montgomery {
return self.mul(&mut Big::new_int(e as isize));
} else {
let mut P = ECP::new();
@@ -970,7 +975,7 @@ impl ECP {
for i in (0..bts).rev() {
let b = ((e >> i) & 1) as isize;
P.copy(&R1);
- P.add(&mut R0);
+ P.add(&R0);
R0.cswap(&mut R1, b);
R1.copy(&P);
R0.dbl();
@@ -989,7 +994,7 @@ impl ECP {
return ECP::new();
}
let mut P = ECP::new();
- if CURVETYPE == CurveType::MONTGOMERY {
+ if CURVETYPE == CurveType::Montgomery {
/* use Ladder */
let mut D = ECP::new();
let mut R0 = ECP::new();
@@ -1040,7 +1045,7 @@ impl ECP {
for i in 1..8 {
C.copy(&W[i - 1]);
W[i].copy(&C);
- W[i].add(&mut Q);
+ W[i].add(&Q);
}
// make exponent odd - add 2P if even, P if odd
@@ -1074,9 +1079,9 @@ impl ECP {
P.dbl();
P.dbl();
P.dbl();
- P.add(&mut Q);
+ P.add(&Q);
}
- P.sub(&mut C); /* apply correction */
+ P.sub(&C); /* apply correction */
}
P.affine();
return P;
@@ -1119,24 +1124,24 @@ impl ECP {
S.dbl();
C.copy(&W[1]);
W[0].copy(&C);
- W[0].sub(&mut S); // copy to C is stupid Rust thing..
+ W[0].sub(&S); // copy to C is stupid Rust thing..
C.copy(&W[2]);
W[3].copy(&C);
- W[3].add(&mut S);
+ W[3].add(&S);
T.copy(&self);
T.dbl();
C.copy(&W[1]);
W[5].copy(&C);
- W[5].add(&mut T);
+ W[5].add(&T);
C.copy(&W[2]);
W[6].copy(&C);
- W[6].add(&mut T);
+ W[6].add(&T);
C.copy(&W[5]);
W[4].copy(&C);
- W[4].sub(&mut S);
+ W[4].sub(&S);
C.copy(&W[6]);
W[7].copy(&C);
- W[7].add(&mut S);
+ W[7].add(&S);
// if multiplier is odd, add 2, else add 1 to multiplier, and add 2P or P to correction
@@ -1160,7 +1165,7 @@ impl ECP {
mt.norm();
tf.cmove(&mt, s);
S.cmove(&Q, ns);
- C.add(&mut S);
+ C.add(&S);
mt.copy(&te);
mt.add(&tf);
@@ -1186,9 +1191,9 @@ impl ECP {
T.selector(&W, w[i] as i32);
S.dbl();
S.dbl();
- S.add(&mut T);
+ S.add(&T);
}
- S.sub(&mut C); /* apply correction */
+ S.sub(&C); /* apply correction */
S.affine();
return S;
}
@@ -1218,14 +1223,14 @@ impl ECP {
// Map a given byte slice to a point on the curve. The byte slice should be atleast the size of the modulus
#[allow(non_snake_case)]
pub fn mapit(h: &[u8]) -> ECP {
- let mut q = Big::new_ints(&rom::MODULUS);
+ let q = Big::new_ints(&rom::MODULUS);
let mut x = Big::frombytes(h);
- x.rmod(&mut q);
+ x.rmod(&q);
let mut P: ECP;
loop {
loop {
- if CURVETYPE != CurveType::MONTGOMERY {
+ if CURVETYPE != CurveType::Montgomery {
P = ECP::new_bigint(&x, 0);
} else {
P = ECP::new_big(&x);
@@ -1250,7 +1255,7 @@ impl ECP {
let gx = Big::new_ints(&rom::CURVE_GX);
- if CURVETYPE != CurveType::MONTGOMERY {
+ if CURVETYPE != CurveType::Montgomery {
let gy = Big::new_ints(&rom::CURVE_GY);
G = ECP::new_bigs(&gx, &gy);
} else {
diff --git a/src/ecp2.rs b/src/ecp2.rs
index c705863..b0892e4 100644
--- a/src/ecp2.rs
+++ b/src/ecp2.rs
@@ -17,14 +17,14 @@ specific language governing permissions and limitations
under the License.
*/
-use super::rom;
use super::big;
+use super::big::Big;
use super::ecp;
use super::fp2::FP2;
-use super::big::Big;
-use types::{SexticTwist, CurvePairingType, SignOfX};
-use std::str::SplitWhitespace;
+use super::rom;
use std::fmt;
+use std::str::SplitWhitespace;
+use types::{CurvePairingType, SexticTwist, SignOfX};
#[derive(Copy, Clone)]
pub struct ECP2 {
@@ -34,21 +34,21 @@ pub struct ECP2 {
}
impl PartialEq for ECP2 {
- fn eq(&self, other: &ECP2) -> bool {
- self.equals(other)
- }
+ fn eq(&self, other: &ECP2) -> bool {
+ self.equals(other)
+ }
}
impl fmt::Display for ECP2 {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "ECP2: [ {}, {}, {} ]", self.x, self.y, self.z)
- }
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "ECP2: [ {}, {}, {} ]", self.x, self.y, self.z)
+ }
}
impl fmt::Debug for ECP2 {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "ECP2: [ {}, {}, {} ]", self.x, self.y, self.z)
- }
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "ECP2: [ {}, {}, {} ]", self.x, self.y, self.z)
+ }
}
#[allow(non_snake_case)]
@@ -69,10 +69,10 @@ impl ECP2 {
E.z.one();
E.x.norm();
- let mut rhs = ECP2::rhs(&E.x);
+ let rhs = ECP2::rhs(&E.x);
let mut y2 = FP2::new_copy(&E.y);
y2.sqr();
- if !y2.equals(&mut rhs) {
+ if !y2.equals(&rhs) {
E.inf();
}
return E;
@@ -163,14 +163,14 @@ impl ECP2 {
a.mul(&Q.z);
b.mul(&self.z);
- if !a.equals(&mut b) {
+ if !a.equals(&b) {
return false;
}
a.copy(&self.y);
a.mul(&Q.z);
b.copy(&Q.y);
b.mul(&self.z);
- if !a.equals(&mut b) {
+ if !a.equals(&b) {
return false;
}
@@ -182,8 +182,8 @@ impl ECP2 {
if self.is_infinity() {
return;
}
- let mut one = FP2::new_int(1);
- if self.z.equals(&mut one) {
+ let one = FP2::new_int(1);
+ if self.z.equals(&one) {
return;
}
self.z.inverse();
@@ -291,14 +291,19 @@ impl ECP2 {
}
pub fn to_hex(&self) -> String {
- format!("{} {} {}", self.x.to_hex(), self.y.to_hex(), self.z.to_hex())
+ format!(
+ "{} {} {}",
+ self.x.to_hex(),
+ self.y.to_hex(),
+ self.z.to_hex()
+ )
}
pub fn from_hex_iter(iter: &mut SplitWhitespace) -> ECP2 {
ECP2 {
x: FP2::from_hex_iter(iter),
y: FP2::from_hex_iter(iter),
- z: FP2::from_hex_iter(iter)
+ z: FP2::from_hex_iter(iter),
}
}
@@ -312,10 +317,10 @@ impl ECP2 {
let mut r = FP2::new_copy(x);
r.sqr();
let mut b = FP2::new_big(&Big::new_ints(&rom::CURVE_B));
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
b.div_ip();
}
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
b.norm();
b.mul_ip();
b.norm();
@@ -331,14 +336,14 @@ impl ECP2 {
/* self+=self */
pub fn dbl(&mut self) -> isize {
let mut iy = FP2::new_copy(&self.y);
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
iy.mul_ip();
iy.norm();
}
let mut t0 = FP2::new_copy(&self.y); //***** Change
t0.sqr();
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
t0.mul_ip();
}
let mut t1 = FP2::new_copy(&iy);
@@ -354,7 +359,7 @@ impl ECP2 {
self.z.norm();
t2.imul(3 * rom::CURVE_B_I);
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
t2.mul_ip();
t2.norm();
}
@@ -410,7 +415,7 @@ impl ECP2 {
t3.sub(&t4);
t3.norm();
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
t3.mul_ip();
t3.norm(); //t3=(X1+Y1)(X2+Y2)-(X1.X2+Y1.Y2) = X1.Y2+X2.Y1
}
@@ -427,7 +432,7 @@ impl ECP2 {
t4.sub(&x3);
t4.norm();
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
t4.mul_ip();
t4.norm(); //t4=(Y1+Z1)(Y2+Z2) - (Y1.Y2+Z1.Z2) = Y1.Z2+Y2.Z1
}
@@ -443,7 +448,7 @@ impl ECP2 {
y3.rsub(&x3);
y3.norm(); // y3=(X1+Z1)(X2+Z2) - (X1.X2+Z1.Z2) = X1.Z2+X2.Z1
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
t0.mul_ip();
t0.norm(); // x.Q.x
t1.mul_ip();
@@ -454,7 +459,7 @@ impl ECP2 {
t0.add(&x3);
t0.norm();
t2.imul(b);
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
t2.mul_ip();
t2.norm();
}
@@ -464,7 +469,7 @@ impl ECP2 {
t1.sub(&t2);
t1.norm();
y3.imul(b);
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
y3.mul_ip();
y3.norm();
}
@@ -548,7 +553,7 @@ impl ECP2 {
for i in 1..8 {
C.copy(&W[i - 1]);
W[i].copy(&C);
- W[i].add(&mut Q);
+ W[i].add(&Q);
}
/* make exponent odd - add 2P if even, P if odd */
@@ -582,9 +587,9 @@ impl ECP2 {
P.dbl();
P.dbl();
P.dbl();
- P.add(&mut Q);
+ P.add(&Q);
}
- P.sub(&mut C);
+ P.sub(&C);
P.affine();
return P;
}
@@ -629,24 +634,24 @@ impl ECP2 {
T[0].copy(&Q[0]);
W.copy(&T[0]);
T[1].copy(&W);
- T[1].add(&mut Q[1]); // Q[0]+Q[1]
+ T[1].add(&Q[1]); // Q[0]+Q[1]
T[2].copy(&W);
- T[2].add(&mut Q[2]);
+ T[2].add(&Q[2]);
W.copy(&T[1]); // Q[0]+Q[2]
T[3].copy(&W);
- T[3].add(&mut Q[2]);
+ T[3].add(&Q[2]);
W.copy(&T[0]); // Q[0]+Q[1]+Q[2]
T[4].copy(&W);
- T[4].add(&mut Q[3]);
+ T[4].add(&Q[3]);
W.copy(&T[1]); // Q[0]+Q[3]
T[5].copy(&W);
- T[5].add(&mut Q[3]);
+ T[5].add(&Q[3]);
W.copy(&T[2]); // Q[0]+Q[1]+Q[3]
T[6].copy(&W);
- T[6].add(&mut Q[3]);
+ T[6].add(&Q[3]);
W.copy(&T[3]); // Q[0]+Q[2]+Q[3]
T[7].copy(&W);
- T[7].add(&mut Q[3]); // Q[0]+Q[1]+Q[2]+Q[3]
+ T[7].add(&Q[3]); // Q[0]+Q[1]+Q[2]+Q[3]
// Make it odd
let pb = 1 - t[0].parity();
@@ -688,12 +693,12 @@ impl ECP2 {
for i in (0..nb - 1).rev() {
P.dbl();
W.selector(&T, (2 * w[i] + s[i]) as i32);
- P.add(&mut W);
+ P.add(&W);
}
// apply correction
W.copy(&P);
- W.sub(&mut Q[0]);
+ W.sub(&Q[0]);
P.cmove(&W, pb);
P.affine();
@@ -702,9 +707,9 @@ impl ECP2 {
#[allow(non_snake_case)]
pub fn mapit(h: &[u8]) -> ECP2 {
- let mut q = Big::new_ints(&rom::MODULUS);
+ let q = Big::new_ints(&rom::MODULUS);
let mut x = Big::frombytes(h);
- x.rmod(&mut q);
+ x.rmod(&q);
let mut Q: ECP2;
let one = Big::new_int(1);
@@ -718,15 +723,15 @@ impl ECP2 {
x.norm();
}
let mut X = FP2::new_bigs(&Big::new_ints(&rom::FRA), &Big::new_ints(&rom::FRB));
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
X.inverse();
X.norm();
}
x = Big::new_ints(&rom::CURVE_BNX);
- if ecp::CURVE_PAIRING_TYPE == CurvePairingType::BN {
- let mut T = Q.mul(&mut x);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::CURVE_PAIRING_TYPE == CurvePairingType::Bn {
+ let mut T = Q.mul(&x);
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
T.neg();
}
let mut K = ECP2::new();
@@ -744,11 +749,11 @@ impl ECP2 {
T.frob(&X);
Q.add(&T);
}
- if ecp::CURVE_PAIRING_TYPE == CurvePairingType::BLS {
- let mut xQ = Q.mul(&mut x);
- let mut x2Q = xQ.mul(&mut x);
+ if ecp::CURVE_PAIRING_TYPE == CurvePairingType::Bls {
+ let mut xQ = Q.mul(&x);
+ let mut x2Q = xQ.mul(&x);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
xQ.neg();
}
x2Q.sub(&xQ);
diff --git a/src/ecp4.rs b/src/ecp4.rs
index b29b05d..e0dc5dc 100644
--- a/src/ecp4.rs
+++ b/src/ecp4.rs
@@ -17,12 +17,12 @@ specific language governing permissions and limitations
under the License.
*/
-use super::rom;
use super::big;
+use super::big::Big;
use super::ecp;
use super::fp2::FP2;
use super::fp4::FP4;
-use super::big::Big;
+use super::rom;
use types::{SexticTwist, SignOfX};
//use std::str::SplitWhitespace;
@@ -328,10 +328,10 @@ impl ECP4 {
let mut r = FP4::new_copy(x);
r.sqr();
let mut b = FP4::new_fp2(&FP2::new_big(&Big::new_ints(&rom::CURVE_B)));
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
b.div_i();
}
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
b.times_i();
}
@@ -345,13 +345,13 @@ impl ECP4 {
/* self+=self */
pub fn dbl(&mut self) -> isize {
let mut iy = FP4::new_copy(&self.y);
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
iy.times_i(); //iy.norm();
}
let mut t0 = FP4::new_copy(&self.y);
t0.sqr();
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
t0.times_i();
}
let mut t1 = FP4::new_copy(&iy);
@@ -367,7 +367,7 @@ impl ECP4 {
self.z.norm();
t2.imul(3 * rom::CURVE_B_I);
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
t2.times_i();
}
let mut x3 = FP4::new_copy(&t2);
@@ -422,7 +422,7 @@ impl ECP4 {
t3.sub(&t4);
t3.norm();
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
t3.times_i(); //t3=(X1+Y1)(X2+Y2)-(X1.X2+Y1.Y2) = X1.Y2+X2.Y1
}
t4.copy(&self.y);
@@ -438,7 +438,7 @@ impl ECP4 {
t4.sub(&x3);
t4.norm();
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
t4.times_i(); //t4=(Y1+Z1)(Y2+Z2) - (Y1.Y2+Z1.Z2) = Y1.Z2+Y2.Z1
}
x3.copy(&self.x);
@@ -453,7 +453,7 @@ impl ECP4 {
y3.rsub(&x3);
y3.norm(); // y3=(X1+Z1)(X2+Z2) - (X1.X2+Z1.Z2) = X1.Z2+X2.Z1
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
t0.times_i(); // x.Q.x
t1.times_i(); // y.Q.y
}
@@ -462,7 +462,7 @@ impl ECP4 {
t0.add(&x3);
t0.norm();
t2.imul(b);
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
t2.times_i();
}
let mut z3 = FP4::new_copy(&t1);
@@ -471,7 +471,7 @@ impl ECP4 {
t1.sub(&t2);
t1.norm();
y3.imul(b);
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
y3.times_i();
}
x3.copy(&y3);
@@ -517,7 +517,7 @@ impl ECP4 {
f1.sqr();
f2.mul(&f1);
f1.copy(&f);
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
f1.mul_ip();
f1.inverse();
f0.copy(&f1);
@@ -835,7 +835,7 @@ impl ECP4 {
let mut x3Q = x2Q.mul(&mut x);
let mut x4Q = x3Q.mul(&mut x);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
xQ.neg();
x3Q.neg();
}
diff --git a/src/ecp8.rs b/src/ecp8.rs
index 18c8a30..3998c2c 100644
--- a/src/ecp8.rs
+++ b/src/ecp8.rs
@@ -17,13 +17,13 @@ specific language governing permissions and limitations
under the License.
*/
-use super::rom;
use super::big;
+use super::big::Big;
use super::ecp;
use super::fp2::FP2;
use super::fp4::FP4;
use super::fp8::FP8;
-use super::big::Big;
+use super::rom;
use types::{SexticTwist, SignOfX};
pub struct ECP8 {
@@ -414,10 +414,10 @@ impl ECP8 {
let mut r = FP8::new_copy(x);
r.sqr();
let mut b = FP8::new_fp4(&FP4::new_fp2(&FP2::new_big(&Big::new_ints(&rom::CURVE_B))));
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
b.div_i();
}
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
b.times_i();
}
@@ -431,13 +431,13 @@ impl ECP8 {
/* self+=self */
pub fn dbl(&mut self) -> isize {
let mut iy = FP8::new_copy(&self.y);
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
iy.times_i(); //iy.norm();
}
let mut t0 = FP8::new_copy(&self.y);
t0.sqr();
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
t0.times_i();
}
let mut t1 = FP8::new_copy(&iy);
@@ -453,7 +453,7 @@ impl ECP8 {
self.z.norm();
t2.imul(3 * rom::CURVE_B_I);
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
t2.times_i();
}
let mut x3 = FP8::new_copy(&t2);
@@ -508,7 +508,7 @@ impl ECP8 {
t3.sub(&t4);
t3.norm();
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
t3.times_i(); //t3=(X1+Y1)(X2+Y2)-(X1.X2+Y1.Y2) = X1.Y2+X2.Y1
}
t4.copy(&self.y);
@@ -524,7 +524,7 @@ impl ECP8 {
t4.sub(&x3);
t4.norm();
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
t4.times_i(); //t4=(Y1+Z1)(Y2+Z2) - (Y1.Y2+Z1.Z2) = Y1.Z2+Y2.Z1
}
x3.copy(&self.x);
@@ -539,7 +539,7 @@ impl ECP8 {
y3.rsub(&x3);
y3.norm(); // y3=(X1+Z1)(X2+Z2) - (X1.X2+Z1.Z2) = X1.Z2+X2.Z1
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
t0.times_i(); // x.Q.x
t1.times_i(); // y.Q.y
}
@@ -548,7 +548,7 @@ impl ECP8 {
t0.add(&x3);
t0.norm();
t2.imul(b);
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
t2.times_i();
}
let mut z3 = FP8::new_copy(&t1);
@@ -557,7 +557,7 @@ impl ECP8 {
t1.sub(&t2);
t1.norm();
y3.imul(b);
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
y3.times_i();
}
x3.copy(&y3);
@@ -607,7 +607,7 @@ impl ECP8 {
f2.norm();
f1.copy(&f);
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
f1.mul_ip();
f1.inverse();
f0.copy(&f1);
@@ -626,18 +626,18 @@ impl ECP8 {
for _i in 0..n {
self.x.frob(&f[2]);
self.x.qmul(&f[0]);
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
self.x.div_i2();
}
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
self.x.times_i2();
}
self.y.frob(&f[2]);
self.y.qmul(&f[1]);
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
self.y.div_i();
}
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
self.y.times_i2();
self.y.times_i2();
self.y.times_i();
@@ -914,7 +914,7 @@ impl ECP8 {
// Number of bits
mt.zero();
for i in 0..16 {
- t[i].norm();
+ t[i].norm();
mt.or(&t[i]);
}
@@ -1105,7 +1105,7 @@ impl ECP8 {
let mut x7Q = x6Q.mul(&mut x);
let mut x8Q = x7Q.mul(&mut x);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
xQ.neg();
x3Q.neg();
x5Q.neg();
diff --git a/src/ff.rs b/src/ff.rs
index 5855d88..54e7a32 100644
--- a/src/ff.rs
+++ b/src/ff.rs
@@ -17,10 +17,10 @@ specific language governing permissions and limitations
under the License.
*/
+use super::super::arch::Chunk;
use super::big;
-use super::dbig::DBig;
use super::big::Big;
-use super::super::arch::Chunk;
+use super::dbig::DBig;
use rand::RAND;
use super::super::arch::DChunk;
diff --git a/src/fp.rs b/src/fp.rs
index 205d8d6..72b7390 100644
--- a/src/fp.rs
+++ b/src/fp.rs
@@ -17,14 +17,14 @@ specific language governing permissions and limitations
under the License.
*/
+use super::super::arch;
+use super::super::arch::Chunk;
use super::big;
use super::big::Big;
use super::dbig::DBig;
use super::rom;
-use super::super::arch::Chunk;
-use super::super::arch;
-use types::ModType;
use std::str::FromStr;
+use types::ModType;
#[derive(Copy, Clone)]
pub struct FP {
@@ -50,17 +50,17 @@ impl fmt::Debug for FP {
}
}
-pub use super::rom::{MODBITS, MOD8, MODTYPE, SH};
-use std::str::SplitWhitespace;
+pub use super::rom::{MOD8, MODBITS, MODTYPE, SH};
use std::fmt;
+use std::str::SplitWhitespace;
-pub const FEXCESS:i32 = (((1 as i32)<<SH)-1);
-pub const OMASK:Chunk = (-1)<<(MODBITS%big::BASEBITS);
-pub const TBITS:usize=MODBITS%big::BASEBITS; // Number of active bits in top word
-pub const TMASK:Chunk=(1<<TBITS)-1;
+pub const FEXCESS: i32 = (((1 as i32) << SH) - 1);
+pub const OMASK: Chunk = (-1) << (MODBITS % big::BASEBITS);
+pub const TBITS: usize = MODBITS % big::BASEBITS; // Number of active bits in top word
+pub const TMASK: Chunk = (1 << TBITS) - 1;
impl FP {
- /* Constructors */
+ // Constructors
pub fn new() -> FP {
FP {
x: Big::new(),
@@ -90,9 +90,9 @@ impl FP {
}
pub fn nres(&mut self) {
- if MODTYPE != ModType::PSEUDO_MERSENNE && MODTYPE != ModType::GENERALISED_MERSENNE {
- let r=Big::new_ints(&rom::R2MODP);
- let mut d=Big::mul(&(self.x),&r);
+ if MODTYPE != ModType::PseudoMersenne && MODTYPE != ModType::GeneralisedMersenne {
+ let r = Big::new_ints(&rom::R2MODP);
+ let mut d = Big::mul(&(self.x), &r);
self.x.copy(&FP::modulo(&mut d));
self.xes = 2;
} else {
@@ -104,8 +104,8 @@ impl FP {
let xes = i32::from_str(iter.next().unwrap()).unwrap();
let x = iter.next().unwrap();
FP {
- x: Big::from_hex(x.to_string()),
- xes
+ x: Big::fromstring(x.to_string()),
+ xes,
}
}
@@ -115,28 +115,26 @@ impl FP {
}
pub fn to_hex(&self) -> String {
- let mut x = self.x;
- let big = x.to_hex();
+ let x = self.x;
+ let big = x.tostring();
format!("{} {}", self.xes, big)
}
-/* convert back to regular form */
+ // convert back to regular form
pub fn redc(&mut self) -> Big {
- if MODTYPE != ModType::PSEUDO_MERSENNE && MODTYPE != ModType::GENERALISED_MERSENNE {
- let mut d=DBig::new_scopy(&(self.x));
+ if MODTYPE != ModType::PseudoMersenne && MODTYPE != ModType::GeneralisedMersenne {
+ let mut d = DBig::new_scopy(&(self.x));
return FP::modulo(&mut d);
- } else {
- let r = Big::new_copy(&(self.x));
- return r;
}
+ Big::new_copy(&(self.x))
}
- /* reduce a DBig to a Big using the appropriate form of the modulus */
- /* dd */
+ // reduce a DBig to a Big using the appropriate form of the modulus
+ // dd
pub fn modulo(d: &mut DBig) -> Big {
- if MODTYPE==ModType::PSEUDO_MERSENNE {
- let mut b=Big::new();
- let mut t=d.split(MODBITS);
+ if MODTYPE == ModType::PseudoMersenne {
+ let mut b = Big::new();
+ let mut t = d.split(MODBITS);
b.dcopy(&d);
let v = t.pmul(rom::MCONST as isize);
@@ -150,7 +148,7 @@ impl FP {
return t;
}
- if MODTYPE==ModType::MONTGOMERY_FRIENDLY {
+ if MODTYPE == ModType::MontgomeryFriendly {
let mut b = Big::new();
for i in 0..big::NLEN {
let x = d.w[i];
@@ -169,7 +167,7 @@ impl FP {
return b;
}
- if MODTYPE == ModType::GENERALISED_MERSENNE {
+ if MODTYPE == ModType::GeneralisedMersenne {
// GoldiLocks Only
let mut b = Big::new();
let t = d.split(MODBITS);
@@ -195,20 +193,19 @@ impl FP {
b.norm();
return b;
}
- if MODTYPE == ModType::NOT_SPECIAL {
+ if MODTYPE == ModType::NotSpecial {
let m = Big::new_ints(&rom::MODULUS);
return Big::monty(&m, rom::MCONST, d);
}
- return Big::new();
+ Big::new()
}
- /* convert to string */
+ // convert to string
pub fn tostring(&mut self) -> String {
- let s = self.redc().tostring();
- return s;
+ self.redc().tostring()
}
- /* reduce this mod Modulus */
+ // reduce this mod Modulus
pub fn reduce(&mut self) {
let mut m = Big::new_ints(&rom::MODULUS);
let mut r = Big::new_copy(&m);
@@ -229,48 +226,48 @@ impl FP {
while sb > 0 {
let sr = Big::ssn(&mut r, &self.x, &mut m);
self.x.cmove(&r, 1 - sr);
- sb = sb - 1;
+ sb -= 1;
}
self.xes = 1;
}
- /* test this=0? */
+ // test this=0?
pub fn iszilch(&self) -> bool {
let mut a = FP::new_copy(self);
a.reduce();
- return a.x.iszilch();
+ a.x.iszilch()
}
- /* copy from FP b */
+ // copy from FP b
pub fn copy(&mut self, b: &FP) {
self.x.copy(&(b.x));
self.xes = b.xes;
}
- /* copy from Big b */
+ // copy from Big b
pub fn bcopy(&mut self, b: &Big) {
self.x.copy(&b);
self.nres();
}
- /* set this=0 */
+ // set this=0
pub fn zero(&mut self) {
self.x.zero();
self.xes = 1;
}
- /* set this=1 */
+ // set this=1
pub fn one(&mut self) {
self.x.one();
self.nres()
}
- /* normalise this */
+ // normalise this
pub fn norm(&mut self) {
self.x.norm();
}
- /* swap FPs depending on d */
+ // swap FPs depending on d
pub fn cswap(&mut self, b: &mut FP, d: isize) {
self.x.cswap(&mut (b.x), d);
let mut c = d as i32;
@@ -280,16 +277,16 @@ impl FP {
b.xes ^= t;
}
- /* copy FPs depending on d */
+ // copy FPs depending on d
pub fn cmove(&mut self, b: &FP, d: isize) {
self.x.cmove(&(b.x), d);
let c = d as i32;
self.xes ^= (self.xes ^ b.xes) & (-c);
}
- /* this*=b mod Modulus */
+ // this*=b mod Modulus
pub fn mul(&mut self, b: &FP) {
- if (self.xes as i64) * (b.xes as i64) > FEXCESS as i64 {
+ if i64::from(self.xes) * i64::from(b.xes) > i64::from(FEXCESS) {
self.reduce()
}
@@ -308,8 +305,7 @@ impl FP {
v = v - ((v >> 1) & 0x55555555);
v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
- let r = ((((v + (v >> 4)) & 0xF0F0F0F).wrapping_mul(0x1010101)) >> 24) as usize;
- return r;
+ ((((v + (v >> 4)) & 0xF0F0F0F).wrapping_mul(0x1010101)) >> 24) as usize
}
// find approximation to quotient of a/m
@@ -330,7 +326,7 @@ impl FP {
}
}
- /* this = -this mod Modulus */
+ // this = -this mod Modulus
pub fn neg(&mut self) {
let mut p = Big::new_ints(&rom::MODULUS);
let sb = FP::logb2((self.xes - 1) as u32);
@@ -343,7 +339,7 @@ impl FP {
}
}
- /* this*=c mod Modulus, where c is a small int */
+ // this*=c mod Modulus, where c is a small int
pub fn imul(&mut self, c: isize) {
let mut cc = c;
let mut s = false;
@@ -352,7 +348,7 @@ impl FP {
s = true;
}
- if MODTYPE == ModType::PSEUDO_MERSENNE || MODTYPE == ModType::GENERALISED_MERSENNE {
+ if MODTYPE == ModType::PseudoMersenne || MODTYPE == ModType::GeneralisedMersenne {
let mut d = self.x.pxmul(cc);
self.x.copy(&FP::modulo(&mut d));
self.xes = 2
@@ -372,9 +368,9 @@ impl FP {
}
}
- /* self*=self mod Modulus */
+ // self*=self mod Modulus
pub fn sqr(&mut self) {
- if (self.xes as i64) * (self.xes as i64) > FEXCESS as i64 {
+ if i64::from(self.xes) * i64::from(self.xes) > i64::from(FEXCESS) {
self.reduce()
}
@@ -383,7 +379,7 @@ impl FP {
self.xes = 2
}
- /* self+=b */
+ // self+=b
pub fn add(&mut self, b: &FP) {
self.x.add(&(b.x));
self.xes += b.xes;
@@ -392,7 +388,7 @@ impl FP {
}
}
- /* self+=self */
+ // self+=self
pub fn dbl(&mut self) {
self.x.dbl();
self.xes += self.xes;
@@ -401,20 +397,20 @@ impl FP {
}
}
- /* self-=b */
+ // self-=b
pub fn sub(&mut self, b: &FP) {
let mut n = FP::new_copy(b);
n.neg();
self.add(&n);
}
- /* self=b-self */
+ // self=b-self
pub fn rsub(&mut self, b: &FP) {
self.neg();
self.add(&b);
}
- /* self/=2 mod Modulus */
+ // self/=2 mod Modulus
pub fn div2(&mut self) {
if self.x.parity() == 0 {
self.x.fshr(1);
@@ -479,7 +475,7 @@ impl FP {
let mut n = MODBITS as isize;
let c: isize;
- if MODTYPE == ModType::GENERALISED_MERSENNE {
+ if MODTYPE == ModType::GeneralisedMersenne {
// Goldilocks ONLY
n /= 2;
}
@@ -564,21 +560,21 @@ impl FP {
}
r.mul(&key);
}
- if MODTYPE == ModType::GENERALISED_MERSENNE {
+ if MODTYPE == ModType::GeneralisedMersenne {
// Goldilocks ONLY
key.copy(&r);
r.sqr();
r.mul(&self);
- for _ in 0..n + 1 {
+ for _ in 0..=n {
r.sqr();
}
r.mul(&key);
}
- return r;
+ r
}
- /* self=1/self mod Modulus */
+ // self=1/self mod Modulus
pub fn inverse(&mut self) {
- if MODTYPE == ModType::PSEUDO_MERSENNE || MODTYPE == ModType::GENERALISED_MERSENNE {
+ if MODTYPE == ModType::PseudoMersenne || MODTYPE == ModType::GeneralisedMersenne {
let mut y = self.fpow();
if MOD8 == 5 {
let mut t = FP::new_copy(self);
@@ -600,7 +596,7 @@ impl FP {
}
}
- /* return TRUE if self==a */
+ // return TRUE if self==a
pub fn equals(&self, a: &FP) -> bool {
let mut f = FP::new_copy(self);
let mut s = FP::new_copy(a);
@@ -612,7 +608,7 @@ impl FP {
return false;
}
- /* return self^e mod Modulus */
+ // return self^e mod Modulus
pub fn pow(&mut self, e: &mut Big) -> FP {
let mut tb: [FP; 16] = [
FP::new(),
@@ -668,7 +664,7 @@ impl FP {
return r;
}
- /* return sqrt(this) mod Modulus */
+ // return sqrt(this) mod Modulus
pub fn sqrt(&mut self) -> FP {
self.reduce();
@@ -676,7 +672,7 @@ impl FP {
let v: FP;
let mut i = FP::new_copy(self);
i.x.shl(1);
- if MODTYPE == ModType::PSEUDO_MERSENNE || MODTYPE == ModType::GENERALISED_MERSENNE {
+ if MODTYPE == ModType::PseudoMersenne || MODTYPE == ModType::GeneralisedMersenne {
v = i.fpow();
} else {
let mut p = Big::new_ints(&rom::MODULUS);
@@ -695,7 +691,7 @@ impl FP {
return r;
} else {
let mut r: FP;
- if MODTYPE == ModType::PSEUDO_MERSENNE || MODTYPE == ModType::GENERALISED_MERSENNE {
+ if MODTYPE == ModType::PseudoMersenne || MODTYPE == ModType::GeneralisedMersenne {
r = self.fpow();
r.mul(self);
} else {
@@ -708,10 +704,10 @@ impl FP {
return r;
}
}
- /* return jacobi symbol (this/Modulus) */
+ // return jacobi symbol (this/Modulus)
pub fn jacobi(&mut self) -> isize {
- let mut p = Big::new_ints(&rom::MODULUS);
+ let p = Big::new_ints(&rom::MODULUS);
let mut w = self.redc();
- return w.jacobi(&mut p);
+ return w.jacobi(&p);
}
}
diff --git a/src/fp12.rs b/src/fp12.rs
index 311fe87..0ba5fc1 100644
--- a/src/fp12.rs
+++ b/src/fp12.rs
@@ -18,19 +18,19 @@ under the License.
*/
use super::big;
+use super::big::Big;
+use super::ecp;
use super::fp2::FP2;
use super::fp4::FP4;
-use super::big::Big;
use super::rom;
-use types::SexticTwist;
use std::str::SplitWhitespace;
-use super::ecp;
+use types::SexticTwist;
-pub const ZERO: usize=0;
-pub const ONE: usize=1;
-pub const SPARSER: usize=2;
-pub const SPARSE: usize=3;
-pub const DENSE: usize=4;
+pub const ZERO: usize = 0;
+pub const ONE: usize = 1;
+pub const SPARSER: usize = 2;
+pub const SPARSE: usize = 3;
+pub const DENSE: usize = 4;
#[derive(Copy, Clone)]
pub struct FP12 {
@@ -41,9 +41,9 @@ pub struct FP12 {
}
impl PartialEq for FP12 {
- fn eq(&self, other: &FP12) -> bool {
- self.equals(other)
- }
+ fn eq(&self, other: &FP12) -> bool {
+ self.equals(other)
+ }
}
impl FP12 {
@@ -52,12 +52,12 @@ impl FP12 {
a: FP4::new(),
b: FP4::new(),
c: FP4::new(),
- stype: ZERO,
+ stype: ZERO,
}
}
- pub fn settype(&mut self,t: usize) {
- self.stype = t;
+ pub fn settype(&mut self, t: usize) {
+ self.stype = t;
}
pub fn gettype(&self) -> usize {
@@ -69,11 +69,11 @@ impl FP12 {
f.a.copy(&FP4::new_int(a));
f.b.zero();
f.c.zero();
- if a == 1 {
- f.stype=ONE;
- } else {
- f.stype=SPARSER;
- }
+ if a == 1 {
+ f.stype = ONE;
+ } else {
+ f.stype = SPARSER;
+ }
return f;
}
@@ -82,7 +82,7 @@ impl FP12 {
f.a.copy(&x.a);
f.b.copy(&x.b);
f.c.copy(&x.c);
- f.stype=x.stype;
+ f.stype = x.stype;
return f;
}
@@ -91,7 +91,7 @@ impl FP12 {
g.a.copy(d);
g.b.copy(e);
g.c.copy(f);
- g.stype=DENSE;
+ g.stype = DENSE;
return g;
}
@@ -100,7 +100,7 @@ impl FP12 {
g.a.copy(d);
g.b.zero();
g.c.zero();
- g.stype=SPARSER;
+ g.stype = SPARSER;
return g;
}
@@ -129,9 +129,9 @@ impl FP12 {
self.a.cmove(&g.a, d);
self.b.cmove(&g.b, d);
self.c.cmove(&g.c, d);
- let mut u=d as usize;
- u=!(u-1);
- self.stype^=(self.stype^g.stype)&u;
+ let mut u = d as usize;
+ u = !(u - 1);
+ self.stype ^= (self.stype ^ g.stype) & u;
}
/* return 1 if b==c, no branching */
@@ -175,20 +175,20 @@ impl FP12 {
pub fn geta(&mut self) -> FP4 {
return self.a;
-// let f = FP4::new_copy(&self.a);
-// return f;
+ // let f = FP4::new_copy(&self.a);
+ // return f;
}
pub fn getb(&mut self) -> FP4 {
return self.b;
-// let f = FP4::new_copy(&self.b);
-// return f;
+ // let f = FP4::new_copy(&self.b);
+ // return f;
}
pub fn getc(&mut self) -> FP4 {
return self.c;
-// let f = FP4::new_copy(&self.c);
-// return f;
+ // let f = FP4::new_copy(&self.c);
+ // return f;
}
/* copy self=x */
@@ -196,7 +196,7 @@ impl FP12 {
self.a.copy(&x.a);
self.b.copy(&x.b);
self.c.copy(&x.c);
- self.stype=x.stype;
+ self.stype = x.stype;
}
/* set self=1 */
@@ -204,7 +204,7 @@ impl FP12 {
self.a.one();
self.b.zero();
self.c.zero();
- self.stype=ONE;
+ self.stype = ONE;
}
/* set self=0 */
@@ -212,7 +212,7 @@ impl FP12 {
self.a.zero();
self.b.zero();
self.c.zero();
- self.stype=ZERO;
+ self.stype = ZERO;
}
/* this=conj(this) */
@@ -260,13 +260,13 @@ impl FP12 {
self.c.dbl();
self.b.add(&b);
self.c.add(&c);
- self.stype=DENSE;
+ self.stype = DENSE;
self.reduce();
}
/* Chung-Hasan SQR2 method from http://cacr.uwaterloo.ca/techreports/2006/cacr2006-24.pdf */
pub fn sqr(&mut self) {
- if self.stype==ONE {
+ if self.stype == ONE {
return;
}
@@ -304,10 +304,10 @@ impl FP12 {
self.b.copy(&c);
self.b.add(&d);
self.c.add(&a);
- if self.stype==SPARSER {
- self.stype=SPARSE;
+ if self.stype == SPARSER {
+ self.stype = SPARSE;
} else {
- self.stype=DENSE;
+ self.stype = DENSE;
}
self.norm();
}
@@ -316,7 +316,7 @@ impl FP12 {
pub fn mul(&mut self, y: &FP12) {
let mut z0 = FP4::new_copy(&self.a);
let mut z1 = FP4::new();
- let mut z2 = FP4::new_copy(&mut self.b);
+ let mut z2 = FP4::new_copy(&self.b);
let mut z3 = FP4::new();
let mut t0 = FP4::new_copy(&self.a);
let mut t1 = FP4::new_copy(&y.a);
@@ -379,100 +379,112 @@ impl FP12 {
z3.times_i();
self.a.copy(&z0);
self.a.add(&z3);
- self.stype=DENSE;
+ self.stype = DENSE;
self.norm();
}
-
-/* FP12 full multiplication w=w*y */
-/* Supports sparse multiplicands */
-/* Usually w is denser than y */
+ /* FP12 full multiplication w=w*y */
+ /* Supports sparse multiplicands */
+ /* Usually w is denser than y */
pub fn ssmul(&mut self, y: &FP12) {
- if self.stype==ONE {
+ if self.stype == ONE {
self.copy(&y);
return;
}
- if y.stype==ONE {
+ if y.stype == ONE {
return;
}
- if y.stype>=SPARSE {
- let mut z0=FP4::new_copy(&self.a);
- let mut z1=FP4::new_int(0);
- let mut z2=FP4::new_int(0);
- let mut z3=FP4::new_int(0);
+ if y.stype >= SPARSE {
+ let mut z0 = FP4::new_copy(&self.a);
+ let mut z1 = FP4::new_int(0);
+ let mut z2 = FP4::new_int(0);
+ let mut z3 = FP4::new_int(0);
z0.mul(&y.a);
- if ecp::SEXTIC_TWIST==SexticTwist::M_TYPE {
- if y.stype==SPARSE || self.stype==SPARSE {
-
- let mut ga=FP2::new_int(0);
- let mut gb=FP2::new_int(0);
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
+ if y.stype == SPARSE || self.stype == SPARSE {
+ let mut ga = FP2::new_int(0);
+ let mut gb = FP2::new_int(0);
gb.copy(&self.b.getb());
gb.mul(&y.b.getb());
ga.zero();
- if y.stype!=SPARSE {
+ if y.stype != SPARSE {
ga.copy(&self.b.getb());
ga.mul(&y.b.geta());
}
- if self.stype!=SPARSE {
+ if self.stype != SPARSE {
ga.copy(&self.b.geta());
ga.mul(&y.b.getb());
}
- z2.set_fp2s(&ga,&gb);
+ z2.set_fp2s(&ga, &gb);
z2.times_i();
} else {
z2.copy(&self.b);
z2.mul(&y.b);
}
} else {
- z2.copy(&self.b);
- z2.mul(&y.b);
+ z2.copy(&self.b);
+ z2.mul(&y.b);
}
- let mut t0=FP4::new_copy(&self.a);
- let mut t1=FP4::new_copy(&y.a);
- t0.add(&self.b); t0.norm();
- t1.add(&y.b); t1.norm();
-
- z1.copy(&t0); z1.mul(&t1);
- t0.copy(&self.b); t0.add(&self.c); t0.norm();
- t1.copy(&y.b); t1.add(&y.c); t1.norm();
-
- z3.copy(&t0); z3.mul(&t1);
-
- t0.copy(&z0); t0.neg();
- t1.copy(&z2); t1.neg();
+ let mut t0 = FP4::new_copy(&self.a);
+ let mut t1 = FP4::new_copy(&y.a);
+ t0.add(&self.b);
+ t0.norm();
+ t1.add(&y.b);
+ t1.norm();
+
+ z1.copy(&t0);
+ z1.mul(&t1);
+ t0.copy(&self.b);
+ t0.add(&self.c);
+ t0.norm();
+ t1.copy(&y.b);
+ t1.add(&y.c);
+ t1.norm();
+
+ z3.copy(&t0);
+ z3.mul(&t1);
+
+ t0.copy(&z0);
+ t0.neg();
+ t1.copy(&z2);
+ t1.neg();
z1.add(&t0);
- self.b.copy(&z1); self.b.add(&t1);
+ self.b.copy(&z1);
+ self.b.add(&t1);
z3.add(&t1);
z2.add(&t0);
- t0.copy(&self.a); t0.add(&self.c); t0.norm();
- t1.copy(&y.a); t1.add(&y.c); t1.norm();
+ t0.copy(&self.a);
+ t0.add(&self.c);
+ t0.norm();
+ t1.copy(&y.a);
+ t1.add(&y.c);
+ t1.norm();
t0.mul(&t1);
z2.add(&t0);
- if ecp::SEXTIC_TWIST==SexticTwist::D_TYPE {
- if y.stype==SPARSE || self.stype==SPARSE {
-
- let mut ga=FP2::new_int(0);
- let mut gb=FP2::new_int(0);
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
+ if y.stype == SPARSE || self.stype == SPARSE {
+ let mut ga = FP2::new_int(0);
+ let mut gb = FP2::new_int(0);
ga.copy(&self.c.geta());
ga.mul(&y.c.geta());
gb.zero();
- if y.stype!=SPARSE {
+ if y.stype != SPARSE {
gb.copy(&self.c.geta());
gb.mul(&y.c.getb());
}
- if self.stype!=SPARSE {
+ if self.stype != SPARSE {
gb.copy(&self.c.getb());
gb.mul(&y.c.geta());
}
- t0.set_fp2s(&ga,&gb);
+ t0.set_fp2s(&ga, &gb);
} else {
t0.copy(&self.c);
t0.mul(&y.c);
@@ -481,26 +493,30 @@ impl FP12 {
t0.copy(&self.c);
t0.mul(&y.c);
}
- t1.copy(&t0); t1.neg();
+ t1.copy(&t0);
+ t1.neg();
- self.c.copy(&z2); self.c.add(&t1);
+ self.c.copy(&z2);
+ self.c.add(&t1);
z3.add(&t1);
t0.times_i();
self.b.add(&t0);
z3.norm();
z3.times_i();
- self.a.copy(&z0); self.a.add(&z3);
+ self.a.copy(&z0);
+ self.a.add(&z3);
} else {
- if self.stype==SPARSER {
+ if self.stype == SPARSER {
self.smul(&y);
return;
}
- if ecp::SEXTIC_TWIST==SexticTwist::D_TYPE { // dense by sparser - 13m
- let mut z0=FP4::new_copy(&self.a);
- let mut z2=FP4::new_copy(&self.b);
- let mut z3=FP4::new_copy(&self.b);
- let mut t0=FP4::new_int(0);
- let mut t1=FP4::new_copy(&y.a);
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
+ // dense by sparser - 13m
+ let mut z0 = FP4::new_copy(&self.a);
+ let mut z2 = FP4::new_copy(&self.b);
+ let mut z3 = FP4::new_copy(&self.b);
+ let mut t0 = FP4::new_int(0);
+ let mut t1 = FP4::new_copy(&y.a);
z0.mul(&y.a);
z2.pmul(&y.b.geta());
@@ -514,8 +530,10 @@ impl FP12 {
z3.norm();
z3.pmul(&y.b.geta());
- t0.copy(&z0); t0.neg();
- t1.copy(&z2); t1.neg();
+ t0.copy(&z0);
+ t0.neg();
+ t1.copy(&z2);
+ t1.neg();
self.b.add(&t0);
@@ -523,16 +541,19 @@ impl FP12 {
z3.add(&t1);
z2.add(&t0);
- t0.copy(&self.a); t0.add(&self.c); t0.norm();
+ t0.copy(&self.a);
+ t0.add(&self.c);
+ t0.norm();
z3.norm();
t0.mul(&y.a);
- self.c.copy(&z2); self.c.add(&t0);
+ self.c.copy(&z2);
+ self.c.add(&t0);
z3.times_i();
- self.a.copy(&z0); self.a.add(&z3);
+ self.a.copy(&z0);
+ self.a.add(&z3);
}
- if ecp::SEXTIC_TWIST==SexticTwist::M_TYPE {
-
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
let mut z0 = FP4::new_copy(&self.a);
let mut z1 = FP4::new();
let mut z2 = FP4::new();
@@ -541,23 +562,31 @@ impl FP12 {
let mut t1 = FP4::new();
z0.mul(&y.a);
- t0.add(&self.b); t0.norm();
+ t0.add(&self.b);
+ t0.norm();
- z1.copy(&t0); z1.mul(&y.a);
- t0.copy(&self.b); t0.add(&self.c);
+ z1.copy(&t0);
+ z1.mul(&y.a);
+ t0.copy(&self.b);
+ t0.add(&self.c);
t0.norm();
z3.copy(&t0);
z3.pmul(&y.c.getb());
z3.times_i();
- t0.copy(&z0); t0.neg();
+ t0.copy(&z0);
+ t0.neg();
z1.add(&t0);
self.b.copy(&z1);
z2.copy(&t0);
- t0.copy(&self.a); t0.add(&self.c); t0.norm();
- t1.copy(&y.a); t1.add(&y.c); t1.norm();
+ t0.copy(&self.a);
+ t0.add(&self.c);
+ t0.norm();
+ t1.copy(&y.a);
+ t1.add(&y.c);
+ t1.norm();
t0.mul(&t1);
z2.add(&t0);
@@ -565,55 +594,68 @@ impl FP12 {
t0.pmul(&y.c.getb());
t0.times_i();
- t1.copy(&t0); t1.neg();
+ t1.copy(&t0);
+ t1.neg();
- self.c.copy(&z2); self.c.add(&t1);
+ self.c.copy(&z2);
+ self.c.add(&t1);
z3.add(&t1);
t0.times_i();
self.b.add(&t0);
z3.norm();
z3.times_i();
- self.a.copy(&z0); self.a.add(&z3);
- }
+ self.a.copy(&z0);
+ self.a.add(&z3);
+ }
}
- self.stype=DENSE;
+ self.stype = DENSE;
self.norm();
}
/* Special case of multiplication arises from special form of ATE pairing line function */
pub fn smul(&mut self, y: &FP12) {
- if ecp::SEXTIC_TWIST==SexticTwist::D_TYPE {
- let mut w1=FP2::new_copy(&self.a.geta());
- let mut w2=FP2::new_copy(&self.a.getb());
- let mut w3=FP2::new_copy(&self.b.geta());
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
+ let mut w1 = FP2::new_copy(&self.a.geta());
+ let mut w2 = FP2::new_copy(&self.a.getb());
+ let mut w3 = FP2::new_copy(&self.b.geta());
w1.mul(&y.a.geta());
w2.mul(&y.a.getb());
w3.mul(&y.b.geta());
- let mut ta=FP2::new_copy(&self.a.geta());
- let mut tb=FP2::new_copy(&y.a.geta());
- ta.add(&self.a.getb()); ta.norm();
- tb.add(&y.a.getb()); tb.norm();
- let mut tc=FP2::new_copy(&ta);
+ let mut ta = FP2::new_copy(&self.a.geta());
+ let mut tb = FP2::new_copy(&y.a.geta());
+ ta.add(&self.a.getb());
+ ta.norm();
+ tb.add(&y.a.getb());
+ tb.norm();
+ let mut tc = FP2::new_copy(&ta);
tc.mul(&tb);
- let mut t=FP2::new_copy(&w1);
+ let mut t = FP2::new_copy(&w1);
t.add(&w2);
t.neg();
tc.add(&t);
- ta.copy(&self.a.geta()); ta.add(&self.b.geta()); ta.norm();
- tb.copy(&y.a.geta()); tb.add(&y.b.geta()); tb.norm();
- let mut td=FP2::new_copy(&ta);
+ ta.copy(&self.a.geta());
+ ta.add(&self.b.geta());
+ ta.norm();
+ tb.copy(&y.a.geta());
+ tb.add(&y.b.geta());
+ tb.norm();
+ let mut td = FP2::new_copy(&ta);
td.mul(&tb);
t.copy(&w1);
t.add(&w3);
t.neg();
td.add(&t);
- ta.copy(&self.a.getb()); ta.add(&self.b.geta()); ta.norm();
- tb.copy(&y.a.getb()); tb.add(&y.b.geta()); tb.norm();
- let mut te=FP2::new_copy(&ta);
+ ta.copy(&self.a.getb());
+ ta.add(&self.b.geta());
+ ta.norm();
+ tb.copy(&y.a.getb());
+ tb.add(&y.b.geta());
+ tb.norm();
+ let mut te = FP2::new_copy(&ta);
te.mul(&tb);
t.copy(&w2);
t.add(&w3);
@@ -623,44 +665,54 @@ impl FP12 {
w2.mul_ip();
w1.add(&w2);
- self.a.set_fp2s(&w1,&tc);
- self.b.set_fp2s(&td,&te);
- self.c.set_fp2(&w3);
+ self.a.set_fp2s(&w1, &tc);
+ self.b.set_fp2s(&td, &te);
+ self.c.set_fp2(&w3);
self.a.norm();
self.b.norm();
} else {
- let mut w1=FP2::new_copy(&self.a.geta());
- let mut w2=FP2::new_copy(&self.a.getb());
- let mut w3=FP2::new_copy(&self.c.getb());
+ let mut w1 = FP2::new_copy(&self.a.geta());
+ let mut w2 = FP2::new_copy(&self.a.getb());
+ let mut w3 = FP2::new_copy(&self.c.getb());
w1.mul(&y.a.geta());
w2.mul(&y.a.getb());
w3.mul(&y.c.getb());
- let mut ta=FP2::new_copy(&self.a.geta());
- let mut tb=FP2::new_copy(&y.a.geta());
- ta.add(&self.a.getb()); ta.norm();
- tb.add(&y.a.getb()); tb.norm();
- let mut tc=FP2::new_copy(&ta);
+ let mut ta = FP2::new_copy(&self.a.geta());
+ let mut tb = FP2::new_copy(&y.a.geta());
+ ta.add(&self.a.getb());
+ ta.norm();
+ tb.add(&y.a.getb());
+ tb.norm();
+ let mut tc = FP2::new_copy(&ta);
tc.mul(&tb);
- let mut t=FP2::new_copy(&w1);
+ let mut t = FP2::new_copy(&w1);
t.add(&w2);
t.neg();
tc.add(&t);
- ta.copy(&self.a.geta()); ta.add(&self.c.getb()); ta.norm();
- tb.copy(&y.a.geta()); tb.add(&y.c.getb()); tb.norm();
- let mut td=FP2::new_copy(&ta);
+ ta.copy(&self.a.geta());
+ ta.add(&self.c.getb());
+ ta.norm();
+ tb.copy(&y.a.geta());
+ tb.add(&y.c.getb());
+ tb.norm();
+ let mut td = FP2::new_copy(&ta);
td.mul(&tb);
t.copy(&w1);
t.add(&w3);
t.neg();
td.add(&t);
- ta.copy(&self.a.getb()); ta.add(&self.c.getb()); ta.norm();
- tb.copy(&y.a.getb()); tb.add(&y.c.getb()); tb.norm();
- let mut te=FP2::new_copy(&ta);
+ ta.copy(&self.a.getb());
+ ta.add(&self.c.getb());
+ ta.norm();
+ tb.copy(&y.a.getb());
+ tb.add(&y.c.getb());
+ tb.norm();
+ let mut te = FP2::new_copy(&ta);
te.mul(&tb);
t.copy(&w2);
t.add(&w3);
@@ -669,20 +721,20 @@ impl FP12 {
w2.mul_ip();
w1.add(&w2);
- self.a.set_fp2s(&w1,&tc);
+ self.a.set_fp2s(&w1, &tc);
w3.mul_ip();
w3.norm();
- self.b.set_fp2h(&w3);
+ self.b.set_fp2h(&w3);
te.norm();
te.mul_ip();
- self.c.set_fp2s(&te,&td);
+ self.c.set_fp2s(&te, &td);
self.a.norm();
self.c.norm();
- }
- self.stype=SPARSE;
+ }
+ self.stype = SPARSE;
}
/* self=1/self */
@@ -730,7 +782,7 @@ impl FP12 {
self.b.mul(&f3);
self.c.copy(&f2);
self.c.mul(&f3);
- self.stype=DENSE;
+ self.stype = DENSE;
}
/* self=self^p using Frobenius */
@@ -747,7 +799,7 @@ impl FP12 {
self.b.pmul(f);
self.c.pmul(&f2);
- self.stype=DENSE;
+ self.stype = DENSE;
}
/* trace function */
@@ -902,7 +954,12 @@ impl FP12 {
}
pub fn to_hex(&self) -> String {
- format!("{} {} {}", self.a.to_hex(), self.b.to_hex(), self.c.to_hex())
+ format!(
+ "{} {} {}",
+ self.a.to_hex(),
+ self.b.to_hex(),
+ self.c.to_hex()
+ )
}
pub fn from_hex_iter(iter: &mut SplitWhitespace) -> FP12 {
@@ -910,7 +967,7 @@ impl FP12 {
a: FP4::from_hex_iter(iter),
b: FP4::from_hex_iter(iter),
c: FP4::from_hex_iter(iter),
- stype: DENSE
+ stype: DENSE,
}
}
@@ -973,15 +1030,15 @@ impl FP12 {
m.rmod(&r);
let mut a = Big::new_copy(&e);
- a.rmod(&mut m);
+ a.rmod(&m);
let mut b = Big::new_copy(&e);
- b.div(&mut m);
+ b.div(&m);
let mut c = g1.trace();
if b.iszilch() {
- c = c.xtr_pow(&mut a);
+ c = c.xtr_pow(&a);
return c;
}
@@ -993,7 +1050,7 @@ impl FP12 {
g2.mul(&g1);
let cpm2 = g2.trace();
- c = c.xtr_pow2(&cp, &cpm1, &cpm2, &mut a, &mut b);
+ c = c.xtr_pow2(&cp, &cpm1, &cpm2, &a, &b);
return c;
}
@@ -1086,15 +1143,15 @@ impl FP12 {
t[j].dec((bt >> 1) as isize);
t[j].norm();
w[i] += bt * (k as i8);
- k = 2 * k;
+ k *= 2;
}
}
// Main loop
- p.selector(&g, (2 * w[nb - 1] + 1) as i32);
+ p.selector(&g, i32::from(2 * w[nb - 1] + 1));
for i in (0..nb - 1).rev() {
p.usqr();
- r.selector(&g, (2 * w[i] + s[i]) as i32);
+ r.selector(&g, i32::from(2 * w[i] + s[i]));
p.mul(&r);
}
diff --git a/src/fp16.rs b/src/fp16.rs
index 2c4e976..55dd573 100644
--- a/src/fp16.rs
+++ b/src/fp16.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
+use super::big::Big;
use super::fp2::FP2;
use super::fp8::FP8;
-use super::big::Big;
//use std::str::SplitWhitespace;
#[derive(Copy, Clone)]
@@ -64,19 +64,19 @@ impl FP16 {
return f;
}
- pub fn set_fp8s(&mut self,c: &FP8, d: &FP8) {
+ pub fn set_fp8s(&mut self, c: &FP8, d: &FP8) {
self.a.copy(&c);
- self.b.copy(&d);
+ self.b.copy(&d);
}
- pub fn set_fp8(&mut self,c: &FP8) {
+ pub fn set_fp8(&mut self, c: &FP8) {
self.a.copy(&c);
- self.b.zero();
+ self.b.zero();
}
- pub fn set_fp8h(&mut self,c: &FP8) {
+ pub fn set_fp8h(&mut self, c: &FP8) {
self.b.copy(&c);
- self.a.zero();
+ self.a.zero();
}
/* reduce components mod Modulus */
@@ -119,14 +119,14 @@ impl FP16 {
pub fn geta(&self) -> FP8 {
return self.a;
-// let f = FP8::new_copy(&self.a);
-// return f;
+ // let f = FP8::new_copy(&self.a);
+ // return f;
}
/* extract imaginary part b */
pub fn getb(&self) -> FP8 {
return self.b;
-// let f = FP8::new_copy(&self.b);
-// return f;
+ // let f = FP8::new_copy(&self.b);
+ // return f;
}
/* test self=x */
@@ -359,7 +359,7 @@ impl FP16 {
let bt = z.parity();
z.fshr(1);
if bt == 1 {
- r.mul(&mut w)
+ r.mul(&w)
};
if z.iszilch() {
break;
diff --git a/src/fp2.rs b/src/fp2.rs
index 060b9de..7ed108b 100644
--- a/src/fp2.rs
+++ b/src/fp2.rs
@@ -17,13 +17,13 @@ specific language governing permissions and limitations
under the License.
*/
-use super::fp;
-use super::fp::FP;
use super::big::Big;
use super::dbig::DBig;
+use super::fp;
+use super::fp::FP;
use super::rom;
-use std::str::SplitWhitespace;
use std::fmt;
+use std::str::SplitWhitespace;
#[derive(Copy, Clone)]
pub struct FP2 {
@@ -32,21 +32,21 @@ pub struct FP2 {
}
impl PartialEq for FP2 {
- fn eq(&self, other: &FP2) -> bool {
- self.equals(other)
- }
+ fn eq(&self, other: &FP2) -> bool {
+ self.equals(other)
+ }
}
impl fmt::Display for FP2 {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "FP2: [ {}, {} ]", self.a, self.b)
- }
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "FP2: [ {}, {} ]", self.a, self.b)
+ }
}
impl fmt::Debug for FP2 {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "FP2: [ {}, {} ]", self.a, self.b)
- }
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "FP2: [ {}, {} ]", self.a, self.b)
+ }
}
impl FP2 {
@@ -239,7 +239,9 @@ impl FP2 {
/* this*=y */
pub fn mul(&mut self, y: &FP2) {
- if ((self.a.xes + self.b.xes) as i64) * ((y.a.xes + y.b.xes) as i64) > fp::FEXCESS as i64 {
+ if i64::from(self.a.xes + self.b.xes) * i64::from(y.a.xes + y.b.xes)
+ > i64::from(fp::FEXCESS)
+ {
if self.a.xes > 1 {
self.a.reduce()
}
@@ -331,7 +333,7 @@ impl FP2 {
pub fn from_hex_iter(iter: &mut SplitWhitespace) -> FP2 {
FP2 {
a: FP::from_hex_iter(iter),
- b: FP::from_hex_iter(iter)
+ b: FP::from_hex_iter(iter),
}
}
diff --git a/src/fp24.rs b/src/fp24.rs
index 3deb850..93c1266 100644
--- a/src/fp24.rs
+++ b/src/fp24.rs
@@ -18,20 +18,20 @@ under the License.
*/
use super::big;
+use super::big::Big;
use super::ecp;
use super::fp2::FP2;
use super::fp4::FP4;
use super::fp8::FP8;
-use super::big::Big;
use super::rom;
-use types::{SexticTwist};
+use types::SexticTwist;
//use std::str::SplitWhitespace;
-pub const ZERO: usize=0;
-pub const ONE: usize=1;
-pub const SPARSER: usize=2;
-pub const SPARSE: usize=3;
-pub const DENSE: usize=4;
+pub const ZERO: usize = 0;
+pub const ONE: usize = 1;
+pub const SPARSER: usize = 2;
+pub const SPARSE: usize = 3;
+pub const DENSE: usize = 4;
#[derive(Copy, Clone)]
pub struct FP24 {
@@ -51,8 +51,8 @@ impl FP24 {
}
}
- pub fn settype(&mut self,t: usize) {
- self.stype = t;
+ pub fn settype(&mut self, t: usize) {
+ self.stype = t;
}
pub fn gettype(&self) -> usize {
@@ -64,11 +64,11 @@ impl FP24 {
f.a.copy(&FP8::new_int(a));
f.b.zero();
f.c.zero();
- if a == 1 {
- f.stype=ONE;
- } else {
- f.stype=SPARSER;
- }
+ if a == 1 {
+ f.stype = ONE;
+ } else {
+ f.stype = SPARSER;
+ }
return f;
}
@@ -77,7 +77,7 @@ impl FP24 {
f.a.copy(&x.a);
f.b.copy(&x.b);
f.c.copy(&x.c);
- f.stype=x.stype;
+ f.stype = x.stype;
return f;
}
@@ -86,7 +86,7 @@ impl FP24 {
g.a.copy(d);
g.b.copy(e);
g.c.copy(f);
- g.stype=DENSE;
+ g.stype = DENSE;
return g;
}
@@ -95,7 +95,7 @@ impl FP24 {
g.a.copy(d);
g.b.zero();
g.c.zero();
- g.stype=SPARSER;
+ g.stype = SPARSER;
return g;
}
@@ -123,9 +123,9 @@ impl FP24 {
self.a.cmove(&g.a, d);
self.b.cmove(&g.b, d);
self.c.cmove(&g.c, d);
- let mut u=d as usize;
- u=!(u-1);
- self.stype^=(self.stype^g.stype)&u;
+ let mut u = d as usize;
+ u = !(u - 1);
+ self.stype ^= (self.stype ^ g.stype) & u;
}
/* return 1 if b==c, no branching */
@@ -169,20 +169,20 @@ impl FP24 {
pub fn geta(&mut self) -> FP8 {
return self.a;
-// let f = FP8::new_copy(&self.a);
-// return f;
+ // let f = FP8::new_copy(&self.a);
+ // return f;
}
pub fn getb(&mut self) -> FP8 {
return self.b;
-// let f = FP8::new_copy(&self.b);
-// return f;
+ // let f = FP8::new_copy(&self.b);
+ // return f;
}
pub fn getc(&mut self) -> FP8 {
return self.c;
-// let f = FP8::new_copy(&self.c);
-// return f;
+ // let f = FP8::new_copy(&self.c);
+ // return f;
}
/* copy self=x */
@@ -190,7 +190,7 @@ impl FP24 {
self.a.copy(&x.a);
self.b.copy(&x.b);
self.c.copy(&x.c);
- self.stype=x.stype;
+ self.stype = x.stype;
}
/* set self=1 */
@@ -198,7 +198,7 @@ impl FP24 {
self.a.one();
self.b.zero();
self.c.zero();
- self.stype=ONE;
+ self.stype = ONE;
}
/* set self=0 */
@@ -206,7 +206,7 @@ impl FP24 {
self.a.zero();
self.b.zero();
self.c.zero();
- self.stype=ZERO;
+ self.stype = ZERO;
}
/* this=conj(this) */
@@ -254,13 +254,13 @@ impl FP24 {
self.c.dbl();
self.b.add(&b);
self.c.add(&c);
- self.stype=DENSE;
+ self.stype = DENSE;
self.reduce();
}
/* Chung-Hasan SQR2 method from http://cacr.uwaterloo.ca/techreports/2006/cacr2006-24.pdf */
pub fn sqr(&mut self) {
- if self.stype==ONE {
+ if self.stype == ONE {
return;
}
let mut a = FP8::new_copy(&self.a);
@@ -297,10 +297,10 @@ impl FP24 {
self.b.copy(&c);
self.b.add(&d);
self.c.add(&a);
- if self.stype==SPARSER {
- self.stype=SPARSE;
+ if self.stype == SPARSER {
+ self.stype = SPARSE;
} else {
- self.stype=DENSE;
+ self.stype = DENSE;
}
self.norm();
}
@@ -373,99 +373,112 @@ impl FP24 {
z3.times_i();
self.a.copy(&z0);
self.a.add(&z3);
- self.stype=DENSE;
+ self.stype = DENSE;
self.norm();
}
-/* FP24 full multiplication w=w*y */
-/* Supports sparse multiplicands */
-/* Usually w is denser than y */
+ /* FP24 full multiplication w=w*y */
+ /* Supports sparse multiplicands */
+ /* Usually w is denser than y */
pub fn ssmul(&mut self, y: &FP24) {
- if self.stype==ONE {
+ if self.stype == ONE {
self.copy(&y);
return;
}
- if y.stype==ONE {
+ if y.stype == ONE {
return;
}
- if y.stype>=SPARSE {
- let mut z0=FP8::new_copy(&self.a);
- let mut z1=FP8::new_int(0);
- let mut z2=FP8::new_int(0);
- let mut z3=FP8::new_int(0);
+ if y.stype >= SPARSE {
+ let mut z0 = FP8::new_copy(&self.a);
+ let mut z1 = FP8::new_int(0);
+ let mut z2 = FP8::new_int(0);
+ let mut z3 = FP8::new_int(0);
z0.mul(&y.a);
- if ecp::SEXTIC_TWIST==SexticTwist::M_TYPE {
- if y.stype==SPARSE || self.stype==SPARSE {
-
- let mut ga=FP4::new_int(0);
- let mut gb=FP4::new_int(0);
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
+ if y.stype == SPARSE || self.stype == SPARSE {
+ let mut ga = FP4::new_int(0);
+ let mut gb = FP4::new_int(0);
gb.copy(&self.b.getb());
gb.mul(&y.b.getb());
ga.zero();
- if y.stype!=SPARSE {
+ if y.stype != SPARSE {
ga.copy(&self.b.getb());
ga.mul(&y.b.geta());
}
- if self.stype!=SPARSE {
+ if self.stype != SPARSE {
ga.copy(&self.b.geta());
ga.mul(&y.b.getb());
}
- z2.set_fp4s(&ga,&gb);
+ z2.set_fp4s(&ga, &gb);
z2.times_i();
} else {
z2.copy(&self.b);
z2.mul(&y.b);
}
} else {
- z2.copy(&self.b);
- z2.mul(&y.b);
+ z2.copy(&self.b);
+ z2.mul(&y.b);
}
- let mut t0=FP8::new_copy(&self.a);
- let mut t1=FP8::new_copy(&y.a);
- t0.add(&self.b); t0.norm();
- t1.add(&y.b); t1.norm();
-
- z1.copy(&t0); z1.mul(&t1);
- t0.copy(&self.b); t0.add(&self.c); t0.norm();
- t1.copy(&y.b); t1.add(&y.c); t1.norm();
-
- z3.copy(&t0); z3.mul(&t1);
-
- t0.copy(&z0); t0.neg();
- t1.copy(&z2); t1.neg();
+ let mut t0 = FP8::new_copy(&self.a);
+ let mut t1 = FP8::new_copy(&y.a);
+ t0.add(&self.b);
+ t0.norm();
+ t1.add(&y.b);
+ t1.norm();
+
+ z1.copy(&t0);
+ z1.mul(&t1);
+ t0.copy(&self.b);
+ t0.add(&self.c);
+ t0.norm();
+ t1.copy(&y.b);
+ t1.add(&y.c);
+ t1.norm();
+
+ z3.copy(&t0);
+ z3.mul(&t1);
+
+ t0.copy(&z0);
+ t0.neg();
+ t1.copy(&z2);
+ t1.neg();
z1.add(&t0);
- self.b.copy(&z1); self.b.add(&t1);
+ self.b.copy(&z1);
+ self.b.add(&t1);
z3.add(&t1);
z2.add(&t0);
- t0.copy(&self.a); t0.add(&self.c); t0.norm();
- t1.copy(&y.a); t1.add(&y.c); t1.norm();
+ t0.copy(&self.a);
+ t0.add(&self.c);
+ t0.norm();
+ t1.copy(&y.a);
+ t1.add(&y.c);
+ t1.norm();
t0.mul(&t1);
z2.add(&t0);
- if ecp::SEXTIC_TWIST==SexticTwist::D_TYPE {
- if y.stype==SPARSE || self.stype==SPARSE {
-
- let mut ga=FP4::new_int(0);
- let mut gb=FP4::new_int(0);
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
+ if y.stype == SPARSE || self.stype == SPARSE {
+ let mut ga = FP4::new_int(0);
+ let mut gb = FP4::new_int(0);
ga.copy(&self.c.geta());
ga.mul(&y.c.geta());
gb.zero();
- if y.stype!=SPARSE {
+ if y.stype != SPARSE {
gb.copy(&self.c.geta());
gb.mul(&y.c.getb());
}
- if self.stype!=SPARSE {
+ if self.stype != SPARSE {
gb.copy(&self.c.getb());
gb.mul(&y.c.geta());
}
- t0.set_fp4s(&ga,&gb);
+ t0.set_fp4s(&ga, &gb);
} else {
t0.copy(&self.c);
t0.mul(&y.c);
@@ -474,26 +487,30 @@ impl FP24 {
t0.copy(&self.c);
t0.mul(&y.c);
}
- t1.copy(&t0); t1.neg();
+ t1.copy(&t0);
+ t1.neg();
- self.c.copy(&z2); self.c.add(&t1);
+ self.c.copy(&z2);
+ self.c.add(&t1);
z3.add(&t1);
t0.times_i();
self.b.add(&t0);
z3.norm();
z3.times_i();
- self.a.copy(&z0); self.a.add(&z3);
+ self.a.copy(&z0);
+ self.a.add(&z3);
} else {
- if self.stype==SPARSER {
+ if self.stype == SPARSER {
self.smul(&y);
return;
}
- if ecp::SEXTIC_TWIST==SexticTwist::D_TYPE { // dense by sparser - 13m
- let mut z0=FP8::new_copy(&self.a);
- let mut z2=FP8::new_copy(&self.b);
- let mut z3=FP8::new_copy(&self.b);
- let mut t0=FP8::new_int(0);
- let mut t1=FP8::new_copy(&y.a);
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
+ // dense by sparser - 13m
+ let mut z0 = FP8::new_copy(&self.a);
+ let mut z2 = FP8::new_copy(&self.b);
+ let mut z3 = FP8::new_copy(&self.b);
+ let mut t0 = FP8::new_int(0);
+ let mut t1 = FP8::new_copy(&y.a);
z0.mul(&y.a);
z2.pmul(&y.b.geta());
@@ -507,8 +524,10 @@ impl FP24 {
z3.norm();
z3.pmul(&y.b.geta());
- t0.copy(&z0); t0.neg();
- t1.copy(&z2); t1.neg();
+ t0.copy(&z0);
+ t0.neg();
+ t1.copy(&z2);
+ t1.neg();
self.b.add(&t0);
@@ -516,16 +535,19 @@ impl FP24 {
z3.add(&t1);
z2.add(&t0);
- t0.copy(&self.a); t0.add(&self.c); t0.norm();
+ t0.copy(&self.a);
+ t0.add(&self.c);
+ t0.norm();
z3.norm();
t0.mul(&y.a);
- self.c.copy(&z2); self.c.add(&t0);
+ self.c.copy(&z2);
+ self.c.add(&t0);
z3.times_i();
- self.a.copy(&z0); self.a.add(&z3);
+ self.a.copy(&z0);
+ self.a.add(&z3);
}
- if ecp::SEXTIC_TWIST==SexticTwist::M_TYPE {
-
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
let mut z0 = FP8::new_copy(&self.a);
let mut z1 = FP8::new();
let mut z2 = FP8::new();
@@ -534,23 +556,31 @@ impl FP24 {
let mut t1 = FP8::new();
z0.mul(&y.a);
- t0.add(&self.b); t0.norm();
+ t0.add(&self.b);
+ t0.norm();
- z1.copy(&t0); z1.mul(&y.a);
- t0.copy(&self.b); t0.add(&self.c);
+ z1.copy(&t0);
+ z1.mul(&y.a);
+ t0.copy(&self.b);
+ t0.add(&self.c);
t0.norm();
z3.copy(&t0);
z3.pmul(&y.c.getb());
z3.times_i();
- t0.copy(&z0); t0.neg();
+ t0.copy(&z0);
+ t0.neg();
z1.add(&t0);
self.b.copy(&z1);
z2.copy(&t0);
- t0.copy(&self.a); t0.add(&self.c); t0.norm();
- t1.copy(&y.a); t1.add(&y.c); t1.norm();
+ t0.copy(&self.a);
+ t0.add(&self.c);
+ t0.norm();
+ t1.copy(&y.a);
+ t1.add(&y.c);
+ t1.norm();
t0.mul(&t1);
z2.add(&t0);
@@ -558,56 +588,68 @@ impl FP24 {
t0.pmul(&y.c.getb());
t0.times_i();
- t1.copy(&t0); t1.neg();
+ t1.copy(&t0);
+ t1.neg();
- self.c.copy(&z2); self.c.add(&t1);
+ self.c.copy(&z2);
+ self.c.add(&t1);
z3.add(&t1);
t0.times_i();
self.b.add(&t0);
z3.norm();
z3.times_i();
- self.a.copy(&z0); self.a.add(&z3);
- }
+ self.a.copy(&z0);
+ self.a.add(&z3);
+ }
}
- self.stype=DENSE;
+ self.stype = DENSE;
self.norm();
}
-
/* Special case of multiplication arises from special form of ATE pairing line function */
pub fn smul(&mut self, y: &FP24) {
- if ecp::SEXTIC_TWIST==SexticTwist::D_TYPE {
- let mut w1=FP4::new_copy(&self.a.geta());
- let mut w2=FP4::new_copy(&self.a.getb());
- let mut w3=FP4::new_copy(&self.b.geta());
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
+ let mut w1 = FP4::new_copy(&self.a.geta());
+ let mut w2 = FP4::new_copy(&self.a.getb());
+ let mut w3 = FP4::new_copy(&self.b.geta());
w1.mul(&y.a.geta());
w2.mul(&y.a.getb());
w3.mul(&y.b.geta());
- let mut ta=FP4::new_copy(&self.a.geta());
- let mut tb=FP4::new_copy(&y.a.geta());
- ta.add(&self.a.getb()); ta.norm();
- tb.add(&y.a.getb()); tb.norm();
- let mut tc=FP4::new_copy(&ta);
+ let mut ta = FP4::new_copy(&self.a.geta());
+ let mut tb = FP4::new_copy(&y.a.geta());
+ ta.add(&self.a.getb());
+ ta.norm();
+ tb.add(&y.a.getb());
+ tb.norm();
+ let mut tc = FP4::new_copy(&ta);
tc.mul(&tb);
- let mut t=FP4::new_copy(&w1);
+ let mut t = FP4::new_copy(&w1);
t.add(&w2);
t.neg();
tc.add(&t);
- ta.copy(&self.a.geta()); ta.add(&self.b.geta()); ta.norm();
- tb.copy(&y.a.geta()); tb.add(&y.b.geta()); tb.norm();
- let mut td=FP4::new_copy(&ta);
+ ta.copy(&self.a.geta());
+ ta.add(&self.b.geta());
+ ta.norm();
+ tb.copy(&y.a.geta());
+ tb.add(&y.b.geta());
+ tb.norm();
+ let mut td = FP4::new_copy(&ta);
td.mul(&tb);
t.copy(&w1);
t.add(&w3);
t.neg();
td.add(&t);
- ta.copy(&self.a.getb()); ta.add(&self.b.geta()); ta.norm();
- tb.copy(&y.a.getb()); tb.add(&y.b.geta()); tb.norm();
- let mut te=FP4::new_copy(&ta);
+ ta.copy(&self.a.getb());
+ ta.add(&self.b.geta());
+ ta.norm();
+ tb.copy(&y.a.getb());
+ tb.add(&y.b.geta());
+ tb.norm();
+ let mut te = FP4::new_copy(&ta);
te.mul(&tb);
t.copy(&w2);
t.add(&w3);
@@ -617,44 +659,54 @@ impl FP24 {
w2.times_i();
w1.add(&w2);
- self.a.set_fp4s(&w1,&tc);
- self.b.set_fp4s(&td,&te);
- self.c.set_fp4(&w3);
+ self.a.set_fp4s(&w1, &tc);
+ self.b.set_fp4s(&td, &te);
+ self.c.set_fp4(&w3);
self.a.norm();
self.b.norm();
} else {
- let mut w1=FP4::new_copy(&self.a.geta());
- let mut w2=FP4::new_copy(&self.a.getb());
- let mut w3=FP4::new_copy(&self.c.getb());
+ let mut w1 = FP4::new_copy(&self.a.geta());
+ let mut w2 = FP4::new_copy(&self.a.getb());
+ let mut w3 = FP4::new_copy(&self.c.getb());
w1.mul(&y.a.geta());
w2.mul(&y.a.getb());
w3.mul(&y.c.getb());
- let mut ta=FP4::new_copy(&self.a.geta());
- let mut tb=FP4::new_copy(&y.a.geta());
- ta.add(&self.a.getb()); ta.norm();
- tb.add(&y.a.getb()); tb.norm();
- let mut tc=FP4::new_copy(&ta);
+ let mut ta = FP4::new_copy(&self.a.geta());
+ let mut tb = FP4::new_copy(&y.a.geta());
+ ta.add(&self.a.getb());
+ ta.norm();
+ tb.add(&y.a.getb());
+ tb.norm();
+ let mut tc = FP4::new_copy(&ta);
tc.mul(&tb);
- let mut t=FP4::new_copy(&w1);
+ let mut t = FP4::new_copy(&w1);
t.add(&w2);
t.neg();
tc.add(&t);
- ta.copy(&self.a.geta()); ta.add(&self.c.getb()); ta.norm();
- tb.copy(&y.a.geta()); tb.add(&y.c.getb()); tb.norm();
- let mut td=FP4::new_copy(&ta);
+ ta.copy(&self.a.geta());
+ ta.add(&self.c.getb());
+ ta.norm();
+ tb.copy(&y.a.geta());
+ tb.add(&y.c.getb());
+ tb.norm();
+ let mut td = FP4::new_copy(&ta);
td.mul(&tb);
t.copy(&w1);
t.add(&w3);
t.neg();
td.add(&t);
- ta.copy(&self.a.getb()); ta.add(&self.c.getb()); ta.norm();
- tb.copy(&y.a.getb()); tb.add(&y.c.getb()); tb.norm();
- let mut te=FP4::new_copy(&ta);
+ ta.copy(&self.a.getb());
+ ta.add(&self.c.getb());
+ ta.norm();
+ tb.copy(&y.a.getb());
+ tb.add(&y.c.getb());
+ tb.norm();
+ let mut te = FP4::new_copy(&ta);
te.mul(&tb);
t.copy(&w2);
t.add(&w3);
@@ -663,20 +715,20 @@ impl FP24 {
w2.times_i();
w1.add(&w2);
- self.a.set_fp4s(&w1,&tc);
+ self.a.set_fp4s(&w1, &tc);
w3.times_i();
w3.norm();
- self.b.set_fp4h(&w3);
+ self.b.set_fp4h(&w3);
te.norm();
te.times_i();
- self.c.set_fp4s(&te,&td);
+ self.c.set_fp4s(&te, &td);
self.a.norm();
self.c.norm();
- }
- self.stype=SPARSE;
+ }
+ self.stype = SPARSE;
}
/* self=1/self */
@@ -724,7 +776,7 @@ impl FP24 {
self.b.mul(&f3);
self.c.copy(&f2);
self.c.mul(&f3);
- self.stype=DENSE;
+ self.stype = DENSE;
}
/* self=self^p using Frobenius */
@@ -749,7 +801,7 @@ impl FP24 {
self.c.times_i2();
self.c.times_i2();
}
- self.stype=DENSE;
+ self.stype = DENSE;
}
/* trace function */
diff --git a/src/fp4.rs b/src/fp4.rs
index d2d890b..3fda179 100644
--- a/src/fp4.rs
+++ b/src/fp4.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
+use super::big::Big;
use super::fp::FP;
use super::fp2::FP2;
-use super::big::Big;
use std::str::SplitWhitespace;
#[derive(Copy, Clone)]
@@ -29,9 +29,9 @@ pub struct FP4 {
}
impl PartialEq for FP4 {
- fn eq(&self, other: &FP4) -> bool {
- self.equals(other)
- }
+ fn eq(&self, other: &FP4) -> bool {
+ self.equals(other)
+ }
}
impl FP4 {
@@ -70,19 +70,19 @@ impl FP4 {
return f;
}
- pub fn set_fp2s(&mut self,c: &FP2, d: &FP2) {
+ pub fn set_fp2s(&mut self, c: &FP2, d: &FP2) {
self.a.copy(&c);
- self.b.copy(&d);
+ self.b.copy(&d);
}
- pub fn set_fp2(&mut self,c: &FP2) {
+ pub fn set_fp2(&mut self, c: &FP2) {
self.a.copy(&c);
- self.b.zero();
+ self.b.zero();
}
- pub fn set_fp2h(&mut self,c: &FP2) {
+ pub fn set_fp2h(&mut self, c: &FP2) {
self.b.copy(&c);
- self.a.zero();
+ self.a.zero();
}
/* reduce components mod Modulus */
@@ -125,14 +125,14 @@ impl FP4 {
pub fn geta(&self) -> FP2 {
return self.a;
-// let f = FP2::new_copy(&self.a);
-// return f;
+ // let f = FP2::new_copy(&self.a);
+ // return f;
}
/* extract imaginary part b */
pub fn getb(&self) -> FP2 {
return self.b;
-// let f = FP2::new_copy(&self.b);
-// return f;
+ // let f = FP2::new_copy(&self.b);
+ // return f;
}
/* test self=x */
@@ -313,7 +313,7 @@ impl FP4 {
pub fn from_hex_iter(iter: &mut SplitWhitespace) -> FP4 {
FP4 {
a: FP2::from_hex_iter(iter),
- b: FP2::from_hex_iter(iter)
+ b: FP2::from_hex_iter(iter),
}
}
@@ -370,7 +370,7 @@ impl FP4 {
let bt = z.parity();
z.fshr(1);
if bt == 1 {
- r.mul(&mut w)
+ r.mul(&w)
};
if z.iszilch() {
break;
@@ -607,7 +607,7 @@ impl FP4 {
for _ in 0..f2 {
r.xtr_d()
}
- r = r.xtr_pow(&mut d);
+ r = r.xtr_pow(&d);
return r;
}
diff --git a/src/fp48.rs b/src/fp48.rs
index ff64d4c..8ab6063 100644
--- a/src/fp48.rs
+++ b/src/fp48.rs
@@ -18,21 +18,21 @@ under the License.
*/
use super::big;
+use super::big::Big;
use super::ecp;
+use super::fp16::FP16;
use super::fp2::FP2;
use super::fp4::FP4;
use super::fp8::FP8;
-use super::fp16::FP16;
-use super::big::Big;
use super::rom;
use types::SexticTwist;
//use std::str::SplitWhitespace;
-pub const ZERO: usize=0;
-pub const ONE: usize=1;
-pub const SPARSER: usize=2;
-pub const SPARSE: usize=3;
-pub const DENSE: usize=4;
+pub const ZERO: usize = 0;
+pub const ONE: usize = 1;
+pub const SPARSER: usize = 2;
+pub const SPARSE: usize = 3;
+pub const DENSE: usize = 4;
#[derive(Copy, Clone)]
pub struct FP48 {
@@ -48,12 +48,12 @@ impl FP48 {
a: FP16::new(),
b: FP16::new(),
c: FP16::new(),
- stype: ZERO,
+ stype: ZERO,
}
}
- pub fn settype(&mut self,t: usize) {
- self.stype = t;
+ pub fn settype(&mut self, t: usize) {
+ self.stype = t;
}
pub fn gettype(&self) -> usize {
@@ -65,11 +65,11 @@ impl FP48 {
f.a.copy(&FP16::new_int(a));
f.b.zero();
f.c.zero();
- if a == 1 {
- f.stype=ONE;
- } else {
- f.stype=SPARSER;
- }
+ if a == 1 {
+ f.stype = ONE;
+ } else {
+ f.stype = SPARSER;
+ }
return f;
}
@@ -78,7 +78,7 @@ impl FP48 {
f.a.copy(&x.a);
f.b.copy(&x.b);
f.c.copy(&x.c);
- f.stype=x.stype;
+ f.stype = x.stype;
return f;
}
@@ -87,7 +87,7 @@ impl FP48 {
g.a.copy(d);
g.b.copy(e);
g.c.copy(f);
- g.stype=DENSE;
+ g.stype = DENSE;
return g;
}
@@ -96,7 +96,7 @@ impl FP48 {
g.a.copy(d);
g.b.zero();
g.c.zero();
- g.stype=SPARSER;
+ g.stype = SPARSER;
return g;
}
@@ -124,9 +124,9 @@ impl FP48 {
self.a.cmove(&g.a, d);
self.b.cmove(&g.b, d);
self.c.cmove(&g.c, d);
- let mut u=d as usize;
- u=!(u-1);
- self.stype^=(self.stype^g.stype)&u;
+ let mut u = d as usize;
+ u = !(u - 1);
+ self.stype ^= (self.stype ^ g.stype) & u;
}
/* return 1 if b==c, no branching */
@@ -170,20 +170,20 @@ impl FP48 {
pub fn geta(&mut self) -> FP16 {
return self.a;
-// let f = FP16::new_copy(&self.a);
-// return f;
+ // let f = FP16::new_copy(&self.a);
+ // return f;
}
pub fn getb(&mut self) -> FP16 {
return self.b;
-// let f = FP16::new_copy(&self.b);
-// return f;
+ // let f = FP16::new_copy(&self.b);
+ // return f;
}
pub fn getc(&mut self) -> FP16 {
return self.c;
-// let f = FP16::new_copy(&self.c);
-// return f;
+ // let f = FP16::new_copy(&self.c);
+ // return f;
}
/* copy self=x */
@@ -191,7 +191,7 @@ impl FP48 {
self.a.copy(&x.a);
self.b.copy(&x.b);
self.c.copy(&x.c);
- self.stype=x.stype;
+ self.stype = x.stype;
}
/* set self=1 */
@@ -199,7 +199,7 @@ impl FP48 {
self.a.one();
self.b.zero();
self.c.zero();
- self.stype=ONE;
+ self.stype = ONE;
}
/* set self=0 */
@@ -207,7 +207,7 @@ impl FP48 {
self.a.zero();
self.b.zero();
self.c.zero();
- self.stype=ZERO;
+ self.stype = ZERO;
}
/* this=conj(this) */
@@ -255,13 +255,13 @@ impl FP48 {
self.c.dbl();
self.b.add(&b);
self.c.add(&c);
- self.stype=DENSE;
+ self.stype = DENSE;
self.reduce();
}
/* Chung-Hasan SQR2 method from http://cacr.uwaterloo.ca/techreports/2006/cacr2006-24.pdf */
pub fn sqr(&mut self) {
- if self.stype==ONE {
+ if self.stype == ONE {
return;
}
let mut a = FP16::new_copy(&self.a);
@@ -298,10 +298,10 @@ impl FP48 {
self.b.copy(&c);
self.b.add(&d);
self.c.add(&a);
- if self.stype==SPARSER {
- self.stype=SPARSE;
+ if self.stype == SPARSER {
+ self.stype = SPARSE;
} else {
- self.stype=DENSE;
+ self.stype = DENSE;
}
self.norm();
}
@@ -373,99 +373,112 @@ impl FP48 {
z3.times_i();
self.a.copy(&z0);
self.a.add(&z3);
- self.stype=DENSE;
+ self.stype = DENSE;
self.norm();
}
-/* FP48 full multiplication w=w*y */
-/* Supports sparse multiplicands */
-/* Usually w is denser than y */
+ /* FP48 full multiplication w=w*y */
+ /* Supports sparse multiplicands */
+ /* Usually w is denser than y */
pub fn ssmul(&mut self, y: &FP48) {
- if self.stype==ONE {
+ if self.stype == ONE {
self.copy(&y);
return;
}
- if y.stype==ONE {
+ if y.stype == ONE {
return;
}
- if y.stype>=SPARSE {
- let mut z0=FP16::new_copy(&self.a);
- let mut z1=FP16::new_int(0);
- let mut z2=FP16::new_int(0);
- let mut z3=FP16::new_int(0);
+ if y.stype >= SPARSE {
+ let mut z0 = FP16::new_copy(&self.a);
+ let mut z1 = FP16::new_int(0);
+ let mut z2 = FP16::new_int(0);
+ let mut z3 = FP16::new_int(0);
z0.mul(&y.a);
- if ecp::SEXTIC_TWIST==SexticTwist::M_TYPE {
- if y.stype==SPARSE || self.stype==SPARSE {
-
- let mut ga=FP8::new_int(0);
- let mut gb=FP8::new_int(0);
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
+ if y.stype == SPARSE || self.stype == SPARSE {
+ let mut ga = FP8::new_int(0);
+ let mut gb = FP8::new_int(0);
gb.copy(&self.b.getb());
gb.mul(&y.b.getb());
ga.zero();
- if y.stype!=SPARSE {
+ if y.stype != SPARSE {
ga.copy(&self.b.getb());
ga.mul(&y.b.geta());
}
- if self.stype!=SPARSE {
+ if self.stype != SPARSE {
ga.copy(&self.b.geta());
ga.mul(&y.b.getb());
}
- z2.set_fp8s(&ga,&gb);
+ z2.set_fp8s(&ga, &gb);
z2.times_i();
} else {
z2.copy(&self.b);
z2.mul(&y.b);
}
} else {
- z2.copy(&self.b);
- z2.mul(&y.b);
+ z2.copy(&self.b);
+ z2.mul(&y.b);
}
- let mut t0=FP16::new_copy(&self.a);
- let mut t1=FP16::new_copy(&y.a);
- t0.add(&self.b); t0.norm();
- t1.add(&y.b); t1.norm();
-
- z1.copy(&t0); z1.mul(&t1);
- t0.copy(&self.b); t0.add(&self.c); t0.norm();
- t1.copy(&y.b); t1.add(&y.c); t1.norm();
-
- z3.copy(&t0); z3.mul(&t1);
-
- t0.copy(&z0); t0.neg();
- t1.copy(&z2); t1.neg();
+ let mut t0 = FP16::new_copy(&self.a);
+ let mut t1 = FP16::new_copy(&y.a);
+ t0.add(&self.b);
+ t0.norm();
+ t1.add(&y.b);
+ t1.norm();
+
+ z1.copy(&t0);
+ z1.mul(&t1);
+ t0.copy(&self.b);
+ t0.add(&self.c);
+ t0.norm();
+ t1.copy(&y.b);
+ t1.add(&y.c);
+ t1.norm();
+
+ z3.copy(&t0);
+ z3.mul(&t1);
+
+ t0.copy(&z0);
+ t0.neg();
+ t1.copy(&z2);
+ t1.neg();
z1.add(&t0);
- self.b.copy(&z1); self.b.add(&t1);
+ self.b.copy(&z1);
+ self.b.add(&t1);
z3.add(&t1);
z2.add(&t0);
- t0.copy(&self.a); t0.add(&self.c); t0.norm();
- t1.copy(&y.a); t1.add(&y.c); t1.norm();
+ t0.copy(&self.a);
+ t0.add(&self.c);
+ t0.norm();
+ t1.copy(&y.a);
+ t1.add(&y.c);
+ t1.norm();
t0.mul(&t1);
z2.add(&t0);
- if ecp::SEXTIC_TWIST==SexticTwist::D_TYPE {
- if y.stype==SPARSE || self.stype==SPARSE {
-
- let mut ga=FP8::new_int(0);
- let mut gb=FP8::new_int(0);
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
+ if y.stype == SPARSE || self.stype == SPARSE {
+ let mut ga = FP8::new_int(0);
+ let mut gb = FP8::new_int(0);
ga.copy(&self.c.geta());
ga.mul(&y.c.geta());
gb.zero();
- if y.stype!=SPARSE {
+ if y.stype != SPARSE {
gb.copy(&self.c.geta());
gb.mul(&y.c.getb());
}
- if self.stype!=SPARSE {
+ if self.stype != SPARSE {
gb.copy(&self.c.getb());
gb.mul(&y.c.geta());
}
- t0.set_fp8s(&ga,&gb);
+ t0.set_fp8s(&ga, &gb);
} else {
t0.copy(&self.c);
t0.mul(&y.c);
@@ -474,26 +487,30 @@ impl FP48 {
t0.copy(&self.c);
t0.mul(&y.c);
}
- t1.copy(&t0); t1.neg();
+ t1.copy(&t0);
+ t1.neg();
- self.c.copy(&z2); self.c.add(&t1);
+ self.c.copy(&z2);
+ self.c.add(&t1);
z3.add(&t1);
t0.times_i();
self.b.add(&t0);
z3.norm();
z3.times_i();
- self.a.copy(&z0); self.a.add(&z3);
+ self.a.copy(&z0);
+ self.a.add(&z3);
} else {
- if self.stype==SPARSER {
+ if self.stype == SPARSER {
self.smul(&y);
return;
}
- if ecp::SEXTIC_TWIST==SexticTwist::D_TYPE { // dense by sparser - 13m
- let mut z0=FP16::new_copy(&self.a);
- let mut z2=FP16::new_copy(&self.b);
- let mut z3=FP16::new_copy(&self.b);
- let mut t0=FP16::new_int(0);
- let mut t1=FP16::new_copy(&y.a);
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
+ // dense by sparser - 13m
+ let mut z0 = FP16::new_copy(&self.a);
+ let mut z2 = FP16::new_copy(&self.b);
+ let mut z3 = FP16::new_copy(&self.b);
+ let mut t0 = FP16::new_int(0);
+ let mut t1 = FP16::new_copy(&y.a);
z0.mul(&y.a);
z2.pmul(&y.b.geta());
@@ -507,8 +524,10 @@ impl FP48 {
z3.norm();
z3.pmul(&y.b.geta());
- t0.copy(&z0); t0.neg();
- t1.copy(&z2); t1.neg();
+ t0.copy(&z0);
+ t0.neg();
+ t1.copy(&z2);
+ t1.neg();
self.b.add(&t0);
@@ -516,16 +535,19 @@ impl FP48 {
z3.add(&t1);
z2.add(&t0);
- t0.copy(&self.a); t0.add(&self.c); t0.norm();
+ t0.copy(&self.a);
+ t0.add(&self.c);
+ t0.norm();
z3.norm();
t0.mul(&y.a);
- self.c.copy(&z2); self.c.add(&t0);
+ self.c.copy(&z2);
+ self.c.add(&t0);
z3.times_i();
- self.a.copy(&z0); self.a.add(&z3);
+ self.a.copy(&z0);
+ self.a.add(&z3);
}
- if ecp::SEXTIC_TWIST==SexticTwist::M_TYPE {
-
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
let mut z0 = FP16::new_copy(&self.a);
let mut z1 = FP16::new();
let mut z2 = FP16::new();
@@ -534,23 +556,31 @@ impl FP48 {
let mut t1 = FP16::new();
z0.mul(&y.a);
- t0.add(&self.b); t0.norm();
+ t0.add(&self.b);
+ t0.norm();
- z1.copy(&t0); z1.mul(&y.a);
- t0.copy(&self.b); t0.add(&self.c);
+ z1.copy(&t0);
+ z1.mul(&y.a);
+ t0.copy(&self.b);
+ t0.add(&self.c);
t0.norm();
z3.copy(&t0);
z3.pmul(&y.c.getb());
z3.times_i();
- t0.copy(&z0); t0.neg();
+ t0.copy(&z0);
+ t0.neg();
z1.add(&t0);
self.b.copy(&z1);
z2.copy(&t0);
- t0.copy(&self.a); t0.add(&self.c); t0.norm();
- t1.copy(&y.a); t1.add(&y.c); t1.norm();
+ t0.copy(&self.a);
+ t0.add(&self.c);
+ t0.norm();
+ t1.copy(&y.a);
+ t1.add(&y.c);
+ t1.norm();
t0.mul(&t1);
z2.add(&t0);
@@ -558,56 +588,68 @@ impl FP48 {
t0.pmul(&y.c.getb());
t0.times_i();
- t1.copy(&t0); t1.neg();
+ t1.copy(&t0);
+ t1.neg();
- self.c.copy(&z2); self.c.add(&t1);
+ self.c.copy(&z2);
+ self.c.add(&t1);
z3.add(&t1);
t0.times_i();
self.b.add(&t0);
z3.norm();
z3.times_i();
- self.a.copy(&z0); self.a.add(&z3);
- }
+ self.a.copy(&z0);
+ self.a.add(&z3);
+ }
}
- self.stype=DENSE;
+ self.stype = DENSE;
self.norm();
}
-
/* Special case of multiplication arises from special form of ATE pairing line function */
pub fn smul(&mut self, y: &FP48) {
- if ecp::SEXTIC_TWIST==SexticTwist::D_TYPE {
- let mut w1=FP8::new_copy(&self.a.geta());
- let mut w2=FP8::new_copy(&self.a.getb());
- let mut w3=FP8::new_copy(&self.b.geta());
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
+ let mut w1 = FP8::new_copy(&self.a.geta());
+ let mut w2 = FP8::new_copy(&self.a.getb());
+ let mut w3 = FP8::new_copy(&self.b.geta());
w1.mul(&y.a.geta());
w2.mul(&y.a.getb());
w3.mul(&y.b.geta());
- let mut ta=FP8::new_copy(&self.a.geta());
- let mut tb=FP8::new_copy(&y.a.geta());
- ta.add(&self.a.getb()); ta.norm();
- tb.add(&y.a.getb()); tb.norm();
- let mut tc=FP8::new_copy(&ta);
+ let mut ta = FP8::new_copy(&self.a.geta());
+ let mut tb = FP8::new_copy(&y.a.geta());
+ ta.add(&self.a.getb());
+ ta.norm();
+ tb.add(&y.a.getb());
+ tb.norm();
+ let mut tc = FP8::new_copy(&ta);
tc.mul(&tb);
- let mut t=FP8::new_copy(&w1);
+ let mut t = FP8::new_copy(&w1);
t.add(&w2);
t.neg();
tc.add(&t);
- ta.copy(&self.a.geta()); ta.add(&self.b.geta()); ta.norm();
- tb.copy(&y.a.geta()); tb.add(&y.b.geta()); tb.norm();
- let mut td=FP8::new_copy(&ta);
+ ta.copy(&self.a.geta());
+ ta.add(&self.b.geta());
+ ta.norm();
+ tb.copy(&y.a.geta());
+ tb.add(&y.b.geta());
+ tb.norm();
+ let mut td = FP8::new_copy(&ta);
td.mul(&tb);
t.copy(&w1);
t.add(&w3);
t.neg();
td.add(&t);
- ta.copy(&self.a.getb()); ta.add(&self.b.geta()); ta.norm();
- tb.copy(&y.a.getb()); tb.add(&y.b.geta()); tb.norm();
- let mut te=FP8::new_copy(&ta);
+ ta.copy(&self.a.getb());
+ ta.add(&self.b.geta());
+ ta.norm();
+ tb.copy(&y.a.getb());
+ tb.add(&y.b.geta());
+ tb.norm();
+ let mut te = FP8::new_copy(&ta);
te.mul(&tb);
t.copy(&w2);
t.add(&w3);
@@ -617,44 +659,54 @@ impl FP48 {
w2.times_i();
w1.add(&w2);
- self.a.set_fp8s(&w1,&tc);
- self.b.set_fp8s(&td,&te);
- self.c.set_fp8(&w3);
+ self.a.set_fp8s(&w1, &tc);
+ self.b.set_fp8s(&td, &te);
+ self.c.set_fp8(&w3);
self.a.norm();
self.b.norm();
} else {
- let mut w1=FP8::new_copy(&self.a.geta());
- let mut w2=FP8::new_copy(&self.a.getb());
- let mut w3=FP8::new_copy(&self.c.getb());
+ let mut w1 = FP8::new_copy(&self.a.geta());
+ let mut w2 = FP8::new_copy(&self.a.getb());
+ let mut w3 = FP8::new_copy(&self.c.getb());
w1.mul(&y.a.geta());
w2.mul(&y.a.getb());
w3.mul(&y.c.getb());
- let mut ta=FP8::new_copy(&self.a.geta());
- let mut tb=FP8::new_copy(&y.a.geta());
- ta.add(&self.a.getb()); ta.norm();
- tb.add(&y.a.getb()); tb.norm();
- let mut tc=FP8::new_copy(&ta);
+ let mut ta = FP8::new_copy(&self.a.geta());
+ let mut tb = FP8::new_copy(&y.a.geta());
+ ta.add(&self.a.getb());
+ ta.norm();
+ tb.add(&y.a.getb());
+ tb.norm();
+ let mut tc = FP8::new_copy(&ta);
tc.mul(&tb);
- let mut t=FP8::new_copy(&w1);
+ let mut t = FP8::new_copy(&w1);
t.add(&w2);
t.neg();
tc.add(&t);
- ta.copy(&self.a.geta()); ta.add(&self.c.getb()); ta.norm();
- tb.copy(&y.a.geta()); tb.add(&y.c.getb()); tb.norm();
- let mut td=FP8::new_copy(&ta);
+ ta.copy(&self.a.geta());
+ ta.add(&self.c.getb());
+ ta.norm();
+ tb.copy(&y.a.geta());
+ tb.add(&y.c.getb());
+ tb.norm();
+ let mut td = FP8::new_copy(&ta);
td.mul(&tb);
t.copy(&w1);
t.add(&w3);
t.neg();
td.add(&t);
- ta.copy(&self.a.getb()); ta.add(&self.c.getb()); ta.norm();
- tb.copy(&y.a.getb()); tb.add(&y.c.getb()); tb.norm();
- let mut te=FP8::new_copy(&ta);
+ ta.copy(&self.a.getb());
+ ta.add(&self.c.getb());
+ ta.norm();
+ tb.copy(&y.a.getb());
+ tb.add(&y.c.getb());
+ tb.norm();
+ let mut te = FP8::new_copy(&ta);
te.mul(&tb);
t.copy(&w2);
t.add(&w3);
@@ -663,20 +715,20 @@ impl FP48 {
w2.times_i();
w1.add(&w2);
- self.a.set_fp8s(&w1,&tc);
+ self.a.set_fp8s(&w1, &tc);
w3.times_i();
w3.norm();
- self.b.set_fp8h(&w3);
+ self.b.set_fp8h(&w3);
te.norm();
te.times_i();
- self.c.set_fp8s(&te,&td);
+ self.c.set_fp8s(&te, &td);
self.a.norm();
self.c.norm();
- }
- self.stype=SPARSE;
+ }
+ self.stype = SPARSE;
}
/* self=1/self */
@@ -724,7 +776,7 @@ impl FP48 {
self.b.mul(&f3);
self.c.copy(&f2);
self.c.mul(&f3);
- self.stype=DENSE;
+ self.stype = DENSE;
}
/* self=self^p using Frobenius */
@@ -753,7 +805,7 @@ impl FP48 {
self.c.times_i4();
self.c.times_i4();
}
- self.stype=DENSE;
+ self.stype = DENSE;
}
/* trace function */
diff --git a/src/fp8.rs b/src/fp8.rs
index 1fcc336..38515a8 100644
--- a/src/fp8.rs
+++ b/src/fp8.rs
@@ -17,10 +17,10 @@ specific language governing permissions and limitations
under the License.
*/
+use super::big::Big;
use super::fp::FP;
use super::fp2::FP2;
use super::fp4::FP4;
-use super::big::Big;
//use std::str::SplitWhitespace;
#[derive(Copy, Clone)]
@@ -65,22 +65,21 @@ impl FP8 {
return f;
}
- pub fn set_fp4s(&mut self,c: &FP4, d: &FP4) {
+ pub fn set_fp4s(&mut self, c: &FP4, d: &FP4) {
self.a.copy(&c);
- self.b.copy(&d);
+ self.b.copy(&d);
}
- pub fn set_fp4(&mut self,c: &FP4) {
+ pub fn set_fp4(&mut self, c: &FP4) {
self.a.copy(&c);
- self.b.zero();
+ self.b.zero();
}
- pub fn set_fp4h(&mut self,c: &FP4) {
+ pub fn set_fp4h(&mut self, c: &FP4) {
self.b.copy(&c);
- self.a.zero();
+ self.a.zero();
}
-
/* reduce components mod Modulus */
pub fn reduce(&mut self) {
self.a.reduce();
@@ -121,14 +120,14 @@ impl FP8 {
pub fn geta(&self) -> FP4 {
return self.a;
-// let f = FP4::new_copy(&self.a);
-// return f;
+ // let f = FP4::new_copy(&self.a);
+ // return f;
}
/* extract imaginary part b */
pub fn getb(&self) -> FP4 {
return self.b;
-// let f = FP4::new_copy(&self.b);
-// return f;
+ // let f = FP4::new_copy(&self.b);
+ // return f;
}
/* test self=x */
@@ -368,7 +367,7 @@ impl FP8 {
let bt = z.parity();
z.fshr(1);
if bt == 1 {
- r.mul(&mut w)
+ r.mul(&w)
};
if z.iszilch() {
break;
diff --git a/src/hash256.rs b/src/hash256.rs
index e8d6260..5df85d9 100644
--- a/src/hash256.rs
+++ b/src/hash256.rs
@@ -17,14 +17,14 @@ specific language governing permissions and limitations
under the License.
*/
-const HASH256_H0: u32 = 0x6A09E667;
-const HASH256_H1: u32 = 0xBB67AE85;
-const HASH256_H2: u32 = 0x3C6EF372;
-const HASH256_H3: u32 = 0xA54FF53A;
-const HASH256_H4: u32 = 0x510E527F;
-const HASH256_H5: u32 = 0x9B05688C;
-const HASH256_H6: u32 = 0x1F83D9AB;
-const HASH256_H7: u32 = 0x5BE0CD19;
+const HASH256_H0: u32 = 0x6A09_E667;
+const HASH256_H1: u32 = 0xBB67_AE85;
+const HASH256_H2: u32 = 0x3C6E_F372;
+const HASH256_H3: u32 = 0xA54F_F53A;
+const HASH256_H4: u32 = 0x510E_527F;
+const HASH256_H5: u32 = 0x9B05_688C;
+const HASH256_H6: u32 = 0x1F83_D9AB;
+const HASH256_H7: u32 = 0x5BE0_CD19;
const HASH256_K: [u32; 64] = [
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
diff --git a/src/lib.rs b/src/lib.rs
index 108057b..c68a165 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,18 +1,18 @@
pub mod aes;
+#[cfg(target_pointer_width = "32")]
+#[path = "arch/arch32.rs"]
+pub mod arch;
+#[cfg(target_pointer_width = "64")]
+#[path = "arch/arch64.rs"]
+pub mod arch;
pub mod gcm;
pub mod hash256;
pub mod hash384;
pub mod hash512;
+pub mod nhs;
pub mod rand;
pub mod sha3;
-pub mod nhs;
pub mod types;
-#[cfg(target_pointer_width = "32")]
-#[path = "arch/arch32.rs"]
-pub mod arch;
-#[cfg(target_pointer_width = "64")]
-#[path = "arch/arch64.rs"]
-pub mod arch;
#[cfg(feature = "bls48")]
#[path = "./"]
@@ -25,18 +25,18 @@ pub mod bls48 {
pub mod rom;
pub mod big;
+ pub mod bls256;
pub mod dbig;
- pub mod fp;
pub mod ecp;
pub mod ecp8;
+ pub mod fp;
+ pub mod fp16;
pub mod fp2;
pub mod fp4;
- pub mod fp8;
- pub mod fp16;
pub mod fp48;
- pub mod pair256;
+ pub mod fp8;
pub mod mpin256;
- pub mod bls256;
+ pub mod pair256;
}
#[cfg(feature = "bls461")]
@@ -50,16 +50,16 @@ pub mod bls461 {
pub mod rom;
pub mod big;
+ pub mod bls;
pub mod dbig;
- pub mod fp;
pub mod ecp;
pub mod ecp2;
+ pub mod fp;
+ pub mod fp12;
pub mod fp2;
pub mod fp4;
- pub mod fp12;
- pub mod pair;
pub mod mpin;
- pub mod bls;
+ pub mod pair;
}
#[cfg(feature = "bls383")]
@@ -73,16 +73,16 @@ pub mod bls383 {
pub mod rom;
pub mod big;
+ pub mod bls;
pub mod dbig;
- pub mod fp;
pub mod ecp;
pub mod ecp2;
+ pub mod fp;
+ pub mod fp12;
pub mod fp2;
pub mod fp4;
- pub mod fp12;
- pub mod pair;
pub mod mpin;
- pub mod bls;
+ pub mod pair;
}
#[cfg(feature = "bls381")]
@@ -96,16 +96,16 @@ pub mod bls381 {
pub mod rom;
pub mod big;
+ pub mod bls;
pub mod dbig;
- pub mod fp;
pub mod ecp;
pub mod ecp2;
+ pub mod fp;
+ pub mod fp12;
pub mod fp2;
pub mod fp4;
- pub mod fp12;
- pub mod pair;
pub mod mpin;
- pub mod bls;
+ pub mod pair;
}
#[cfg(feature = "fp512bn")]
@@ -119,16 +119,16 @@ pub mod fp512bn {
pub mod rom;
pub mod big;
+ pub mod bls;
pub mod dbig;
- pub mod fp;
pub mod ecp;
pub mod ecp2;
+ pub mod fp;
+ pub mod fp12;
pub mod fp2;
pub mod fp4;
- pub mod fp12;
- pub mod pair;
pub mod mpin;
- pub mod bls;
+ pub mod pair;
}
#[cfg(feature = "fp256bn")]
@@ -142,16 +142,16 @@ pub mod fp256bn {
pub mod rom;
pub mod big;
+ pub mod bls;
pub mod dbig;
- pub mod fp;
pub mod ecp;
pub mod ecp2;
+ pub mod fp;
+ pub mod fp12;
pub mod fp2;
pub mod fp4;
- pub mod fp12;
- pub mod pair;
pub mod mpin;
- pub mod bls;
+ pub mod pair;
}
#[cfg(feature = "bls24")]
@@ -165,17 +165,17 @@ pub mod bls24 {
pub mod rom;
pub mod big;
+ pub mod bls192;
pub mod dbig;
+ pub mod ecp;
+ pub mod ecp4;
pub mod fp;
pub mod fp2;
+ pub mod fp24;
pub mod fp4;
pub mod fp8;
- pub mod fp24;
- pub mod ecp;
- pub mod ecp4;
- pub mod pair192;
pub mod mpin192;
- pub mod bls192;
+ pub mod pair192;
}
#[cfg(feature = "anssi")]
@@ -190,9 +190,9 @@ pub mod anssi {
pub mod big;
pub mod dbig;
- pub mod fp;
- pub mod ecp;
pub mod ecdh;
+ pub mod ecp;
+ pub mod fp;
}
#[cfg(feature = "brainpool")]
@@ -207,9 +207,9 @@ pub mod brainpool {
pub mod big;
pub mod dbig;
- pub mod fp;
- pub mod ecp;
pub mod ecdh;
+ pub mod ecp;
+ pub mod fp;
}
#[cfg(feature = "goldilocks")]
@@ -224,9 +224,9 @@ pub mod goldilocks {
pub mod big;
pub mod dbig;
- pub mod fp;
- pub mod ecp;
pub mod ecdh;
+ pub mod ecp;
+ pub mod fp;
}
#[cfg(feature = "hifive")]
@@ -241,9 +241,9 @@ pub mod hifive {
pub mod big;
pub mod dbig;
- pub mod fp;
- pub mod ecp;
pub mod ecdh;
+ pub mod ecp;
+ pub mod fp;
}
#[cfg(feature = "nist256")]
@@ -258,9 +258,9 @@ pub mod nist256 {
pub mod big;
pub mod dbig;
- pub mod fp;
- pub mod ecp;
pub mod ecdh;
+ pub mod ecp;
+ pub mod fp;
}
#[cfg(feature = "nist384")]
@@ -275,9 +275,9 @@ pub mod nist384 {
pub mod big;
pub mod dbig;
- pub mod fp;
- pub mod ecp;
pub mod ecdh;
+ pub mod ecp;
+ pub mod fp;
}
#[cfg(feature = "nist521")]
@@ -292,9 +292,9 @@ pub mod nist521 {
pub mod big;
pub mod dbig;
- pub mod fp;
- pub mod ecp;
pub mod ecdh;
+ pub mod ecp;
+ pub mod fp;
}
#[cfg(feature = "nums256e")]
@@ -309,9 +309,9 @@ pub mod nums256e {
pub mod big;
pub mod dbig;
- pub mod fp;
- pub mod ecp;
pub mod ecdh;
+ pub mod ecp;
+ pub mod fp;
}
#[cfg(feature = "nums256w")]
@@ -326,9 +326,9 @@ pub mod nums256w {
pub mod big;
pub mod dbig;
- pub mod fp;
- pub mod ecp;
pub mod ecdh;
+ pub mod ecp;
+ pub mod fp;
}
#[cfg(feature = "nums384e")]
@@ -343,9 +343,9 @@ pub mod nums384e {
pub mod big;
pub mod dbig;
- pub mod fp;
- pub mod ecp;
pub mod ecdh;
+ pub mod ecp;
+ pub mod fp;
}
#[cfg(feature = "nums384w")]
@@ -360,9 +360,9 @@ pub mod nums384w {
pub mod big;
pub mod dbig;
- pub mod fp;
- pub mod ecp;
pub mod ecdh;
+ pub mod ecp;
+ pub mod fp;
}
#[cfg(feature = "nums512w")]
@@ -377,9 +377,9 @@ pub mod nums512w {
pub mod big;
pub mod dbig;
- pub mod fp;
- pub mod ecp;
pub mod ecdh;
+ pub mod ecp;
+ pub mod fp;
}
#[cfg(feature = "nums512e")]
@@ -394,9 +394,9 @@ pub mod nums512e {
pub mod big;
pub mod dbig;
- pub mod fp;
- pub mod ecp;
pub mod ecdh;
+ pub mod ecp;
+ pub mod fp;
}
#[cfg(feature = "secp256k1")]
@@ -411,9 +411,9 @@ pub mod secp256k1 {
pub mod big;
pub mod dbig;
- pub mod fp;
- pub mod ecp;
pub mod ecdh;
+ pub mod ecp;
+ pub mod fp;
}
#[cfg(feature = "c25519")]
@@ -428,9 +428,9 @@ pub mod c25519 {
pub mod big;
pub mod dbig;
- pub mod fp;
- pub mod ecp;
pub mod ecdh;
+ pub mod ecp;
+ pub mod fp;
}
#[cfg(feature = "c41417")]
@@ -445,9 +445,9 @@ pub mod c41417 {
pub mod big;
pub mod dbig;
- pub mod fp;
- pub mod ecp;
pub mod ecdh;
+ pub mod ecp;
+ pub mod fp;
}
#[cfg(feature = "ed25519")]
@@ -462,9 +462,9 @@ pub mod ed25519 {
pub mod big;
pub mod dbig;
- pub mod fp;
- pub mod ecp;
pub mod ecdh;
+ pub mod ecp;
+ pub mod fp;
}
#[cfg(feature = "bn254CX")]
@@ -478,17 +478,17 @@ pub mod bn254CX {
pub mod rom;
pub mod big;
+ pub mod bls;
pub mod dbig;
- pub mod fp;
- pub mod ecp;
pub mod ecdh;
+ pub mod ecp;
pub mod ecp2;
+ pub mod fp;
+ pub mod fp12;
pub mod fp2;
pub mod fp4;
- pub mod fp12;
- pub mod pair;
pub mod mpin;
- pub mod bls;
+ pub mod pair;
}
#[cfg(feature = "bn254")]
@@ -502,60 +502,60 @@ pub mod bn254 {
pub mod rom;
pub mod big;
+ pub mod bls;
pub mod dbig;
- pub mod fp;
- pub mod ecp;
pub mod ecdh;
+ pub mod ecp;
pub mod ecp2;
+ pub mod fp;
+ pub mod fp12;
pub mod fp2;
pub mod fp4;
- pub mod fp12;
- pub mod pair;
pub mod mpin;
- pub mod bls;
+ pub mod pair;
}
#[cfg(feature = "rsa2048")]
#[path = "./"]
pub mod rsa2048 {
+ pub mod big;
+ pub mod dbig;
+ pub mod ff;
#[cfg(target_pointer_width = "32")]
#[path = "roms/rom_rsa2048_32.rs"]
pub mod rom;
#[cfg(target_pointer_width = "64")]
#[path = "roms/rom_rsa2048_64.rs"]
pub mod rom;
- pub mod big;
- pub mod dbig;
- pub mod ff;
pub mod rsa;
}
#[cfg(feature = "rsa3072")]
#[path = "./"]
pub mod rsa3072 {
+ pub mod big;
+ pub mod dbig;
+ pub mod ff;
#[cfg(target_pointer_width = "32")]
#[path = "roms/rom_rsa3072_32.rs"]
pub mod rom;
#[cfg(target_pointer_width = "64")]
#[path = "roms/rom_rsa3072_64.rs"]
pub mod rom;
- pub mod big;
- pub mod dbig;
- pub mod ff;
pub mod rsa;
}
#[cfg(feature = "rsa4096")]
#[path = "./"]
pub mod rsa4096 {
+ pub mod big;
+ pub mod dbig;
+ pub mod ff;
#[cfg(target_pointer_width = "32")]
#[path = "roms/rom_rsa4096_32.rs"]
mod rom;
#[cfg(target_pointer_width = "64")]
#[path = "roms/rom_rsa4096_64.rs"]
mod rom;
- pub mod big;
- pub mod dbig;
- pub mod ff;
pub mod rsa;
-}
\ No newline at end of file
+}
diff --git a/src/mpin.rs b/src/mpin.rs
index ba272d1..425d03e 100644
--- a/src/mpin.rs
+++ b/src/mpin.rs
@@ -20,21 +20,20 @@ under the License.
use std::time::SystemTime;
use std::time::UNIX_EPOCH;
+use super::big;
+use super::big::Big;
use super::ecp;
use super::ecp::ECP;
use super::ecp2::ECP2;
-use super::fp4::FP4;
use super::fp12::FP12;
-use super::big::Big;
+use super::fp4::FP4;
use super::pair;
-use super::big;
use super::rom;
-use rand::RAND;
use hash256::HASH256;
use hash384::HASH384;
use hash512::HASH512;
-
+use rand::RAND;
/* MPIN API Functions */
@@ -196,8 +195,8 @@ pub fn today() -> usize {
fn emap(u: &Big, cb: isize) -> ECP {
let mut P: ECP;
let mut x = Big::new_copy(u);
- let mut p = Big::new_ints(&rom::MODULUS);
- x.rmod(&mut p);
+ let p = Big::new_ints(&rom::MODULUS);
+ x.rmod(&p);
loop {
P = ECP::new_bigint(&x, cb);
if !P.is_infinity() {
@@ -260,8 +259,8 @@ pub fn encoding(rng: &mut RAND, e: &mut [u8]) -> isize {
let mut su = rng.getbyte() as isize;
su %= 2;
- let mut W = emap(&mut u, su);
- P.sub(&mut W);
+ let W = emap(&u, su);
+ P.sub(&W);
let sv = P.gets();
let rn = unmap(&mut v, &mut P);
let mut m = rng.getbyte() as isize;
@@ -299,9 +298,9 @@ pub fn decoding(d: &mut [u8]) -> isize {
let su = (d[0] & 1) as isize;
let sv = ((d[0] >> 1) & 1) as isize;
- let mut W = emap(&mut u, su);
- let mut P = emap(&mut v, sv);
- P.add(&mut W);
+ let W = emap(&u, su);
+ let mut P = emap(&v, sv);
+ P.add(&W);
u = P.getx();
v = P.gety();
d[0] = 0x04;
@@ -321,13 +320,13 @@ pub fn decoding(d: &mut [u8]) -> isize {
#[allow(non_snake_case)]
pub fn recombine_g1(r1: &[u8], r2: &[u8], r: &mut [u8]) -> isize {
let mut P = ECP::frombytes(&r1);
- let mut Q = ECP::frombytes(&r2);
+ let Q = ECP::frombytes(&r2);
if P.is_infinity() || Q.is_infinity() {
return INVALID_POINT;
}
- P.add(&mut Q);
+ P.add(&Q);
P.tobytes(r, false);
return 0;
@@ -337,13 +336,13 @@ pub fn recombine_g1(r1: &[u8], r2: &[u8], r: &mut [u8]) -> isize {
#[allow(non_snake_case)]
pub fn recombine_g2(w1: &[u8], w2: &[u8], w: &mut [u8]) -> isize {
let mut P = ECP2::frombytes(&w1);
- let mut Q = ECP2::frombytes(&w2);
+ let Q = ECP2::frombytes(&w2);
if P.is_infinity() || Q.is_infinity() {
return INVALID_POINT;
}
- P.add(&mut Q);
+ P.add(&Q);
P.tobytes(w);
return 0;
@@ -362,8 +361,8 @@ pub fn random_generate(rng: &mut RAND, s: &mut [u8]) -> isize {
pub fn get_server_secret(s: &[u8], sst: &mut [u8]) -> isize {
let mut Q = ECP2::generator();
- let mut sc = Big::frombytes(s);
- Q = pair::g2mul(&mut Q, &mut sc);
+ let sc = Big::frombytes(s);
+ Q = pair::g2mul(&Q, &sc);
Q.tobytes(sst);
return 0;
}
@@ -391,7 +390,7 @@ pub fn get_g1_multiple(
} else {
sx = Big::frombytes(x);
}
- let mut P: ECP;
+ let P: ECP;
if typ == 0 {
P = ECP::frombytes(g);
@@ -402,7 +401,7 @@ pub fn get_g1_multiple(
P = ECP::mapit(g)
}
- pair::g1mul(&mut P, &mut sx).tobytes(w, false);
+ pair::g1mul(&P, &mut sx).tobytes(w, false);
return 0;
}
@@ -437,7 +436,7 @@ pub fn extract_factor(
let mut R = ECP::mapit(&h);
R = R.pinmul(factor, facbits);
- P.sub(&mut R);
+ P.sub(&R);
P.tobytes(token, false);
@@ -463,7 +462,7 @@ pub fn restore_factor(
let mut R = ECP::mapit(&h);
R = R.pinmul(factor, facbits);
- P.add(&mut R);
+ P.add(&R);
P.tobytes(token, false);
@@ -499,10 +498,10 @@ pub fn get_client_permit(sha: usize, date: usize, s: &[u8], cid: &[u8], ctt: &mu
const RM: usize = big::MODBYTES as usize;
let mut h: [u8; RM] = [0; RM];
hashit(sha, date, cid, &mut h);
- let mut P = ECP::mapit(&h);
+ let P = ECP::mapit(&h);
let mut sc = Big::frombytes(s);
- pair::g1mul(&mut P, &mut sc).tobytes(ctt, false);
+ pair::g1mul(&P, &mut sc).tobytes(ctt, false);
return 0;
}
@@ -544,7 +543,7 @@ pub fn client_1(
}
let mut W = P.pinmul((pin as i32) % MAXPIN, PBLEN);
- T.add(&mut W);
+ T.add(&W);
if date != 0 {
if let Some(rpermit) = permit {
W = ECP::frombytes(&rpermit);
@@ -552,25 +551,25 @@ pub fn client_1(
if W.is_infinity() {
return INVALID_POINT;
}
- T.add(&mut W);
+ T.add(&W);
let mut h2: [u8; RM] = [0; RM];
hashit(sha, date, &h, &mut h2);
W = ECP::mapit(&h2);
if let Some(mut rxid) = xid {
- P = pair::g1mul(&mut P, &mut sx);
+ P = pair::g1mul(&P, &mut sx);
P.tobytes(&mut rxid, false);
- W = pair::g1mul(&mut W, &mut sx);
- P.add(&mut W);
+ W = pair::g1mul(&W, &mut sx);
+ P.add(&W);
} else {
- P.add(&mut W);
- P = pair::g1mul(&mut P, &mut sx);
+ P.add(&W);
+ P = pair::g1mul(&P, &mut sx);
}
if let Some(mut rxcid) = xcid {
P.tobytes(&mut rxcid, false)
}
} else {
if let Some(mut rxid) = xid {
- P = pair::g1mul(&mut P, &mut sx);
+ P = pair::g1mul(&P, &mut sx);
P.tobytes(&mut rxid, false);
}
}
@@ -593,8 +592,8 @@ pub fn server_1(sha: usize, date: usize, cid: &[u8], hid: &mut [u8], htid: Optio
if date != 0 {
let mut h2: [u8; RM] = [0; RM];
hashit(sha, date, &h, &mut h2);
- let mut R = ECP::mapit(&h2);
- P.add(&mut R);
+ let R = ECP::mapit(&h2);
+ P.add(&R);
if let Some(rhtid) = htid {
P.tobytes(rhtid, false);
}
@@ -604,7 +603,7 @@ pub fn server_1(sha: usize, date: usize, cid: &[u8], hid: &mut [u8], htid: Optio
/* Implement step 2 on client side of MPin protocol */
#[allow(non_snake_case)]
pub fn client_2(x: &[u8], y: &[u8], sec: &mut [u8]) -> isize {
- let mut r = Big::new_ints(&rom::CURVE_ORDER);
+ let r = Big::new_ints(&rom::CURVE_ORDER);
let mut P = ECP::frombytes(sec);
if P.is_infinity() {
return INVALID_POINT;
@@ -613,9 +612,9 @@ pub fn client_2(x: &[u8], y: &[u8], sec: &mut [u8]) -> isize {
let mut px = Big::frombytes(x);
let py = Big::frombytes(y);
px.add(&py);
- px.rmod(&mut r);
+ px.rmod(&r);
- P = pair::g1mul(&mut P, &mut px);
+ P = pair::g1mul(&P, &mut px);
P.neg();
P.tobytes(sec, false);
@@ -638,8 +637,8 @@ pub fn get_y(sha: usize, timevalue: usize, xcid: &[u8], y: &mut [u8]) {
hashit(sha, timevalue, xcid, &mut h);
let mut sy = Big::frombytes(&h);
- let mut q = Big::new_ints(&rom::CURVE_ORDER);
- sy.rmod(&mut q);
+ let q = Big::new_ints(&rom::CURVE_ORDER);
+ sy.rmod(&q);
sy.tobytes(y);
}
@@ -698,8 +697,8 @@ pub fn server_2(
return INVALID_POINT;
}
- P = pair::g1mul(&mut P, &mut sy);
- P.add(&mut R);
+ P = pair::g1mul(&P, &mut sy);
+ P.add(&R);
R = ECP::frombytes(&msec);
if R.is_infinity() {
return INVALID_POINT;
@@ -724,8 +723,8 @@ pub fn server_2(
if R.is_infinity() {
return INVALID_POINT;
}
- P = pair::g1mul(&mut P, &mut sy);
- P.add(&mut R); //P.affine();
+ P = pair::g1mul(&P, &mut sy);
+ P.add(&R); //P.affine();
}
g = pair::ate(&Q, &P);
g = pair::fexp(&g);
@@ -760,7 +759,7 @@ pub fn kangaroo(e: &[u8], f: &[u8]) -> isize {
let mut i: usize;
for _ in 0..TRAP {
i = (t.geta().geta().geta().lastbits(20) % (TS as isize)) as usize;
- t.mul(&mut table[i]);
+ t.mul(&table[i]);
dn += distance[i];
}
gf.copy(&t);
@@ -774,13 +773,13 @@ pub fn kangaroo(e: &[u8], f: &[u8]) -> isize {
break;
}
i = (ge.geta().geta().geta().lastbits(20) % (TS as isize)) as usize;
- ge.mul(&mut table[i]);
+ ge.mul(&table[i]);
dm += distance[i];
- if ge.equals(&mut t) {
+ if ge.equals(&t) {
res = dm - dn;
break;
}
- if ge.equals(&mut gf) {
+ if ge.equals(&gf) {
res = dn - dm;
break;
}
@@ -873,17 +872,17 @@ pub fn client_key(
return INVALID_POINT;
}
- W = pair::g1mul(&mut W, &mut x);
+ W = pair::g1mul(&W, &mut x);
- let mut r = Big::new_ints(&rom::CURVE_ORDER);
+ let r = Big::new_ints(&rom::CURVE_ORDER);
z.add(&h); //new
- z.rmod(&mut r);
+ z.rmod(&r);
g2.pinpow(pin as i32, PBLEN);
- g1.mul(&mut g2);
+ g1.mul(&g2);
- let mut c = g1.compow(&z, &mut r);
+ let mut c = g1.compow(&z, &r);
hash(sha, &mut c, &mut W, ck);
@@ -930,10 +929,10 @@ pub fn server_key(
let mut w = Big::frombytes(&w);
let mut h = Big::frombytes(&h);
- A = pair::g1mul(&mut A, &mut h); // new
- R.add(&mut A);
+ A = pair::g1mul(&A, &mut h); // new
+ R.add(&A);
- U = pair::g1mul(&mut U, &mut w);
+ U = pair::g1mul(&U, &mut w);
let mut g = pair::ate(&sQ, &R);
g = pair::fexp(&g);
diff --git a/src/mpin192.rs b/src/mpin192.rs
index e133dcd..63970d1 100644
--- a/src/mpin192.rs
+++ b/src/mpin192.rs
@@ -20,21 +20,20 @@ under the License.
use std::time::SystemTime;
use std::time::UNIX_EPOCH;
+use super::big;
+use super::big::Big;
use super::ecp;
use super::ecp::ECP;
use super::ecp4::ECP4;
-use super::fp8::FP8;
use super::fp24::FP24;
-use super::big::Big;
+use super::fp8::FP8;
use super::pair192;
-use super::big;
use super::rom;
-use rand::RAND;
use hash256::HASH256;
use hash384::HASH384;
use hash512::HASH512;
-
+use rand::RAND;
/* MPIN API Functions */
diff --git a/src/mpin256.rs b/src/mpin256.rs
index 4892ff5..5f9cee9 100644
--- a/src/mpin256.rs
+++ b/src/mpin256.rs
@@ -20,20 +20,20 @@ under the License.
use std::time::SystemTime;
use std::time::UNIX_EPOCH;
+use super::big;
+use super::big::Big;
use super::ecp;
use super::ecp::ECP;
use super::ecp8::ECP8;
use super::fp16::FP16;
use super::fp48::FP48;
-use super::big::Big;
use super::pair256;
-use super::big;
use super::rom;
-use rand::RAND;
use hash256::HASH256;
use hash384::HASH384;
use hash512::HASH512;
+use rand::RAND;
/* MPIN API Functions */
diff --git a/src/nhs.rs b/src/nhs.rs
index 7f2f605..dda49b0 100644
--- a/src/nhs.rs
+++ b/src/nhs.rs
@@ -313,7 +313,7 @@ fn encode(key: &[u8], poly: &mut [i32]) {
let mut kj = key[j];
j += 1;
for _ in 0..8 {
- let b = (kj & 1) as i32;
+ let b = i32::from(kj & 1);
poly[i] = b * q2;
poly[i + 256] = b * q2;
poly[i + 512] = b * q2;
@@ -359,13 +359,13 @@ fn parse(seed: &[u8], poly: &mut [i32]) {
let mut j = 0;
for i in 0..DEGREE {
- let mut n = (hash[j] & 0x7f) as i32;
+ let mut n = i32::from(hash[j] & 0x7f);
n <<= 8;
- n += (hash[j + 1]) as i32;
+ n += i32::from(hash[j + 1]);
n <<= 8;
- n += (hash[j + 2]) as i32;
+ n += i32::from(hash[j + 2]);
n <<= 8;
- n += (hash[j + 3]) as i32;
+ n += i32::from(hash[j + 3]);
j += 4;
poly[i] = nres(n);
//poly[i]=modmul(n,ONE); // reduce 31-bit random number mod q
diff --git a/src/pair.rs b/src/pair.rs
index b85efaa..36c9045 100644
--- a/src/pair.rs
+++ b/src/pair.rs
@@ -17,19 +17,18 @@ specific language governing permissions and limitations
under the License.
*/
-
-use super::fp::FP;
+use super::big::Big;
+use super::dbig::DBig;
+use super::ecp;
use super::ecp::ECP;
-use super::fp2::FP2;
use super::ecp2::ECP2;
-use super::fp4::FP4;
+use super::fp::FP;
use super::fp12;
use super::fp12::FP12;
-use super::big::Big;
-use super::dbig::DBig;
-use super::ecp;
+use super::fp2::FP2;
+use super::fp4::FP4;
use super::rom;
-use types::{SexticTwist, CurvePairingType, SignOfX};
+use types::{CurvePairingType, SexticTwist, SignOfX};
#[allow(non_snake_case)]
fn linedbl(A: &mut ECP2, qx: &FP, qy: &FP) -> FP12 {
@@ -56,10 +55,10 @@ fn linedbl(A: &mut ECP2, qx: &FP, qy: &FP) -> FP12 {
let sb = 3 * rom::CURVE_B_I;
zz.imul(sb);
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
zz.div_ip2();
}
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
zz.mul_ip();
zz.dbl();
yz.mul_ip();
@@ -73,15 +72,15 @@ fn linedbl(A: &mut ECP2, qx: &FP, qy: &FP) -> FP12 {
zz.norm(); // 3b.Z^2-Y^2
a.copy(&FP4::new_fp2s(&yz, &zz)); // -2YZ.Ys | 3b.Z^2-Y^2 | 3X^2.Xs
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
b.copy(&FP4::new_fp2(&xx)); // L(0,1) | L(0,0) | L(1,0)
}
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
c.copy(&FP4::new_fp2(&xx));
c.times_i();
}
A.dbl();
- let mut res= FP12::new_fp4s(&a, &b, &c);
+ let mut res = FP12::new_fp4s(&a, &b, &c);
res.settype(fp12::SPARSER);
return res;
}
@@ -107,7 +106,7 @@ fn lineadd(A: &mut ECP2, B: &ECP2, qx: &FP, qy: &FP) -> FP12 {
t1.copy(&x1); // T1=X1-Z1.X2
x1.pmul(qy); // X1=(X1-Z1.X2).Ys
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
x1.mul_ip();
x1.norm();
}
@@ -123,27 +122,27 @@ fn lineadd(A: &mut ECP2, B: &ECP2, qx: &FP, qy: &FP) -> FP12 {
y1.norm(); // Y1=-(Y1-Z1.Y2).Xs
a.copy(&FP4::new_fp2s(&x1, &t2)); // (X1-Z1.X2).Ys | (Y1-Z1.Y2).X2 - (X1-Z1.X2).Y2 | - (Y1-Z1.Y2).Xs
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
b.copy(&FP4::new_fp2(&y1));
}
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
c.copy(&FP4::new_fp2(&y1));
c.times_i();
}
A.add(B);
- let mut res= FP12::new_fp4s(&a, &b, &c);
+ let mut res = FP12::new_fp4s(&a, &b, &c);
res.settype(fp12::SPARSER);
return res;
}
/* prepare ate parameter, n=6u+2 (BN) or n=u (BLS), n3=3*n */
#[allow(non_snake_case)]
-fn lbits(n3: &mut Big,n: &mut Big) -> usize {
+fn lbits(n3: &mut Big, n: &mut Big) -> usize {
n.copy(&Big::new_ints(&rom::CURVE_BNX));
- if ecp::CURVE_PAIRING_TYPE==CurvePairingType::BN {
+ if ecp::CURVE_PAIRING_TYPE == CurvePairingType::Bn {
n.pmul(6);
- if ecp::SIGN_OF_X==SignOfX::POSITIVEX {
+ if ecp::SIGN_OF_X == SignOfX::PositiveX {
n.inc(2);
} else {
n.dec(2);
@@ -159,18 +158,18 @@ fn lbits(n3: &mut Big,n: &mut Big) -> usize {
/* prepare for multi-pairing */
pub fn initmp() -> [FP12; rom::ATE_BITS] {
let r: [FP12; rom::ATE_BITS] = [FP12::new_int(1); rom::ATE_BITS];
- return r
+ return r;
}
/* basic Miller loop */
-pub fn miller(r:&[FP12]) -> FP12 {
- let mut res=FP12::new_int(1);
+pub fn miller(r: &[FP12]) -> FP12 {
+ let mut res = FP12::new_int(1);
for i in (1..rom::ATE_BITS).rev() {
res.sqr();
res.ssmul(&r[i]);
}
- if ecp::SIGN_OF_X==SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
res.conj();
}
res.ssmul(&r[0]);
@@ -179,14 +178,13 @@ pub fn miller(r:&[FP12]) -> FP12 {
/* Accumulate another set of line functions for n-pairing */
#[allow(non_snake_case)]
-pub fn another(r:&mut [FP12],P1: &ECP2,Q1: &ECP) {
+pub fn another(r: &mut [FP12], P1: &ECP2, Q1: &ECP) {
let mut f = FP2::new_bigs(&Big::new_ints(&rom::FRA), &Big::new_ints(&rom::FRB));
let mut n = Big::new();
let mut n3 = Big::new();
let mut K = ECP2::new();
-
-// P is needed in affine form for line function, Q for (Qx,Qy) extraction
+ // P is needed in affine form for line function, Q for (Qx,Qy) extraction
let mut P = ECP2::new();
P.copy(P1);
P.affine();
@@ -194,8 +192,8 @@ pub fn another(r:&mut [FP12],P1: &ECP2,Q1: &ECP) {
Q.copy(Q1);
Q.affine();
- if ecp::CURVE_PAIRING_TYPE==CurvePairingType::BN {
- if ecp::SEXTIC_TWIST==SexticTwist::M_TYPE {
+ if ecp::CURVE_PAIRING_TYPE == CurvePairingType::Bn {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
f.inverse();
f.norm();
}
@@ -210,36 +208,36 @@ pub fn another(r:&mut [FP12],P1: &ECP2,Q1: &ECP) {
NP.copy(&P);
NP.neg();
- let nb=lbits(&mut n3,&mut n);
+ let nb = lbits(&mut n3, &mut n);
- for i in (1..nb-1).rev() {
- let mut lv=linedbl(&mut A,&qx,&qy);
+ for i in (1..nb - 1).rev() {
+ let mut lv = linedbl(&mut A, &qx, &qy);
- let bt=n3.bit(i)-n.bit(i);
- if bt==1 {
- let lv2=lineadd(&mut A,&P,&qx,&qy);
+ let bt = n3.bit(i) - n.bit(i);
+ if bt == 1 {
+ let lv2 = lineadd(&mut A, &P, &qx, &qy);
lv.smul(&lv2);
}
- if bt==-1 {
- let lv2=lineadd(&mut A,&NP,&qx,&qy);
+ if bt == -1 {
+ let lv2 = lineadd(&mut A, &NP, &qx, &qy);
lv.smul(&lv2);
}
r[i].ssmul(&lv);
}
-/* R-ate fixup required for BN curves */
- if ecp::CURVE_PAIRING_TYPE==CurvePairingType::BN {
- if ecp::SIGN_OF_X==SignOfX::NEGATIVEX {
+ /* R-ate fixup required for BN curves */
+ if ecp::CURVE_PAIRING_TYPE == CurvePairingType::Bn {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
A.neg();
}
K.copy(&P);
K.frob(&f);
- let mut lv=lineadd(&mut A,&K,&qx,&qy);
+ let mut lv = lineadd(&mut A, &K, &qx, &qy);
K.frob(&f);
K.neg();
- let lv2=lineadd(&mut A,&K,&qx,&qy);
+ let lv2 = lineadd(&mut A, &K, &qx, &qy);
lv.smul(&lv2);
- r[0].ssmul(&lv);
+ r[0].ssmul(&lv);
}
}
@@ -251,8 +249,8 @@ pub fn ate(P1: &ECP2, Q1: &ECP) -> FP12 {
let mut n3 = Big::new();
let mut K = ECP2::new();
- if ecp::CURVE_PAIRING_TYPE == CurvePairingType::BN {
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::CURVE_PAIRING_TYPE == CurvePairingType::Bn {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
f.inverse();
f.norm();
}
@@ -275,7 +273,7 @@ pub fn ate(P1: &ECP2, Q1: &ECP) -> FP12 {
NP.copy(&P);
NP.neg();
- let nb=lbits(&mut n3,&mut n);
+ let nb = lbits(&mut n3, &mut n);
for i in (1..nb - 1).rev() {
r.sqr();
@@ -292,14 +290,14 @@ pub fn ate(P1: &ECP2, Q1: &ECP) -> FP12 {
r.ssmul(&lv);
}
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
r.conj();
}
/* R-ate fixup required for BN curves */
- if ecp::CURVE_PAIRING_TYPE == CurvePairingType::BN {
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::CURVE_PAIRING_TYPE == CurvePairingType::Bn {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
A.neg();
}
@@ -310,7 +308,7 @@ pub fn ate(P1: &ECP2, Q1: &ECP) -> FP12 {
K.frob(&f);
K.neg();
let lv2 = lineadd(&mut A, &K, &qx, &qy);
- lv.smul(&lv2);
+ lv.smul(&lv2);
r.ssmul(&lv);
}
@@ -325,8 +323,8 @@ pub fn ate2(P1: &ECP2, Q1: &ECP, R1: &ECP2, S1: &ECP) -> FP12 {
let mut n3 = Big::new();
let mut K = ECP2::new();
- if ecp::CURVE_PAIRING_TYPE == CurvePairingType::BN {
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::CURVE_PAIRING_TYPE == CurvePairingType::Bn {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
f.inverse();
f.norm();
}
@@ -365,36 +363,36 @@ pub fn ate2(P1: &ECP2, Q1: &ECP, R1: &ECP2, S1: &ECP) -> FP12 {
NR.copy(&R);
NR.neg();
- let nb=lbits(&mut n3,&mut n);
+ let nb = lbits(&mut n3, &mut n);
for i in (1..nb - 1).rev() {
r.sqr();
let mut lv = linedbl(&mut A, &qx, &qy);
let lv2 = linedbl(&mut B, &sx, &sy);
- lv.smul(&lv2);
+ lv.smul(&lv2);
r.ssmul(&lv);
let bt = n3.bit(i) - n.bit(i);
if bt == 1 {
lv = lineadd(&mut A, &P, &qx, &qy);
let lv2 = lineadd(&mut B, &R, &sx, &sy);
- lv.smul(&lv2);
+ lv.smul(&lv2);
r.ssmul(&lv);
}
if bt == -1 {
lv = lineadd(&mut A, &NP, &qx, &qy);
let lv2 = lineadd(&mut B, &NR, &sx, &sy);
- lv.smul(&lv2);
+ lv.smul(&lv2);
r.ssmul(&lv);
}
}
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
r.conj();
}
- /* R-ate fixup */
- if ecp::CURVE_PAIRING_TYPE == CurvePairingType::BN {
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ // R-ate fixup
+ if ecp::CURVE_PAIRING_TYPE == CurvePairingType::Bn {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
A.neg();
B.neg();
}
@@ -405,7 +403,7 @@ pub fn ate2(P1: &ECP2, Q1: &ECP, R1: &ECP2, S1: &ECP) -> FP12 {
K.frob(&f);
K.neg();
let mut lv2 = lineadd(&mut A, &K, &qx, &qy);
- lv.smul(&lv2);
+ lv.smul(&lv2);
r.ssmul(&lv);
K.copy(&R);
@@ -415,21 +413,20 @@ pub fn ate2(P1: &ECP2, Q1: &ECP, R1: &ECP2, S1: &ECP) -> FP12 {
K.frob(&f);
K.neg();
lv2 = lineadd(&mut B, &K, &sx, &sy);
- lv.smul(&lv2);
+ lv.smul(&lv2);
r.ssmul(&lv);
-
}
return r;
}
-/* final exponentiation - keep separate for multi-pairings and to avoid thrashing stack */
+// final exponentiation - keep separate for multi-pairings and to avoid thrashing stack
pub fn fexp(m: &FP12) -> FP12 {
let f = FP2::new_bigs(&Big::new_ints(&rom::FRA), &Big::new_ints(&rom::FRB));
let mut x = Big::new_ints(&rom::CURVE_BNX);
let mut r = FP12::new_copy(m);
- /* Easy part of final exp */
+ // Easy part of final exp
let mut lv = FP12::new_copy(&r);
lv.inverse();
r.conj();
@@ -439,13 +436,13 @@ pub fn fexp(m: &FP12) -> FP12 {
r.frob(&f);
r.frob(&f);
r.mul(&lv);
-// if r.isunity() {
-// r.zero();
-// return r;
-// }
+ // if r.isunity() {
+ // r.zero();
+ // return r;
+ // }
/* Hard part of final exp */
- if ecp::CURVE_PAIRING_TYPE == CurvePairingType::BN {
+ if ecp::CURVE_PAIRING_TYPE == CurvePairingType::Bn {
lv.copy(&r);
lv.frob(&f);
let mut x0 = FP12::new_copy(&lv);
@@ -455,22 +452,22 @@ pub fn fexp(m: &FP12) -> FP12 {
x0.frob(&f);
let mut x1 = FP12::new_copy(&r);
x1.conj();
- let mut x4 = r.pow(&mut x);
- if ecp::SIGN_OF_X == SignOfX::POSITIVEX {
+ let mut x4 = r.pow(&x);
+ if ecp::SIGN_OF_X == SignOfX::PositiveX {
x4.conj();
}
let mut x3 = FP12::new_copy(&x4);
x3.frob(&f);
- let mut x2 = x4.pow(&mut x);
- if ecp::SIGN_OF_X == SignOfX::POSITIVEX {
+ let mut x2 = x4.pow(&x);
+ if ecp::SIGN_OF_X == SignOfX::PositiveX {
x2.conj();
}
let mut x5 = FP12::new_copy(&x2);
x5.conj();
- lv = x2.pow(&mut x);
- if ecp::SIGN_OF_X == SignOfX::POSITIVEX {
+ lv = x2.pow(&x);
+ if ecp::SIGN_OF_X == SignOfX::PositiveX {
lv.conj();
}
x2.frob(&f);
@@ -505,13 +502,13 @@ pub fn fexp(m: &FP12) -> FP12 {
let mut y0 = FP12::new_copy(&r);
y0.usqr();
- let mut y1 = y0.pow(&mut x);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ let mut y1 = y0.pow(&x);
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
y1.conj();
}
x.fshr(1);
- let mut y2 = y1.pow(&mut x);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ let mut y2 = y1.pow(&x);
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
y2.conj();
}
x.fshl(1);
@@ -522,12 +519,12 @@ pub fn fexp(m: &FP12) -> FP12 {
y1.conj();
y1.mul(&y2);
- y2 = y1.pow(&mut x);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ y2 = y1.pow(&x);
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
y2.conj();
}
- y3 = y2.pow(&mut x);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ y3 = y2.pow(&x);
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
y3.conj();
}
y1.conj();
@@ -541,8 +538,8 @@ pub fn fexp(m: &FP12) -> FP12 {
y2.frob(&f);
y1.mul(&y2);
- y2 = y3.pow(&mut x);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ y2 = y3.pow(&x);
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
y2.conj();
}
y2.mul(&y0);
@@ -562,7 +559,7 @@ pub fn fexp(m: &FP12) -> FP12 {
/* GLV method */
fn glv(e: &Big) -> [Big; 2] {
let mut u: [Big; 2] = [Big::new(), Big::new()];
- if ecp::CURVE_PAIRING_TYPE == CurvePairingType::BN {
+ if ecp::CURVE_PAIRING_TYPE == CurvePairingType::Bn {
let mut t = Big::new();
let q = Big::new_ints(&rom::CURVE_ORDER);
let mut v: [Big; 2] = [Big::new(), Big::new()];
@@ -576,7 +573,7 @@ fn glv(e: &Big) -> [Big; 2] {
for i in 0..2 {
for j in 0..2 {
t = Big::new_ints(&rom::CURVE_SB[j][i]);
- t = Big::modmul(&mut v[j], &mut t, &q);
+ t = Big::modmul(&v[j], &t, &q);
u[i].add(&q);
u[i].sub(&t);
u[i].rmod(&q);
@@ -599,7 +596,7 @@ fn glv(e: &Big) -> [Big; 2] {
/* Galbraith & Scott Method */
pub fn gs(e: &Big) -> [Big; 4] {
let mut u: [Big; 4] = [Big::new(), Big::new(), Big::new(), Big::new()];
- if ecp::CURVE_PAIRING_TYPE == CurvePairingType::BN {
+ if ecp::CURVE_PAIRING_TYPE == CurvePairingType::Bn {
let mut t = Big::new();
let q = Big::new_ints(&rom::CURVE_ORDER);
@@ -613,7 +610,7 @@ pub fn gs(e: &Big) -> [Big; 4] {
for i in 0..4 {
for j in 0..4 {
t = Big::new_ints(&rom::CURVE_BB[j][i]);
- t = Big::modmul(&mut v[j], &mut t, &q);
+ t = Big::modmul(&v[j], &t, &q);
u[i].add(&q);
u[i].sub(&t);
u[i].rmod(&q);
@@ -629,11 +626,11 @@ pub fn gs(e: &Big) -> [Big; 4] {
w.div(&x);
}
u[3].copy(&w);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
let mut t = Big::new();
- t.copy(&Big::modneg(&mut u[1], &q));
+ t.copy(&Big::modneg(&u[1], &q));
u[1].copy(&t);
- t.copy(&Big::modneg(&mut u[3], &q));
+ t.copy(&Big::modneg(&u[3], &q));
u[3].copy(&t);
}
}
@@ -655,7 +652,7 @@ pub fn g1mul(P: &ECP, e: &mut Big) -> ECP {
Q.mulx(&mut cru);
let mut np = u[0].nbits();
- let mut t: Big = Big::modneg(&mut u[0], &q);
+ let mut t: Big = Big::modneg(&u[0], &q);
let mut nn = t.nbits();
if nn < np {
u[0].copy(&t);
@@ -663,7 +660,7 @@ pub fn g1mul(P: &ECP, e: &mut Big) -> ECP {
}
np = u[1].nbits();
- t = Big::modneg(&mut u[1], &q);
+ t = Big::modneg(&u[1], &q);
nn = t.nbits();
if nn < np {
u[1].copy(&t);
@@ -671,7 +668,7 @@ pub fn g1mul(P: &ECP, e: &mut Big) -> ECP {
}
u[0].norm();
u[1].norm();
- R = R.mul2(&u[0], &mut Q, &u[1]);
+ R = R.mul2(&u[0], &Q, &u[1]);
} else {
R = P.mul(e);
}
@@ -689,7 +686,7 @@ pub fn g2mul(P: &ECP2, e: &Big) -> ECP2 {
let mut u = gs(e);
let mut T = ECP2::new();
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
f.inverse();
f.norm();
}
@@ -703,7 +700,7 @@ pub fn g2mul(P: &ECP2, e: &Big) -> ECP2 {
}
for i in 0..4 {
let np = u[i].nbits();
- t.copy(&Big::modneg(&mut u[i], &q));
+ t.copy(&Big::modneg(&u[i], &q));
let nn = t.nbits();
if nn < np {
u[i].copy(&t);
@@ -739,7 +736,7 @@ pub fn gtpow(d: &FP12, e: &Big) -> FP12 {
}
for i in 0..4 {
let np = u[i].nbits();
- t.copy(&Big::modneg(&mut u[i], &q));
+ t.copy(&Big::modneg(&u[i], &q));
let nn = t.nbits();
if nn < np {
u[i].copy(&t);
@@ -747,7 +744,7 @@ pub fn gtpow(d: &FP12, e: &Big) -> FP12 {
}
u[i].norm();
}
- r.copy(&FP12::pow4(&mut g, &u));
+ r.copy(&FP12::pow4(&g, &u));
} else {
r.copy(&d.pow(e));
}
diff --git a/src/pair192.rs b/src/pair192.rs
index a7c2993..84a9f03 100644
--- a/src/pair192.rs
+++ b/src/pair192.rs
@@ -17,17 +17,16 @@ specific language governing permissions and limitations
under the License.
*/
-
-use super::fp::FP;
+use super::big::Big;
+use super::ecp;
use super::ecp::ECP;
-use super::fp2::FP2;
use super::ecp4::ECP4;
-use super::fp4::FP4;
-use super::fp8::FP8;
+use super::fp::FP;
+use super::fp2::FP2;
use super::fp24;
use super::fp24::FP24;
-use super::big::Big;
-use super::ecp;
+use super::fp4::FP4;
+use super::fp8::FP8;
use super::rom;
use types::{SexticTwist, SignOfX};
@@ -56,10 +55,10 @@ fn linedbl(A: &mut ECP4, qx: &FP, qy: &FP) -> FP24 {
let sb = 3 * rom::CURVE_B_I;
zz.imul(sb);
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
zz.div_2i();
}
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
zz.times_i();
zz.dbl();
yz.times_i();
@@ -72,15 +71,15 @@ fn linedbl(A: &mut ECP4, qx: &FP, qy: &FP) -> FP24 {
zz.norm(); // 3b.Z^2-Y^2
a.copy(&FP8::new_fp4s(&yz, &zz)); // -2YZ.Ys | 3b.Z^2-Y^2 | 3X^2.Xs
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
b.copy(&FP8::new_fp4(&xx)); // L(0,1) | L(0,0) | L(1,0)
}
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
c.copy(&FP8::new_fp4(&xx));
c.times_i();
}
A.dbl();
- let mut res= FP24::new_fp8s(&a, &b, &c);
+ let mut res = FP24::new_fp8s(&a, &b, &c);
res.settype(fp24::SPARSER);
return res;
}
@@ -106,7 +105,7 @@ fn lineadd(A: &mut ECP4, B: &ECP4, qx: &FP, qy: &FP) -> FP24 {
t1.copy(&x1); // T1=X1-Z1.X2
x1.qmul(qy); // X1=(X1-Z1.X2).Ys
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
x1.times_i();
}
@@ -121,23 +120,23 @@ fn lineadd(A: &mut ECP4, B: &ECP4, qx: &FP, qy: &FP) -> FP24 {
y1.norm(); // Y1=-(Y1-Z1.Y2).Xs
a.copy(&FP8::new_fp4s(&x1, &t2)); // (X1-Z1.X2).Ys | (Y1-Z1.Y2).X2 - (X1-Z1.X2).Y2 | - (Y1-Z1.Y2).Xs
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
b.copy(&FP8::new_fp4(&y1));
}
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
c.copy(&FP8::new_fp4(&y1));
c.times_i();
}
A.add(B);
- let mut res= FP24::new_fp8s(&a, &b, &c);
+ let mut res = FP24::new_fp8s(&a, &b, &c);
res.settype(fp24::SPARSER);
return res;
}
/* prepare ate parameter, n=6u+2 (BN) or n=u (BLS), n3=3*n */
#[allow(non_snake_case)]
-fn lbits(n3: &mut Big,n: &mut Big) -> usize {
+fn lbits(n3: &mut Big, n: &mut Big) -> usize {
n.copy(&Big::new_ints(&rom::CURVE_BNX));
n3.copy(&n);
n3.pmul(3);
@@ -148,18 +147,18 @@ fn lbits(n3: &mut Big,n: &mut Big) -> usize {
/* prepare for multi-pairing */
pub fn initmp() -> [FP24; rom::ATE_BITS] {
let r: [FP24; rom::ATE_BITS] = [FP24::new_int(1); rom::ATE_BITS];
- return r
+ return r;
}
/* basic Miller loop */
-pub fn miller(r:&[FP24]) -> FP24 {
- let mut res=FP24::new_int(1);
+pub fn miller(r: &[FP24]) -> FP24 {
+ let mut res = FP24::new_int(1);
for i in (1..rom::ATE_BITS).rev() {
res.sqr();
res.ssmul(&r[i]);
}
- if ecp::SIGN_OF_X==SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
res.conj();
}
res.ssmul(&r[0]);
@@ -168,11 +167,11 @@ pub fn miller(r:&[FP24]) -> FP24 {
/* Accumulate another set of line functions for n-pairing */
#[allow(non_snake_case)]
-pub fn another(r:&mut [FP24],P1: &ECP4,Q1: &ECP) {
+pub fn another(r: &mut [FP24], P1: &ECP4, Q1: &ECP) {
let mut n = Big::new();
let mut n3 = Big::new();
-// P is needed in affine form for line function, Q for (Qx,Qy) extraction
+ // P is needed in affine form for line function, Q for (Qx,Qy) extraction
let mut P = ECP4::new();
P.copy(P1);
P.affine();
@@ -189,18 +188,18 @@ pub fn another(r:&mut [FP24],P1: &ECP4,Q1: &ECP) {
NP.copy(&P);
NP.neg();
- let nb=lbits(&mut n3,&mut n);
+ let nb = lbits(&mut n3, &mut n);
- for i in (1..nb-1).rev() {
- let mut lv=linedbl(&mut A,&qx,&qy);
+ for i in (1..nb - 1).rev() {
+ let mut lv = linedbl(&mut A, &qx, &qy);
- let bt=n3.bit(i)-n.bit(i);
- if bt==1 {
- let lv2=lineadd(&mut A,&P,&qx,&qy);
+ let bt = n3.bit(i) - n.bit(i);
+ if bt == 1 {
+ let lv2 = lineadd(&mut A, &P, &qx, &qy);
lv.smul(&lv2);
}
- if bt==-1 {
- let lv2=lineadd(&mut A,&NP,&qx,&qy);
+ if bt == -1 {
+ let lv2 = lineadd(&mut A, &NP, &qx, &qy);
lv.smul(&lv2);
}
r[i].ssmul(&lv);
@@ -231,7 +230,7 @@ pub fn ate(P1: &ECP4, Q1: &ECP) -> FP24 {
NP.copy(&P);
NP.neg();
- let nb=lbits(&mut n3,&mut n);
+ let nb = lbits(&mut n3, &mut n);
for i in (1..nb - 1).rev() {
r.sqr();
@@ -250,7 +249,7 @@ pub fn ate(P1: &ECP4, Q1: &ECP) -> FP24 {
r.ssmul(&lv);
}
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
r.conj();
}
@@ -296,30 +295,30 @@ pub fn ate2(P1: &ECP4, Q1: &ECP, R1: &ECP4, S1: &ECP) -> FP24 {
NR.copy(&R);
NR.neg();
- let nb=lbits(&mut n3,&mut n);
+ let nb = lbits(&mut n3, &mut n);
for i in (1..nb - 1).rev() {
r.sqr();
let mut lv = linedbl(&mut A, &qx, &qy);
let lv2 = linedbl(&mut B, &sx, &sy);
- lv.smul(&lv2);
+ lv.smul(&lv2);
r.ssmul(&lv);
let bt = n3.bit(i) - n.bit(i);
if bt == 1 {
lv = lineadd(&mut A, &P, &qx, &qy);
let lv2 = lineadd(&mut B, &R, &sx, &sy);
- lv.smul(&lv2);
+ lv.smul(&lv2);
r.ssmul(&lv);
}
if bt == -1 {
lv = lineadd(&mut A, &NP, &qx, &qy);
let lv2 = lineadd(&mut B, &NR, &sx, &sy);
- lv.smul(&lv2);
+ lv.smul(&lv2);
r.ssmul(&lv);
}
}
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
r.conj();
}
@@ -341,10 +340,10 @@ pub fn fexp(m: &FP24) -> FP24 {
lv.copy(&r);
r.frob(&f, 4);
r.mul(&lv);
-// if r.isunity() {
-// r.zero();
-// return r;
-// }
+ // if r.isunity() {
+ // r.zero();
+ // return r;
+ // }
/* Hard part of final exp */
// Ghamman & Fouotsa Method
@@ -356,7 +355,7 @@ pub fn fexp(m: &FP24) -> FP24 {
let mut t2 = t1.pow(&mut x);
x.fshl(1);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
t1.conj();
}
let mut t3 = FP24::new_copy(&t1);
@@ -368,7 +367,7 @@ pub fn fexp(m: &FP24) -> FP24 {
let mut t4 = t3.pow(&mut x);
let mut t5 = t4.pow(&mut x);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
t3.conj();
t5.conj();
}
@@ -378,7 +377,7 @@ pub fn fexp(m: &FP24) -> FP24 {
t3.mul(&t4);
let mut t6 = t5.pow(&mut x);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
t6.conj();
}
@@ -396,7 +395,7 @@ pub fn fexp(m: &FP24) -> FP24 {
t5.copy(&t6.pow(&mut x));
t6.copy(&t5.pow(&mut x));
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
t5.conj();
}
@@ -409,7 +408,7 @@ pub fn fexp(m: &FP24) -> FP24 {
t3.mul(&t0);
t5.copy(&t6.pow(&mut x));
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
t5.conj();
}
t2.frob(&f, 7);
@@ -463,7 +462,7 @@ pub fn gs(e: &Big) -> [Big; 8] {
w.div(&x);
}
u[7].copy(&w);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
let mut t = Big::new();
t.copy(&Big::modneg(&mut u[1], &q));
u[1].copy(&t);
diff --git a/src/pair256.rs b/src/pair256.rs
index f25676c..c9b073e 100644
--- a/src/pair256.rs
+++ b/src/pair256.rs
@@ -17,19 +17,18 @@ specific language governing permissions and limitations
under the License.
*/
-
-use super::fp::FP;
+use super::big::Big;
+use super::ecp;
use super::ecp::ECP;
-use super::fp2::FP2;
use super::ecp8::ECP8;
-use super::fp8::FP8;
+use super::fp::FP;
use super::fp16::FP16;
+use super::fp2::FP2;
use super::fp48;
use super::fp48::FP48;
-use super::big::Big;
-use super::ecp;
+use super::fp8::FP8;
use super::rom;
-use types::{SignOfX, SexticTwist};
+use types::{SexticTwist, SignOfX};
#[allow(non_snake_case)]
fn linedbl(A: &mut ECP8, qx: &FP, qy: &FP) -> FP48 {
@@ -56,10 +55,10 @@ fn linedbl(A: &mut ECP8, qx: &FP, qy: &FP) -> FP48 {
let sb = 3 * rom::CURVE_B_I;
zz.imul(sb);
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
zz.div_2i();
}
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
zz.times_i();
zz.dbl();
yz.times_i();
@@ -72,15 +71,15 @@ fn linedbl(A: &mut ECP8, qx: &FP, qy: &FP) -> FP48 {
zz.norm(); // 3b.Z^2-Y^2
a.copy(&FP16::new_fp8s(&yz, &zz)); // -2YZ.Ys | 3b.Z^2-Y^2 | 3X^2.Xs
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
b.copy(&FP16::new_fp8(&xx)); // L(0,1) | L(0,0) | L(1,0)
}
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
c.copy(&FP16::new_fp8(&xx));
c.times_i();
}
A.dbl();
- let mut res= FP48::new_fp16s(&a, &b, &c);
+ let mut res = FP48::new_fp16s(&a, &b, &c);
res.settype(fp48::SPARSER);
return res;
}
@@ -106,7 +105,7 @@ fn lineadd(A: &mut ECP8, B: &ECP8, qx: &FP, qy: &FP) -> FP48 {
t1.copy(&x1); // T1=X1-Z1.X2
x1.tmul(qy); // X1=(X1-Z1.X2).Ys
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
x1.times_i();
}
@@ -121,23 +120,23 @@ fn lineadd(A: &mut ECP8, B: &ECP8, qx: &FP, qy: &FP) -> FP48 {
y1.norm(); // Y1=-(Y1-Z1.Y2).Xs
a.copy(&FP16::new_fp8s(&x1, &t2)); // (X1-Z1.X2).Ys | (Y1-Z1.Y2).X2 - (X1-Z1.X2).Y2 | - (Y1-Z1.Y2).Xs
- if ecp::SEXTIC_TWIST == SexticTwist::D_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::DType {
b.copy(&FP16::new_fp8(&y1));
}
- if ecp::SEXTIC_TWIST == SexticTwist::M_TYPE {
+ if ecp::SEXTIC_TWIST == SexticTwist::MType {
c.copy(&FP16::new_fp8(&y1));
c.times_i();
}
A.add(B);
- let mut res= FP48::new_fp16s(&a, &b, &c);
+ let mut res = FP48::new_fp16s(&a, &b, &c);
res.settype(fp48::SPARSER);
return res;
}
/* prepare ate parameter, n=6u+2 (BN) or n=u (BLS), n3=3*n */
#[allow(non_snake_case)]
-fn lbits(n3: &mut Big,n: &mut Big) -> usize {
+fn lbits(n3: &mut Big, n: &mut Big) -> usize {
n.copy(&Big::new_ints(&rom::CURVE_BNX));
n3.copy(&n);
n3.pmul(3);
@@ -148,18 +147,18 @@ fn lbits(n3: &mut Big,n: &mut Big) -> usize {
/* prepare for multi-pairing */
pub fn initmp() -> [FP48; rom::ATE_BITS] {
let r: [FP48; rom::ATE_BITS] = [FP48::new_int(1); rom::ATE_BITS];
- return r
+ return r;
}
/* basic Miller loop */
-pub fn miller(r:&[FP48]) -> FP48 {
- let mut res=FP48::new_int(1);
+pub fn miller(r: &[FP48]) -> FP48 {
+ let mut res = FP48::new_int(1);
for i in (1..rom::ATE_BITS).rev() {
res.sqr();
res.ssmul(&r[i]);
}
- if ecp::SIGN_OF_X==SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
res.conj();
}
res.ssmul(&r[0]);
@@ -168,11 +167,11 @@ pub fn miller(r:&[FP48]) -> FP48 {
/* Accumulate another set of line functions for n-pairing */
#[allow(non_snake_case)]
-pub fn another(r:&mut [FP48],P1: &ECP8,Q1: &ECP) {
+pub fn another(r: &mut [FP48], P1: &ECP8, Q1: &ECP) {
let mut n = Big::new();
let mut n3 = Big::new();
-// P is needed in affine form for line function, Q for (Qx,Qy) extraction
+ // P is needed in affine form for line function, Q for (Qx,Qy) extraction
let mut P = ECP8::new();
P.copy(P1);
P.affine();
@@ -189,18 +188,18 @@ pub fn another(r:&mut [FP48],P1: &ECP8,Q1: &ECP) {
NP.copy(&P);
NP.neg();
- let nb=lbits(&mut n3,&mut n);
+ let nb = lbits(&mut n3, &mut n);
- for i in (1..nb-1).rev() {
- let mut lv=linedbl(&mut A,&qx,&qy);
+ for i in (1..nb - 1).rev() {
+ let mut lv = linedbl(&mut A, &qx, &qy);
- let bt=n3.bit(i)-n.bit(i);
- if bt==1 {
- let lv2=lineadd(&mut A,&P,&qx,&qy);
+ let bt = n3.bit(i) - n.bit(i);
+ if bt == 1 {
+ let lv2 = lineadd(&mut A, &P, &qx, &qy);
lv.smul(&lv2);
}
- if bt==-1 {
- let lv2=lineadd(&mut A,&NP,&qx,&qy);
+ if bt == -1 {
+ let lv2 = lineadd(&mut A, &NP, &qx, &qy);
lv.smul(&lv2);
}
r[i].ssmul(&lv);
@@ -231,7 +230,7 @@ pub fn ate(P1: &ECP8, Q1: &ECP) -> FP48 {
NP.copy(&P);
NP.neg();
- let nb=lbits(&mut n3,&mut n);
+ let nb = lbits(&mut n3, &mut n);
for i in (1..nb - 1).rev() {
r.sqr();
@@ -248,7 +247,7 @@ pub fn ate(P1: &ECP8, Q1: &ECP) -> FP48 {
r.ssmul(&lv);
}
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
r.conj();
}
@@ -294,30 +293,30 @@ pub fn ate2(P1: &ECP8, Q1: &ECP, R1: &ECP8, S1: &ECP) -> FP48 {
NR.copy(&R);
NR.neg();
- let nb=lbits(&mut n3,&mut n);
+ let nb = lbits(&mut n3, &mut n);
for i in (1..nb - 1).rev() {
r.sqr();
let mut lv = linedbl(&mut A, &qx, &qy);
let lv2 = linedbl(&mut B, &sx, &sy);
- lv.smul(&lv2);
+ lv.smul(&lv2);
r.ssmul(&lv);
let bt = n3.bit(i) - n.bit(i);
if bt == 1 {
lv = lineadd(&mut A, &P, &qx, &qy);
let lv2 = lineadd(&mut B, &R, &sx, &sy);
- lv.smul(&lv2);
+ lv.smul(&lv2);
r.ssmul(&lv);
}
if bt == -1 {
lv = lineadd(&mut A, &NP, &qx, &qy);
let lv2 = lineadd(&mut B, &NR, &sx, &sy);
- lv.smul(&lv2);
+ lv.smul(&lv2);
r.ssmul(&lv);
}
}
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
r.conj();
}
@@ -339,10 +338,10 @@ pub fn fexp(m: &FP48) -> FP48 {
lv.copy(&r);
r.frob(&f, 8);
r.mul(&lv);
-// if r.isunity() {
-// r.zero();
-// return r;
-// }
+ // if r.isunity() {
+ // r.zero();
+ // return r;
+ // }
/* Hard part of final exp */
// Ghamman & Fouotsa Method
@@ -354,7 +353,7 @@ pub fn fexp(m: &FP48) -> FP48 {
let mut t2 = t1.pow(&mut x);
x.fshl(1);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
t1.conj();
}
@@ -367,7 +366,7 @@ pub fn fexp(m: &FP48) -> FP48 {
t1.copy(&t2.pow(&mut x));
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
t1.conj();
}
t3.copy(&t1);
@@ -375,7 +374,7 @@ pub fn fexp(m: &FP48) -> FP48 {
r.mul(&t3);
lv.copy(&t1.pow(&mut x));
t1.copy(&lv);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
t1.conj();
}
@@ -384,7 +383,7 @@ pub fn fexp(m: &FP48) -> FP48 {
r.mul(&t3);
lv.copy(&t1.pow(&mut x));
t1.copy(&lv);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
t1.conj();
}
@@ -393,7 +392,7 @@ pub fn fexp(m: &FP48) -> FP48 {
r.mul(&t3);
lv.copy(&t1.pow(&mut x));
t1.copy(&lv);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
t1.conj();
}
@@ -402,7 +401,7 @@ pub fn fexp(m: &FP48) -> FP48 {
r.mul(&t3);
lv.copy(&t1.pow(&mut x));
t1.copy(&lv);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
t1.conj();
}
@@ -411,7 +410,7 @@ pub fn fexp(m: &FP48) -> FP48 {
r.mul(&t3);
lv.copy(&t1.pow(&mut x));
t1.copy(&lv);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
t1.conj();
}
@@ -420,7 +419,7 @@ pub fn fexp(m: &FP48) -> FP48 {
r.mul(&t3);
lv.copy(&t1.pow(&mut x));
t1.copy(&lv);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
t1.conj();
}
@@ -429,7 +428,7 @@ pub fn fexp(m: &FP48) -> FP48 {
r.mul(&t3);
lv.copy(&t1.pow(&mut x));
t1.copy(&lv);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
t1.conj();
}
@@ -441,7 +440,7 @@ pub fn fexp(m: &FP48) -> FP48 {
r.mul(&t3);
lv.copy(&t1.pow(&mut x));
t1.copy(&lv);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
t1.conj();
}
@@ -450,7 +449,7 @@ pub fn fexp(m: &FP48) -> FP48 {
r.mul(&t3);
lv.copy(&t1.pow(&mut x));
t1.copy(&lv);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
t1.conj();
}
@@ -459,7 +458,7 @@ pub fn fexp(m: &FP48) -> FP48 {
r.mul(&t3);
lv.copy(&t1.pow(&mut x));
t1.copy(&lv);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
t1.conj();
}
@@ -468,7 +467,7 @@ pub fn fexp(m: &FP48) -> FP48 {
r.mul(&t3);
lv.copy(&t1.pow(&mut x));
t1.copy(&lv);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
t1.conj();
}
@@ -477,7 +476,7 @@ pub fn fexp(m: &FP48) -> FP48 {
r.mul(&t3);
lv.copy(&t1.pow(&mut x));
t1.copy(&lv);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
t1.conj();
}
@@ -486,7 +485,7 @@ pub fn fexp(m: &FP48) -> FP48 {
r.mul(&t3);
lv.copy(&t1.pow(&mut x));
t1.copy(&lv);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
t1.conj();
}
@@ -495,7 +494,7 @@ pub fn fexp(m: &FP48) -> FP48 {
r.mul(&t3);
lv.copy(&t1.pow(&mut x));
t1.copy(&lv);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
t1.conj();
}
@@ -555,7 +554,7 @@ pub fn gs(e: &Big) -> [Big; 16] {
w.div(&x);
}
u[15].copy(&w);
- if ecp::SIGN_OF_X == SignOfX::NEGATIVEX {
+ if ecp::SIGN_OF_X == SignOfX::NegativeX {
let mut t = Big::new();
t.copy(&Big::modneg(&mut u[1], &q));
u[1].copy(&t);
diff --git a/src/rand.rs b/src/rand.rs
index 34c264d..1ef961a 100644
--- a/src/rand.rs
+++ b/src/rand.rs
@@ -158,7 +158,7 @@ impl RAND {
if self.pool_ptr >= 32 {
self.fill_pool()
}
- return (r & 0xff) as u8;
+ return u8::from(r);
}
}
diff --git a/src/roms/rom_anssi_32.rs b/src/roms/rom_anssi_32.rs
index 403fb04..3523fa4 100644
--- a/src/roms/rom_anssi_32.rs
+++ b/src/roms/rom_anssi_32.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use anssi::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use anssi::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 28
// anssi Modulus
@@ -61,13 +61,13 @@ pub const BASEBITS: usize = 28;
pub const MODBITS: usize = 256;
pub const MOD8: usize = 7;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 14;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_anssi_64.rs b/src/roms/rom_anssi_64.rs
index b0add0f..1c32ea1 100644
--- a/src/roms/rom_anssi_64.rs
+++ b/src/roms/rom_anssi_64.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use anssi::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use anssi::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 56
// anssi Modulus
@@ -79,13 +79,13 @@ pub const BASEBITS: usize = 56;
pub const MODBITS: usize = 256;
pub const MOD8: usize = 7;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 24;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_bls24_32.rs b/src/roms/rom_bls24_32.rs
index 72afe58..4a41136 100644
--- a/src/roms/rom_bls24_32.rs
+++ b/src/roms/rom_bls24_32.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use bls24::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use bls24::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 29
// bls24 Modulus
@@ -228,13 +228,13 @@ pub const BASEBITS: usize = 29;
pub const MODBITS: usize = 479;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 14;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::BLS;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::M_TYPE;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Bls;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::MType;
pub const ATE_BITS: usize = 49;
-pub const SIGN_OF_X: SignOfX = SignOfX::POSITIVEX;
+pub const SIGN_OF_X: SignOfX = SignOfX::PositiveX;
pub const HASH_TYPE: usize = 48;
pub const AESKEY: usize = 24;
diff --git a/src/roms/rom_bls24_64.rs b/src/roms/rom_bls24_64.rs
index 0c500da..8324005 100644
--- a/src/roms/rom_bls24_64.rs
+++ b/src/roms/rom_bls24_64.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use bls24::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use bls24::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 56
// bls24 Modulus
@@ -276,13 +276,13 @@ pub const BASEBITS: usize = 56;
pub const MODBITS: usize = 479;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 25;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::BLS;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::M_TYPE;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Bls;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::MType;
pub const ATE_BITS: usize = 49;
-pub const SIGN_OF_X: SignOfX = SignOfX::POSITIVEX;
+pub const SIGN_OF_X: SignOfX = SignOfX::PositiveX;
pub const HASH_TYPE: usize = 48;
pub const AESKEY: usize = 24;
diff --git a/src/roms/rom_bls381_32.rs b/src/roms/rom_bls381_32.rs
index 1ba0fe5..e282e9d 100644
--- a/src/roms/rom_bls381_32.rs
+++ b/src/roms/rom_bls381_32.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use bls381::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use bls381::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 29
// bls381 Modulus
@@ -197,13 +197,13 @@ pub const BASEBITS: usize = 29;
pub const MODBITS: usize = 381;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 14;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::BLS;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::M_TYPE;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Bls;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::MType;
pub const ATE_BITS: usize = 65;
-pub const SIGN_OF_X: SignOfX = SignOfX::NEGATIVEX;
+pub const SIGN_OF_X: SignOfX = SignOfX::NegativeX;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_bls381_64.rs b/src/roms/rom_bls381_64.rs
index 08df12c..4d95fdb 100644
--- a/src/roms/rom_bls381_64.rs
+++ b/src/roms/rom_bls381_64.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use bls381::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use bls381::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 58
// bls381 Modulus
@@ -199,13 +199,13 @@ pub const BASEBITS: usize = 58;
pub const MODBITS: usize = 381;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 25;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::BLS;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::M_TYPE;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Bls;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::MType;
pub const ATE_BITS: usize = 65;
-pub const SIGN_OF_X: SignOfX = SignOfX::NEGATIVEX;
+pub const SIGN_OF_X: SignOfX = SignOfX::NegativeX;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_bls383_32.rs b/src/roms/rom_bls383_32.rs
index 0ccb42d..b61a4dd 100644
--- a/src/roms/rom_bls383_32.rs
+++ b/src/roms/rom_bls383_32.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use bls383::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use bls383::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 29
pub const MODULUS: [Chunk; NLEN] = [
@@ -195,13 +195,13 @@ pub const BASEBITS: usize = 29;
pub const MODBITS: usize = 383;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 14;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::BLS;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::M_TYPE;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Bls;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::MType;
pub const ATE_BITS: usize = 65;
-pub const SIGN_OF_X: SignOfX = SignOfX::POSITIVEX;
+pub const SIGN_OF_X: SignOfX = SignOfX::PositiveX;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_bls383_64.rs b/src/roms/rom_bls383_64.rs
index 71bef66..af4d009 100644
--- a/src/roms/rom_bls383_64.rs
+++ b/src/roms/rom_bls383_64.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use bls383::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use bls383::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 58
pub const MODULUS: [Chunk; NLEN] = [
@@ -206,13 +206,13 @@ pub const BASEBITS: usize = 58;
pub const MODBITS: usize = 383;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 23;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::BLS;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::M_TYPE;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Bls;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::MType;
pub const ATE_BITS: usize = 65;
-pub const SIGN_OF_X: SignOfX = SignOfX::POSITIVEX;
+pub const SIGN_OF_X: SignOfX = SignOfX::PositiveX;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_bls461_32.rs b/src/roms/rom_bls461_32.rs
index c452a9f..65abfd5 100644
--- a/src/roms/rom_bls461_32.rs
+++ b/src/roms/rom_bls461_32.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use bls461::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use bls461::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 28
// bls461 Modulus
@@ -197,13 +197,13 @@ pub const BASEBITS: usize = 28;
pub const MODBITS: usize = 461;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 14;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::BLS;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::M_TYPE;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Bls;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::MType;
pub const ATE_BITS: usize = 78;
-pub const SIGN_OF_X: SignOfX = SignOfX::NEGATIVEX;
+pub const SIGN_OF_X: SignOfX = SignOfX::NegativeX;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_bls461_64.rs b/src/roms/rom_bls461_64.rs
index 500ef04..e0fb356 100644
--- a/src/roms/rom_bls461_64.rs
+++ b/src/roms/rom_bls461_64.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use bls461::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use bls461::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 60
// bls461 Modulus
@@ -220,13 +220,13 @@ pub const BASEBITS: usize = 60;
pub const MODBITS: usize = 461;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 19;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::BLS;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::M_TYPE;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Bls;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::MType;
pub const ATE_BITS: usize = 78;
-pub const SIGN_OF_X: SignOfX = SignOfX::NEGATIVEX;
+pub const SIGN_OF_X: SignOfX = SignOfX::NegativeX;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_bls48_32.rs b/src/roms/rom_bls48_32.rs
index 83517a8..13fafe1 100644
--- a/src/roms/rom_bls48_32.rs
+++ b/src/roms/rom_bls48_32.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use bls48::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use bls48::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 29
// bls48 Modulus
@@ -297,13 +297,13 @@ pub const BASEBITS: usize = 29;
pub const MODBITS: usize = 556;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 14;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::BLS;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::M_TYPE;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Bls;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::MType;
pub const ATE_BITS: usize = 32;
-pub const SIGN_OF_X: SignOfX = SignOfX::POSITIVEX;
+pub const SIGN_OF_X: SignOfX = SignOfX::PositiveX;
pub const HASH_TYPE: usize = 64;
pub const AESKEY: usize = 32;
diff --git a/src/roms/rom_bls48_64.rs b/src/roms/rom_bls48_64.rs
index 129c776..3b63ce7 100644
--- a/src/roms/rom_bls48_64.rs
+++ b/src/roms/rom_bls48_64.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use bls48::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use bls48::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 58
// bls48 Modulus
@@ -389,13 +389,13 @@ pub const BASEBITS: usize = 58;
pub const MODBITS: usize = 556;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 24;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::BLS;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::M_TYPE;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Bls;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::MType;
pub const ATE_BITS: usize = 32;
-pub const SIGN_OF_X: SignOfX = SignOfX::POSITIVEX;
+pub const SIGN_OF_X: SignOfX = SignOfX::PositiveX;
pub const HASH_TYPE: usize = 64;
pub const AESKEY: usize = 32;
diff --git a/src/roms/rom_bn254CX_32.rs b/src/roms/rom_bn254CX_32.rs
index e1cff0d..a6e7ef8 100644
--- a/src/roms/rom_bn254CX_32.rs
+++ b/src/roms/rom_bn254CX_32.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use bn254CX::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use bn254CX::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 28
// bn254CX Modulus
@@ -171,13 +171,13 @@ pub const BASEBITS: usize = 28;
pub const MODBITS: usize = 254;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 14;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::BN;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::D_TYPE;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Bn;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::DType;
pub const ATE_BITS: usize = 66;
-pub const SIGN_OF_X: SignOfX = SignOfX::NEGATIVEX;
+pub const SIGN_OF_X: SignOfX = SignOfX::NegativeX;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_bn254CX_64.rs b/src/roms/rom_bn254CX_64.rs
index 7f6d274..75d4c28 100644
--- a/src/roms/rom_bn254CX_64.rs
+++ b/src/roms/rom_bn254CX_64.rs
@@ -17,10 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use bn254CX::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
-
+use bn254CX::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 56
// bn254CX Modulus
@@ -230,13 +229,13 @@ pub const BASEBITS: usize = 56;
pub const MODBITS: usize = 254;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 64;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::BN;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::D_TYPE;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Bn;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::DType;
pub const ATE_BITS: usize = 66;
-pub const SIGN_OF_X: SignOfX = SignOfX::NEGATIVEX;
+pub const SIGN_OF_X: SignOfX = SignOfX::NegativeX;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_bn254_32.rs b/src/roms/rom_bn254_32.rs
index c9ae5ec..1899c4a 100644
--- a/src/roms/rom_bn254_32.rs
+++ b/src/roms/rom_bn254_32.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use bn254::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use bn254::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 28
pub const MODULUS: [Chunk; NLEN] = [
@@ -159,13 +159,13 @@ pub const BASEBITS: usize = 28;
pub const MODBITS: usize = 254;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 14;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::BN;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::D_TYPE;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Bn;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::DType;
pub const ATE_BITS: usize = 66;
-pub const SIGN_OF_X: SignOfX = SignOfX::NEGATIVEX;
+pub const SIGN_OF_X: SignOfX = SignOfX::NegativeX;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_bn254_64.rs b/src/roms/rom_bn254_64.rs
index f61b542..08502f3 100644
--- a/src/roms/rom_bn254_64.rs
+++ b/src/roms/rom_bn254_64.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use bn254::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use bn254::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// BN254 Modulus
// Base Bits= 56
@@ -196,13 +196,13 @@ pub const BASEBITS: usize = 56;
pub const MODBITS: usize = 254;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 26;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::BN;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::D_TYPE;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Bn;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::DType;
pub const ATE_BITS: usize = 66;
-pub const SIGN_OF_X: SignOfX = SignOfX::NEGATIVEX;
+pub const SIGN_OF_X: SignOfX = SignOfX::NegativeX;
pub const HASH_TYPE: usize = 32;
-pub const AESKEY: usize = 16;
\ No newline at end of file
+pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_brainpool_32.rs b/src/roms/rom_brainpool_32.rs
index b788632..17b1268 100644
--- a/src/roms/rom_brainpool_32.rs
+++ b/src/roms/rom_brainpool_32.rs
@@ -19,9 +19,9 @@ under the License.
/* Note that the original curve has been transformed to an isomorphic curve with A=-3 */
-use brainpool::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use brainpool::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 28
// brainpool Modulus
@@ -62,13 +62,13 @@ pub const BASEBITS: usize = 28;
pub const MODBITS: usize = 256;
pub const MOD8: usize = 7;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 14;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_brainpool_64.rs b/src/roms/rom_brainpool_64.rs
index 8191561..89a445e 100644
--- a/src/roms/rom_brainpool_64.rs
+++ b/src/roms/rom_brainpool_64.rs
@@ -19,9 +19,9 @@ under the License.
/* Note that the original curve has been transformed to an isomorphic curve with A=-3 */
-use brainpool::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use brainpool::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 56
// brainpool Modulus
@@ -80,13 +80,13 @@ pub const BASEBITS: usize = 56;
pub const MODBITS: usize = 256;
pub const MOD8: usize = 7;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 24;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const ATE_BITS: usize = 0;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_c25519_32.rs b/src/roms/rom_c25519_32.rs
index 6da6a05..d07207e 100644
--- a/src/roms/rom_c25519_32.rs
+++ b/src/roms/rom_c25519_32.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use c25519::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use c25519::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 29
// Curve25519 Modulus
@@ -47,13 +47,13 @@ pub const BASEBITS: usize = 29;
pub const MODBITS: usize = 255;
pub const MOD8: usize = 5;
-pub const MODTYPE: ModType = ModType::PSEUDO_MERSENNE;
+pub const MODTYPE: ModType = ModType::PseudoMersenne;
pub const SH: usize = 6;
-pub const CURVETYPE: CurveType = CurveType::MONTGOMERY;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Montgomery;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_c25519_64.rs b/src/roms/rom_c25519_64.rs
index 9a8c59f..42b1d70 100644
--- a/src/roms/rom_c25519_64.rs
+++ b/src/roms/rom_c25519_64.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use c25519::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use c25519::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 56
// Curve25519 Modulus
@@ -49,13 +49,13 @@ pub const BASEBITS: usize = 56;
pub const MODBITS: usize = 255;
pub const MOD8: usize = 5;
-pub const MODTYPE: ModType = ModType::PSEUDO_MERSENNE;
+pub const MODTYPE: ModType = ModType::PseudoMersenne;
pub const SH: usize = 25;
-pub const CURVETYPE: CurveType = CurveType::MONTGOMERY;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Montgomery;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_c41417_32.rs b/src/roms/rom_c41417_32.rs
index a8330cb..c471f76 100644
--- a/src/roms/rom_c41417_32.rs
+++ b/src/roms/rom_c41417_32.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use c41417::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use c41417::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 29
// c41417 Modulus
@@ -59,13 +59,13 @@ pub const BASEBITS: usize = 29;
pub const MODBITS: usize = 414;
pub const MOD8: usize = 7;
-pub const MODTYPE: ModType = ModType::PSEUDO_MERSENNE;
+pub const MODTYPE: ModType = ModType::PseudoMersenne;
pub const SH: usize = 14;
-pub const CURVETYPE: CurveType = CurveType::EDWARDS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Edwards;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 64;
pub const AESKEY: usize = 32;
diff --git a/src/roms/rom_c41417_64.rs b/src/roms/rom_c41417_64.rs
index 52b51b1..3a2ef58 100644
--- a/src/roms/rom_c41417_64.rs
+++ b/src/roms/rom_c41417_64.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use c41417::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use c41417::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 60
// c41417 Modulus
@@ -66,13 +66,13 @@ pub const BASEBITS: usize = 60;
pub const MODBITS: usize = 414;
pub const MOD8: usize = 7;
-pub const MODTYPE: ModType = ModType::PSEUDO_MERSENNE;
+pub const MODTYPE: ModType = ModType::PseudoMersenne;
pub const SH: usize = 6;
-pub const CURVETYPE: CurveType = CurveType::EDWARDS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Edwards;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 64;
pub const AESKEY: usize = 32;
diff --git a/src/roms/rom_ed25519_32.rs b/src/roms/rom_ed25519_32.rs
index be1d156..c866d50 100644
--- a/src/roms/rom_ed25519_32.rs
+++ b/src/roms/rom_ed25519_32.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use ed25519::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use ed25519::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 29
// Curve25519 Modulus
@@ -56,13 +56,13 @@ pub const BASEBITS: usize = 29;
pub const MODBITS: usize = 255;
pub const MOD8: usize = 5;
-pub const MODTYPE: ModType = ModType::PSEUDO_MERSENNE;
+pub const MODTYPE: ModType = ModType::PseudoMersenne;
pub const SH: usize = 6;
-pub const CURVETYPE: CurveType = CurveType::EDWARDS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Edwards;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_ed25519_64.rs b/src/roms/rom_ed25519_64.rs
index cf23672..a26461b 100644
--- a/src/roms/rom_ed25519_64.rs
+++ b/src/roms/rom_ed25519_64.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use ed25519::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use ed25519::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 56
// Curve25519 Modulus
@@ -67,13 +67,13 @@ pub const BASEBITS: usize = 56;
pub const MODBITS: usize = 255;
pub const MOD8: usize = 5;
-pub const MODTYPE: ModType = ModType::PSEUDO_MERSENNE;
+pub const MODTYPE: ModType = ModType::PseudoMersenne;
pub const SH: usize = 25;
-pub const CURVETYPE: CurveType = CurveType::EDWARDS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Edwards;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_fp256bn_32.rs b/src/roms/rom_fp256bn_32.rs
index e3cabe1..0f196b0 100644
--- a/src/roms/rom_fp256bn_32.rs
+++ b/src/roms/rom_fp256bn_32.rs
@@ -17,10 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use fp256bn::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
-
+use fp256bn::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 28
pub const MODULUS: [Chunk; NLEN] = [
@@ -168,13 +167,13 @@ pub const BASEBITS: usize = 28;
pub const MODBITS: usize = 256;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 14;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::BN;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::M_TYPE;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Bn;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::MType;
pub const ATE_BITS: usize = 66;
-pub const SIGN_OF_X: SignOfX = SignOfX::NEGATIVEX;
+pub const SIGN_OF_X: SignOfX = SignOfX::NegativeX;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_fp256bn_64.rs b/src/roms/rom_fp256bn_64.rs
index bde7639..d1a38b9 100644
--- a/src/roms/rom_fp256bn_64.rs
+++ b/src/roms/rom_fp256bn_64.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use fp256bn::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use fp256bn::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// fp256bn Modulus
// Base Bits= 56
@@ -221,13 +221,13 @@ pub const BASEBITS: usize = 56;
pub const MODBITS: usize = 256;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 24;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::BN;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::M_TYPE;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Bn;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::MType;
pub const ATE_BITS: usize = 66;
-pub const SIGN_OF_X: SignOfX = SignOfX::NEGATIVEX;
+pub const SIGN_OF_X: SignOfX = SignOfX::NegativeX;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_fp512bn_32.rs b/src/roms/rom_fp512bn_32.rs
index cdc44af..e18646b 100644
--- a/src/roms/rom_fp512bn_32.rs
+++ b/src/roms/rom_fp512bn_32.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use fp512bn::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use fp512bn::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 29
pub const MODULUS: [Chunk; NLEN] = [
@@ -237,13 +237,13 @@ pub const BASEBITS: usize = 28;
pub const MODBITS: usize = 512;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 10;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::BN;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::M_TYPE;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Bn;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::MType;
pub const ATE_BITS: usize = 130;
-pub const SIGN_OF_X: SignOfX = SignOfX::POSITIVEX;
+pub const SIGN_OF_X: SignOfX = SignOfX::PositiveX;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_fp512bn_64.rs b/src/roms/rom_fp512bn_64.rs
index 54d85c4..a3e5f57 100644
--- a/src/roms/rom_fp512bn_64.rs
+++ b/src/roms/rom_fp512bn_64.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use fp512bn::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use fp512bn::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 60
pub const MODULUS: [Chunk; NLEN] = [
@@ -470,13 +470,13 @@ pub const BASEBITS: usize = 60;
pub const MODBITS: usize = 512;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 28;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::BN;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::M_TYPE;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Bn;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::MType;
pub const ATE_BITS: usize = 130;
-pub const SIGN_OF_X: SignOfX = SignOfX::POSITIVEX;
+pub const SIGN_OF_X: SignOfX = SignOfX::PositiveX;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_goldilocks_32.rs b/src/roms/rom_goldilocks_32.rs
index 5d5f8bb..096ff30 100644
--- a/src/roms/rom_goldilocks_32.rs
+++ b/src/roms/rom_goldilocks_32.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use goldilocks::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use goldilocks::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 29
// Goldilocks modulus
@@ -61,13 +61,13 @@ pub const BASEBITS: usize = 29;
pub const MODBITS: usize = 448;
pub const MOD8: usize = 7;
-pub const MODTYPE: ModType = ModType::GENERALISED_MERSENNE;
+pub const MODTYPE: ModType = ModType::GeneralisedMersenne;
pub const SH: usize = 14;
-pub const CURVETYPE: CurveType = CurveType::EDWARDS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Edwards;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 64;
pub const AESKEY: usize = 32;
diff --git a/src/roms/rom_goldilocks_64.rs b/src/roms/rom_goldilocks_64.rs
index d6cadf1..6547052 100644
--- a/src/roms/rom_goldilocks_64.rs
+++ b/src/roms/rom_goldilocks_64.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use goldilocks::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use goldilocks::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 58
// Goldilocks modulus
@@ -87,13 +87,13 @@ pub const BASEBITS: usize = 58;
pub const MODBITS: usize = 448;
pub const MOD8: usize = 7;
-pub const MODTYPE: ModType = ModType::GENERALISED_MERSENNE;
+pub const MODTYPE: ModType = ModType::GeneralisedMersenne;
pub const SH: usize = 16;
-pub const CURVETYPE: CurveType = CurveType::EDWARDS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Edwards;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 64;
pub const AESKEY: usize = 32;
diff --git a/src/roms/rom_hifive_32.rs b/src/roms/rom_hifive_32.rs
index cfa9f59..01dcb03 100644
--- a/src/roms/rom_hifive_32.rs
+++ b/src/roms/rom_hifive_32.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use hifive::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use hifive::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 29
@@ -56,13 +56,13 @@ pub const BASEBITS: usize = 29;
pub const MODBITS: usize = 336;
pub const MOD8: usize = 5;
-pub const MODTYPE: ModType = ModType::PSEUDO_MERSENNE;
+pub const MODTYPE: ModType = ModType::PseudoMersenne;
pub const SH: usize = 12;
-pub const CURVETYPE: CurveType = CurveType::EDWARDS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Edwards;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 48;
pub const AESKEY: usize = 24;
diff --git a/src/roms/rom_hifive_64.rs b/src/roms/rom_hifive_64.rs
index b2eebb9..f7b5621 100644
--- a/src/roms/rom_hifive_64.rs
+++ b/src/roms/rom_hifive_64.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use hifive::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use hifive::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 60
@@ -65,13 +65,13 @@ pub const BASEBITS: usize = 60;
pub const MODBITS: usize = 336;
pub const MOD8: usize = 5;
-pub const MODTYPE: ModType = ModType::PSEUDO_MERSENNE;
+pub const MODTYPE: ModType = ModType::PseudoMersenne;
pub const SH: usize = 24;
-pub const CURVETYPE: CurveType = CurveType::EDWARDS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Edwards;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 48;
pub const AESKEY: usize = 24;
diff --git a/src/roms/rom_nist256_32.rs b/src/roms/rom_nist256_32.rs
index 6859da5..12c47f9 100644
--- a/src/roms/rom_nist256_32.rs
+++ b/src/roms/rom_nist256_32.rs
@@ -19,9 +19,9 @@ under the License.
/* Fixed Data in ROM - Field and Curve parameters */
-use nist256::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use nist256::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 28
@@ -45,8 +45,7 @@ pub const CURVE_B: [Chunk; NLEN] = [
0xAC635D8, 0x5,
];
pub const CURVE_ORDER: [Chunk; NLEN] = [
- 0xC632551, 0xB9CAC2F, 0x79E84F3, 0xFAADA71, 0xFFFBCE6, 0xFFFFFFF, 0xFFFFFF, 0x0, 0xFFFFFFF,
- 0xF,
+ 0xC632551, 0xB9CAC2F, 0x79E84F3, 0xFAADA71, 0xFFFBCE6, 0xFFFFFFF, 0xFFFFFF, 0x0, 0xFFFFFFF, 0xF,
];
pub const CURVE_GX: [Chunk; NLEN] = [
0x898C296, 0xA13945D, 0xB33A0F4, 0x7D812DE, 0xF27703, 0xE563A44, 0x7F8BCE6, 0xE12C424,
@@ -62,13 +61,13 @@ pub const BASEBITS: usize = 28;
pub const MODBITS: usize = 256;
pub const MOD8: usize = 7;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 14;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_nist256_64.rs b/src/roms/rom_nist256_64.rs
index 015bbb3..5da758c 100644
--- a/src/roms/rom_nist256_64.rs
+++ b/src/roms/rom_nist256_64.rs
@@ -19,9 +19,9 @@ under the License.
/* Fixed Data in ROM - Field and Curve parameters */
-use nist256::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use nist256::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 56
// nist256 modulus
@@ -74,13 +74,13 @@ pub const BASEBITS: usize = 56;
pub const MODBITS: usize = 256;
pub const MOD8: usize = 7;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 24;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_nist384_32.rs b/src/roms/rom_nist384_32.rs
index 48d7826..2939f30 100644
--- a/src/roms/rom_nist384_32.rs
+++ b/src/roms/rom_nist384_32.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use nist384::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use nist384::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 29
@@ -64,13 +64,13 @@ pub const BASEBITS: usize = 29;
pub const MODBITS: usize = 384;
pub const MOD8: usize = 7;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 14;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 48;
pub const AESKEY: usize = 24;
diff --git a/src/roms/rom_nist384_64.rs b/src/roms/rom_nist384_64.rs
index f0f5c69..4654ec6 100644
--- a/src/roms/rom_nist384_64.rs
+++ b/src/roms/rom_nist384_64.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use nist384::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use nist384::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 56
@@ -44,7 +44,6 @@ pub const R2MODP: [Chunk; NLEN] = [
];
pub const MCONST: Chunk = 0x100000001;
-
// nist384 Curve
pub const CURVE_COF_I: isize = 1;
pub const CURVE_A: isize = -3;
@@ -92,13 +91,13 @@ pub const BASEBITS: usize = 56;
pub const MODBITS: usize = 384;
pub const MOD8: usize = 7;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 8;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 48;
pub const AESKEY: usize = 24;
diff --git a/src/roms/rom_nist521_32.rs b/src/roms/rom_nist521_32.rs
index 55cbf30..7a74956 100644
--- a/src/roms/rom_nist521_32.rs
+++ b/src/roms/rom_nist521_32.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use nist521::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use nist521::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 28
// nist521 Modulus
@@ -67,13 +67,13 @@ pub const BASEBITS: usize = 28;
pub const MODBITS: usize = 521;
pub const MOD8: usize = 7;
-pub const MODTYPE: ModType = ModType::PSEUDO_MERSENNE;
+pub const MODTYPE: ModType = ModType::PseudoMersenne;
pub const SH: usize = 11;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 64;
pub const AESKEY: usize = 32;
diff --git a/src/roms/rom_nist521_64.rs b/src/roms/rom_nist521_64.rs
index bf241b2..dec3c9c 100644
--- a/src/roms/rom_nist521_64.rs
+++ b/src/roms/rom_nist521_64.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use nist521::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use nist521::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 60
// nist521 Modulus
@@ -92,13 +92,13 @@ pub const BASEBITS: usize = 60;
pub const MODBITS: usize = 521;
pub const MOD8: usize = 7;
-pub const MODTYPE: ModType = ModType::PSEUDO_MERSENNE;
+pub const MODTYPE: ModType = ModType::PseudoMersenne;
pub const SH: usize = 19;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 64;
pub const AESKEY: usize = 32;
diff --git a/src/roms/rom_nums256e_32.rs b/src/roms/rom_nums256e_32.rs
index 45506bd..b1d20c3 100644
--- a/src/roms/rom_nums256e_32.rs
+++ b/src/roms/rom_nums256e_32.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use nums256e::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use nums256e::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 29
@@ -58,14 +58,13 @@ pub const BASEBITS: usize = 29;
pub const MODBITS: usize = 256;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::PSEUDO_MERSENNE;
+pub const MODTYPE: ModType = ModType::PseudoMersenne;
pub const SH: usize = 5;
-pub const CURVETYPE: CurveType = CurveType::EDWARDS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Edwards;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
-
diff --git a/src/roms/rom_nums256e_64.rs b/src/roms/rom_nums256e_64.rs
index 4382924..b8ac09e 100644
--- a/src/roms/rom_nums256e_64.rs
+++ b/src/roms/rom_nums256e_64.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use nums256e::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use nums256e::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 56
// nums256 Modulus
@@ -67,14 +67,13 @@ pub const BASEBITS: usize = 56;
pub const MODBITS: usize = 256;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::PSEUDO_MERSENNE;
+pub const MODTYPE: ModType = ModType::PseudoMersenne;
pub const SH: usize = 24;
-pub const CURVETYPE: CurveType = CurveType::EDWARDS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Edwards;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
-
diff --git a/src/roms/rom_nums256w_32.rs b/src/roms/rom_nums256w_32.rs
index b768380..4ffb798 100644
--- a/src/roms/rom_nums256w_32.rs
+++ b/src/roms/rom_nums256w_32.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use nums256w::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use nums256w::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 28
// nums256 modulus
@@ -54,13 +54,13 @@ pub const BASEBITS: usize = 28;
pub const MODBITS: usize = 256;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::PSEUDO_MERSENNE;
+pub const MODTYPE: ModType = ModType::PseudoMersenne;
pub const SH: usize = 14;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_nums256w_64.rs b/src/roms/rom_nums256w_64.rs
index 5b5d491..be3b7ff 100644
--- a/src/roms/rom_nums256w_64.rs
+++ b/src/roms/rom_nums256w_64.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use nums256w::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use nums256w::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 56
// nums256 Modulus
@@ -66,13 +66,13 @@ pub const BASEBITS: usize = 56;
pub const MODBITS: usize = 256;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::PSEUDO_MERSENNE;
+pub const MODTYPE: ModType = ModType::PseudoMersenne;
pub const SH: usize = 24;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_nums384e_32.rs b/src/roms/rom_nums384e_32.rs
index eaad1c8..787f4c1 100644
--- a/src/roms/rom_nums384e_32.rs
+++ b/src/roms/rom_nums384e_32.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use nums384e::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use nums384e::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 29
// nums384 Modulus
@@ -61,14 +61,13 @@ pub const BASEBITS: usize = 29;
pub const MODBITS: usize = 384;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::PSEUDO_MERSENNE;
+pub const MODTYPE: ModType = ModType::PseudoMersenne;
pub const SH: usize = 14;
-pub const CURVETYPE: CurveType = CurveType::EDWARDS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Edwards;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 48;
pub const AESKEY: usize = 24;
-
diff --git a/src/roms/rom_nums384e_64.rs b/src/roms/rom_nums384e_64.rs
index 08d83c2..a1a4318 100644
--- a/src/roms/rom_nums384e_64.rs
+++ b/src/roms/rom_nums384e_64.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use nums384e::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use nums384e::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 56
// nums384 Modulus
@@ -82,14 +82,13 @@ pub const BASEBITS: usize = 56;
pub const MODBITS: usize = 384;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::PSEUDO_MERSENNE;
+pub const MODTYPE: ModType = ModType::PseudoMersenne;
pub const SH: usize = 8;
-pub const CURVETYPE: CurveType = CurveType::EDWARDS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Edwards;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 48;
pub const AESKEY: usize = 24;
-
diff --git a/src/roms/rom_nums384w_32.rs b/src/roms/rom_nums384w_32.rs
index 92181a6..74d5216 100644
--- a/src/roms/rom_nums384w_32.rs
+++ b/src/roms/rom_nums384w_32.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use nums384w::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use nums384w::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 29
// nums384 Modulus
@@ -61,14 +61,13 @@ pub const BASEBITS: usize = 29;
pub const MODBITS: usize = 384;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::PSEUDO_MERSENNE;
+pub const MODTYPE: ModType = ModType::PseudoMersenne;
pub const SH: usize = 14;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 48;
pub const AESKEY: usize = 24;
-
diff --git a/src/roms/rom_nums384w_64.rs b/src/roms/rom_nums384w_64.rs
index 3f51d94..bd057e2 100644
--- a/src/roms/rom_nums384w_64.rs
+++ b/src/roms/rom_nums384w_64.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use nums384w::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use nums384w::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 58
// nums384 Modulus
@@ -81,14 +81,13 @@ pub const BASEBITS: usize = 58;
pub const MODBITS: usize = 384;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::PSEUDO_MERSENNE;
+pub const MODTYPE: ModType = ModType::PseudoMersenne;
pub const SH: usize = 22;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 48;
pub const AESKEY: usize = 24;
-
diff --git a/src/roms/rom_nums512e_32.rs b/src/roms/rom_nums512e_32.rs
index 8d53f9f..48ca9ea 100644
--- a/src/roms/rom_nums512e_32.rs
+++ b/src/roms/rom_nums512e_32.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use nums512e::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use nums512e::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 29
// nums512 Modulus
@@ -67,13 +67,13 @@ pub const BASEBITS: usize = 29;
pub const MODBITS: usize = 512;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::PSEUDO_MERSENNE;
+pub const MODTYPE: ModType = ModType::PseudoMersenne;
pub const SH: usize = 10;
-pub const CURVETYPE: CurveType = CurveType::EDWARDS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Edwards;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 64;
pub const AESKEY: usize = 32;
diff --git a/src/roms/rom_nums512e_64.rs b/src/roms/rom_nums512e_64.rs
index 298f3cc..f645d85 100644
--- a/src/roms/rom_nums512e_64.rs
+++ b/src/roms/rom_nums512e_64.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use nums512e::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use nums512e::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 60
// nums512 Modulus
@@ -92,13 +92,13 @@ pub const BASEBITS: usize = 60;
pub const MODBITS: usize = 512;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::PSEUDO_MERSENNE;
+pub const MODTYPE: ModType = ModType::PseudoMersenne;
pub const SH: usize = 28;
-pub const CURVETYPE: CurveType = CurveType::EDWARDS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Edwards;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 64;
pub const AESKEY: usize = 32;
diff --git a/src/roms/rom_nums512w_32.rs b/src/roms/rom_nums512w_32.rs
index 785070c..c787795 100644
--- a/src/roms/rom_nums512w_32.rs
+++ b/src/roms/rom_nums512w_32.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use nums512w::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use nums512w::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 29
// nums512 Modulus
@@ -65,13 +65,13 @@ pub const BASEBITS: usize = 29;
pub const MODBITS: usize = 512;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::PSEUDO_MERSENNE;
+pub const MODTYPE: ModType = ModType::PseudoMersenne;
pub const SH: usize = 10;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 64;
pub const AESKEY: usize = 32;
diff --git a/src/roms/rom_nums512w_64.rs b/src/roms/rom_nums512w_64.rs
index 6868c87..79ed127 100644
--- a/src/roms/rom_nums512w_64.rs
+++ b/src/roms/rom_nums512w_64.rs
@@ -17,9 +17,9 @@ specific language governing permissions and limitations
under the License.
*/
-use nums512w::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use nums512w::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 60
// nums512 Modulus
@@ -82,13 +82,13 @@ pub const BASEBITS: usize = 60;
pub const MODBITS: usize = 512;
pub const MOD8: usize = 3;
-pub const MODTYPE: ModType = ModType::PSEUDO_MERSENNE;
+pub const MODTYPE: ModType = ModType::PseudoMersenne;
pub const SH: usize = 28;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 64;
pub const AESKEY: usize = 32;
diff --git a/src/roms/rom_rsa2048_32.rs b/src/roms/rom_rsa2048_32.rs
index 6dd06a6..29b5a60 100644
--- a/src/roms/rom_rsa2048_32.rs
+++ b/src/roms/rom_rsa2048_32.rs
@@ -1,3 +1,3 @@
pub const MODBYTES: usize = 128;
pub const BASEBITS: usize = 28;
-pub const FFLEN: usize = 2;
\ No newline at end of file
+pub const FFLEN: usize = 2;
diff --git a/src/roms/rom_rsa2048_64.rs b/src/roms/rom_rsa2048_64.rs
index be3ba0d..4caac22 100644
--- a/src/roms/rom_rsa2048_64.rs
+++ b/src/roms/rom_rsa2048_64.rs
@@ -1,3 +1,3 @@
pub const MODBYTES: usize = 128;
pub const BASEBITS: usize = 58;
-pub const FFLEN: usize = 2;
\ No newline at end of file
+pub const FFLEN: usize = 2;
diff --git a/src/roms/rom_rsa3072_32.rs b/src/roms/rom_rsa3072_32.rs
index d5622e2..62b929e 100644
--- a/src/roms/rom_rsa3072_32.rs
+++ b/src/roms/rom_rsa3072_32.rs
@@ -1,3 +1,3 @@
pub const MODBYTES: usize = 48;
pub const BASEBITS: usize = 28;
-pub const FFLEN: usize = 8;
\ No newline at end of file
+pub const FFLEN: usize = 8;
diff --git a/src/roms/rom_rsa3072_64.rs b/src/roms/rom_rsa3072_64.rs
index 4d1ed2b..ef66da7 100644
--- a/src/roms/rom_rsa3072_64.rs
+++ b/src/roms/rom_rsa3072_64.rs
@@ -1,3 +1,3 @@
pub const MODBYTES: usize = 48;
pub const BASEBITS: usize = 58;
-pub const FFLEN: usize = 8;
\ No newline at end of file
+pub const FFLEN: usize = 8;
diff --git a/src/roms/rom_rsa4096_32.rs b/src/roms/rom_rsa4096_32.rs
index 223cb7d..16ade15 100644
--- a/src/roms/rom_rsa4096_32.rs
+++ b/src/roms/rom_rsa4096_32.rs
@@ -1,3 +1,3 @@
pub const MODBYTES: usize = 64;
pub const BASEBITS: usize = 29;
-pub const FFLEN: usize = 8;
\ No newline at end of file
+pub const FFLEN: usize = 8;
diff --git a/src/roms/rom_rsa4096_64.rs b/src/roms/rom_rsa4096_64.rs
index 77d3eb6..e8ebfc6 100644
--- a/src/roms/rom_rsa4096_64.rs
+++ b/src/roms/rom_rsa4096_64.rs
@@ -1,3 +1,3 @@
pub const MODBYTES: usize = 64;
pub const BASEBITS: usize = 60;
-pub const FFLEN: usize = 8;
\ No newline at end of file
+pub const FFLEN: usize = 8;
diff --git a/src/roms/rom_secp256k1_32.rs b/src/roms/rom_secp256k1_32.rs
index 94bbbaa..cb9b32b 100644
--- a/src/roms/rom_secp256k1_32.rs
+++ b/src/roms/rom_secp256k1_32.rs
@@ -19,9 +19,9 @@ under the License.
/* Fixed Data in ROM - Field and Curve parameters */
-use secp256k1::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use secp256k1::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 28
// secp256k1 modulus
@@ -58,13 +58,13 @@ pub const BASEBITS: usize = 28;
pub const MODBITS: usize = 256;
pub const MOD8: usize = 7;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 14;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/roms/rom_secp256k1_64.rs b/src/roms/rom_secp256k1_64.rs
index b22d875..0b100b6 100644
--- a/src/roms/rom_secp256k1_64.rs
+++ b/src/roms/rom_secp256k1_64.rs
@@ -19,9 +19,9 @@ under the License.
/* Fixed Data in ROM - Field and Curve parameters */
-use secp256k1::big::NLEN;
use super::super::arch::Chunk;
-use types::{ModType, CurveType, CurvePairingType, SexticTwist, SignOfX};
+use secp256k1::big::NLEN;
+use types::{CurvePairingType, CurveType, ModType, SexticTwist, SignOfX};
// Base Bits= 56
@@ -69,13 +69,13 @@ pub const BASEBITS: usize = 56;
pub const MODBITS: usize = 256;
pub const MOD8: usize = 7;
-pub const MODTYPE: ModType = ModType::NOT_SPECIAL;
+pub const MODTYPE: ModType = ModType::NotSpecial;
pub const SH: usize = 24;
-pub const CURVETYPE: CurveType = CurveType::WEIERSTRASS;
-pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::NOT;
-pub const SEXTIC_TWIST: SexticTwist = SexticTwist::NOT;
+pub const CURVETYPE: CurveType = CurveType::Weierstrass;
+pub const CURVE_PAIRING_TYPE: CurvePairingType = CurvePairingType::Not;
+pub const SEXTIC_TWIST: SexticTwist = SexticTwist::Not;
pub const ATE_BITS: usize = 0;
-pub const SIGN_OF_X: SignOfX = SignOfX::NOT;
+pub const SIGN_OF_X: SignOfX = SignOfX::Not;
pub const HASH_TYPE: usize = 32;
pub const AESKEY: usize = 16;
diff --git a/src/sha3.rs b/src/sha3.rs
index eeaf953..710d20e 100644
--- a/src/sha3.rs
+++ b/src/sha3.rs
@@ -162,7 +162,7 @@ impl SHA3 {
let ind = cnt / 8;
let i = ind % 5;
let j = ind / 5;
- self.s[i][j] ^= ((byt & 0xff) as u64) << (8 * b);
+ self.s[i][j] ^= u64::from(byt) << (8 * b);
self.length += 1;
if cnt + 1 == self.rate {
self.transform();
diff --git a/src/types.rs b/src/types.rs
index ea310d7..9db4257 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -1,45 +1,44 @@
#[derive(PartialEq)]
pub enum ModType {
- NOT_SPECIAL,
- PSEUDO_MERSENNE,
- MONTGOMERY_FRIENDLY,
- GENERALISED_MERSENNE,
+ NotSpecial,
+ PseudoMersenne,
+ MontgomeryFriendly,
+ GeneralisedMersenne,
}
#[derive(PartialEq)]
pub enum CurveType {
- EDWARDS,
- WEIERSTRASS,
- MONTGOMERY,
+ Edwards,
+ Weierstrass,
+ Montgomery,
}
#[derive(PartialEq)]
pub enum CurvePairingType {
- NOT,
- BN,
- BLS,
+ Not,
+ Bn,
+ Bls,
}
#[derive(PartialEq)]
pub enum SexticTwist {
- NOT,
- D_TYPE,
- M_TYPE,
+ Not,
+ DType,
+ MType,
}
impl Into<usize> for SexticTwist {
fn into(self) -> usize {
match self {
- SexticTwist::NOT => 0,
- SexticTwist::D_TYPE => 0,
- SexticTwist::M_TYPE => 1,
+ SexticTwist::Not => 0,
+ SexticTwist::DType => 0,
+ SexticTwist::MType => 1,
}
}
}
#[derive(PartialEq)]
pub enum SignOfX {
- NOT,
- POSITIVEX,
- NEGATIVEX,
+ Not,
+ PositiveX,
+ NegativeX,
}
-