clean code (#555)
This commit is contained in:
parent
81d94478f2
commit
95f2ca74a6
|
@ -28,6 +28,7 @@ import java.security.spec.ECPoint;
|
||||||
|
|
||||||
public class ECsecp256k1 {
|
public class ECsecp256k1 {
|
||||||
static private final BigInteger TWO = new BigInteger("2");
|
static private final BigInteger TWO = new BigInteger("2");
|
||||||
|
static private final BigInteger THREE = new BigInteger("3");
|
||||||
static public final BigInteger p = new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F", 16);
|
static public final BigInteger p = new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F", 16);
|
||||||
static public final BigInteger a = new BigInteger("0000000000000000000000000000000000000000000000000000000000000000", 16);
|
static public final BigInteger a = new BigInteger("0000000000000000000000000000000000000000000000000000000000000000", 16);
|
||||||
static public final BigInteger b = new BigInteger("0000000000000000000000000000000000000000000000000000000000000007", 16);
|
static public final BigInteger b = new BigInteger("0000000000000000000000000000000000000000000000000000000000000007", 16);
|
||||||
|
@ -61,19 +62,18 @@ public class ECsecp256k1 {
|
||||||
return s;
|
return s;
|
||||||
else if (s.equals(ECPoint.POINT_INFINITY))
|
else if (s.equals(ECPoint.POINT_INFINITY))
|
||||||
return r;
|
return r;
|
||||||
BigInteger slope = (r.getAffineY().subtract(s.getAffineY())).multiply(r.getAffineX().subtract(s.getAffineX()).modInverse(p)).mod(p);
|
BigInteger slope = (r.getAffineY().subtract(s.getAffineY()))
|
||||||
|
.multiply(r.getAffineX().subtract(s.getAffineX()).modInverse(p));
|
||||||
BigInteger Xout = (slope.modPow(TWO, p).subtract(r.getAffineX())).subtract(s.getAffineX()).mod(p);
|
BigInteger Xout = (slope.modPow(TWO, p).subtract(r.getAffineX())).subtract(s.getAffineX()).mod(p);
|
||||||
BigInteger Yout = s.getAffineY().negate().mod(p);
|
BigInteger Yout = s.getAffineY().negate().add(slope.multiply(s.getAffineX().subtract(Xout))).mod(p);
|
||||||
Yout = Yout.add(slope.multiply(s.getAffineX().subtract(Xout))).mod(p);
|
|
||||||
return new ECPoint(Xout, Yout);
|
return new ECPoint(Xout, Yout);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ECPoint doublePoint(ECPoint r) {
|
public static ECPoint doublePoint(ECPoint r) {
|
||||||
if (r.equals(ECPoint.POINT_INFINITY))
|
if (r.equals(ECPoint.POINT_INFINITY))
|
||||||
return r;
|
return r;
|
||||||
BigInteger slope = (r.getAffineX().pow(2)).multiply(new BigInteger("3"));
|
BigInteger slope = (r.getAffineX().pow(2)).multiply(THREE).add(a)
|
||||||
slope = slope.add(a);
|
.multiply((r.getAffineY().multiply(TWO)).modInverse(p));
|
||||||
slope = slope.multiply((r.getAffineY().multiply(TWO)).modInverse(p));
|
|
||||||
BigInteger Xout = slope.pow(2).subtract(r.getAffineX().multiply(TWO)).mod(p);
|
BigInteger Xout = slope.pow(2).subtract(r.getAffineX().multiply(TWO)).mod(p);
|
||||||
BigInteger Yout = (r.getAffineY().negate()).add(slope.multiply(r.getAffineX().subtract(Xout))).mod(p);
|
BigInteger Yout = (r.getAffineY().negate()).add(slope.multiply(r.getAffineX().subtract(Xout))).mod(p);
|
||||||
return new ECPoint(Xout, Yout);
|
return new ECPoint(Xout, Yout);
|
||||||
|
|
Loading…
Reference in New Issue