mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-11-03 12:57:03 +00:00
Make Field::square take &self and return Self
This commit is contained in:
@@ -54,10 +54,8 @@ macro_rules! curve_impl {
|
||||
// are equal when (X * Z^2) = (X' * Z'^2)
|
||||
// and (Y * Z^3) = (Y' * Z'^3).
|
||||
|
||||
let mut z1 = self.z;
|
||||
z1.square();
|
||||
let mut z2 = other.z;
|
||||
z2.square();
|
||||
let mut z1 = self.z.square();
|
||||
let mut z2 = other.z.square();
|
||||
|
||||
let mut tmp1 = self.x;
|
||||
tmp1.mul_assign(&z2);
|
||||
@@ -101,8 +99,7 @@ macro_rules! curve_impl {
|
||||
/// largest y-coordinate be selected.
|
||||
fn get_point_from_x(x: $basefield, greatest: bool) -> Option<$affine> {
|
||||
// Compute x^3 + b
|
||||
let mut x3b = x;
|
||||
x3b.square();
|
||||
let mut x3b = x.square();
|
||||
x3b.mul_assign(&x);
|
||||
x3b.add_assign(&$affine::get_coeff_b());
|
||||
|
||||
@@ -122,11 +119,9 @@ macro_rules! curve_impl {
|
||||
true
|
||||
} else {
|
||||
// Check that the point is on the curve
|
||||
let mut y2 = self.y;
|
||||
y2.square();
|
||||
let y2 = self.y.square();
|
||||
|
||||
let mut x3b = self.x;
|
||||
x3b.square();
|
||||
let mut x3b = self.x.square();
|
||||
x3b.mul_assign(&self.x);
|
||||
x3b.add_assign(&Self::get_coeff_b());
|
||||
|
||||
@@ -283,8 +278,7 @@ macro_rules! curve_impl {
|
||||
|
||||
// Perform affine transformations
|
||||
for g in v.iter_mut().filter(|g| !g.is_normalized()) {
|
||||
let mut z = g.z; // 1/z
|
||||
z.square(); // 1/z^2
|
||||
let mut z = g.z.square(); // 1/z^2
|
||||
g.x.mul_assign(&z); // x/z^2
|
||||
z.mul_assign(&g.z); // 1/z^3
|
||||
g.y.mul_assign(&z); // y/z^3
|
||||
@@ -305,21 +299,18 @@ macro_rules! curve_impl {
|
||||
// http://www.hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#doubling-dbl-2009-l
|
||||
|
||||
// A = X1^2
|
||||
let mut a = self.x;
|
||||
a.square();
|
||||
let a = self.x.square();
|
||||
|
||||
// B = Y1^2
|
||||
let mut b = self.y;
|
||||
b.square();
|
||||
let b = self.y.square();
|
||||
|
||||
// C = B^2
|
||||
let mut c = b;
|
||||
c.square();
|
||||
let mut c = b.square();
|
||||
|
||||
// D = 2*((X1+B)2-A-C)
|
||||
let mut d = self.x;
|
||||
d.add_assign(&b);
|
||||
d.square();
|
||||
d = d.square();
|
||||
d.sub_assign(&a);
|
||||
d.sub_assign(&c);
|
||||
d = d.double();
|
||||
@@ -329,8 +320,7 @@ macro_rules! curve_impl {
|
||||
e.add_assign(&a);
|
||||
|
||||
// F = E^2
|
||||
let mut f = e;
|
||||
f.square();
|
||||
let f = e.square();
|
||||
|
||||
// Z3 = 2*Y1*Z1
|
||||
self.z.mul_assign(&self.y);
|
||||
@@ -362,12 +352,10 @@ macro_rules! curve_impl {
|
||||
// http://www.hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#addition-add-2007-bl
|
||||
|
||||
// Z1Z1 = Z1^2
|
||||
let mut z1z1 = self.z;
|
||||
z1z1.square();
|
||||
let z1z1 = self.z.square();
|
||||
|
||||
// Z2Z2 = Z2^2
|
||||
let mut z2z2 = other.z;
|
||||
z2z2.square();
|
||||
let z2z2 = other.z.square();
|
||||
|
||||
// U1 = X1*Z2Z2
|
||||
let mut u1 = self.x;
|
||||
@@ -398,8 +386,7 @@ macro_rules! curve_impl {
|
||||
h.sub_assign(&u1);
|
||||
|
||||
// I = (2*H)^2
|
||||
let mut i = h.double();
|
||||
i.square();
|
||||
let i = h.double().square();
|
||||
|
||||
// J = H*I
|
||||
let mut j = h;
|
||||
@@ -415,8 +402,7 @@ macro_rules! curve_impl {
|
||||
v.mul_assign(&i);
|
||||
|
||||
// X3 = r^2 - J - 2*V
|
||||
self.x = r;
|
||||
self.x.square();
|
||||
self.x = r.square();
|
||||
self.x.sub_assign(&j);
|
||||
self.x.sub_assign(&v);
|
||||
self.x.sub_assign(&v);
|
||||
@@ -431,7 +417,7 @@ macro_rules! curve_impl {
|
||||
|
||||
// Z3 = ((Z1+Z2)^2 - Z1Z1 - Z2Z2)*H
|
||||
self.z.add_assign(&other.z);
|
||||
self.z.square();
|
||||
self.z = self.z.square();
|
||||
self.z.sub_assign(&z1z1);
|
||||
self.z.sub_assign(&z2z2);
|
||||
self.z.mul_assign(&h);
|
||||
@@ -453,8 +439,7 @@ macro_rules! curve_impl {
|
||||
// http://www.hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#addition-madd-2007-bl
|
||||
|
||||
// Z1Z1 = Z1^2
|
||||
let mut z1z1 = self.z;
|
||||
z1z1.square();
|
||||
let z1z1 = self.z.square();
|
||||
|
||||
// U2 = X2*Z1Z1
|
||||
let mut u2 = other.x;
|
||||
@@ -476,8 +461,7 @@ macro_rules! curve_impl {
|
||||
h.sub_assign(&self.x);
|
||||
|
||||
// HH = H^2
|
||||
let mut hh = h;
|
||||
hh.square();
|
||||
let hh = h.square();
|
||||
|
||||
// I = 4*HH
|
||||
let i = hh.double().double();
|
||||
@@ -496,8 +480,7 @@ macro_rules! curve_impl {
|
||||
v.mul_assign(&i);
|
||||
|
||||
// X3 = r^2 - J - 2*V
|
||||
self.x = r;
|
||||
self.x.square();
|
||||
self.x = r.square();
|
||||
self.x.sub_assign(&j);
|
||||
self.x.sub_assign(&v);
|
||||
self.x.sub_assign(&v);
|
||||
@@ -512,7 +495,7 @@ macro_rules! curve_impl {
|
||||
|
||||
// Z3 = (Z1+H)^2-Z1Z1-HH
|
||||
self.z.add_assign(&h);
|
||||
self.z.square();
|
||||
self.z = self.z.square();
|
||||
self.z.sub_assign(&z1z1);
|
||||
self.z.sub_assign(&hh);
|
||||
}
|
||||
@@ -589,8 +572,7 @@ macro_rules! curve_impl {
|
||||
} else {
|
||||
// Z is nonzero, so it must have an inverse in a field.
|
||||
let zinv = p.z.inverse().unwrap();
|
||||
let mut zinv_powered = zinv;
|
||||
zinv_powered.square();
|
||||
let mut zinv_powered = zinv.square();
|
||||
|
||||
// X/Z^2
|
||||
let mut x = p.x;
|
||||
@@ -933,8 +915,7 @@ pub mod g1 {
|
||||
let mut i = 0;
|
||||
loop {
|
||||
// y^2 = x^3 + b
|
||||
let mut rhs = x;
|
||||
rhs.square();
|
||||
let mut rhs = x.square();
|
||||
rhs.mul_assign(&x);
|
||||
rhs.add_assign(&G1Affine::get_coeff_b());
|
||||
|
||||
@@ -1638,8 +1619,7 @@ pub mod g2 {
|
||||
let mut i = 0;
|
||||
loop {
|
||||
// y^2 = x^3 + b
|
||||
let mut rhs = x;
|
||||
rhs.square();
|
||||
let mut rhs = x.square();
|
||||
rhs.mul_assign(&x);
|
||||
rhs.add_assign(&G2Affine::get_coeff_b());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user