Merge pull request #43 from sigp/tests-big
Tests big
diff --git a/benches/BenchtestALL.rs b/benches/BenchtestALL.rs
index f4d163b..8e17ca4 100644
--- a/benches/BenchtestALL.rs
+++ b/benches/BenchtestALL.rs
@@ -100,7 +100,7 @@
let mut g = pair::gtpow(&mut w, &mut r);
- if !g.isunity() {
+ if !g.is_unity() {
println!("FAILURE - g^r!=1");
return;
}
@@ -259,7 +259,7 @@
let mut g = pair::gtpow(&mut w, &mut r);
- if !g.isunity() {
+ if !g.is_unity() {
println!("FAILURE - g^r!=1");
return;
}
@@ -418,7 +418,7 @@
let mut g = pair192::gtpow(&mut w, &mut r);
- if !g.isunity() {
+ if !g.is_unity() {
println!("FAILURE - g^r!=1");
return;
}
@@ -577,7 +577,7 @@
let mut g = pair256::gtpow(&mut w, &mut r);
- if !g.isunity() {
+ if !g.is_unity() {
println!("FAILURE - g^r!=1");
return;
}
diff --git a/src/big.rs b/src/big.rs
index 52eb21e..545c022 100644
--- a/src/big.rs
+++ b/src/big.rs
@@ -42,13 +42,13 @@
impl fmt::Display for Big {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "Big: [ {} ]", self.tostring())
+ write!(f, "Big: [ {} ]", self.to_string())
}
}
impl fmt::Debug for Big {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "Big: [ {} ]", self.tostring())
+ write!(f, "Big: [ {} ]", self.to_string())
}
}
@@ -80,12 +80,17 @@
}
impl Big {
+ /// New
+ ///
+ /// Creates a new Big set to zero.
#[inline(always)]
pub fn new() -> Big {
Big { w: [0; NLEN] }
}
- /// Convert a integer to a Big
+ /// New Int
+ ///
+ /// Convert an integer to a Big
#[inline(always)]
pub fn new_int(x: isize) -> Big {
let mut s = Big::new();
@@ -93,6 +98,8 @@
s
}
+ /// New Ints
+ ///
/// Takes an array of integers and converts to a Big
#[inline(always)]
pub fn new_ints(a: &[Chunk]) -> Big {
@@ -103,6 +110,9 @@
s
}
+ /// New Double Copy
+ ///
+ /// Copies the least significant bytes from a `DBig`.
#[inline(always)]
pub fn new_dcopy(y: &DBig) -> Big {
let mut s = Big::new();
@@ -112,24 +122,31 @@
s
}
+ /// Get
+ ///
+ /// Retrives the Chunk at a given index.
pub fn get(&self, i: usize) -> Chunk {
self.w[i]
}
+ /// Set
+ ///
+ /// Sets the chunk at a given index.
pub fn set(&mut self, i: usize, x: Chunk) {
self.w[i] = x;
}
- pub fn xortop(&mut self, x: Chunk) {
+ /// XOR Top
+ ///
+ /// Performs XOR on the most significant byte.
+ pub fn xor_top(&mut self, x: Chunk) {
self.w[NLEN - 1] ^= x;
}
- pub fn ortop(&mut self, x: Chunk) {
- self.w[NLEN - 1] |= x;
- }
-
- /// test for zero
- pub fn iszilch(&self) -> bool {
+ /// Is Zilch
+ ///
+ /// self == zero
+ pub fn is_zilch(&self) -> bool {
for i in 0..NLEN {
if self.w[i] != 0 {
return false;
@@ -138,15 +155,19 @@
true
}
- /// set to zero
+ /// Zero
+ ///
+ /// Set to zero.
pub fn zero(&mut self) {
for i in 0..NLEN {
self.w[i] = 0
}
}
- /// Test for equal to one
- pub fn isunity(&self) -> bool {
+ /// Is Unity
+ ///
+ /// self == one
+ pub fn is_unity(&self) -> bool {
for i in 1..NLEN {
if self.w[i] != 0 {
return false;
@@ -158,7 +179,9 @@
true
}
- /// Set to one
+ /// One
+ ///
+ /// Set to one.
pub fn one(&mut self) {
self.w[0] = 1;
for i in 1..NLEN {
@@ -166,22 +189,28 @@
}
}
- /// Copy from a DBig
+ /// Double Copy
+ ///
+ /// Copy least significant bytes from a `DBig`
pub fn dcopy(&mut self, x: &DBig) {
for i in 0..NLEN {
self.w[i] = x.w[i]
}
}
- /// Get top and bottom half of =x*y+c+r
- pub fn muladd(a: Chunk, b: Chunk, c: Chunk, r: Chunk) -> (Chunk, Chunk) {
+ /// Multiply Addition
+ ///
+ /// Get top and bottom half of = x * y + c + r
+ pub fn mul_add(a: Chunk, b: Chunk, c: Chunk, r: Chunk) -> (Chunk, Chunk) {
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;
(top, bot)
}
- /// normalise Big - force all digits < 2^BASEBITS
+ /// Normalise
+ ///
+ /// Force all digits < 2^BASEBITS
pub fn norm(&mut self) -> Chunk {
let mut carry = 0 as Chunk;
for i in 0..NLEN - 1 {
@@ -193,6 +222,8 @@
(self.w[NLEN - 1] >> ((8 * MODBYTES) % BASEBITS)) as Chunk
}
+ /// Conditional Swap
+ ///
/// Conditional swap of two bigs depending on d using XOR - no branches
pub fn cswap(&mut self, b: &mut Big, d: isize) {
let mut c = d as Chunk;
@@ -204,6 +235,9 @@
}
}
+ /// Conditional Move
+ ///
+ /// Conditional move of two bigs depending on d using XOR - no branches
pub fn cmove(&mut self, g: &Big, d: isize) {
let b = -d as Chunk;
for i in 0..NLEN {
@@ -211,7 +245,9 @@
}
}
- /// Shift right by less than a word
+ /// Partial Shift Right
+ ///
+ /// Shift right by less than a word.
pub fn fshr(&mut self, k: usize) -> isize {
let n = k;
let w = self.w[0] & ((1 << n) - 1); // shifted out part
@@ -222,7 +258,9 @@
return w as isize;
}
- /// general shift right
+ /// Shift Right
+ ///
+ /// General shift right.
pub fn shr(&mut self, k: usize) {
let n = k % BASEBITS;
let m = k / BASEBITS;
@@ -235,7 +273,9 @@
}
}
- /// Shift right by less than a word
+ /// Partial Shift Left
+ ///
+ /// Shift left by less than a word.
pub fn fshl(&mut self, k: usize) -> isize {
let n = k;
self.w[NLEN - 1] = (self.w[NLEN - 1] << n) | (self.w[NLEN - 2] >> (BASEBITS - n));
@@ -247,7 +287,9 @@
(self.w[NLEN - 1] >> ((8 * MODBYTES) % BASEBITS)) as isize
}
- /// General shift left
+ /// Shift Left
+ ///
+ /// General shift left.
pub fn shl(&mut self, k: usize) {
let n = k % BASEBITS;
let m = k / BASEBITS;
@@ -265,6 +307,8 @@
}
}
+ /// Number of Bits
+ ///
/// Return number of bits
pub fn nbits(&self) -> usize {
let mut k = NLEN - 1;
@@ -285,8 +329,10 @@
bts
}
- // Convert to Hex String
- pub fn tostring(&self) -> String {
+ /// To String
+ ///
+ /// Converts a `Big` to a hex string.
+ pub fn to_string(&self) -> String {
let mut s = String::new();
let mut len = self.nbits();
@@ -309,9 +355,11 @@
s
}
- /// From Hex String
+ /// From String
+ ///
+ /// Converts to `Big` from hex string.
#[inline(always)]
- pub fn fromstring(val: String) -> Big {
+ pub fn from_string(val: String) -> Big {
let mut res = Big::new();
let len = val.len();
let op = &val[0..1];
@@ -326,27 +374,35 @@
res
}
- // Self += r
+ /// Add
+ ///
+ /// self += r
pub fn add(&mut self, r: &Big) {
for i in 0..NLEN {
self.w[i] += r.w[i]
}
}
- //? Bitwise OR
+ /// OR
+ ///
+ /// self |= r
pub fn or(&mut self, r: &Big) {
for i in 0..NLEN {
self.w[i] |= r.w[i]
}
}
- /// Self * 2
+ /// Double
+ ///
+ /// self *= 2
pub fn dbl(&mut self) {
for i in 0..NLEN {
self.w[i] += self.w[i]
}
}
+ /// Plus
+ ///
/// Return self + x
#[inline(always)]
pub fn plus(&self, x: &Big) -> Big {
@@ -357,13 +413,17 @@
s
}
- /// Return self + 1
+ /// Increment
+ ///
+ /// self += x
pub fn inc(&mut self, x: isize) {
self.norm();
self.w[0] += x as Chunk;
}
- /// Return self - x
+ /// Minus
+ ///
+ /// Return self - x
#[inline(always)]
pub fn minus(&self, x: &Big) -> Big {
let mut d = Big::new();
@@ -373,6 +433,8 @@
d
}
+ /// Subtraction
+ ///
/// self -= x
pub fn sub(&mut self, x: &Big) {
for i in 0..NLEN {
@@ -380,20 +442,27 @@
}
}
- /// reverse subtract this=x-this
+ /// Reverse Subtraction
+ ///
+ /// self = x - self
pub fn rsub(&mut self, x: &Big) {
for i in 0..NLEN {
self.w[i] = x.w[i] - self.w[i]
}
}
- /// self-=x, where x is int
+ /// Decrement
+ ///
+ /// self -= x, where x is int
pub fn dec(&mut self, x: isize) {
self.norm();
self.w[0] -= x as Chunk;
}
- /// self*=x, where x is small int<NEXCESS
+ /// Integer Multiplication
+ ///
+ /// self *= x,
+ /// Require: x < NEXCESS
pub fn imul(&mut self, c: isize) {
for i in 0..NLEN {
self.w[i] *= c as Chunk;
@@ -403,7 +472,7 @@
/// To Byte Array
///
/// Convert this Big to byte array from index `n`
- pub fn tobytearray(&self, b: &mut [u8], n: usize) {
+ pub fn to_byte_array(&self, b: &mut [u8], n: usize) {
let mut c = self.clone();
c.norm();
@@ -417,7 +486,7 @@
///
/// Convert from byte array starting at index `n` to Big
#[inline(always)]
- pub fn frombytearray(b: &[u8], n: usize) -> Big {
+ pub fn from_byte_array(b: &[u8], n: usize) -> Big {
let mut m = Big::new();
// Restrict length
@@ -438,8 +507,8 @@
/// To Bytes
///
/// Convert to bytes from index 0
- pub fn tobytes(&self, b: &mut [u8]) {
- self.tobytearray(b, 0)
+ pub fn to_bytes(&self, b: &mut [u8]) {
+ self.to_byte_array(b, 0)
}
/// From bytes
@@ -447,29 +516,35 @@
/// Convert from bytes from index 0
/// Panics if input bytes length is less than required.
#[inline(always)]
- pub fn frombytes(b: &[u8]) -> Big {
- Big::frombytearray(b, 0)
+ pub fn from_bytes(b: &[u8]) -> Big {
+ Big::from_byte_array(b, 0)
}
- // self*=x, where x is >NEXCESS
+ /// P Multiply
+ ///
+ /// self *= x
+ /// Require: x > NEXCESS, returns overflow
pub fn pmul(&mut self, c: isize) -> Chunk {
let mut carry = 0 as Chunk;
for i in 0..NLEN {
let ak = self.w[i];
- let tuple = Big::muladd(ak, c as Chunk, carry, 0 as Chunk);
+ let tuple = Big::mul_add(ak, c as Chunk, carry, 0 as Chunk);
carry = tuple.0;
self.w[i] = tuple.1;
}
carry
}
- /// self *= c and catch overflow in DBig
+ /// PX Multiply
+ ///
+ /// self *= c
+ /// Note: catches overflow in DBig
#[inline(always)]
pub fn pxmul(&self, c: isize) -> DBig {
let mut m = DBig::new();
let mut carry = 0 as Chunk;
for j in 0..NLEN {
- let tuple = Big::muladd(self.w[j], c as Chunk, carry, m.w[j]);
+ let tuple = Big::mul_add(self.w[j], c as Chunk, carry, m.w[j]);
carry = tuple.0;
m.w[j] = tuple.1;
}
@@ -477,7 +552,10 @@
m
}
- /// divide by 3
+ /// Divide 3
+ ///
+ /// self /= 3
+ /// Returns carry
pub fn div3(&mut self) -> Chunk {
let mut carry = 0 as Chunk;
self.norm();
@@ -490,7 +568,10 @@
carry
}
- /// return a*b where result fits in a Big
+ /// Small Multiply
+ ///
+ /// return a * b
+ /// Require: a * b to fit in a Big.
#[inline(always)]
pub fn smul(a: &Big, b: &Big) -> Big {
let mut c = Big::new();
@@ -498,7 +579,7 @@
let mut carry = 0 as Chunk;
for j in 0..NLEN {
if i + j < NLEN {
- let tuple = Big::muladd(a.w[i], b.w[j], carry, c.w[i + j]);
+ let tuple = Big::mul_add(a.w[i], b.w[j], carry, c.w[i + j]);
carry = tuple.0;
c.w[i + j] = tuple.1;
}
@@ -507,7 +588,10 @@
c
}
- /// Compare a and b, return 0 if a==b, -1 if a<b, +1 if a>b. Inputs must be normalised
+ /// Compare
+ ///
+ /// Compare a and b, return 0 if a == b; -1 if a < b; +1 if a > b.
+ /// Require: a and b must be normalised
pub fn comp(a: &Big, b: &Big) -> isize {
for i in (0..NLEN).rev() {
if a.w[i] == b.w[i] {
@@ -522,7 +606,9 @@
0
}
- /// set x = x mod 2^m
+ /// Mod 2^m
+ ///
+ /// set self = self mod 2^m
pub fn mod2m(&mut self, m: usize) {
let wd = m / BASEBITS;
let bt = m % BASEBITS;
@@ -533,6 +619,8 @@
}
}
+ /// Inverse Modulus 256
+ ///
/// Arazi and Qi inversion mod 256
pub fn invmod256(a: isize) -> isize {
let mut t1: isize = 0;
@@ -572,12 +660,16 @@
u
}
- /// Return parity
+ /// Parity
+ ///
+ /// Returns self % 2
pub fn parity(&self) -> isize {
(self.w[0] % 2) as isize
}
- /// Return n-th bit
+ /// Bit
+ ///
+ /// Returns the `n`-th bit
pub fn bit(&self, n: usize) -> isize {
if (self.w[n / (BASEBITS as usize)] & (1 << (n % BASEBITS))) > 0 {
return 1;
@@ -585,13 +677,17 @@
0
}
- /// Return n last bits
+ /// Last Bits
+ ///
+ /// Returns last `n` bits
pub fn lastbits(&mut self, n: usize) -> isize {
let msk = ((1 << n) - 1) as Chunk;
self.norm();
(self.w[0] & msk) as isize
}
+ /// Inverse Modulu 2^m
+ ///
/// a = 1/a mod 2^256. This is very fast!
pub fn invmod2m(&mut self) {
let mut u = Big::new();
@@ -747,11 +843,14 @@
m
}
- /// Jacobi Symbol (this/p). Returns 0, 1 or -1
+ /// Jacobi Symbol
+ ///
+ /// Performs jacobi(self/p)
+ /// Returns 0, 1 or -1
pub fn jacobi(&mut self, p: &Big) -> isize {
let mut m: usize = 0;
let one = Big::new_int(1);
- if p.parity() == 0 || self.iszilch() || Big::comp(p, &one) <= 0 {
+ if p.parity() == 0 || self.is_zilch() || Big::comp(p, &one) <= 0 {
return 0;
}
self.norm();
@@ -761,7 +860,7 @@
x.rmod(p);
while Big::comp(&n, &one) > 0 {
- if x.iszilch() {
+ if x.is_zilch() {
return 0;
}
let n8 = n.lastbits(3) as usize;
@@ -1006,6 +1105,7 @@
b
}
+ /// SSN
pub fn ssn(r: &mut Big, a: &Big, m: &mut Big) -> isize {
let n = NLEN - 1;
m.w[0] = (m.w[0] >> 1) | ((m.w[1] << (BASEBITS - 1)) & BMASK);
@@ -1072,7 +1172,7 @@
if bt == 1 {
a = Big::modmul(&a, &s, m)
}
- if z.iszilch() {
+ if z.is_zilch() {
break;
}
s = Big::modsqr(&s, m);
@@ -1080,3 +1180,131 @@
a
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_zero() {
+ let zero = Big::new_int(0);
+ assert!(zero.is_zilch());
+
+ let zero2 = Big::new();
+ assert!(zero2.is_zilch());
+ assert_eq!(zero, zero2);
+
+ let zero2 = Big::new_ints(&[0; NLEN]);
+ assert!(zero2.is_zilch());
+
+ let mut zero2 = Big::new_int(123456789);
+ zero2.zero();
+ assert!(zero2.is_zilch());
+
+ let mut zero2 = Big::new_int(9876543210);
+ let zero_dbig = DBig::new();
+ zero2.dcopy(&zero_dbig);
+ assert!(zero2.is_zilch());
+ }
+
+ #[test]
+ fn test_one() {
+ let one = Big::new_int(1);
+ assert!(one.is_unity());
+
+ let mut one2 = Big::new();
+ one2.one();
+ assert!(one2.is_unity());
+ }
+
+ #[test]
+ fn test_add_int() {
+ // 9999 + 77 = 10076
+ let a = Big::new_int(9999);
+ let mut b = Big::new_int(77);
+ let mut c = a.clone();
+ c.add(&b);
+ assert_eq!(c, Big::new_int(10076));
+
+ // 77 + 9999 = 10076
+ b.add(&a);
+ assert_eq!(b, Big::new_int(10076));
+
+ // -1000 + 1000 = 0
+ let mut negatives = Big::new_int(-1000);
+ let positives = Big::new_int(1000);
+ negatives.add(&positives);
+ assert!(negatives.is_zilch());
+ }
+
+ #[test]
+ fn test_sub_int() {
+ // 1 - 1 = 0
+ let one = Big::new_int(1);
+ let mut zero = one.clone();
+ zero.sub(&one);
+ assert!(zero.is_zilch());
+
+ // -3 - 1 = -4
+ let mut minus_4 = Big::new_int(-3);
+ minus_4.sub(&one);
+ assert_eq!(minus_4, Big::new_int(-4));
+
+ // -10 - (-23) = 13
+ let mut thirteen = Big::new_int(-10);
+ let minus_23 = Big::new_int(-23);
+ thirteen.sub(&minus_23);
+ assert_eq!(thirteen, Big::new_int(13));
+
+ // 1000 - 333 = 777
+ let mut sevens = Big::new_int(1000);
+ let twos = Big::new_int(223);
+ sevens.sub(&twos);
+ assert_eq!(sevens, Big::new_int(777));
+ }
+
+ #[test]
+ fn test_get_set() {
+ let mut big = Big::new();
+
+ for i in 0..NLEN {
+ assert_eq!(big.get(i), 0);
+
+ let a: Chunk = (i + 1) as Chunk;
+ big.set(i, a);
+ assert_eq!(big.get(i), a);
+ }
+ }
+
+ #[test]
+ fn test_xor_top() {
+ let mut big = Big::new();
+ let a = 0b1100_0011;
+ big.set(NLEN - 1, a);
+
+ let b = 0b1001_1001;
+ big.xor_top(b);
+
+ assert_eq!(big.get(NLEN - 1), a ^ b);
+ }
+
+ #[test]
+ fn test_dcopy() {
+ // Create DBig with words 0, 1, 2, ...
+ let mut dbig = DBig::new();
+ for (i, a) in dbig.w.iter_mut().enumerate() {
+ *a = i as Chunk;
+ }
+
+ let mut big = Big::new();
+ big.dcopy(&dbig);
+ for i in 0..NLEN {
+ assert_eq!(big.get(i), i as Chunk);
+ }
+
+ let big2 = Big::new_dcopy(&dbig);
+ for i in 0..NLEN {
+ assert_eq!(big2.get(i), i as Chunk);
+ }
+ }
+}
diff --git a/src/bls.rs b/src/bls.rs
index 5ed2e14..8aafb29 100644
--- a/src/bls.rs
+++ b/src/bls.rs
@@ -54,25 +54,25 @@
let q = Big::new_ints(&rom::CURVE_ORDER);
let g = ECP2::generator();
let sc = Big::randomnum(&q, &mut rng);
- sc.tobytes(s);
- pair::g2mul(&g, &sc).tobytes(w);
+ sc.to_bytes(s);
+ pair::g2mul(&g, &sc).to_bytes(w);
BLS_OK
}
/// 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);
+ let mut sc = Big::from_bytes(&s);
+ pair::g1mul(&d, &mut sc).to_bytes(sig, true);
BLS_OK
}
/// 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);
+ let mut d = ECP::from_bytes(&sig);
let g = ECP2::generator();
- let pk = ECP2::frombytes(&w);
+ let pk = ECP2::from_bytes(&w);
d.neg();
// Use new multi-pairing mechanism
@@ -85,7 +85,7 @@
// let mut v = pair::ate2(&g, &d, &pk, &hm);
v = pair::fexp(&v);
- if v.isunity() {
+ if v.is_unity() {
return BLS_OK;
}
BLS_FAIL
diff --git a/src/bls192.rs b/src/bls192.rs
index 4c54223..ca13d57 100644
--- a/src/bls192.rs
+++ b/src/bls192.rs
@@ -55,25 +55,25 @@
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);
+ sc.to_bytes(s);
+ pair192::g2mul(&g, &mut sc).to_bytes(w);
BLS_OK
}
/// 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);
+ let mut sc = Big::from_bytes(&s);
+ pair192::g1mul(&d, &mut sc).to_bytes(sig, true);
BLS_OK
}
/// 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);
+ let mut d = ECP::from_bytes(&sig);
let g = ECP4::generator();
- let pk = ECP4::frombytes(&w);
+ let pk = ECP4::from_bytes(&w);
d.neg();
// Use new multi-pairing mechanism
@@ -86,7 +86,7 @@
// let mut v = pair192::ate2(&g, &d, &pk, &hm);
v = pair192::fexp(&v);
- if v.isunity() {
+ if v.is_unity() {
return BLS_OK;
}
BLS_FAIL
diff --git a/src/bls256.rs b/src/bls256.rs
index 372f35c..508f23b 100644
--- a/src/bls256.rs
+++ b/src/bls256.rs
@@ -54,25 +54,25 @@
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);
+ sc.to_bytes(s);
+ pair256::g2mul(&g, &mut sc).to_bytes(w);
BLS_OK
}
/// 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);
- pair256::g1mul(&d, &mut sc).tobytes(sig, true);
+ let mut sc = Big::from_bytes(&s);
+ pair256::g1mul(&d, &mut sc).to_bytes(sig, true);
BLS_OK
}
/// 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);
+ let mut d = ECP::from_bytes(&sig);
let g = ECP8::generator();
- let pk = ECP8::frombytes(&w);
+ let pk = ECP8::from_bytes(&w);
d.neg();
// Use new multi-pairing mechanism
@@ -85,7 +85,7 @@
// let mut v = pair256::ate2(&g, &d, &pk, &hm);
v = pair256::fexp(&v);
- if v.isunity() {
+ if v.is_unity() {
return BLS_OK;
}
BLS_FAIL
diff --git a/src/bls381/core.rs b/src/bls381/core.rs
index fb881d7..48028c9 100644
--- a/src/bls381/core.rs
+++ b/src/bls381/core.rs
@@ -67,7 +67,7 @@
// SK = OS2IP(OKM) mod r
let r = Big::new_ints(&CURVE_ORDER);
- let mut secret_key = Big::frombytes(&okm);
+ let mut secret_key = Big::from_bytes(&okm);
secret_key.rmod(&r);
secret_key_to_bytes(&secret_key)
@@ -84,7 +84,7 @@
secret_key_bytes[MODBYTES - SECRET_KEY_BYTES..].copy_from_slice(secret_key);
// Ensure secret key is in the range [0, r-1].
- let secret_key = Big::frombytes(&secret_key_bytes);
+ let secret_key = Big::from_bytes(&secret_key_bytes);
if secret_key >= Big::new_ints(&CURVE_ORDER) {
return Err(AmclError::InvalidSecretKeyRange);
}
@@ -95,7 +95,7 @@
// Converts secret key Big to bytes
pub fn secret_key_to_bytes(secret_key: &Big) -> [u8; SECRET_KEY_BYTES] {
let mut big_bytes = [0u8; MODBYTES];
- secret_key.tobytes(&mut big_bytes);
+ secret_key.to_bytes(&mut big_bytes);
let mut secret_key_bytes = [0u8; SECRET_KEY_BYTES];
secret_key_bytes.copy_from_slice(&big_bytes[MODBYTES - SECRET_KEY_BYTES..]);
secret_key_bytes
@@ -142,7 +142,7 @@
// Convert x-coordinate to bytes
let mut result = [0u8; G1_BYTES];
- g1.getx().tobytes(&mut result);
+ g1.getx().to_bytes(&mut result);
// Evaluate if y > -y
let mut tmp = g1.clone();
@@ -172,8 +172,8 @@
}
// Convert x-coordinate to bytes
- g1.getx().tobytes(&mut result[..MODBYTES]);
- g1.gety().tobytes(&mut result[MODBYTES..]);
+ g1.getx().to_bytes(&mut result[..MODBYTES]);
+ g1.gety().to_bytes(&mut result[MODBYTES..]);
result
}
@@ -221,7 +221,7 @@
// Zero flags
let mut g1_bytes = g1_bytes.to_owned();
g1_bytes[0] = g1_bytes[0] & 0b_0001_1111;
- let x = Big::frombytes(&g1_bytes);
+ let x = Big::from_bytes(&g1_bytes);
// Require element less than field modulus
let m = Big::new_ints(&MODULUS);
@@ -277,8 +277,8 @@
// Zero flags
let mut g1_bytes = g1_bytes.to_owned();
g1_bytes[0] = g1_bytes[0] & 0b_0001_1111;
- let x = Big::frombytes(&g1_bytes[..MODBYTES]);
- let y = Big::frombytes(&g1_bytes[MODBYTES..]);
+ let x = Big::from_bytes(&g1_bytes[..MODBYTES]);
+ let y = Big::from_bytes(&g1_bytes[MODBYTES..]);
// Require elements less than field modulus
let m = Big::new_ints(&MODULUS);
@@ -310,8 +310,8 @@
// Note: Zcash uses (x_im, x_re)
let mut result = [0u8; G2_BYTES];
let x = g2.getx();
- x.geta().tobytes(&mut result[MODBYTES..(MODBYTES * 2)]);
- x.getb().tobytes(&mut result[0..MODBYTES]);
+ x.geta().to_bytes(&mut result[MODBYTES..(MODBYTES * 2)]);
+ x.getb().to_bytes(&mut result[0..MODBYTES]);
// Check y value
let mut y = g2.gety();
@@ -342,12 +342,12 @@
// Convert to bytes
// Note: Zcash uses (x_im, x_re), (y_im, y_re)
let x = g2.getx();
- x.getb().tobytes(&mut result[0..MODBYTES]);
- x.geta().tobytes(&mut result[MODBYTES..(MODBYTES * 2)]);
+ x.getb().to_bytes(&mut result[0..MODBYTES]);
+ x.geta().to_bytes(&mut result[MODBYTES..(MODBYTES * 2)]);
let x = g2.gety();
x.getb()
- .tobytes(&mut result[(MODBYTES * 2)..(MODBYTES * 3)]);
- x.geta().tobytes(&mut result[(MODBYTES * 3)..]);
+ .to_bytes(&mut result[(MODBYTES * 2)..(MODBYTES * 3)]);
+ x.geta().to_bytes(&mut result[(MODBYTES * 3)..]);
result
}
@@ -395,8 +395,8 @@
g2_bytes[0] = g2_bytes[0] & 0b_0001_1111;
// Convert from array to FP2
- let x_imaginary = Big::frombytes(&g2_bytes[0..MODBYTES]);
- let x_real = Big::frombytes(&g2_bytes[MODBYTES..]);
+ let x_imaginary = Big::from_bytes(&g2_bytes[0..MODBYTES]);
+ let x_real = Big::from_bytes(&g2_bytes[MODBYTES..]);
// Require elements less than field modulus
let m = Big::new_ints(&MODULUS);
@@ -452,10 +452,10 @@
g2_bytes[0] = g2_bytes[0] & 0b_0001_1111;
// Convert from array to FP2
- let x_imaginary = Big::frombytes(&g2_bytes[..MODBYTES]);
- let x_real = Big::frombytes(&g2_bytes[MODBYTES..(MODBYTES * 2)]);
- let y_imaginary = Big::frombytes(&g2_bytes[(MODBYTES * 2)..(MODBYTES * 3)]);
- let y_real = Big::frombytes(&g2_bytes[(MODBYTES * 3)..]);
+ let x_imaginary = Big::from_bytes(&g2_bytes[..MODBYTES]);
+ let x_real = Big::from_bytes(&g2_bytes[MODBYTES..(MODBYTES * 2)]);
+ let y_imaginary = Big::from_bytes(&g2_bytes[(MODBYTES * 2)..(MODBYTES * 3)]);
+ let y_real = Big::from_bytes(&g2_bytes[(MODBYTES * 3)..]);
// Require elements less than field modulus
let m = Big::new_ints(&MODULUS);
@@ -554,7 +554,7 @@
v = pair::fexp(&v);
// True if pairing output is 1
- v.isunity()
+ v.is_unity()
}
/// Aggregate
@@ -623,7 +623,7 @@
// True if pairing output is 1
let mut v = pair::miller(&r);
v = pair::fexp(&v);
- v.isunity()
+ v.is_unity()
}
/*************************************************************************************************
@@ -708,7 +708,7 @@
v = pair::fexp(&v);
// True if pairing output is 1
- v.isunity()
+ v.is_unity()
}
/// Aggregate
@@ -778,7 +778,7 @@
// True if pairing output is 1
let mut v = pair::miller(&r);
v = pair::fexp(&v);
- v.isunity()
+ v.is_unity()
}
/*************************************************************************************************
@@ -873,8 +873,8 @@
for (i, u_str) in case.u.iter().enumerate() {
// Convert case 'u[i]' to FP2
let u_str_parts: Vec<&str> = u_str.split(',').collect();
- let a = Big::frombytes(&hex::decode(&u_str_parts[0].get(2..).unwrap()).unwrap());
- let b = Big::frombytes(&hex::decode(&u_str_parts[1].get(2..).unwrap()).unwrap());
+ let a = Big::from_bytes(&hex::decode(&u_str_parts[0].get(2..).unwrap()).unwrap());
+ let b = Big::from_bytes(&hex::decode(&u_str_parts[1].get(2..).unwrap()).unwrap());
let expected_u_i = FP2::new_bigs(a, b);
// Verify u[i]
@@ -883,13 +883,13 @@
// Check Q0
let x_str_parts: Vec<&str> = case.Q0.x.split(',').collect();
- let a = Big::frombytes(&hex::decode(&x_str_parts[0].get(2..).unwrap()).unwrap());
- let b = Big::frombytes(&hex::decode(&x_str_parts[1].get(2..).unwrap()).unwrap());
+ let a = Big::from_bytes(&hex::decode(&x_str_parts[0].get(2..).unwrap()).unwrap());
+ let b = Big::from_bytes(&hex::decode(&x_str_parts[1].get(2..).unwrap()).unwrap());
let expected_x = FP2::new_bigs(a, b);
let y_str_parts: Vec<&str> = case.Q0.y.split(',').collect();
- let a = Big::frombytes(&hex::decode(&y_str_parts[0].get(2..).unwrap()).unwrap());
- let b = Big::frombytes(&hex::decode(&y_str_parts[1].get(2..).unwrap()).unwrap());
+ let a = Big::from_bytes(&hex::decode(&y_str_parts[0].get(2..).unwrap()).unwrap());
+ let b = Big::from_bytes(&hex::decode(&y_str_parts[1].get(2..).unwrap()).unwrap());
let expected_y = FP2::new_bigs(a, b);
let expected_q0 = ECP2::new_fp2s(expected_x, expected_y);
@@ -897,13 +897,13 @@
// Check Q1
let x_str_parts: Vec<&str> = case.Q1.x.split(',').collect();
- let a = Big::frombytes(&hex::decode(&x_str_parts[0].get(2..).unwrap()).unwrap());
- let b = Big::frombytes(&hex::decode(&x_str_parts[1].get(2..).unwrap()).unwrap());
+ let a = Big::from_bytes(&hex::decode(&x_str_parts[0].get(2..).unwrap()).unwrap());
+ let b = Big::from_bytes(&hex::decode(&x_str_parts[1].get(2..).unwrap()).unwrap());
let expected_x = FP2::new_bigs(a, b);
let y_str_parts: Vec<&str> = case.Q1.y.split(',').collect();
- let a = Big::frombytes(&hex::decode(&y_str_parts[0].get(2..).unwrap()).unwrap());
- let b = Big::frombytes(&hex::decode(&y_str_parts[1].get(2..).unwrap()).unwrap());
+ let a = Big::from_bytes(&hex::decode(&y_str_parts[0].get(2..).unwrap()).unwrap());
+ let b = Big::from_bytes(&hex::decode(&y_str_parts[1].get(2..).unwrap()).unwrap());
let expected_y = FP2::new_bigs(a, b);
let expected_q1 = ECP2::new_fp2s(expected_x, expected_y);
@@ -911,13 +911,13 @@
// Check P
let x_str_parts: Vec<&str> = case.P.x.split(',').collect();
- let a = Big::frombytes(&hex::decode(&x_str_parts[0].get(2..).unwrap()).unwrap());
- let b = Big::frombytes(&hex::decode(&x_str_parts[1].get(2..).unwrap()).unwrap());
+ let a = Big::from_bytes(&hex::decode(&x_str_parts[0].get(2..).unwrap()).unwrap());
+ let b = Big::from_bytes(&hex::decode(&x_str_parts[1].get(2..).unwrap()).unwrap());
let expected_x = FP2::new_bigs(a, b);
let y_str_parts: Vec<&str> = case.P.y.split(',').collect();
- let a = Big::frombytes(&hex::decode(&y_str_parts[0].get(2..).unwrap()).unwrap());
- let b = Big::frombytes(&hex::decode(&y_str_parts[1].get(2..).unwrap()).unwrap());
+ let a = Big::from_bytes(&hex::decode(&y_str_parts[0].get(2..).unwrap()).unwrap());
+ let b = Big::from_bytes(&hex::decode(&y_str_parts[1].get(2..).unwrap()).unwrap());
let expected_y = FP2::new_bigs(a, b);
let expected_p = ECP2::new_fp2s(expected_x, expected_y);
@@ -953,7 +953,7 @@
assert_eq!(case.u.len(), u.len());
for (i, u_str) in case.u.iter().enumerate() {
// Convert case 'u[i]' to FP
- let a = Big::frombytes(&hex::decode(&u_str.get(2..).unwrap()).unwrap());
+ let a = Big::from_bytes(&hex::decode(&u_str.get(2..).unwrap()).unwrap());
let expected_u_i = FP::new_big(a);
// Verify u[i]
@@ -961,30 +961,30 @@
}
// Check Q0
- let a = Big::frombytes(&hex::decode(&case.Q0.x.get(2..).unwrap()).unwrap());
+ let a = Big::from_bytes(&hex::decode(&case.Q0.x.get(2..).unwrap()).unwrap());
let expected_x = FP::new_big(a);
- let a = Big::frombytes(&hex::decode(&case.Q0.y.get(2..).unwrap()).unwrap());
+ let a = Big::from_bytes(&hex::decode(&case.Q0.y.get(2..).unwrap()).unwrap());
let expected_y = FP::new_big(a);
let expected_q0 = ECP::new_fps(expected_x, expected_y);
assert_eq!(expected_q0, q0);
// Check Q1
- let a = Big::frombytes(&hex::decode(&case.Q1.x.get(2..).unwrap()).unwrap());
+ let a = Big::from_bytes(&hex::decode(&case.Q1.x.get(2..).unwrap()).unwrap());
let expected_x = FP::new_big(a);
- let a = Big::frombytes(&hex::decode(&case.Q1.y.get(2..).unwrap()).unwrap());
+ let a = Big::from_bytes(&hex::decode(&case.Q1.y.get(2..).unwrap()).unwrap());
let expected_y = FP::new_big(a);
let expected_q1 = ECP::new_fps(expected_x, expected_y);
assert_eq!(expected_q1, q1);
// Check P
- let a = Big::frombytes(&hex::decode(&case.P.x.get(2..).unwrap()).unwrap());
+ let a = Big::from_bytes(&hex::decode(&case.P.x.get(2..).unwrap()).unwrap());
let expected_x = FP::new_big(a);
- let a = Big::frombytes(&hex::decode(&case.P.y.get(2..).unwrap()).unwrap());
+ let a = Big::from_bytes(&hex::decode(&case.P.y.get(2..).unwrap()).unwrap());
let expected_y = FP::new_big(a);
let expected_p = ECP::new_fps(expected_x, expected_y);
diff --git a/src/bls381/proof_of_possession.rs b/src/bls381/proof_of_possession.rs
index 75061c5..ddc959a 100644
--- a/src/bls381/proof_of_possession.rs
+++ b/src/bls381/proof_of_possession.rs
@@ -144,7 +144,7 @@
v = pair::fexp(&v);
// True if pairing output is 1
- v.isunity()
+ v.is_unity()
}
/// Proof of Possession - FastAggregateVerify
@@ -165,7 +165,7 @@
let mut g = ECP2::generator();
g.neg();
- let mut aggregate_public_key = ECP2::frombytes(&public_keys[0]);
+ let mut aggregate_public_key = ECP2::from_bytes(&public_keys[0]);
for public_key in public_keys.iter().skip(1) {
let public_key = deserialize_g2(public_key);
if public_key.is_err() {
@@ -184,7 +184,7 @@
v = pair::fexp(&v);
// True if pairing output is 1
- v.isunity()
+ v.is_unity()
}
/*************************************************************************************************
@@ -278,7 +278,7 @@
v = pair::fexp(&v);
// True if pairing output is 1
- v.isunity()
+ v.is_unity()
}
/// Proof of Possession - FastAggregateVerify
@@ -299,7 +299,7 @@
let mut g = ECP::generator();
g.neg();
- let mut aggregate_public_key = ECP::frombytes(&public_keys[0]);
+ let mut aggregate_public_key = ECP::from_bytes(&public_keys[0]);
for public_key in public_keys.iter().skip(1) {
let public_key = deserialize_g1(public_key);
if public_key.is_err() {
@@ -318,5 +318,5 @@
v = pair::fexp(&v);
// True if pairing output is 1
- v.isunity()
+ v.is_unity()
}
diff --git a/src/dbig.rs b/src/dbig.rs
index 9e003da..c77335c 100644
--- a/src/dbig.rs
+++ b/src/dbig.rs
@@ -291,7 +291,7 @@
// convert from byte array to DBig
#[inline(always)]
- pub fn frombytes(b: &[u8]) -> DBig {
+ pub fn from_bytes(b: &[u8]) -> DBig {
let mut m = DBig::new();
// Restrict length
diff --git a/src/ecdh.rs b/src/ecdh.rs
index 23f2c91..0b144e1 100644
--- a/src/ecdh.rs
+++ b/src/ecdh.rs
@@ -41,7 +41,7 @@
#[allow(non_snake_case)]
-fn inttobytes(n: usize, b: &mut [u8]) {
+fn intto_bytes(n: usize, b: &mut [u8]) {
let mut i = b.len();
let mut m = n;
while m > 0 && i > 0 {
@@ -197,7 +197,7 @@
for j in 0..sl {
s[j] = salt[j]
}
- inttobytes(i + 1, &mut n);
+ intto_bytes(i + 1, &mut n);
for j in 0..4 {
s[sl + j] = n[j]
}
@@ -404,15 +404,15 @@
if let Some(mut x) = rng {
sc = Big::randomnum(&r, &mut x);
} else {
- sc = Big::frombytes(&s);
+ sc = Big::from_bytes(&s);
sc.rmod(&r);
}
- sc.tobytes(s);
+ sc.to_bytes(s);
let WP = G.mul(&sc);
- WP.tobytes(w, false); // To use point compression on public keys, change to true
+ WP.to_bytes(w, false); // To use point compression on public keys, change to true
res
}
@@ -420,7 +420,7 @@
/// Validate public key
#[allow(non_snake_case)]
pub fn public_key_validate(w: &[u8]) -> isize {
- let mut WP = ECP::frombytes(w);
+ let mut WP = ECP::from_bytes(w);
let mut res = 0;
let r = Big::new_ints(&rom::CURVE_ORDER);
@@ -442,7 +442,7 @@
WP.dbl();
}
- if !k.isunity() {
+ if !k.is_unity() {
WP = WP.mul(&k)
}
if WP.is_infinity() {
@@ -458,9 +458,9 @@
let mut res = 0;
let mut t: [u8; EFS] = [0; EFS];
- let mut sc = Big::frombytes(&s);
+ let mut sc = Big::from_bytes(&s);
- let mut W = ECP::frombytes(&wd);
+ let mut W = ECP::from_bytes(&wd);
if W.is_infinity() {
res = ERROR
}
@@ -472,7 +472,7 @@
if W.is_infinity() {
res = ERROR;
} else {
- W.getx().tobytes(&mut t);
+ W.getx().to_bytes(&mut t);
for i in 0..EFS {
z[i] = t[i]
}
@@ -500,13 +500,13 @@
let r = Big::new_ints(&rom::CURVE_ORDER);
- let sc = Big::frombytes(s); // s or &s?
- let fb = Big::frombytes(&b);
+ let sc = Big::from_bytes(s); // s or &s?
+ let fb = Big::from_bytes(&b);
let mut cb = Big::new();
let mut db = Big::new();
- while db.iszilch() {
+ while db.is_zilch() {
let mut u = Big::randomnum(&r, rng);
let w = Big::randomnum(&r, rng); // side channel masking
@@ -515,7 +515,7 @@
let vx = V.getx();
cb = vx.clone();
cb.rmod(&r);
- if cb.iszilch() {
+ if cb.is_zilch() {
continue;
}
@@ -533,11 +533,11 @@
db = tb.clone();
}
- cb.tobytes(&mut t);
+ cb.to_bytes(&mut t);
for i in 0..EFS {
c[i] = t[i]
}
- db.tobytes(&mut t);
+ db.to_bytes(&mut t);
for i in 0..EFS {
d[i] = t[i]
}
@@ -556,21 +556,21 @@
let G = ECP::generator();
let r = Big::new_ints(&rom::CURVE_ORDER);
- let cb = Big::frombytes(c); // c or &c ?
- let mut db = Big::frombytes(d); // d or &d ?
+ let cb = Big::from_bytes(c); // c or &c ?
+ let mut db = Big::from_bytes(d); // d or &d ?
- if cb.iszilch() || Big::comp(&cb, &r) >= 0 || db.iszilch() || Big::comp(&db, &r) >= 0 {
+ if cb.is_zilch() || Big::comp(&cb, &r) >= 0 || db.is_zilch() || Big::comp(&db, &r) >= 0 {
res = INVALID;
}
if res == 0 {
- let mut fb = Big::frombytes(&b);
+ let mut fb = Big::from_bytes(&b);
db.invmodp(&r);
let tb = Big::modmul(&fb, &db, &r);
fb = tb.clone();
let h2 = Big::modmul(&cb, &db, &r);
- let WP = ECP::frombytes(&w);
+ let WP = ECP::from_bytes(&w);
if WP.is_infinity() {
res = ERROR;
} else {
@@ -639,7 +639,7 @@
let mut l2: [u8; 8] = [0; 8];
let p2l = p2.len();
- inttobytes(p2l, &mut l2);
+ intto_bytes(p2l, &mut l2);
for i in 0..p2l {
c.push(p2[i]);
@@ -719,7 +719,7 @@
let mut l2: [u8; 8] = [0; 8];
let p2l = p2.len();
- inttobytes(p2l, &mut l2);
+ intto_bytes(p2l, &mut l2);
for i in 0..p2l {
c.push(p2[i]);
diff --git a/src/ecp.rs b/src/ecp.rs
index bed0f1b..ddaf49d 100644
--- a/src/ecp.rs
+++ b/src/ecp.rs
@@ -251,9 +251,9 @@
/// self == 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.is_zilch() && self.y.equals(&self.z),
+ CurveType::Weierstrass => self.x.is_zilch() && self.z.is_zilch(),
+ CurveType::Montgomery => self.z.is_zilch(),
}
}
@@ -429,13 +429,13 @@
///
/// Convert to byte array
/// Panics if byte array is insufficient length.
- pub fn tobytes(&self, b: &mut [u8], compress: bool) {
+ pub fn to_bytes(&self, b: &mut [u8], compress: bool) {
let mb = big::MODBYTES as usize;
let mut t: [u8; big::MODBYTES as usize] = [0; big::MODBYTES as usize];
let mut W = self.clone();
W.affine();
- W.x.redc().tobytes(&mut t);
+ W.x.redc().to_bytes(&mut t);
for i in 0..mb {
b[i + 1] = t[i]
}
@@ -455,7 +455,7 @@
b[0] = 0x04;
- W.y.redc().tobytes(&mut t);
+ W.y.redc().to_bytes(&mut t);
for i in 0..mb {
b[i + mb + 1] = t[i]
}
@@ -466,7 +466,7 @@
/// Convert from byte array to point
/// Panics if input bytes are less than required bytes.
#[inline(always)]
- pub fn frombytes(b: &[u8]) -> ECP {
+ pub fn from_bytes(b: &[u8]) -> ECP {
let mut t: [u8; big::MODBYTES as usize] = [0; big::MODBYTES as usize];
let mb = big::MODBYTES as usize;
let p = Big::new_ints(&rom::MODULUS);
@@ -474,7 +474,7 @@
for i in 0..mb {
t[i] = b[i + 1]
}
- let px = Big::frombytes(&t);
+ let px = Big::from_bytes(&t);
if Big::comp(&px, &p) >= 0 {
return ECP::new();
}
@@ -487,7 +487,7 @@
for i in 0..mb {
t[i] = b[i + mb + 1]
}
- let py = Big::frombytes(&t);
+ let py = Big::from_bytes(&t);
if Big::comp(&py, &p) >= 0 {
return ECP::new();
}
@@ -503,17 +503,17 @@
/// To String
///
- /// Convert to hex string
- pub fn tostring(&self) -> String {
+ /// Converts `ECP` to a hex string.
+ pub fn to_string(&self) -> String {
let mut W = self.clone();
W.affine();
if W.is_infinity() {
return String::from("infinity");
}
if CURVETYPE == CurveType::Montgomery {
- return format!("({})", W.x.redc().tostring());
+ return format!("({})", W.x.redc().to_string());
} else {
- return format!("({},{})", W.x.redc().tostring(), W.y.redc().tostring());
+ return format!("({},{})", W.x.redc().to_string(), W.y.redc().to_string());
};
}
@@ -1072,7 +1072,7 @@
/// Return e * self
#[inline(always)]
pub fn mul(&self, e: &Big) -> ECP {
- if e.iszilch() || self.is_infinity() {
+ if e.is_zilch() || self.is_infinity() {
return ECP::new();
}
let mut T = if CURVETYPE == CurveType::Montgomery {
@@ -1296,7 +1296,7 @@
#[inline(always)]
pub fn mapit(h: &[u8]) -> ECP {
let q = Big::new_ints(&rom::MODULUS);
- let mut x = Big::frombytes(h);
+ let mut x = Big::from_bytes(h);
x.rmod(&q);
let mut P: ECP;
diff --git a/src/ecp2.rs b/src/ecp2.rs
index af9eeff..9be3f59 100644
--- a/src/ecp2.rs
+++ b/src/ecp2.rs
@@ -126,7 +126,7 @@
/* Test this=O? */
pub fn is_infinity(&self) -> bool {
- self.x.iszilch() && self.z.iszilch()
+ self.x.is_zilch() && self.z.is_zilch()
}
/* set self=O */
@@ -245,26 +245,26 @@
}
/* convert to byte array */
- pub fn tobytes(&self, b: &mut [u8]) {
+ pub fn to_bytes(&self, b: &mut [u8]) {
let mut t: [u8; big::MODBYTES as usize] = [0; big::MODBYTES as usize];
let mb = big::MODBYTES as usize;
let mut W = self.clone();
W.affine();
- W.x.geta().tobytes(&mut t);
+ W.x.geta().to_bytes(&mut t);
for i in 0..mb {
b[i] = t[i]
}
- W.x.getb().tobytes(&mut t);
+ W.x.getb().to_bytes(&mut t);
for i in 0..mb {
b[i + mb] = t[i]
}
- W.y.geta().tobytes(&mut t);
+ W.y.geta().to_bytes(&mut t);
for i in 0..mb {
b[i + 2 * mb] = t[i]
}
- W.y.getb().tobytes(&mut t);
+ W.y.getb().to_bytes(&mut t);
for i in 0..mb {
b[i + 3 * mb] = t[i]
}
@@ -275,41 +275,43 @@
/// Converts byte array to point.
/// Pancis if insufficient bytes are given.
#[inline(always)]
- pub fn frombytes(b: &[u8]) -> ECP2 {
+ pub fn from_bytes(b: &[u8]) -> ECP2 {
let mut t: [u8; big::MODBYTES as usize] = [0; big::MODBYTES as usize];
let mb = big::MODBYTES as usize;
for i in 0..mb {
t[i] = b[i]
}
- let ra = Big::frombytes(&t);
+ let ra = Big::from_bytes(&t);
for i in 0..mb {
t[i] = b[i + mb]
}
- let rb = Big::frombytes(&t);
+ let rb = Big::from_bytes(&t);
let rx = FP2::new_bigs(ra, rb);
for i in 0..mb {
t[i] = b[i + 2 * mb]
}
- let ra = Big::frombytes(&t);
+ let ra = Big::from_bytes(&t);
for i in 0..mb {
t[i] = b[i + 3 * mb]
}
- let rb = Big::frombytes(&t);
+ let rb = Big::from_bytes(&t);
let ry = FP2::new_bigs(ra, rb);
ECP2::new_fp2s(rx, ry)
}
- /* convert this to hex string */
- pub fn tostring(&self) -> String {
+ /// To String
+ ///
+ /// Converts `ECP2` to a hex string.
+ pub fn to_string(&self) -> String {
let mut W = self.clone();
W.affine();
if W.is_infinity() {
return String::from("infinity");
}
- return format!("({},{})", W.x.tostring(), W.y.tostring());
+ return format!("({},{})", W.x.to_string(), W.y.to_string());
}
/// To Hex
@@ -725,7 +727,7 @@
return P;
}
-
+
/// Map It
///
/// Maps bytes to a curve point using hash and test.
@@ -734,7 +736,7 @@
#[inline(always)]
pub fn mapit(h: &[u8]) -> ECP2 {
let q = Big::new_ints(&rom::MODULUS);
- let mut x = Big::frombytes(h);
+ let mut x = Big::from_bytes(h);
x.rmod(&q);
let mut Q: ECP2;
let one = Big::new_int(1);
diff --git a/src/ecp4.rs b/src/ecp4.rs
index d593fea..899d074 100644
--- a/src/ecp4.rs
+++ b/src/ecp4.rs
@@ -32,6 +32,14 @@
z: FP4,
}
+impl PartialEq for ECP4 {
+ fn eq(&self, other: &ECP4) -> bool {
+ self.equals(other)
+ }
+}
+
+impl Eq for ECP4 {}
+
#[allow(non_snake_case)]
impl ECP4 {
/// New
@@ -91,7 +99,7 @@
pub fn is_infinity(&self) -> bool {
let xx = self.getpx();
let zz = self.getpz();
- return xx.iszilch() && zz.iszilch();
+ return xx.is_zilch() && zz.is_zilch();
}
/* set self=O */
@@ -144,20 +152,20 @@
}
/* Test if P == Q */
- pub fn equals(&mut self, Q: &mut ECP4) -> bool {
+ pub fn equals(&self, Q: &ECP4) -> bool {
let mut a = self.getpx();
let mut b = Q.getpx();
a.mul(&Q.z);
b.mul(&self.z);
- if !a.equals(&mut b) {
+ if !a.equals(&b) {
return false;
}
a = self.getpy();
a.mul(&Q.z);
b = Q.getpy();
b.mul(&self.z);
- if !a.equals(&mut b) {
+ if !a.equals(&b) {
return false;
}
@@ -210,7 +218,7 @@
}
/* convert to byte array */
- pub fn tobytes(&self, b: &mut [u8]) {
+ pub fn to_bytes(&self, b: &mut [u8]) {
let mut t: [u8; big::MODBYTES as usize] = [0; big::MODBYTES as usize];
let mb = big::MODBYTES as usize;
@@ -218,38 +226,38 @@
W.affine();
- W.x.geta().geta().tobytes(&mut t);
+ W.x.geta().geta().to_bytes(&mut t);
for i in 0..mb {
b[i] = t[i]
}
- W.x.geta().getb().tobytes(&mut t);
+ W.x.geta().getb().to_bytes(&mut t);
for i in 0..mb {
b[i + mb] = t[i]
}
- W.x.getb().geta().tobytes(&mut t);
+ W.x.getb().geta().to_bytes(&mut t);
for i in 0..mb {
b[i + 2 * mb] = t[i]
}
- W.x.getb().getb().tobytes(&mut t);
+ W.x.getb().getb().to_bytes(&mut t);
for i in 0..mb {
b[i + 3 * mb] = t[i]
}
- W.y.geta().geta().tobytes(&mut t);
+ W.y.geta().geta().to_bytes(&mut t);
for i in 0..mb {
b[i + 4 * mb] = t[i]
}
- W.y.geta().getb().tobytes(&mut t);
+ W.y.geta().getb().to_bytes(&mut t);
for i in 0..mb {
b[i + 5 * mb] = t[i]
}
- W.y.getb().geta().tobytes(&mut t);
+ W.y.getb().geta().to_bytes(&mut t);
for i in 0..mb {
b[i + 6 * mb] = t[i]
}
- W.y.getb().getb().tobytes(&mut t);
+ W.y.getb().getb().to_bytes(&mut t);
for i in 0..mb {
b[i + 7 * mb] = t[i]
}
@@ -260,29 +268,29 @@
/// Convert from byte array to point
/// Panics if insufficient bytes are given.
#[inline(always)]
- pub fn frombytes(b: &[u8]) -> ECP4 {
+ pub fn from_bytes(b: &[u8]) -> ECP4 {
let mut t: [u8; big::MODBYTES as usize] = [0; big::MODBYTES as usize];
let mb = big::MODBYTES as usize;
for i in 0..mb {
t[i] = b[i]
}
- let ra = Big::frombytes(&t);
+ let ra = Big::from_bytes(&t);
for i in 0..mb {
t[i] = b[i + mb]
}
- let rb = Big::frombytes(&t);
+ let rb = Big::from_bytes(&t);
let ra4 = FP2::new_bigs(ra, rb);
for i in 0..mb {
t[i] = b[i + 2 * mb]
}
- let ra = Big::frombytes(&t);
+ let ra = Big::from_bytes(&t);
for i in 0..mb {
t[i] = b[i + 3 * mb]
}
- let rb = Big::frombytes(&t);
+ let rb = Big::from_bytes(&t);
let rb4 = FP2::new_bigs(ra, rb);
@@ -291,22 +299,22 @@
for i in 0..mb {
t[i] = b[i + 4 * mb]
}
- let ra = Big::frombytes(&t);
+ let ra = Big::from_bytes(&t);
for i in 0..mb {
t[i] = b[i + 5 * mb]
}
- let rb = Big::frombytes(&t);
+ let rb = Big::from_bytes(&t);
let ra4 = FP2::new_bigs(ra, rb);
for i in 0..mb {
t[i] = b[i + 6 * mb]
}
- let ra = Big::frombytes(&t);
+ let ra = Big::from_bytes(&t);
for i in 0..mb {
t[i] = b[i + 7 * mb]
}
- let rb = Big::frombytes(&t);
+ let rb = Big::from_bytes(&t);
let rb4 = FP2::new_bigs(ra, rb);
@@ -315,16 +323,19 @@
ECP4::new_fp4s(&rx, &ry)
}
- /* convert this to hex string */
- pub fn tostring(&self) -> String {
+ /// To String
+ ///
+ /// Converts `ECP4` to a hex string.
+ pub fn to_string(&self) -> String {
let mut W = self.clone();
W.affine();
if W.is_infinity() {
return String::from("infinity");
}
- return format!("({},{})", W.x.tostring(), W.y.tostring());
+ return format!("({},{})", W.x.to_string(), W.y.to_string());
}
+
/* Calculate RHS of twisted curve equation x^3+B/i */
pub fn rhs(x: &FP4) -> FP4 {
//x.norm();
@@ -820,7 +831,7 @@
#[inline(always)]
pub fn mapit(h: &[u8]) -> ECP4 {
let mut q = Big::new_ints(&rom::MODULUS);
- let mut x = Big::frombytes(h);
+ let mut x = Big::from_bytes(h);
x.rmod(&mut q);
let mut Q: ECP4;
let one = Big::new_int(1);
diff --git a/src/ecp8.rs b/src/ecp8.rs
index a597249..cfaa00d 100644
--- a/src/ecp8.rs
+++ b/src/ecp8.rs
@@ -37,6 +37,15 @@
z: FP8,
}
+impl PartialEq for ECP8 {
+ fn eq(&self, other: &ECP8) -> bool {
+ self.equals(other)
+ }
+}
+
+impl Eq for ECP8 {}
+
+
#[allow(non_snake_case)]
impl ECP8 {
/// New
@@ -98,7 +107,7 @@
pub fn is_infinity(&self) -> bool {
let xx = self.getpx();
let zz = self.getpz();
- return xx.iszilch() && zz.iszilch();
+ return xx.is_zilch() && zz.is_zilch();
}
/* set self=O */
@@ -151,7 +160,7 @@
}
/* Test if P == Q */
- pub fn equals(&mut self, Q: &mut ECP8) -> bool {
+ pub fn equals(&self, Q: &ECP8) -> bool {
let mut a = self.getpx();
let mut b = Q.getpx();
@@ -219,81 +228,81 @@
}
/// Convert to byte array
- pub fn tobytes(&self, b: &mut [u8]) {
+ pub fn to_bytes(&self, b: &mut [u8]) {
let mut t: [u8; big::MODBYTES as usize] = [0; big::MODBYTES as usize];
let mb = big::MODBYTES as usize;
let mut W = self.clone();
W.affine();
- W.x.geta().geta().geta().tobytes(&mut t);
+ W.x.geta().geta().geta().to_bytes(&mut t);
for i in 0..mb {
b[i] = t[i]
}
- W.x.geta().geta().getb().tobytes(&mut t);
+ W.x.geta().geta().getb().to_bytes(&mut t);
for i in 0..mb {
b[i + mb] = t[i]
}
- W.x.geta().getb().geta().tobytes(&mut t);
+ W.x.geta().getb().geta().to_bytes(&mut t);
for i in 0..mb {
b[i + 2 * mb] = t[i]
}
- W.x.geta().getb().getb().tobytes(&mut t);
+ W.x.geta().getb().getb().to_bytes(&mut t);
for i in 0..mb {
b[i + 3 * mb] = t[i]
}
- W.x.getb().geta().geta().tobytes(&mut t);
+ W.x.getb().geta().geta().to_bytes(&mut t);
for i in 0..mb {
b[i + 4 * mb] = t[i]
}
- W.x.getb().geta().getb().tobytes(&mut t);
+ W.x.getb().geta().getb().to_bytes(&mut t);
for i in 0..mb {
b[i + 5 * mb] = t[i]
}
- W.x.getb().getb().geta().tobytes(&mut t);
+ W.x.getb().getb().geta().to_bytes(&mut t);
for i in 0..mb {
b[i + 6 * mb] = t[i]
}
- W.x.getb().getb().getb().tobytes(&mut t);
+ W.x.getb().getb().getb().to_bytes(&mut t);
for i in 0..mb {
b[i + 7 * mb] = t[i]
}
- W.y.geta().geta().geta().tobytes(&mut t);
+ W.y.geta().geta().geta().to_bytes(&mut t);
for i in 0..mb {
b[i + 8 * mb] = t[i]
}
- W.y.geta().geta().getb().tobytes(&mut t);
+ W.y.geta().geta().getb().to_bytes(&mut t);
for i in 0..mb {
b[i + 9 * mb] = t[i]
}
- W.y.geta().getb().geta().tobytes(&mut t);
+ W.y.geta().getb().geta().to_bytes(&mut t);
for i in 0..mb {
b[i + 10 * mb] = t[i]
}
- W.y.geta().getb().getb().tobytes(&mut t);
+ W.y.geta().getb().getb().to_bytes(&mut t);
for i in 0..mb {
b[i + 11 * mb] = t[i]
}
- W.y.getb().geta().geta().tobytes(&mut t);
+ W.y.getb().geta().geta().to_bytes(&mut t);
for i in 0..mb {
b[i + 12 * mb] = t[i]
}
- W.y.getb().geta().getb().tobytes(&mut t);
+ W.y.getb().geta().getb().to_bytes(&mut t);
for i in 0..mb {
b[i + 13 * mb] = t[i]
}
- W.y.getb().getb().geta().tobytes(&mut t);
+ W.y.getb().getb().geta().to_bytes(&mut t);
for i in 0..mb {
b[i + 14 * mb] = t[i]
}
- W.y.getb().getb().getb().tobytes(&mut t);
+ W.y.getb().getb().getb().to_bytes(&mut t);
for i in 0..mb {
b[i + 15 * mb] = t[i]
}
@@ -304,29 +313,29 @@
/// Convert from byte array to point
/// Panics if insufficient bytes are given.
#[inline(always)]
- pub fn frombytes(b: &[u8]) -> ECP8 {
+ pub fn from_bytes(b: &[u8]) -> ECP8 {
let mut t: [u8; big::MODBYTES as usize] = [0; big::MODBYTES as usize];
let mb = big::MODBYTES as usize;
for i in 0..mb {
t[i] = b[i]
}
- let ra = Big::frombytes(&t);
+ let ra = Big::from_bytes(&t);
for i in 0..mb {
t[i] = b[i + mb]
}
- let rb = Big::frombytes(&t);
+ let rb = Big::from_bytes(&t);
let ra4 = FP2::new_bigs(ra, rb);
for i in 0..mb {
t[i] = b[i + 2 * mb]
}
- let ra = Big::frombytes(&t);
+ let ra = Big::from_bytes(&t);
for i in 0..mb {
t[i] = b[i + 3 * mb]
}
- let rb = Big::frombytes(&t);
+ let rb = Big::from_bytes(&t);
let rb4 = FP2::new_bigs(ra, rb);
@@ -335,22 +344,22 @@
for i in 0..mb {
t[i] = b[i + 4 * mb]
}
- let ra = Big::frombytes(&t);
+ let ra = Big::from_bytes(&t);
for i in 0..mb {
t[i] = b[i + 5 * mb]
}
- let rb = Big::frombytes(&t);
+ let rb = Big::from_bytes(&t);
let ra4 = FP2::new_bigs(ra, rb);
for i in 0..mb {
t[i] = b[i + 6 * mb]
}
- let ra = Big::frombytes(&t);
+ let ra = Big::from_bytes(&t);
for i in 0..mb {
t[i] = b[i + 7 * mb]
}
- let rb = Big::frombytes(&t);
+ let rb = Big::from_bytes(&t);
let rb4 = FP2::new_bigs(ra, rb);
@@ -361,22 +370,22 @@
for i in 0..mb {
t[i] = b[i + 8 * mb]
}
- let ra = Big::frombytes(&t);
+ let ra = Big::from_bytes(&t);
for i in 0..mb {
t[i] = b[i + 9 * mb]
}
- let rb = Big::frombytes(&t);
+ let rb = Big::from_bytes(&t);
let ra4 = FP2::new_bigs(ra, rb);
for i in 0..mb {
t[i] = b[i + 10 * mb]
}
- let ra = Big::frombytes(&t);
+ let ra = Big::from_bytes(&t);
for i in 0..mb {
t[i] = b[i + 11 * mb]
}
- let rb = Big::frombytes(&t);
+ let rb = Big::from_bytes(&t);
let rb4 = FP2::new_bigs(ra, rb);
@@ -385,22 +394,22 @@
for i in 0..mb {
t[i] = b[i + 12 * mb]
}
- let ra = Big::frombytes(&t);
+ let ra = Big::from_bytes(&t);
for i in 0..mb {
t[i] = b[i + 13 * mb]
}
- let rb = Big::frombytes(&t);
+ let rb = Big::from_bytes(&t);
let ra4 = FP2::new_bigs(ra, rb);
for i in 0..mb {
t[i] = b[i + 14 * mb]
}
- let ra = Big::frombytes(&t);
+ let ra = Big::from_bytes(&t);
for i in 0..mb {
t[i] = b[i + 15 * mb]
}
- let rb = Big::frombytes(&t);
+ let rb = Big::from_bytes(&t);
let rb4 = FP2::new_bigs(ra, rb);
@@ -411,14 +420,16 @@
return ECP8::new_fp8s(&rx, &ry);
}
- /* convert this to hex string */
- pub fn tostring(&self) -> String {
+ /// To String
+ ///
+ /// Converts `ECP8` to a hex string.
+ pub fn to_string(&self) -> String {
let mut W = self.clone();
W.affine();
if W.is_infinity() {
return String::from("infinity");
}
- return format!("({},{})", W.x.tostring(), W.y.tostring());
+ return format!("({},{})", W.x.to_string(), W.y.to_string());
}
/* Calculate RHS of twisted curve equation x^3+B/i */
@@ -1098,7 +1109,7 @@
#[inline(always)]
pub fn mapit(h: &[u8]) -> ECP8 {
let mut q = Big::new_ints(&rom::MODULUS);
- let mut x = Big::frombytes(h);
+ let mut x = Big::from_bytes(h);
x.rmod(&mut q);
let mut Q: ECP8;
let one = Big::new_int(1);
diff --git a/src/ff.rs b/src/ff.rs
index e460517..26f6345 100644
--- a/src/ff.rs
+++ b/src/ff.rs
@@ -6,7 +6,7 @@
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
-if debug {println!("sf2= {}",self.tostring())}
+if debug {println!("sf2= {}",self.to_string())}
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
@@ -131,9 +131,9 @@
}
/* test equals 0 */
- pub fn iszilch(&mut self) -> bool {
+ pub fn is_zilch(&mut self) -> bool {
for i in 0..self.length {
- if !self.v[i].iszilch() {
+ if !self.v[i].is_zilch() {
return false;
}
}
@@ -252,12 +252,12 @@
}
for i in 0..nn - 1 {
carry = self.v[vp + i].norm();
- self.v[vp + i].xortop(carry << P_TBITS);
+ self.v[vp + i].xor_top(carry << P_TBITS);
self.v[vp + i + 1].w[0] += carry;
}
carry = self.v[vp + nn - 1].norm();
if trunc {
- self.v[vp + nn - 1].xortop(carry << P_TBITS);
+ self.v[vp + nn - 1].xor_top(carry << P_TBITS);
}
}
@@ -283,7 +283,7 @@
for i in 0..self.length - 1 {
let carry = self.v[i].fshl(1);
self.v[i].inc(delay_carry);
- self.v[i].xortop((carry as Chunk) << P_TBITS);
+ self.v[i].xor_top((carry as Chunk) << P_TBITS);
delay_carry = carry;
}
self.v[self.length - 1].fshl(1);
@@ -296,19 +296,21 @@
let mut i = self.length - 1;
while i > 0 {
let carry = self.v[i].fshr(1);
- self.v[i - 1].xortop((carry as Chunk) << P_TBITS);
+ self.v[i - 1].xor_top((carry as Chunk) << P_TBITS);
i -= 1;
}
self.v[0].fshr(1);
}
- /* Convert to Hex String */
- pub fn tostring(&mut self) -> String {
+ /// To String
+ ///
+ /// Converts `FF` to a hex string.
+ pub fn to_string(&mut self) -> String {
self.norm();
let mut s = String::new();
let mut i: usize = self.length - 1;
loop {
- s = s + self.v[i].tostring().as_ref();
+ s = s + self.v[i].to_string().as_ref();
if i == 0 {
break;
}
@@ -318,15 +320,15 @@
}
/* Convert FFs to/from byte arrays */
- pub fn tobytes(&mut self, b: &mut [u8]) {
+ pub fn to_bytes(&mut self, b: &mut [u8]) {
for i in 0..self.length {
- self.v[i].tobytearray(b, (self.length - i - 1) * (big::MODBYTES as usize))
+ self.v[i].to_byte_array(b, (self.length - i - 1) * (big::MODBYTES as usize))
}
}
- pub fn frombytes(x: &mut FF, b: &[u8]) {
+ pub fn from_bytes(x: &mut FF, b: &[u8]) {
for i in 0..x.length {
- x.v[i] = Big::frombytearray(b, (x.length - i - 1) * (big::MODBYTES as usize))
+ x.v[i] = Big::from_byte_array(b, (x.length - i - 1) * (big::MODBYTES as usize))
}
}
@@ -976,14 +978,14 @@
x.sub(&y);
x.norm();
- while !x.iszilch() && x.parity() == 0 {
+ while !x.is_zilch() && x.parity() == 0 {
x.shr()
}
while FF::comp(&x, &y) > 0 {
x.sub(&y);
x.norm();
- while !x.iszilch() && x.parity() == 0 {
+ while !x.is_zilch() && x.parity() == 0 {
x.shr()
}
}
diff --git a/src/fp.rs b/src/fp.rs
index 4e345d3..dfc4322 100644
--- a/src/fp.rs
+++ b/src/fp.rs
@@ -42,13 +42,13 @@
impl fmt::Display for FP {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "FP: [ {} ]", self.tostring())
+ write!(f, "FP: [ {} ]", self.to_string())
}
}
impl fmt::Debug for FP {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "FP: [ {} ]", self.tostring())
+ write!(f, "FP: [ {} ]", self.to_string())
}
}
@@ -113,13 +113,20 @@
}
}
+ /// To String
+ ///
+ /// Converts a `FP` to a hex string.
+ pub fn to_string(&self) -> String {
+ self.redc().to_string()
+ }
+
/// From Hex Iterator
#[inline(always)]
pub fn from_hex_iter(iter: &mut SplitWhitespace) -> FP {
let xes = i32::from_str(iter.next().unwrap()).unwrap();
let x = iter.next().unwrap();
FP {
- x: Big::fromstring(x.to_string()),
+ x: Big::from_string(x.to_string()),
xes,
}
}
@@ -133,10 +140,13 @@
FP::from_hex_iter(&mut s)
}
+ /// To Hex
pub fn to_hex(&self) -> String {
- format!("{} {}", self.xes, self.x.tostring())
+ format!("{} {}", self.xes, self.x.to_string())
}
+ /// Reduce
+ ///
/// convert back to regular form
pub fn redc(&self) -> Big {
if MODTYPE != ModType::PseudoMersenne && MODTYPE != ModType::GeneralisedMersenne {
@@ -146,6 +156,8 @@
self.x.clone()
}
+ /// Modulo
+ ///
/// reduce a DBig to a Big using the appropriate form of the modulus
pub fn modulo(d: &mut DBig) -> Big {
if MODTYPE == ModType::PseudoMersenne {
@@ -169,7 +181,7 @@
for i in 0..big::NLEN {
let x = d.w[i];
- let tuple = Big::muladd(x, rom::MCONST - 1, x, d.w[big::NLEN + i - 1]);
+ let tuple = Big::mul_add(x, rom::MCONST - 1, x, d.w[big::NLEN + i - 1]);
d.w[big::NLEN + i] += tuple.0;
d.w[big::NLEN + i - 1] = tuple.1;
}
@@ -216,11 +228,6 @@
Big::new()
}
- /// convert to string
- pub fn tostring(&self) -> String {
- self.redc().tostring()
- }
-
/// reduce this mod Modulus
pub fn reduce(&mut self) {
let mut m = Big::new_ints(&rom::MODULUS);
@@ -249,10 +256,10 @@
}
/// Check if self is 0
- pub fn iszilch(&self) -> bool {
+ pub fn is_zilch(&self) -> bool {
let mut a = self.clone();
a.reduce();
- a.x.iszilch()
+ a.x.is_zilch()
}
/// copy from Big b
diff --git a/src/fp12.rs b/src/fp12.rs
index 2a96020..1345a84 100644
--- a/src/fp12.rs
+++ b/src/fp12.rs
@@ -115,9 +115,9 @@
}
/* test self=0 ? */
- pub fn iszilch(&self) -> bool {
+ pub fn is_zilch(&self) -> bool {
//self.reduce();
- return self.a.iszilch() && self.b.iszilch() && self.c.iszilch();
+ return self.a.is_zilch() && self.b.is_zilch() && self.c.is_zilch();
}
/* Conditional move of g to self dependant on d */
@@ -159,9 +159,9 @@
}
/* test self=1 ? */
- pub fn isunity(&self) -> bool {
+ pub fn is_unity(&self) -> bool {
let one = FP4::new_int(1);
- self.a.equals(&one) && self.b.iszilch() && self.c.iszilch()
+ self.a.equals(&one) && self.b.is_zilch() && self.c.is_zilch()
}
/* test self=x */
@@ -781,28 +781,28 @@
/* convert from byte array to FP12 */
#[inline(always)]
- pub fn frombytes(w: &[u8]) -> FP12 {
+ pub fn from_bytes(w: &[u8]) -> FP12 {
let mut t: [u8; big::MODBYTES as usize] = [0; big::MODBYTES as usize];
let mb = big::MODBYTES as usize;
for i in 0..mb {
t[i] = w[i]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let c = FP2::new_bigs(a, b);
for i in 0..mb {
t[i] = w[i + 2 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 3 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let d = FP2::new_bigs(a, b);
let e = FP4::new_fp2s(c, d);
@@ -810,21 +810,21 @@
for i in 0..mb {
t[i] = w[i + 4 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 5 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let c = FP2::new_bigs(a, b);
for i in 0..mb {
t[i] = w[i + 6 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 7 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let d = FP2::new_bigs(a, b);
let f = FP4::new_fp2s(c, d);
@@ -832,22 +832,22 @@
for i in 0..mb {
t[i] = w[i + 8 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 9 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let c = FP2::new_bigs(a, b);
for i in 0..mb {
t[i] = w[i + 10 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 11 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let d = FP2::new_bigs(a, b);
let g = FP4::new_fp2s(c, d);
@@ -856,69 +856,71 @@
}
/* convert this to byte array */
- pub fn tobytes(&self, w: &mut [u8]) {
+ pub fn to_bytes(&self, w: &mut [u8]) {
let mut t: [u8; big::MODBYTES as usize] = [0; big::MODBYTES as usize];
let mb = big::MODBYTES as usize;
- self.a.geta().geta().tobytes(&mut t);
+ self.a.geta().geta().to_bytes(&mut t);
for i in 0..mb {
w[i] = t[i]
}
- self.a.geta().getb().tobytes(&mut t);
+ self.a.geta().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + mb] = t[i]
}
- self.a.getb().geta().tobytes(&mut t);
+ self.a.getb().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 2 * mb] = t[i]
}
- self.a.getb().getb().tobytes(&mut t);
+ self.a.getb().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 3 * mb] = t[i]
}
- self.b.geta().geta().tobytes(&mut t);
+ self.b.geta().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 4 * mb] = t[i]
}
- self.b.geta().getb().tobytes(&mut t);
+ self.b.geta().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 5 * mb] = t[i]
}
- self.b.getb().geta().tobytes(&mut t);
+ self.b.getb().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 6 * mb] = t[i]
}
- self.b.getb().getb().tobytes(&mut t);
+ self.b.getb().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 7 * mb] = t[i]
}
- self.c.geta().geta().tobytes(&mut t);
+ self.c.geta().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 8 * mb] = t[i]
}
- self.c.geta().getb().tobytes(&mut t);
+ self.c.geta().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 9 * mb] = t[i]
}
- self.c.getb().geta().tobytes(&mut t);
+ self.c.getb().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 10 * mb] = t[i]
}
- self.c.getb().getb().tobytes(&mut t);
+ self.c.getb().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 11 * mb] = t[i]
}
}
- /* output to hex string */
- pub fn tostring(&self) -> String {
+ /// To String
+ ///
+ /// Converts a `FP12` to a hex string.
+ pub fn to_string(&self) -> String {
return format!(
"[{},{},{}]",
- self.a.tostring(),
- self.b.tostring(),
- self.c.tostring()
+ self.a.to_string(),
+ self.b.to_string(),
+ self.c.to_string()
);
}
@@ -1009,7 +1011,7 @@
let mut c = g1.trace();
- if b.iszilch() {
+ if b.is_zilch() {
c = c.xtr_pow(&a);
return c;
}
diff --git a/src/fp16.rs b/src/fp16.rs
index cd71567..5a1acea 100644
--- a/src/fp16.rs
+++ b/src/fp16.rs
@@ -27,6 +27,14 @@
b: FP8,
}
+impl PartialEq for FP16 {
+ fn eq(&self, other: &FP16) -> bool {
+ self.equals(other)
+ }
+}
+
+impl Eq for FP16 {}
+
impl FP16 {
#[inline(always)]
pub fn new() -> FP16 {
@@ -87,19 +95,19 @@
}
/* test self=0 ? */
- pub fn iszilch(&self) -> bool {
- return self.a.iszilch() && self.b.iszilch();
+ pub fn is_zilch(&self) -> bool {
+ return self.a.is_zilch() && self.b.is_zilch();
}
/* test self=1 ? */
- pub fn isunity(&self) -> bool {
+ pub fn is_unity(&self) -> bool {
let one = FP8::new_int(1);
- return self.a.equals(&one) && self.b.iszilch();
+ return self.a.equals(&one) && self.b.is_zilch();
}
/// Test is w real? That is in a+ib test b is zero */
pub fn isreal(&self) -> bool {
- return self.b.iszilch();
+ return self.b.is_zilch();
}
/// Extract real part a
@@ -276,9 +284,11 @@
self.norm();
}
- /* output to hex string */
- pub fn tostring(&self) -> String {
- return format!("[{},{}]", self.a.tostring(), self.b.tostring());
+ /// To String
+ ///
+ /// Converts a `FP16` to a hex string.
+ pub fn to_string(&self) -> String {
+ return format!("[{},{}]", self.a.to_string(), self.b.to_string());
}
/* self=1/self */
@@ -345,7 +355,7 @@
if bt == 1 {
r.mul(&w)
};
- if z.iszilch() {
+ if z.is_zilch() {
break;
}
w.sqr();
diff --git a/src/fp2.rs b/src/fp2.rs
index b449ef3..ac96b4e 100644
--- a/src/fp2.rs
+++ b/src/fp2.rs
@@ -137,8 +137,8 @@
}
/* test self=0 ? */
- pub fn iszilch(&self) -> bool {
- return self.a.iszilch() && self.b.iszilch();
+ pub fn is_zilch(&self) -> bool {
+ return self.a.is_zilch() && self.b.is_zilch();
}
pub fn cmove(&mut self, g: &FP2, d: isize) {
@@ -147,9 +147,9 @@
}
/* test self=1 ? */
- pub fn isunity(&self) -> bool {
+ pub fn is_unity(&self) -> bool {
let one = FP::new_int(1);
- return self.a.equals(&one) && self.b.iszilch();
+ return self.a.equals(&one) && self.b.is_zilch();
}
/* test self=x */
@@ -302,7 +302,7 @@
/* sqrt(a+ib) = sqrt(a+sqrt(a*a-n*b*b)/2)+ib/(2*sqrt(a+sqrt(a*a-n*b*b)/2)) */
/* returns true if this is QR */
pub fn sqrt(&mut self) -> bool {
- if self.iszilch() {
+ if self.is_zilch() {
return true;
}
let mut w1 = self.b.clone();
@@ -338,11 +338,14 @@
return true;
}
- /* output to hex string */
- pub fn tostring(&self) -> String {
- return format!("[{},{}]", self.a.tostring(), self.b.tostring());
+ /// To String
+ ///
+ /// Converts a `FP2` to a hex string.
+ pub fn to_string(&self) -> String {
+ return format!("[{},{}]", self.a.to_string(), self.b.to_string());
}
+ /// To Hex
pub fn to_hex(&self) -> String {
format!("{} {}", self.a.to_hex(), self.b.to_hex())
}
@@ -444,7 +447,7 @@
/// Not constant time.
/// https://tools.ietf.org/html/draft-irtf-cfrg-hash-to-curve-08#section-4.1
pub fn sgn0(&self) -> bool {
- if self.a.iszilch() {
+ if self.a.is_zilch() {
self.b.sgn0()
} else {
self.a.sgn0()
diff --git a/src/fp24.rs b/src/fp24.rs
index dcca5af..e0275f4 100644
--- a/src/fp24.rs
+++ b/src/fp24.rs
@@ -40,6 +40,14 @@
stype: usize,
}
+impl PartialEq for FP24 {
+ fn eq(&self, other: &FP24) -> bool {
+ self.equals(other)
+ }
+}
+
+impl Eq for FP24 {}
+
impl FP24 {
#[inline(always)]
pub fn new() -> FP24 {
@@ -106,8 +114,8 @@
}
/* test self=0 ? */
- pub fn iszilch(&self) -> bool {
- return self.a.iszilch() && self.b.iszilch() && self.c.iszilch();
+ pub fn is_zilch(&self) -> bool {
+ return self.a.is_zilch() && self.b.is_zilch() && self.c.is_zilch();
}
/* Conditional move of g to self dependant on d */
@@ -149,9 +157,9 @@
}
/* test self=1 ? */
- pub fn isunity(&self) -> bool {
+ pub fn is_unity(&self) -> bool {
let one = FP8::new_int(1);
- return self.a.equals(&one) && self.b.iszilch() && self.c.iszilch();
+ return self.a.equals(&one) && self.b.is_zilch() && self.c.is_zilch();
}
/* test self=x */
@@ -778,28 +786,28 @@
/* convert from byte array to FP24 */
#[inline(always)]
- pub fn frombytes(w: &[u8]) -> FP24 {
+ pub fn from_bytes(w: &[u8]) -> FP24 {
let mut t: [u8; big::MODBYTES as usize] = [0; big::MODBYTES as usize];
let mb = big::MODBYTES as usize;
for i in 0..mb {
t[i] = w[i]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let c = FP2::new_bigs(a, b);
for i in 0..mb {
t[i] = w[i + 2 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 3 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let d = FP2::new_bigs(a, b);
let ea = FP4::new_fp2s(c, d);
@@ -807,21 +815,21 @@
for i in 0..mb {
t[i] = w[i + 4 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 5 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let c = FP2::new_bigs(a, b);
for i in 0..mb {
t[i] = w[i + 6 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 7 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let d = FP2::new_bigs(a, b);
let eb = FP4::new_fp2s(c, d);
@@ -831,21 +839,21 @@
for i in 0..mb {
t[i] = w[i + 8 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 9 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let c = FP2::new_bigs(a, b);
for i in 0..mb {
t[i] = w[i + 10 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 11 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let d = FP2::new_bigs(a, b);
let ea = FP4::new_fp2s(c, d);
@@ -853,21 +861,21 @@
for i in 0..mb {
t[i] = w[i + 12 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 13 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let c = FP2::new_bigs(a, b);
for i in 0..mb {
t[i] = w[i + 14 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 15 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let d = FP2::new_bigs(a, b);
let eb = FP4::new_fp2s(c, d);
@@ -877,22 +885,22 @@
for i in 0..mb {
t[i] = w[i + 16 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 17 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let c = FP2::new_bigs(a, b);
for i in 0..mb {
t[i] = w[i + 18 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 19 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let d = FP2::new_bigs(a, b);
let ea = FP4::new_fp2s(c, d);
@@ -900,22 +908,22 @@
for i in 0..mb {
t[i] = w[i + 20 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 21 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let c = FP2::new_bigs(a, b);
for i in 0..mb {
t[i] = w[i + 22 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 23 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let d = FP2::new_bigs(a, b);
let eb = FP4::new_fp2s(c, d);
@@ -926,120 +934,122 @@
}
/* convert this to byte array */
- pub fn tobytes(&self, w: &mut [u8]) {
+ pub fn to_bytes(&self, w: &mut [u8]) {
let mut t: [u8; big::MODBYTES as usize] = [0; big::MODBYTES as usize];
let mb = big::MODBYTES as usize;
- self.a.geta().geta().geta().tobytes(&mut t);
+ self.a.geta().geta().geta().to_bytes(&mut t);
for i in 0..mb {
w[i] = t[i]
}
- self.a.geta().geta().getb().tobytes(&mut t);
+ self.a.geta().geta().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + mb] = t[i]
}
- self.a.geta().getb().geta().tobytes(&mut t);
+ self.a.geta().getb().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 2 * mb] = t[i]
}
- self.a.geta().getb().getb().tobytes(&mut t);
+ self.a.geta().getb().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 3 * mb] = t[i]
}
- self.a.getb().geta().geta().tobytes(&mut t);
+ self.a.getb().geta().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 4 * mb] = t[i]
}
- self.a.getb().geta().getb().tobytes(&mut t);
+ self.a.getb().geta().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 5 * mb] = t[i]
}
- self.a.getb().getb().geta().tobytes(&mut t);
+ self.a.getb().getb().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 6 * mb] = t[i]
}
- self.a.getb().getb().getb().tobytes(&mut t);
+ self.a.getb().getb().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 7 * mb] = t[i]
}
- self.b.geta().geta().geta().tobytes(&mut t);
+ self.b.geta().geta().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 8 * mb] = t[i]
}
- self.b.geta().geta().getb().tobytes(&mut t);
+ self.b.geta().geta().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 9 * mb] = t[i]
}
- self.b.geta().getb().geta().tobytes(&mut t);
+ self.b.geta().getb().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 10 * mb] = t[i]
}
- self.b.geta().getb().getb().tobytes(&mut t);
+ self.b.geta().getb().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 11 * mb] = t[i]
}
- self.b.getb().geta().geta().tobytes(&mut t);
+ self.b.getb().geta().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 12 * mb] = t[i]
}
- self.b.getb().geta().getb().tobytes(&mut t);
+ self.b.getb().geta().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 13 * mb] = t[i]
}
- self.b.getb().getb().geta().tobytes(&mut t);
+ self.b.getb().getb().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 14 * mb] = t[i]
}
- self.b.getb().getb().getb().tobytes(&mut t);
+ self.b.getb().getb().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 15 * mb] = t[i]
}
- self.c.geta().geta().geta().tobytes(&mut t);
+ self.c.geta().geta().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 16 * mb] = t[i]
}
- self.c.geta().geta().getb().tobytes(&mut t);
+ self.c.geta().geta().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 17 * mb] = t[i]
}
- self.c.geta().getb().geta().tobytes(&mut t);
+ self.c.geta().getb().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 18 * mb] = t[i]
}
- self.c.geta().getb().getb().tobytes(&mut t);
+ self.c.geta().getb().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 19 * mb] = t[i]
}
- self.c.getb().geta().geta().tobytes(&mut t);
+ self.c.getb().geta().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 20 * mb] = t[i]
}
- self.c.getb().geta().getb().tobytes(&mut t);
+ self.c.getb().geta().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 21 * mb] = t[i]
}
- self.c.getb().getb().geta().tobytes(&mut t);
+ self.c.getb().getb().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 22 * mb] = t[i]
}
- self.c.getb().getb().getb().tobytes(&mut t);
+ self.c.getb().getb().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 23 * mb] = t[i]
}
}
- /* output to hex string */
- pub fn tostring(&self) -> String {
+ /// To String
+ ///
+ /// Converts a `FP24` to a hex string.
+ pub fn to_string(&self) -> String {
return format!(
"[{},{},{}]",
- self.a.tostring(),
- self.b.tostring(),
- self.c.tostring()
+ self.a.to_string(),
+ self.b.to_string(),
+ self.c.to_string()
);
}
@@ -1105,7 +1115,7 @@
let mut c = g1.trace();
- if b.iszilch() {
+ if b.is_zilch() {
c = c.xtr_pow(&mut a);
return c;
}
diff --git a/src/fp4.rs b/src/fp4.rs
index 652452c..774a4bd 100644
--- a/src/fp4.rs
+++ b/src/fp4.rs
@@ -107,19 +107,19 @@
}
/* test self=0 ? */
- pub fn iszilch(&self) -> bool {
- self.a.iszilch() && self.b.iszilch()
+ pub fn is_zilch(&self) -> bool {
+ self.a.is_zilch() && self.b.is_zilch()
}
/* test self=1 ? */
- pub fn isunity(&self) -> bool {
+ pub fn is_unity(&self) -> bool {
let one = FP2::new_int(1);
- self.a.equals(&one) && self.b.iszilch()
+ self.a.equals(&one) && self.b.is_zilch()
}
/* test is w real? That is in a+ib test b is zero */
pub fn isreal(&self) -> bool {
- self.b.iszilch()
+ self.b.is_zilch()
}
/// Real
@@ -307,9 +307,11 @@
self.norm();
}
- /* output to hex string */
- pub fn tostring(&self) -> String {
- return format!("[{},{}]", self.a.tostring(), self.b.tostring());
+ /// To String
+ ///
+ /// Converts a `FP4` to a hex string.
+ pub fn to_string(&self) -> String {
+ return format!("[{},{}]", self.a.to_string(), self.b.to_string());
}
pub fn to_hex(&self) -> String {
@@ -387,7 +389,7 @@
if bt == 1 {
r.mul(&w)
};
- if z.iszilch() {
+ if z.is_zilch() {
break;
}
w.sqr();
@@ -651,7 +653,7 @@
/* sqrt(a+ib) = sqrt(a+sqrt(a*a-n*b*b)/2)+ib/(2*sqrt(a+sqrt(a*a-n*b*b)/2)) */
/* returns true if this is QR */
pub fn sqrt(&mut self) -> bool {
- if self.iszilch() {
+ if self.is_zilch() {
return true;
}
@@ -659,7 +661,7 @@
let mut s = self.getb();
let mut t = self.geta();
- if s.iszilch() {
+ if s.is_zilch() {
if t.sqrt() {
self.a = t.clone();
self.b.zero();
diff --git a/src/fp48.rs b/src/fp48.rs
index 74ce7d9..fcc25dc 100644
--- a/src/fp48.rs
+++ b/src/fp48.rs
@@ -41,6 +41,14 @@
stype: usize,
}
+impl PartialEq for FP48 {
+ fn eq(&self, other: &FP48) -> bool {
+ self.equals(other)
+ }
+}
+
+impl Eq for FP48 {}
+
impl FP48 {
#[inline(always)]
pub fn new() -> FP48 {
@@ -109,8 +117,8 @@
}
/* test self=0 ? */
- pub fn iszilch(&self) -> bool {
- return self.a.iszilch() && self.b.iszilch() && self.c.iszilch();
+ pub fn is_zilch(&self) -> bool {
+ return self.a.is_zilch() && self.b.is_zilch() && self.c.is_zilch();
}
/* Conditional move of g to self dependant on d */
@@ -152,9 +160,9 @@
}
/* test self=1 ? */
- pub fn isunity(&self) -> bool {
+ pub fn is_unity(&self) -> bool {
let one = FP16::new_int(1);
- return self.a.equals(&one) && self.b.iszilch() && self.c.iszilch();
+ return self.a.equals(&one) && self.b.is_zilch() && self.c.is_zilch();
}
/* test self=x */
@@ -784,28 +792,28 @@
/// Convert from byte array to FP48
#[inline(always)]
- pub fn frombytes(w: &[u8]) -> FP48 {
+ pub fn from_bytes(w: &[u8]) -> FP48 {
let mut t: [u8; big::MODBYTES as usize] = [0; big::MODBYTES as usize];
let mb = big::MODBYTES as usize;
for i in 0..mb {
t[i] = w[i]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let c = FP2::new_bigs(a, b);
for i in 0..mb {
t[i] = w[i + 2 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 3 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let d = FP2::new_bigs(a, b);
let ea = FP4::new_fp2s(c, d);
@@ -813,21 +821,21 @@
for i in 0..mb {
t[i] = w[i + 4 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 5 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let c = FP2::new_bigs(a, b);
for i in 0..mb {
t[i] = w[i + 6 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 7 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let d = FP2::new_bigs(a, b);
let eb = FP4::new_fp2s(c, d);
@@ -837,21 +845,21 @@
for i in 0..mb {
t[i] = w[i + 8 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 9 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let c = FP2::new_bigs(a, b);
for i in 0..mb {
t[i] = w[i + 10 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 11 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let d = FP2::new_bigs(a, b);
let ea = FP4::new_fp2s(c, d);
@@ -859,21 +867,21 @@
for i in 0..mb {
t[i] = w[i + 12 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 13 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let c = FP2::new_bigs(a, b);
for i in 0..mb {
t[i] = w[i + 14 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 15 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let d = FP2::new_bigs(a, b);
let eb = FP4::new_fp2s(c, d);
@@ -885,21 +893,21 @@
for i in 0..mb {
t[i] = w[i + 16 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 17 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let c = FP2::new_bigs(a, b);
for i in 0..mb {
t[i] = w[i + 18 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 19 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let d = FP2::new_bigs(a, b);
let ea = FP4::new_fp2s(c, d);
@@ -907,21 +915,21 @@
for i in 0..mb {
t[i] = w[i + 20 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 21 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let c = FP2::new_bigs(a, b);
for i in 0..mb {
t[i] = w[i + 22 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 23 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let d = FP2::new_bigs(a, b);
let eb = FP4::new_fp2s(c, d);
@@ -931,21 +939,21 @@
for i in 0..mb {
t[i] = w[i + 24 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 25 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let c = FP2::new_bigs(a, b);
for i in 0..mb {
t[i] = w[i + 26 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 27 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let d = FP2::new_bigs(a, b);
let ea = FP4::new_fp2s(c, d);
@@ -953,21 +961,21 @@
for i in 0..mb {
t[i] = w[i + 28 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 29 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let c = FP2::new_bigs(a, b);
for i in 0..mb {
t[i] = w[i + 30 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 31 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let d = FP2::new_bigs(a, b);
let eb = FP4::new_fp2s(c, d);
@@ -979,21 +987,21 @@
for i in 0..mb {
t[i] = w[i + 32 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 33 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let c = FP2::new_bigs(a, b);
for i in 0..mb {
t[i] = w[i + 34 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 35 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let d = FP2::new_bigs(a, b);
let ea = FP4::new_fp2s(c, d);
@@ -1001,21 +1009,21 @@
for i in 0..mb {
t[i] = w[i + 36 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 37 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let c = FP2::new_bigs(a, b);
for i in 0..mb {
t[i] = w[i + 38 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 39 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let d = FP2::new_bigs(a, b);
let eb = FP4::new_fp2s(c, d);
@@ -1025,22 +1033,22 @@
for i in 0..mb {
t[i] = w[i + 40 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 41 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let c = FP2::new_bigs(a, b);
for i in 0..mb {
t[i] = w[i + 42 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 43 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let d = FP2::new_bigs(a, b);
let ea = FP4::new_fp2s(c, d);
@@ -1048,22 +1056,22 @@
for i in 0..mb {
t[i] = w[i + 44 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 45 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let c = FP2::new_bigs(a, b);
for i in 0..mb {
t[i] = w[i + 46 * mb]
}
- let a = Big::frombytes(&t);
+ let a = Big::from_bytes(&t);
for i in 0..mb {
t[i] = w[i + 47 * mb]
}
- let b = Big::frombytes(&t);
+ let b = Big::from_bytes(&t);
let d = FP2::new_bigs(a, b);
let eb = FP4::new_fp2s(c, d);
@@ -1076,222 +1084,224 @@
}
/* convert this to byte array */
- pub fn tobytes(&self, w: &mut [u8]) {
+ pub fn to_bytes(&self, w: &mut [u8]) {
let mut t: [u8; big::MODBYTES as usize] = [0; big::MODBYTES as usize];
let mb = big::MODBYTES as usize;
- self.a.geta().geta().geta().geta().tobytes(&mut t);
+ self.a.geta().geta().geta().geta().to_bytes(&mut t);
for i in 0..mb {
w[i] = t[i]
}
- self.a.geta().geta().geta().getb().tobytes(&mut t);
+ self.a.geta().geta().geta().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + mb] = t[i]
}
- self.a.geta().geta().getb().geta().tobytes(&mut t);
+ self.a.geta().geta().getb().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 2 * mb] = t[i]
}
- self.a.geta().geta().getb().getb().tobytes(&mut t);
+ self.a.geta().geta().getb().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 3 * mb] = t[i]
}
- self.a.geta().getb().geta().geta().tobytes(&mut t);
+ self.a.geta().getb().geta().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 4 * mb] = t[i]
}
- self.a.geta().getb().geta().getb().tobytes(&mut t);
+ self.a.geta().getb().geta().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 5 * mb] = t[i]
}
- self.a.geta().getb().getb().geta().tobytes(&mut t);
+ self.a.geta().getb().getb().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 6 * mb] = t[i]
}
- self.a.geta().getb().getb().getb().tobytes(&mut t);
+ self.a.geta().getb().getb().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 7 * mb] = t[i]
}
- self.a.getb().geta().geta().geta().tobytes(&mut t);
+ self.a.getb().geta().geta().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 8 * mb] = t[i]
}
- self.a.getb().geta().geta().getb().tobytes(&mut t);
+ self.a.getb().geta().geta().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 9 * mb] = t[i]
}
- self.a.getb().geta().getb().geta().tobytes(&mut t);
+ self.a.getb().geta().getb().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 10 * mb] = t[i]
}
- self.a.getb().geta().getb().getb().tobytes(&mut t);
+ self.a.getb().geta().getb().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 11 * mb] = t[i]
}
- self.a.getb().getb().geta().geta().tobytes(&mut t);
+ self.a.getb().getb().geta().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 12 * mb] = t[i]
}
- self.a.getb().getb().geta().getb().tobytes(&mut t);
+ self.a.getb().getb().geta().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 13 * mb] = t[i]
}
- self.a.getb().getb().getb().geta().tobytes(&mut t);
+ self.a.getb().getb().getb().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 14 * mb] = t[i]
}
- self.a.getb().getb().getb().getb().tobytes(&mut t);
+ self.a.getb().getb().getb().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 15 * mb] = t[i]
}
- self.b.geta().geta().geta().geta().tobytes(&mut t);
+ self.b.geta().geta().geta().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 16 * mb] = t[i]
}
- self.b.geta().geta().geta().getb().tobytes(&mut t);
+ self.b.geta().geta().geta().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 17 * mb] = t[i]
}
- self.b.geta().geta().getb().geta().tobytes(&mut t);
+ self.b.geta().geta().getb().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 18 * mb] = t[i]
}
- self.b.geta().geta().getb().getb().tobytes(&mut t);
+ self.b.geta().geta().getb().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 19 * mb] = t[i]
}
- self.b.geta().getb().geta().geta().tobytes(&mut t);
+ self.b.geta().getb().geta().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 20 * mb] = t[i]
}
- self.b.geta().getb().geta().getb().tobytes(&mut t);
+ self.b.geta().getb().geta().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 21 * mb] = t[i]
}
- self.b.geta().getb().getb().geta().tobytes(&mut t);
+ self.b.geta().getb().getb().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 22 * mb] = t[i]
}
- self.b.geta().getb().getb().getb().tobytes(&mut t);
+ self.b.geta().getb().getb().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 23 * mb] = t[i]
}
- self.b.getb().geta().geta().geta().tobytes(&mut t);
+ self.b.getb().geta().geta().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 24 * mb] = t[i]
}
- self.b.getb().geta().geta().getb().tobytes(&mut t);
+ self.b.getb().geta().geta().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 25 * mb] = t[i]
}
- self.b.getb().geta().getb().geta().tobytes(&mut t);
+ self.b.getb().geta().getb().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 26 * mb] = t[i]
}
- self.b.getb().geta().getb().getb().tobytes(&mut t);
+ self.b.getb().geta().getb().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 27 * mb] = t[i]
}
- self.b.getb().getb().geta().geta().tobytes(&mut t);
+ self.b.getb().getb().geta().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 28 * mb] = t[i]
}
- self.b.getb().getb().geta().getb().tobytes(&mut t);
+ self.b.getb().getb().geta().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 29 * mb] = t[i]
}
- self.b.getb().getb().getb().geta().tobytes(&mut t);
+ self.b.getb().getb().getb().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 30 * mb] = t[i]
}
- self.b.getb().getb().getb().getb().tobytes(&mut t);
+ self.b.getb().getb().getb().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 31 * mb] = t[i]
}
- self.c.geta().geta().geta().geta().tobytes(&mut t);
+ self.c.geta().geta().geta().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 32 * mb] = t[i]
}
- self.c.geta().geta().geta().getb().tobytes(&mut t);
+ self.c.geta().geta().geta().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 33 * mb] = t[i]
}
- self.c.geta().geta().getb().geta().tobytes(&mut t);
+ self.c.geta().geta().getb().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 34 * mb] = t[i]
}
- self.c.geta().geta().getb().getb().tobytes(&mut t);
+ self.c.geta().geta().getb().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 35 * mb] = t[i]
}
- self.c.geta().getb().geta().geta().tobytes(&mut t);
+ self.c.geta().getb().geta().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 36 * mb] = t[i]
}
- self.c.geta().getb().geta().getb().tobytes(&mut t);
+ self.c.geta().getb().geta().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 37 * mb] = t[i]
}
- self.c.geta().getb().getb().geta().tobytes(&mut t);
+ self.c.geta().getb().getb().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 38 * mb] = t[i]
}
- self.c.geta().getb().getb().getb().tobytes(&mut t);
+ self.c.geta().getb().getb().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 39 * mb] = t[i]
}
- self.c.getb().geta().geta().geta().tobytes(&mut t);
+ self.c.getb().geta().geta().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 40 * mb] = t[i]
}
- self.c.getb().geta().geta().getb().tobytes(&mut t);
+ self.c.getb().geta().geta().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 41 * mb] = t[i]
}
- self.c.getb().geta().getb().geta().tobytes(&mut t);
+ self.c.getb().geta().getb().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 42 * mb] = t[i]
}
- self.c.getb().geta().getb().getb().tobytes(&mut t);
+ self.c.getb().geta().getb().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 43 * mb] = t[i]
}
- self.c.getb().getb().geta().geta().tobytes(&mut t);
+ self.c.getb().getb().geta().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 44 * mb] = t[i]
}
- self.c.getb().getb().geta().getb().tobytes(&mut t);
+ self.c.getb().getb().geta().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 45 * mb] = t[i]
}
- self.c.getb().getb().getb().geta().tobytes(&mut t);
+ self.c.getb().getb().getb().geta().to_bytes(&mut t);
for i in 0..mb {
w[i + 46 * mb] = t[i]
}
- self.c.getb().getb().getb().getb().tobytes(&mut t);
+ self.c.getb().getb().getb().getb().to_bytes(&mut t);
for i in 0..mb {
w[i + 47 * mb] = t[i]
}
}
- /* output to hex string */
- pub fn tostring(&self) -> String {
+ /// To String
+ ///
+ /// Converts `FP48` to a hex string.
+ pub fn to_string(&self) -> String {
return format!(
"[{},{},{}]",
- self.a.tostring(),
- self.b.tostring(),
- self.c.tostring()
+ self.a.to_string(),
+ self.b.to_string(),
+ self.c.to_string()
);
}
@@ -1357,7 +1367,7 @@
let mut c = g1.trace();
- if b.iszilch() {
+ if b.is_zilch() {
c = c.xtr_pow(&mut a);
return c;
}
diff --git a/src/fp8.rs b/src/fp8.rs
index 2349898..100208d 100644
--- a/src/fp8.rs
+++ b/src/fp8.rs
@@ -28,6 +28,14 @@
b: FP4,
}
+impl PartialEq for FP8 {
+ fn eq(&self, other: &FP8) -> bool {
+ self.equals(other)
+ }
+}
+
+impl Eq for FP8 {}
+
impl FP8 {
/// New
#[inline(always)]
@@ -92,19 +100,19 @@
}
/* test self=0 ? */
- pub fn iszilch(&self) -> bool {
- return self.a.iszilch() && self.b.iszilch();
+ pub fn is_zilch(&self) -> bool {
+ return self.a.is_zilch() && self.b.is_zilch();
}
/* test self=1 ? */
- pub fn isunity(&self) -> bool {
+ pub fn is_unity(&self) -> bool {
let one = FP4::new_int(1);
- return self.a.equals(&one) && self.b.iszilch();
+ return self.a.equals(&one) && self.b.is_zilch();
}
/* test is w real? That is in a+ib test b is zero */
pub fn isreal(&self) -> bool {
- return self.b.iszilch();
+ return self.b.is_zilch();
}
/// Real
@@ -301,9 +309,11 @@
self.norm();
}
- /* output to hex string */
- pub fn tostring(&self) -> String {
- return format!("[{},{}]", self.a.tostring(), self.b.tostring());
+ /// To String
+ ///
+ /// Converts a `FP8` to a hex string.
+ pub fn to_string(&self) -> String {
+ return format!("[{},{}]", self.a.to_string(), self.b.to_string());
}
/* self=1/self */
@@ -372,7 +382,7 @@
if bt == 1 {
r.mul(&w)
};
- if z.iszilch() {
+ if z.is_zilch() {
break;
}
w.sqr();
@@ -644,7 +654,7 @@
/* sqrt(a+ib) = sqrt(a+sqrt(a*a-n*b*b)/2)+ib/(2*sqrt(a+sqrt(a*a-n*b*b)/2)) */
/* returns true if this is QR */
pub fn sqrt(&mut self) -> bool {
- if self.iszilch() {
+ if self.is_zilch() {
return true;
}
@@ -652,7 +662,7 @@
let mut s = self.getb();
let mut t = self.geta();
- if s.iszilch() {
+ if s.is_zilch() {
if t.sqrt() {
self.a = t.clone();
self.b.zero();
diff --git a/src/hash_to_curve.rs b/src/hash_to_curve.rs
index bb5de43..c52a9bf 100644
--- a/src/hash_to_curve.rs
+++ b/src/hash_to_curve.rs
@@ -97,7 +97,7 @@
for i in 0..count as usize {
let elm_offset = H2C_L as usize * i * m as usize;
let mut dbig =
- DBig::frombytes(&pseudo_random_bytes[elm_offset..elm_offset + H2C_L as usize]);
+ DBig::from_bytes(&pseudo_random_bytes[elm_offset..elm_offset + H2C_L as usize]);
let e: Big = dbig.dmod(&p);
u.push(FP::new_big(e));
}
@@ -122,7 +122,7 @@
for j in 0..m as usize {
let elm_offset = H2C_L as usize * (j + i * m as usize);
let mut big =
- DBig::frombytes(&pseudo_random_bytes[elm_offset..elm_offset + H2C_L as usize]);
+ DBig::from_bytes(&pseudo_random_bytes[elm_offset..elm_offset + H2C_L as usize]);
e.push(big.dmod(&p));
}
u.push(FP2::new_bigs(e[0].clone(), e[1].clone()));
@@ -229,7 +229,7 @@
x.mul(&a_inverse);
// Deal with case where Z^2 * u^4 + Z * u^2 == 0
- if tv1.iszilch() {
+ if tv1.is_zilch() {
// x = B / (Z * A)
x = sswu_z.clone();
x.inverse();
@@ -305,7 +305,7 @@
x.mul(&a_inverse);
// Deal with case where Z^2 * u^4 + Z * u^2 == 0
- if tv1.iszilch() {
+ if tv1.is_zilch() {
// x = B / (Z * A)
x = sswu_z.clone();
x.inverse();
diff --git a/src/mpin.rs b/src/mpin.rs
index 7b86603..58efa07 100644
--- a/src/mpin.rs
+++ b/src/mpin.rs
@@ -58,28 +58,28 @@
let mut w: [u8; EFS] = [0; EFS];
let mut t: [u8; 6 * EFS] = [0; 6 * EFS];
- c.geta().geta().tobytes(&mut w);
+ c.geta().geta().to_bytes(&mut w);
for i in 0..EFS {
t[i] = w[i]
}
- c.geta().getb().tobytes(&mut w);
+ c.geta().getb().to_bytes(&mut w);
for i in EFS..2 * EFS {
t[i] = w[i - EFS]
}
- c.getb().geta().tobytes(&mut w);
+ c.getb().geta().to_bytes(&mut w);
for i in 2 * EFS..3 * EFS {
t[i] = w[i - 2 * EFS]
}
- c.getb().getb().tobytes(&mut w);
+ c.getb().getb().to_bytes(&mut w);
for i in 3 * EFS..4 * EFS {
t[i] = w[i - 3 * EFS]
}
- U.getx().tobytes(&mut w);
+ U.getx().to_bytes(&mut w);
for i in 4 * EFS..5 * EFS {
t[i] = w[i - 4 * EFS]
}
- U.gety().tobytes(&mut w);
+ U.gety().to_bytes(&mut w);
for i in 5 * EFS..6 * EFS {
t[i] = w[i - 5 * EFS]
}
@@ -238,11 +238,11 @@
for i in 0..EFS {
t[i] = e[i + 1]
}
- let mut u = Big::frombytes(&t);
+ let mut u = Big::from_bytes(&t);
for i in 0..EFS {
t[i] = e[i + EFS + 1]
}
- let mut v = Big::frombytes(&t);
+ let mut v = Big::from_bytes(&t);
let mut P = ECP::new_bigs(&u, &v);
if P.is_infinity() {
@@ -263,11 +263,11 @@
m %= rn;
v.inc(m + 1);
e[0] = (su + 2 * sv) as u8;
- u.tobytes(&mut t);
+ u.to_bytes(&mut t);
for i in 0..EFS {
e[i + 1] = t[i]
}
- v.tobytes(&mut t);
+ v.to_bytes(&mut t);
for i in 0..EFS {
e[i + EFS + 1] = t[i]
}
@@ -286,11 +286,11 @@
for i in 0..EFS {
t[i] = d[i + 1]
}
- let mut u = Big::frombytes(&t);
+ let mut u = Big::from_bytes(&t);
for i in 0..EFS {
t[i] = d[i + EFS + 1]
}
- let mut v = Big::frombytes(&t);
+ let mut v = Big::from_bytes(&t);
let su = (d[0] & 1) as isize;
let sv = ((d[0] >> 1) & 1) as isize;
@@ -300,11 +300,11 @@
u = P.getx();
v = P.gety();
d[0] = 0x04;
- u.tobytes(&mut t);
+ u.to_bytes(&mut t);
for i in 0..EFS {
d[i + 1] = t[i]
}
- v.tobytes(&mut t);
+ v.to_bytes(&mut t);
for i in 0..EFS {
d[i + EFS + 1] = t[i]
}
@@ -315,8 +315,8 @@
/// R=R1+R2 in group G1
#[allow(non_snake_case)]
pub fn recombine_g1(r1: &[u8], r2: &[u8], r: &mut [u8]) -> isize {
- let mut P = ECP::frombytes(&r1);
- let Q = ECP::frombytes(&r2);
+ let mut P = ECP::from_bytes(&r1);
+ let Q = ECP::from_bytes(&r2);
if P.is_infinity() || Q.is_infinity() {
return INVALID_POINT;
@@ -324,15 +324,15 @@
P.add(&Q);
- P.tobytes(r, false);
+ P.to_bytes(r, false);
return 0;
}
/// W=W1+W2 in group G2
#[allow(non_snake_case)]
pub fn recombine_g2(w1: &[u8], w2: &[u8], w: &mut [u8]) -> isize {
- let mut P = ECP2::frombytes(&w1);
- let Q = ECP2::frombytes(&w2);
+ let mut P = ECP2::from_bytes(&w1);
+ let Q = ECP2::from_bytes(&w2);
if P.is_infinity() || Q.is_infinity() {
return INVALID_POINT;
@@ -340,7 +340,7 @@
P.add(&Q);
- P.tobytes(w);
+ P.to_bytes(w);
return 0;
}
@@ -348,7 +348,7 @@
pub fn random_generate(rng: &mut RAND, s: &mut [u8]) -> isize {
let r = Big::new_ints(&rom::CURVE_ORDER);
let sc = Big::randomnum(&r, rng);
- sc.tobytes(s);
+ sc.to_bytes(s);
return 0;
}
@@ -357,9 +357,9 @@
pub fn get_server_secret(s: &[u8], sst: &mut [u8]) -> isize {
let mut Q = ECP2::generator();
- let sc = Big::frombytes(s);
+ let sc = Big::from_bytes(s);
Q = pair::g2mul(&Q, &sc);
- Q.tobytes(sst);
+ Q.to_bytes(sst);
return 0;
}
@@ -380,14 +380,14 @@
if let Some(rd) = rng {
sx = Big::randomnum(&r, rd);
- sx.tobytes(x);
+ sx.to_bytes(x);
} else {
- sx = Big::frombytes(x);
+ sx = Big::from_bytes(x);
}
let P: ECP;
if typ == 0 {
- P = ECP::frombytes(g);
+ P = ECP::from_bytes(g);
if P.is_infinity() {
return INVALID_POINT;
}
@@ -395,7 +395,7 @@
P = ECP::mapit(g)
}
- pair::g1mul(&P, &mut sx).tobytes(w, false);
+ pair::g1mul(&P, &mut sx).to_bytes(w, false);
return 0;
}
@@ -420,7 +420,7 @@
facbits: i32,
token: &mut [u8],
) -> isize {
- let mut P = ECP::frombytes(&token);
+ let mut P = ECP::from_bytes(&token);
const RM: usize = big::MODBYTES as usize;
let mut h: [u8; RM] = [0; RM];
if P.is_infinity() {
@@ -432,7 +432,7 @@
R = R.pinmul(factor, facbits);
P.sub(&R);
- P.tobytes(token, false);
+ P.to_bytes(token, false);
return 0;
}
@@ -446,7 +446,7 @@
facbits: i32,
token: &mut [u8],
) -> isize {
- let mut P = ECP::frombytes(&token);
+ let mut P = ECP::from_bytes(&token);
const RM: usize = big::MODBYTES as usize;
let mut h: [u8; RM] = [0; RM];
if P.is_infinity() {
@@ -458,7 +458,7 @@
R = R.pinmul(factor, facbits);
P.add(&R);
- P.tobytes(token, false);
+ P.to_bytes(token, false);
return 0;
}
@@ -466,7 +466,7 @@
/// Functions to support M-Pin Full
#[allow(non_snake_case)]
pub fn precompute(token: &[u8], cid: &[u8], g1: &mut [u8], g2: &mut [u8]) -> isize {
- let T = ECP::frombytes(&token);
+ let T = ECP::from_bytes(&token);
if T.is_infinity() {
return INVALID_POINT;
}
@@ -477,11 +477,11 @@
let mut g = pair::ate(&Q, &T);
g = pair::fexp(&g);
- g.tobytes(g1);
+ g.to_bytes(g1);
g = pair::ate(&Q, &P);
g = pair::fexp(&g);
- g.tobytes(g2);
+ g.to_bytes(g2);
return 0;
}
@@ -494,8 +494,8 @@
hashit(sha, date, cid, &mut h);
let P = ECP::mapit(&h);
- let mut sc = Big::frombytes(s);
- pair::g1mul(&P, &mut sc).tobytes(ctt, false);
+ let mut sc = Big::from_bytes(s);
+ pair::g1mul(&P, &mut sc).to_bytes(ctt, false);
return 0;
}
@@ -520,9 +520,9 @@
if let Some(rd) = rng {
sx = Big::randomnum(&r, rd);
- sx.tobytes(x);
+ sx.to_bytes(x);
} else {
- sx = Big::frombytes(x);
+ sx = Big::from_bytes(x);
}
const RM: usize = big::MODBYTES as usize;
@@ -531,7 +531,7 @@
hashit(sha, 0, &client_id, &mut h);
let mut P = ECP::mapit(&h);
- let mut T = ECP::frombytes(&token);
+ let mut T = ECP::from_bytes(&token);
if T.is_infinity() {
return INVALID_POINT;
}
@@ -540,7 +540,7 @@
T.add(&W);
if date != 0 {
if let Some(rpermit) = permit {
- W = ECP::frombytes(&rpermit);
+ W = ECP::from_bytes(&rpermit);
}
if W.is_infinity() {
return INVALID_POINT;
@@ -551,7 +551,7 @@
W = ECP::mapit(&h2);
if let Some(mut rxid) = xid {
P = pair::g1mul(&P, &mut sx);
- P.tobytes(&mut rxid, false);
+ P.to_bytes(&mut rxid, false);
W = pair::g1mul(&W, &mut sx);
P.add(&W);
} else {
@@ -559,16 +559,16 @@
P = pair::g1mul(&P, &mut sx);
}
if let Some(mut rxcid) = xcid {
- P.tobytes(&mut rxcid, false)
+ P.to_bytes(&mut rxcid, false)
}
} else {
if let Some(mut rxid) = xid {
P = pair::g1mul(&P, &mut sx);
- P.tobytes(&mut rxid, false);
+ P.to_bytes(&mut rxid, false);
}
}
- T.tobytes(sec, false);
+ T.to_bytes(sec, false);
return 0;
}
@@ -582,14 +582,14 @@
let mut P = ECP::mapit(&h);
- P.tobytes(hid, false);
+ P.to_bytes(hid, false);
if date != 0 {
let mut h2: [u8; RM] = [0; RM];
hashit(sha, date, &h, &mut h2);
let R = ECP::mapit(&h2);
P.add(&R);
if let Some(rhtid) = htid {
- P.tobytes(rhtid, false);
+ P.to_bytes(rhtid, false);
}
}
}
@@ -598,19 +598,19 @@
#[allow(non_snake_case)]
pub fn client_2(x: &[u8], y: &[u8], sec: &mut [u8]) -> isize {
let r = Big::new_ints(&rom::CURVE_ORDER);
- let mut P = ECP::frombytes(sec);
+ let mut P = ECP::from_bytes(sec);
if P.is_infinity() {
return INVALID_POINT;
}
- let mut px = Big::frombytes(x);
- let py = Big::frombytes(y);
+ let mut px = Big::from_bytes(x);
+ let py = Big::from_bytes(y);
px.add(&py);
px.rmod(&r);
P = pair::g1mul(&P, &mut px);
P.neg();
- P.tobytes(sec, false);
+ P.to_bytes(sec, false);
return 0;
}
@@ -630,10 +630,10 @@
hashit(sha, timevalue, xcid, &mut h);
- let mut sy = Big::frombytes(&h);
+ let mut sy = Big::from_bytes(&h);
let q = Big::new_ints(&rom::CURVE_ORDER);
sy.rmod(&q);
- sy.tobytes(y);
+ sy.to_bytes(y);
}
/// Implement step 2 of MPin protocol on server side
@@ -652,7 +652,7 @@
) -> isize {
let Q = ECP2::generator();
- let sQ = ECP2::frombytes(&sst);
+ let sQ = ECP2::from_bytes(&sst);
if sQ.is_infinity() {
return INVALID_POINT;
}
@@ -660,13 +660,13 @@
let mut R: ECP;
if date != 0 {
if let Some(rxcid) = xcid {
- R = ECP::frombytes(&rxcid);
+ R = ECP::from_bytes(&rxcid);
} else {
return BAD_PARAMS;
}
} else {
if let Some(rxid) = xid {
- R = ECP::frombytes(&rxid)
+ R = ECP::from_bytes(&rxid)
} else {
return BAD_PARAMS;
}
@@ -675,16 +675,16 @@
return INVALID_POINT;
}
- let mut sy = Big::frombytes(&y);
+ let mut sy = Big::from_bytes(&y);
let mut P: ECP;
if date != 0 {
if let Some(rhtid) = htid {
- P = ECP::frombytes(&rhtid)
+ P = ECP::from_bytes(&rhtid)
} else {
return BAD_PARAMS;
}
} else {
- P = ECP::frombytes(&hid);
+ P = ECP::from_bytes(&hid);
}
if P.is_infinity() {
@@ -693,7 +693,7 @@
P = pair::g1mul(&P, &mut sy);
P.add(&R);
- R = ECP::frombytes(&msec);
+ R = ECP::from_bytes(&msec);
if R.is_infinity() {
return INVALID_POINT;
}
@@ -703,17 +703,17 @@
g = pair::ate2(&Q, &R, &sQ, &P);
g = pair::fexp(&g);
- if !g.isunity() {
+ if !g.is_unity() {
if let Some(rxid) = xid {
if let Some(re) = e {
if let Some(rf) = f {
- g.tobytes(re);
+ g.to_bytes(re);
if date != 0 {
- P = ECP::frombytes(&hid);
+ P = ECP::from_bytes(&hid);
if P.is_infinity() {
return INVALID_POINT;
}
- R = ECP::frombytes(&rxid);
+ R = ECP::from_bytes(&rxid);
if R.is_infinity() {
return INVALID_POINT;
}
@@ -722,7 +722,7 @@
}
g = pair::ate(&Q, &P);
g = pair::fexp(&g);
- g.tobytes(rf);
+ g.to_bytes(rf);
}
}
}
@@ -735,8 +735,8 @@
/// Pollards kangaroos used to return PIN error
pub fn kangaroo(e: &[u8], f: &[u8]) -> isize {
- let mut ge = FP12::frombytes(e);
- let mut gf = FP12::frombytes(f);
+ let mut ge = FP12::from_bytes(e);
+ let mut gf = FP12::from_bytes(f);
let mut distance: [isize; TS] = [0; TS];
let mut t = gf.clone();
@@ -854,13 +854,13 @@
wcid: &[u8],
ck: &mut [u8],
) -> isize {
- let mut g1 = FP12::frombytes(&g1);
- let mut g2 = FP12::frombytes(&g2);
- let mut z = Big::frombytes(&r);
- let mut x = Big::frombytes(&x);
- let h = Big::frombytes(&h);
+ let mut g1 = FP12::from_bytes(&g1);
+ let mut g2 = FP12::from_bytes(&g2);
+ let mut z = Big::from_bytes(&r);
+ let mut x = Big::from_bytes(&x);
+ let h = Big::from_bytes(&h);
- let mut W = ECP::frombytes(&wcid);
+ let mut W = ECP::from_bytes(&wcid);
if W.is_infinity() {
return INVALID_POINT;
}
@@ -896,31 +896,31 @@
xcid: Option<&[u8]>,
sk: &mut [u8],
) -> isize {
- let sQ = ECP2::frombytes(&sst);
+ let sQ = ECP2::from_bytes(&sst);
if sQ.is_infinity() {
return INVALID_POINT;
}
- let mut R = ECP::frombytes(&z);
+ let mut R = ECP::from_bytes(&z);
if R.is_infinity() {
return INVALID_POINT;
}
- let mut A = ECP::frombytes(&hid);
+ let mut A = ECP::from_bytes(&hid);
if A.is_infinity() {
return INVALID_POINT;
}
let mut U = if let Some(rxcid) = xcid {
- ECP::frombytes(&rxcid)
+ ECP::from_bytes(&rxcid)
} else {
- ECP::frombytes(&xid)
+ ECP::from_bytes(&xid)
};
if U.is_infinity() {
return INVALID_POINT;
}
- let mut w = Big::frombytes(&w);
- let mut h = Big::frombytes(&h);
+ let mut w = Big::from_bytes(&w);
+ let mut h = Big::from_bytes(&h);
A = pair::g1mul(&A, &mut h); // new
R.add(&A);
diff --git a/src/mpin192.rs b/src/mpin192.rs
index 143b483..c671f98 100644
--- a/src/mpin192.rs
+++ b/src/mpin192.rs
@@ -58,44 +58,44 @@
let mut w: [u8; EFS] = [0; EFS];
let mut t: [u8; 10 * EFS] = [0; 10 * EFS];
- c.geta().geta().geta().tobytes(&mut w);
+ c.geta().geta().geta().to_bytes(&mut w);
for i in 0..EFS {
t[i] = w[i]
}
- c.geta().geta().getb().tobytes(&mut w);
+ c.geta().geta().getb().to_bytes(&mut w);
for i in EFS..2 * EFS {
t[i] = w[i - EFS]
}
- c.geta().getb().geta().tobytes(&mut w);
+ c.geta().getb().geta().to_bytes(&mut w);
for i in 2 * EFS..3 * EFS {
t[i] = w[i - 2 * EFS]
}
- c.geta().getb().getb().tobytes(&mut w);
+ c.geta().getb().getb().to_bytes(&mut w);
for i in 3 * EFS..4 * EFS {
t[i] = w[i - 3 * EFS]
}
- c.getb().geta().geta().tobytes(&mut w);
+ c.getb().geta().geta().to_bytes(&mut w);
for i in 4 * EFS..5 * EFS {
t[i] = w[i - 4 * EFS]
}
- c.getb().geta().getb().tobytes(&mut w);
+ c.getb().geta().getb().to_bytes(&mut w);
for i in 5 * EFS..6 * EFS {
t[i] = w[i - 5 * EFS]
}
- c.getb().getb().geta().tobytes(&mut w);
+ c.getb().getb().geta().to_bytes(&mut w);
for i in 6 * EFS..7 * EFS {
t[i] = w[i - 6 * EFS]
}
- c.getb().getb().getb().tobytes(&mut w);
+ c.getb().getb().getb().to_bytes(&mut w);
for i in 7 * EFS..8 * EFS {
t[i] = w[i - 7 * EFS]
}
- U.getx().tobytes(&mut w);
+ U.getx().to_bytes(&mut w);
for i in 8 * EFS..9 * EFS {
t[i] = w[i - 8 * EFS]
}
- U.gety().tobytes(&mut w);
+ U.gety().to_bytes(&mut w);
for i in 9 * EFS..10 * EFS {
t[i] = w[i - 9 * EFS]
}
@@ -254,11 +254,11 @@
for i in 0..EFS {
t[i] = e[i + 1]
}
- let mut u = Big::frombytes(&t);
+ let mut u = Big::from_bytes(&t);
for i in 0..EFS {
t[i] = e[i + EFS + 1]
}
- let mut v = Big::frombytes(&t);
+ let mut v = Big::from_bytes(&t);
let mut P = ECP::new_bigs(&u, &v);
if P.is_infinity() {
@@ -279,11 +279,11 @@
m %= rn;
v.inc(m + 1);
e[0] = (su + 2 * sv) as u8;
- u.tobytes(&mut t);
+ u.to_bytes(&mut t);
for i in 0..EFS {
e[i + 1] = t[i]
}
- v.tobytes(&mut t);
+ v.to_bytes(&mut t);
for i in 0..EFS {
e[i + EFS + 1] = t[i]
}
@@ -302,11 +302,11 @@
for i in 0..EFS {
t[i] = d[i + 1]
}
- let mut u = Big::frombytes(&t);
+ let mut u = Big::from_bytes(&t);
for i in 0..EFS {
t[i] = d[i + EFS + 1]
}
- let mut v = Big::frombytes(&t);
+ let mut v = Big::from_bytes(&t);
let su = (d[0] & 1) as isize;
let sv = ((d[0] >> 1) & 1) as isize;
@@ -316,11 +316,11 @@
u = P.getx();
v = P.gety();
d[0] = 0x04;
- u.tobytes(&mut t);
+ u.to_bytes(&mut t);
for i in 0..EFS {
d[i + 1] = t[i]
}
- v.tobytes(&mut t);
+ v.to_bytes(&mut t);
for i in 0..EFS {
d[i + EFS + 1] = t[i]
}
@@ -331,8 +331,8 @@
/// R=R1+R2 in group G1
#[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 mut P = ECP::from_bytes(&r1);
+ let mut Q = ECP::from_bytes(&r2);
if P.is_infinity() || Q.is_infinity() {
return INVALID_POINT;
@@ -340,15 +340,15 @@
P.add(&mut Q);
- P.tobytes(r, false);
+ P.to_bytes(r, false);
return 0;
}
/// W=W1+W2 in group G2
#[allow(non_snake_case)]
pub fn recombine_g2(w1: &[u8], w2: &[u8], w: &mut [u8]) -> isize {
- let mut P = ECP4::frombytes(&w1);
- let mut Q = ECP4::frombytes(&w2);
+ let mut P = ECP4::from_bytes(&w1);
+ let mut Q = ECP4::from_bytes(&w2);
if P.is_infinity() || Q.is_infinity() {
return INVALID_POINT;
@@ -356,7 +356,7 @@
P.add(&mut Q);
- P.tobytes(w);
+ P.to_bytes(w);
return 0;
}
@@ -364,7 +364,7 @@
pub fn random_generate(rng: &mut RAND, s: &mut [u8]) -> isize {
let r = Big::new_ints(&rom::CURVE_ORDER);
let sc = Big::randomnum(&r, rng);
- sc.tobytes(s);
+ sc.to_bytes(s);
return 0;
}
@@ -372,9 +372,9 @@
#[allow(non_snake_case)]
pub fn get_server_secret(s: &[u8], sst: &mut [u8]) -> isize {
let mut Q = ECP4::generator();
- let mut sc = Big::frombytes(s);
+ let mut sc = Big::from_bytes(s);
Q = pair192::g2mul(&mut Q, &mut sc);
- Q.tobytes(sst);
+ Q.to_bytes(sst);
return 0;
}
@@ -395,14 +395,14 @@
if let Some(rd) = rng {
sx = Big::randomnum(&r, rd);
- sx.tobytes(x);
+ sx.to_bytes(x);
} else {
- sx = Big::frombytes(x);
+ sx = Big::from_bytes(x);
}
let mut P: ECP;
if typ == 0 {
- P = ECP::frombytes(g);
+ P = ECP::from_bytes(g);
if P.is_infinity() {
return INVALID_POINT;
}
@@ -410,7 +410,7 @@
P = ECP::mapit(g)
}
- pair192::g1mul(&mut P, &mut sx).tobytes(w, false);
+ pair192::g1mul(&mut P, &mut sx).to_bytes(w, false);
return 0;
}
@@ -435,7 +435,7 @@
facbits: i32,
token: &mut [u8],
) -> isize {
- let mut P = ECP::frombytes(&token);
+ let mut P = ECP::from_bytes(&token);
const RM: usize = big::MODBYTES as usize;
let mut h: [u8; RM] = [0; RM];
if P.is_infinity() {
@@ -447,7 +447,7 @@
R = R.pinmul(factor, facbits);
P.sub(&mut R);
- P.tobytes(token, false);
+ P.to_bytes(token, false);
return 0;
}
@@ -461,7 +461,7 @@
facbits: i32,
token: &mut [u8],
) -> isize {
- let mut P = ECP::frombytes(&token);
+ let mut P = ECP::from_bytes(&token);
const RM: usize = big::MODBYTES as usize;
let mut h: [u8; RM] = [0; RM];
if P.is_infinity() {
@@ -473,7 +473,7 @@
R = R.pinmul(factor, facbits);
P.add(&mut R);
- P.tobytes(token, false);
+ P.to_bytes(token, false);
return 0;
}
@@ -481,7 +481,7 @@
/// Functions to support M-Pin Full
#[allow(non_snake_case)]
pub fn precompute(token: &[u8], cid: &[u8], g1: &mut [u8], g2: &mut [u8]) -> isize {
- let T = ECP::frombytes(&token);
+ let T = ECP::from_bytes(&token);
if T.is_infinity() {
return INVALID_POINT;
}
@@ -492,11 +492,11 @@
let mut g = pair192::ate(&Q, &T);
g = pair192::fexp(&g);
- g.tobytes(g1);
+ g.to_bytes(g1);
g = pair192::ate(&Q, &P);
g = pair192::fexp(&g);
- g.tobytes(g2);
+ g.to_bytes(g2);
return 0;
}
@@ -509,8 +509,8 @@
hashit(sha, date, cid, &mut h);
let mut P = ECP::mapit(&h);
- let mut sc = Big::frombytes(s);
- pair192::g1mul(&mut P, &mut sc).tobytes(ctt, false);
+ let mut sc = Big::from_bytes(s);
+ pair192::g1mul(&mut P, &mut sc).to_bytes(ctt, false);
return 0;
}
@@ -535,9 +535,9 @@
if let Some(rd) = rng {
sx = Big::randomnum(&r, rd);
- sx.tobytes(x);
+ sx.to_bytes(x);
} else {
- sx = Big::frombytes(x);
+ sx = Big::from_bytes(x);
}
const RM: usize = big::MODBYTES as usize;
@@ -546,7 +546,7 @@
hashit(sha, 0, &client_id, &mut h);
let mut P = ECP::mapit(&h);
- let mut T = ECP::frombytes(&token);
+ let mut T = ECP::from_bytes(&token);
if T.is_infinity() {
return INVALID_POINT;
}
@@ -555,7 +555,7 @@
T.add(&mut W);
if date != 0 {
if let Some(rpermit) = permit {
- W = ECP::frombytes(&rpermit);
+ W = ECP::from_bytes(&rpermit);
}
if W.is_infinity() {
return INVALID_POINT;
@@ -566,7 +566,7 @@
W = ECP::mapit(&h2);
if let Some(mut rxid) = xid {
P = pair192::g1mul(&mut P, &mut sx);
- P.tobytes(&mut rxid, false);
+ P.to_bytes(&mut rxid, false);
W = pair192::g1mul(&mut W, &mut sx);
P.add(&mut W);
} else {
@@ -574,16 +574,16 @@
P = pair192::g1mul(&mut P, &mut sx);
}
if let Some(mut rxcid) = xcid {
- P.tobytes(&mut rxcid, false)
+ P.to_bytes(&mut rxcid, false)
}
} else {
if let Some(mut rxid) = xid {
P = pair192::g1mul(&mut P, &mut sx);
- P.tobytes(&mut rxid, false);
+ P.to_bytes(&mut rxid, false);
}
}
- T.tobytes(sec, false);
+ T.to_bytes(sec, false);
return 0;
}
@@ -597,14 +597,14 @@
let mut P = ECP::mapit(&h);
- P.tobytes(hid, false);
+ P.to_bytes(hid, false);
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);
if let Some(rhtid) = htid {
- P.tobytes(rhtid, false);
+ P.to_bytes(rhtid, false);
}
}
}
@@ -613,19 +613,19 @@
#[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 mut P = ECP::frombytes(sec);
+ let mut P = ECP::from_bytes(sec);
if P.is_infinity() {
return INVALID_POINT;
}
- let mut px = Big::frombytes(x);
- let py = Big::frombytes(y);
+ let mut px = Big::from_bytes(x);
+ let py = Big::from_bytes(y);
px.add(&py);
px.rmod(&mut r);
P = pair192::g1mul(&mut P, &mut px);
P.neg();
- P.tobytes(sec, false);
+ P.to_bytes(sec, false);
return 0;
}
@@ -645,10 +645,10 @@
hashit(sha, timevalue, xcid, &mut h);
- let mut sy = Big::frombytes(&h);
+ let mut sy = Big::from_bytes(&h);
let mut q = Big::new_ints(&rom::CURVE_ORDER);
sy.rmod(&mut q);
- sy.tobytes(y);
+ sy.to_bytes(y);
}
/// Implement step 2 of MPin protocol on server side
@@ -667,7 +667,7 @@
) -> isize {
let Q = ECP4::generator();
- let sQ = ECP4::frombytes(&sst);
+ let sQ = ECP4::from_bytes(&sst);
if sQ.is_infinity() {
return INVALID_POINT;
}
@@ -675,13 +675,13 @@
let mut R: ECP;
if date != 0 {
if let Some(rxcid) = xcid {
- R = ECP::frombytes(&rxcid);
+ R = ECP::from_bytes(&rxcid);
} else {
return BAD_PARAMS;
}
} else {
if let Some(rxid) = xid {
- R = ECP::frombytes(&rxid)
+ R = ECP::from_bytes(&rxid)
} else {
return BAD_PARAMS;
}
@@ -690,16 +690,16 @@
return INVALID_POINT;
}
- let mut sy = Big::frombytes(&y);
+ let mut sy = Big::from_bytes(&y);
let mut P: ECP;
if date != 0 {
if let Some(rhtid) = htid {
- P = ECP::frombytes(&rhtid)
+ P = ECP::from_bytes(&rhtid)
} else {
return BAD_PARAMS;
}
} else {
- P = ECP::frombytes(&hid);
+ P = ECP::from_bytes(&hid);
}
if P.is_infinity() {
@@ -708,7 +708,7 @@
P = pair192::g1mul(&mut P, &mut sy);
P.add(&mut R);
- R = ECP::frombytes(&msec);
+ R = ECP::from_bytes(&msec);
if R.is_infinity() {
return INVALID_POINT;
}
@@ -718,17 +718,17 @@
g = pair192::ate2(&Q, &R, &sQ, &P);
g = pair192::fexp(&g);
- if !g.isunity() {
+ if !g.is_unity() {
if let Some(rxid) = xid {
if let Some(re) = e {
if let Some(rf) = f {
- g.tobytes(re);
+ g.to_bytes(re);
if date != 0 {
- P = ECP::frombytes(&hid);
+ P = ECP::from_bytes(&hid);
if P.is_infinity() {
return INVALID_POINT;
}
- R = ECP::frombytes(&rxid);
+ R = ECP::from_bytes(&rxid);
if R.is_infinity() {
return INVALID_POINT;
}
@@ -737,7 +737,7 @@
}
g = pair192::ate(&Q, &P);
g = pair192::fexp(&g);
- g.tobytes(rf);
+ g.to_bytes(rf);
}
}
}
@@ -750,8 +750,8 @@
/// Pollards kangaroos used to return PIN error
pub fn kangaroo(e: &[u8], f: &[u8]) -> isize {
- let mut ge = FP24::frombytes(e);
- let mut gf = FP24::frombytes(f);
+ let mut ge = FP24::from_bytes(e);
+ let mut gf = FP24::from_bytes(f);
let mut distance: [isize; TS] = [0; TS];
let mut t = gf.clone();
@@ -869,13 +869,13 @@
wcid: &[u8],
ck: &mut [u8],
) -> isize {
- let mut g1 = FP24::frombytes(&g1);
- let mut g2 = FP24::frombytes(&g2);
- let mut z = Big::frombytes(&r);
- let mut x = Big::frombytes(&x);
- let h = Big::frombytes(&h);
+ let mut g1 = FP24::from_bytes(&g1);
+ let mut g2 = FP24::from_bytes(&g2);
+ let mut z = Big::from_bytes(&r);
+ let mut x = Big::from_bytes(&x);
+ let h = Big::from_bytes(&h);
- let mut W = ECP::frombytes(&wcid);
+ let mut W = ECP::from_bytes(&wcid);
if W.is_infinity() {
return INVALID_POINT;
}
@@ -911,31 +911,31 @@
xcid: Option<&[u8]>,
sk: &mut [u8],
) -> isize {
- let sQ = ECP4::frombytes(&sst);
+ let sQ = ECP4::from_bytes(&sst);
if sQ.is_infinity() {
return INVALID_POINT;
}
- let mut R = ECP::frombytes(&z);
+ let mut R = ECP::from_bytes(&z);
if R.is_infinity() {
return INVALID_POINT;
}
- let mut A = ECP::frombytes(&hid);
+ let mut A = ECP::from_bytes(&hid);
if A.is_infinity() {
return INVALID_POINT;
}
let mut U = if let Some(rxcid) = xcid {
- ECP::frombytes(&rxcid)
+ ECP::from_bytes(&rxcid)
} else {
- ECP::frombytes(&xid)
+ ECP::from_bytes(&xid)
};
if U.is_infinity() {
return INVALID_POINT;
}
- let mut w = Big::frombytes(&w);
- let mut h = Big::frombytes(&h);
+ let mut w = Big::from_bytes(&w);
+ let mut h = Big::from_bytes(&h);
A = pair192::g1mul(&mut A, &mut h); // new
R.add(&mut A);
diff --git a/src/mpin256.rs b/src/mpin256.rs
index 298b18f..66729d5 100644
--- a/src/mpin256.rs
+++ b/src/mpin256.rs
@@ -58,77 +58,77 @@
let mut w: [u8; EFS] = [0; EFS];
let mut t: [u8; 18 * EFS] = [0; 18 * EFS];
- c.geta().geta().geta().geta().tobytes(&mut w);
+ c.geta().geta().geta().geta().to_bytes(&mut w);
for i in 0..EFS {
t[i] = w[i]
}
- c.geta().geta().geta().getb().tobytes(&mut w);
+ c.geta().geta().geta().getb().to_bytes(&mut w);
for i in EFS..2 * EFS {
t[i] = w[i - EFS]
}
- c.geta().geta().getb().geta().tobytes(&mut w);
+ c.geta().geta().getb().geta().to_bytes(&mut w);
for i in 2 * EFS..3 * EFS {
t[i] = w[i - 2 * EFS]
}
- c.geta().geta().getb().getb().tobytes(&mut w);
+ c.geta().geta().getb().getb().to_bytes(&mut w);
for i in 3 * EFS..4 * EFS {
t[i] = w[i - 3 * EFS]
}
- c.geta().getb().geta().geta().tobytes(&mut w);
+ c.geta().getb().geta().geta().to_bytes(&mut w);
for i in 4 * EFS..5 * EFS {
t[i] = w[i - 4 * EFS]
}
- c.geta().getb().geta().getb().tobytes(&mut w);
+ c.geta().getb().geta().getb().to_bytes(&mut w);
for i in 5 * EFS..6 * EFS {
t[i] = w[i - 5 * EFS]
}
- c.geta().getb().getb().geta().tobytes(&mut w);
+ c.geta().getb().getb().geta().to_bytes(&mut w);
for i in 6 * EFS..7 * EFS {
t[i] = w[i - 6 * EFS]
}
- c.geta().getb().getb().getb().tobytes(&mut w);
+ c.geta().getb().getb().getb().to_bytes(&mut w);
for i in 7 * EFS..8 * EFS {
t[i] = w[i - 7 * EFS]
}
- c.getb().geta().geta().geta().tobytes(&mut w);
+ c.getb().geta().geta().geta().to_bytes(&mut w);
for i in 8 * EFS..9 * EFS {
t[i] = w[i - 8 * EFS]
}
- c.getb().geta().geta().getb().tobytes(&mut w);
+ c.getb().geta().geta().getb().to_bytes(&mut w);
for i in 9 * EFS..10 * EFS {
t[i] = w[i - 9 * EFS]
}
- c.getb().geta().getb().geta().tobytes(&mut w);
+ c.getb().geta().getb().geta().to_bytes(&mut w);
for i in 10 * EFS..11 * EFS {
t[i] = w[i - 10 * EFS]
}
- c.getb().geta().getb().getb().tobytes(&mut w);
+ c.getb().geta().getb().getb().to_bytes(&mut w);
for i in 11 * EFS..12 * EFS {
t[i] = w[i - 11 * EFS]
}
- c.getb().getb().geta().geta().tobytes(&mut w);
+ c.getb().getb().geta().geta().to_bytes(&mut w);
for i in 12 * EFS..13 * EFS {
t[i] = w[i - 12 * EFS]
}
- c.getb().getb().geta().getb().tobytes(&mut w);
+ c.getb().getb().geta().getb().to_bytes(&mut w);
for i in 13 * EFS..14 * EFS {
t[i] = w[i - 13 * EFS]
}
- c.getb().getb().getb().geta().tobytes(&mut w);
+ c.getb().getb().getb().geta().to_bytes(&mut w);
for i in 14 * EFS..15 * EFS {
t[i] = w[i - 14 * EFS]
}
- c.getb().getb().getb().getb().tobytes(&mut w);
+ c.getb().getb().getb().getb().to_bytes(&mut w);
for i in 15 * EFS..16 * EFS {
t[i] = w[i - 15 * EFS]
}
- U.getx().tobytes(&mut w);
+ U.getx().to_bytes(&mut w);
for i in 16 * EFS..17 * EFS {
t[i] = w[i - 16 * EFS]
}
- U.gety().tobytes(&mut w);
+ U.gety().to_bytes(&mut w);
for i in 17 * EFS..18 * EFS {
t[i] = w[i - 17 * EFS]
}
@@ -287,11 +287,11 @@
for i in 0..EFS {
t[i] = e[i + 1]
}
- let mut u = Big::frombytes(&t);
+ let mut u = Big::from_bytes(&t);
for i in 0..EFS {
t[i] = e[i + EFS + 1]
}
- let mut v = Big::frombytes(&t);
+ let mut v = Big::from_bytes(&t);
let mut P = ECP::new_bigs(&u, &v);
if P.is_infinity() {
@@ -312,11 +312,11 @@
m %= rn;
v.inc(m + 1);
e[0] = (su + 2 * sv) as u8;
- u.tobytes(&mut t);
+ u.to_bytes(&mut t);
for i in 0..EFS {
e[i + 1] = t[i]
}
- v.tobytes(&mut t);
+ v.to_bytes(&mut t);
for i in 0..EFS {
e[i + EFS + 1] = t[i]
}
@@ -335,11 +335,11 @@
for i in 0..EFS {
t[i] = d[i + 1]
}
- let mut u = Big::frombytes(&t);
+ let mut u = Big::from_bytes(&t);
for i in 0..EFS {
t[i] = d[i + EFS + 1]
}
- let mut v = Big::frombytes(&t);
+ let mut v = Big::from_bytes(&t);
let su = (d[0] & 1) as isize;
let sv = ((d[0] >> 1) & 1) as isize;
@@ -349,11 +349,11 @@
u = P.getx();
v = P.gety();
d[0] = 0x04;
- u.tobytes(&mut t);
+ u.to_bytes(&mut t);
for i in 0..EFS {
d[i + 1] = t[i]
}
- v.tobytes(&mut t);
+ v.to_bytes(&mut t);
for i in 0..EFS {
d[i + EFS + 1] = t[i]
}
@@ -364,8 +364,8 @@
/// R=R1+R2 in group G1
#[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 mut P = ECP::from_bytes(&r1);
+ let mut Q = ECP::from_bytes(&r2);
if P.is_infinity() || Q.is_infinity() {
return INVALID_POINT;
@@ -373,15 +373,15 @@
P.add(&mut Q);
- P.tobytes(r, false);
+ P.to_bytes(r, false);
return 0;
}
/// W=W1+W2 in group G2
#[allow(non_snake_case)]
pub fn recombine_g2(w1: &[u8], w2: &[u8], w: &mut [u8]) -> isize {
- let mut P = ECP8::frombytes(&w1);
- let mut Q = ECP8::frombytes(&w2);
+ let mut P = ECP8::from_bytes(&w1);
+ let mut Q = ECP8::from_bytes(&w2);
if P.is_infinity() || Q.is_infinity() {
return INVALID_POINT;
@@ -389,7 +389,7 @@
P.add(&mut Q);
- P.tobytes(w);
+ P.to_bytes(w);
return 0;
}
@@ -397,7 +397,7 @@
pub fn random_generate(rng: &mut RAND, s: &mut [u8]) -> isize {
let r = Big::new_ints(&rom::CURVE_ORDER);
let sc = Big::randomnum(&r, rng);
- sc.tobytes(s);
+ sc.to_bytes(s);
return 0;
}
@@ -406,9 +406,9 @@
pub fn get_server_secret(s: &[u8], sst: &mut [u8]) -> isize {
let mut Q = ECP8::generator();
- let mut sc = Big::frombytes(s);
+ let mut sc = Big::from_bytes(s);
Q = pair256::g2mul(&mut Q, &mut sc);
- Q.tobytes(sst);
+ Q.to_bytes(sst);
return 0;
}
@@ -429,14 +429,14 @@
if let Some(rd) = rng {
sx = Big::randomnum(&r, rd);
- sx.tobytes(x);
+ sx.to_bytes(x);
} else {
- sx = Big::frombytes(x);
+ sx = Big::from_bytes(x);
}
let mut P: ECP;
if typ == 0 {
- P = ECP::frombytes(g);
+ P = ECP::from_bytes(g);
if P.is_infinity() {
return INVALID_POINT;
}
@@ -444,7 +444,7 @@
P = ECP::mapit(g)
}
- pair256::g1mul(&mut P, &mut sx).tobytes(w, false);
+ pair256::g1mul(&mut P, &mut sx).to_bytes(w, false);
return 0;
}
@@ -469,7 +469,7 @@
facbits: i32,
token: &mut [u8],
) -> isize {
- let mut P = ECP::frombytes(&token);
+ let mut P = ECP::from_bytes(&token);
const RM: usize = big::MODBYTES as usize;
let mut h: [u8; RM] = [0; RM];
if P.is_infinity() {
@@ -481,7 +481,7 @@
R = R.pinmul(factor, facbits);
P.sub(&mut R);
- P.tobytes(token, false);
+ P.to_bytes(token, false);
return 0;
}
@@ -495,7 +495,7 @@
facbits: i32,
token: &mut [u8],
) -> isize {
- let mut P = ECP::frombytes(&token);
+ let mut P = ECP::from_bytes(&token);
const RM: usize = big::MODBYTES as usize;
let mut h: [u8; RM] = [0; RM];
if P.is_infinity() {
@@ -507,7 +507,7 @@
R = R.pinmul(factor, facbits);
P.add(&mut R);
- P.tobytes(token, false);
+ P.to_bytes(token, false);
return 0;
}
@@ -515,7 +515,7 @@
/// Functions to support M-Pin Full
#[allow(non_snake_case)]
pub fn precompute(token: &[u8], cid: &[u8], g1: &mut [u8], g2: &mut [u8]) -> isize {
- let T = ECP::frombytes(&token);
+ let T = ECP::from_bytes(&token);
if T.is_infinity() {
return INVALID_POINT;
}
@@ -526,11 +526,11 @@
let mut g = pair256::ate(&Q, &T);
g = pair256::fexp(&g);
- g.tobytes(g1);
+ g.to_bytes(g1);
g = pair256::ate(&Q, &P);
g = pair256::fexp(&g);
- g.tobytes(g2);
+ g.to_bytes(g2);
return 0;
}
@@ -543,8 +543,8 @@
hashit(sha, date, cid, &mut h);
let mut P = ECP::mapit(&h);
- let mut sc = Big::frombytes(s);
- pair256::g1mul(&mut P, &mut sc).tobytes(ctt, false);
+ let mut sc = Big::from_bytes(s);
+ pair256::g1mul(&mut P, &mut sc).to_bytes(ctt, false);
return 0;
}
@@ -569,9 +569,9 @@
if let Some(rd) = rng {
sx = Big::randomnum(&r, rd);
- sx.tobytes(x);
+ sx.to_bytes(x);
} else {
- sx = Big::frombytes(x);
+ sx = Big::from_bytes(x);
}
const RM: usize = big::MODBYTES as usize;
@@ -580,7 +580,7 @@
hashit(sha, 0, &client_id, &mut h);
let mut P = ECP::mapit(&h);
- let mut T = ECP::frombytes(&token);
+ let mut T = ECP::from_bytes(&token);
if T.is_infinity() {
return INVALID_POINT;
}
@@ -589,7 +589,7 @@
T.add(&mut W);
if date != 0 {
if let Some(rpermit) = permit {
- W = ECP::frombytes(&rpermit);
+ W = ECP::from_bytes(&rpermit);
}
if W.is_infinity() {
return INVALID_POINT;
@@ -600,7 +600,7 @@
W = ECP::mapit(&h2);
if let Some(mut rxid) = xid {
P = pair256::g1mul(&mut P, &mut sx);
- P.tobytes(&mut rxid, false);
+ P.to_bytes(&mut rxid, false);
W = pair256::g1mul(&mut W, &mut sx);
P.add(&mut W);
} else {
@@ -608,16 +608,16 @@
P = pair256::g1mul(&mut P, &mut sx);
}
if let Some(mut rxcid) = xcid {
- P.tobytes(&mut rxcid, false)
+ P.to_bytes(&mut rxcid, false)
}
} else {
if let Some(mut rxid) = xid {
P = pair256::g1mul(&mut P, &mut sx);
- P.tobytes(&mut rxid, false);
+ P.to_bytes(&mut rxid, false);
}
}
- T.tobytes(sec, false);
+ T.to_bytes(sec, false);
return 0;
}
@@ -631,14 +631,14 @@
let mut P = ECP::mapit(&h);
- P.tobytes(hid, false);
+ P.to_bytes(hid, false);
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);
if let Some(rhtid) = htid {
- P.tobytes(rhtid, false);
+ P.to_bytes(rhtid, false);
}
}
}
@@ -647,19 +647,19 @@
#[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 mut P = ECP::frombytes(sec);
+ let mut P = ECP::from_bytes(sec);
if P.is_infinity() {
return INVALID_POINT;
}
- let mut px = Big::frombytes(x);
- let py = Big::frombytes(y);
+ let mut px = Big::from_bytes(x);
+ let py = Big::from_bytes(y);
px.add(&py);
px.rmod(&mut r);
P = pair256::g1mul(&mut P, &mut px);
P.neg();
- P.tobytes(sec, false);
+ P.to_bytes(sec, false);
return 0;
}
@@ -679,10 +679,10 @@
hashit(sha, timevalue, xcid, &mut h);
- let mut sy = Big::frombytes(&h);
+ let mut sy = Big::from_bytes(&h);
let mut q = Big::new_ints(&rom::CURVE_ORDER);
sy.rmod(&mut q);
- sy.tobytes(y);
+ sy.to_bytes(y);
}
/// Implement step 2 of MPin protocol on server side
@@ -701,7 +701,7 @@
) -> isize {
let Q = ECP8::generator();
- let sQ = ECP8::frombytes(&sst);
+ let sQ = ECP8::from_bytes(&sst);
if sQ.is_infinity() {
return INVALID_POINT;
}
@@ -709,13 +709,13 @@
let mut R: ECP;
if date != 0 {
if let Some(rxcid) = xcid {
- R = ECP::frombytes(&rxcid);
+ R = ECP::from_bytes(&rxcid);
} else {
return BAD_PARAMS;
}
} else {
if let Some(rxid) = xid {
- R = ECP::frombytes(&rxid)
+ R = ECP::from_bytes(&rxid)
} else {
return BAD_PARAMS;
}
@@ -724,16 +724,16 @@
return INVALID_POINT;
}
- let mut sy = Big::frombytes(&y);
+ let mut sy = Big::from_bytes(&y);
let mut P: ECP;
if date != 0 {
if let Some(rhtid) = htid {
- P = ECP::frombytes(&rhtid)
+ P = ECP::from_bytes(&rhtid)
} else {
return BAD_PARAMS;
}
} else {
- P = ECP::frombytes(&hid);
+ P = ECP::from_bytes(&hid);
}
if P.is_infinity() {
@@ -742,7 +742,7 @@
P = pair256::g1mul(&mut P, &mut sy);
P.add(&mut R);
- R = ECP::frombytes(&msec);
+ R = ECP::from_bytes(&msec);
if R.is_infinity() {
return INVALID_POINT;
}
@@ -752,17 +752,17 @@
g = pair256::ate2(&Q, &R, &sQ, &P);
g = pair256::fexp(&g);
- if !g.isunity() {
+ if !g.is_unity() {
if let Some(rxid) = xid {
if let Some(re) = e {
if let Some(rf) = f {
- g.tobytes(re);
+ g.to_bytes(re);
if date != 0 {
- P = ECP::frombytes(&hid);
+ P = ECP::from_bytes(&hid);
if P.is_infinity() {
return INVALID_POINT;
}
- R = ECP::frombytes(&rxid);
+ R = ECP::from_bytes(&rxid);
if R.is_infinity() {
return INVALID_POINT;
}
@@ -771,7 +771,7 @@
}
g = pair256::ate(&Q, &P);
g = pair256::fexp(&g);
- g.tobytes(rf);
+ g.to_bytes(rf);
}
}
}
@@ -784,8 +784,8 @@
/// Pollards kangaroos used to return PIN error
pub fn kangaroo(e: &[u8], f: &[u8]) -> isize {
- let mut ge = FP48::frombytes(e);
- let mut gf = FP48::frombytes(f);
+ let mut ge = FP48::from_bytes(e);
+ let mut gf = FP48::from_bytes(f);
let mut distance: [isize; TS] = [0; TS];
let mut t = gf.clone();
@@ -903,13 +903,13 @@
wcid: &[u8],
ck: &mut [u8],
) -> isize {
- let mut g1 = FP48::frombytes(&g1);
- let mut g2 = FP48::frombytes(&g2);
- let mut z = Big::frombytes(&r);
- let mut x = Big::frombytes(&x);
- let h = Big::frombytes(&h);
+ let mut g1 = FP48::from_bytes(&g1);
+ let mut g2 = FP48::from_bytes(&g2);
+ let mut z = Big::from_bytes(&r);
+ let mut x = Big::from_bytes(&x);
+ let h = Big::from_bytes(&h);
- let mut W = ECP::frombytes(&wcid);
+ let mut W = ECP::from_bytes(&wcid);
if W.is_infinity() {
return INVALID_POINT;
}
@@ -945,31 +945,31 @@
xcid: Option<&[u8]>,
sk: &mut [u8],
) -> isize {
- let sQ = ECP8::frombytes(&sst);
+ let sQ = ECP8::from_bytes(&sst);
if sQ.is_infinity() {
return INVALID_POINT;
}
- let mut R = ECP::frombytes(&z);
+ let mut R = ECP::from_bytes(&z);
if R.is_infinity() {
return INVALID_POINT;
}
- let mut A = ECP::frombytes(&hid);
+ let mut A = ECP::from_bytes(&hid);
if A.is_infinity() {
return INVALID_POINT;
}
let mut U = if let Some(rxcid) = xcid {
- ECP::frombytes(&rxcid)
+ ECP::from_bytes(&rxcid)
} else {
- ECP::frombytes(&xid)
+ ECP::from_bytes(&xid)
};
if U.is_infinity() {
return INVALID_POINT;
}
- let mut w = Big::frombytes(&w);
- let mut h = Big::frombytes(&h);
+ let mut w = Big::from_bytes(&w);
+ let mut h = Big::from_bytes(&h);
A = pair256::g1mul(&mut A, &mut h); // new
R.add(&mut A);
diff --git a/src/pair.rs b/src/pair.rs
index d63abc7..b7d8baf 100644
--- a/src/pair.rs
+++ b/src/pair.rs
@@ -421,7 +421,7 @@
r.frob(&f);
r.frob(&f);
r.mul(&lv);
- // if r.isunity() {
+ // if r.is_unity() {
// r.zero();
// return r;
// }
diff --git a/src/pair192.rs b/src/pair192.rs
index 733b322..6a67fad 100644
--- a/src/pair192.rs
+++ b/src/pair192.rs
@@ -325,7 +325,7 @@
lv = r.clone();
r.frob(&f, 4);
r.mul(&lv);
- // if r.isunity() {
+ // if r.is_unity() {
// r.zero();
// return r;
// }
diff --git a/src/pair256.rs b/src/pair256.rs
index fd68011..983fcae 100644
--- a/src/pair256.rs
+++ b/src/pair256.rs
@@ -323,7 +323,7 @@
lv = r.clone();
r.frob(&f, 8);
r.mul(&lv);
- // if r.isunity() {
+ // if r.is_unity() {
// r.zero();
// return r;
// }
diff --git a/src/rsa.rs b/src/rsa.rs
index d65f832..a6d05f0 100644
--- a/src/rsa.rs
+++ b/src/rsa.rs
@@ -432,9 +432,9 @@
let m = pbc.n.getlen();
let mut r = FF::new_int(m);
- FF::frombytes(&mut r, f);
+ FF::from_bytes(&mut r, f);
r.power(pbc.e, &pbc.n);
- r.tobytes(g);
+ r.to_bytes(g);
}
/* RSA decryption with the private key */
@@ -442,7 +442,7 @@
let n = prv.p.getlen();
let mut r = FF::new_int(2 * n);
- FF::frombytes(&mut r, g);
+ FF::from_bytes(&mut r, g);
let mut jp = r.dmod(&prv.p);
let mut jq = r.dmod(&prv.q);
@@ -465,7 +465,7 @@
r.add(&t);
r.norm();
- r.tobytes(f);
+ r.to_bytes(f);
}
#[cfg(test)]