Browse Source

ec: white space fixes

It is advised to use ?w=0 in comparing this commit.
hk-custom-address
Daniel Cousens 11 years ago
parent
commit
79c7b68d35
  1. 6
      src/ec.js

6
src/ec.js

@ -94,6 +94,7 @@ function pointFpEquals(other) {
if (other == this) return true; if (other == this) return true;
if (this.isInfinity()) return other.isInfinity(); if (this.isInfinity()) return other.isInfinity();
if (other.isInfinity()) return this.isInfinity(); if (other.isInfinity()) return this.isInfinity();
var u, v; var u, v;
// u = Y2 * Z1 - Y1 * Z2 // u = Y2 * Z1 - Y1 * Z2
u = other.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(other.z)).mod(this.curve.q); u = other.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(other.z)).mod(this.curve.q);
@ -130,6 +131,7 @@ function pointFpAdd(b) {
if (u.signum() === 0) { if (u.signum() === 0) {
return this.twice(); // this == b, so double return this.twice(); // this == b, so double
} }
return this.curve.getInfinity(); // this = -b, so infinity return this.curve.getInfinity(); // this = -b, so infinity
} }
@ -161,9 +163,11 @@ function pointFpTwice() {
// w = 3 * x1^2 + a * z1^2 // w = 3 * x1^2 + a * z1^2
var w = x1.square().multiply(THREE); var w = x1.square().multiply(THREE);
if (a.signum() !== 0) { if (a.signum() !== 0) {
w = w.add(this.z.square().multiply(a)); w = w.add(this.z.square().multiply(a));
} }
w = w.mod(this.curve.q); w = w.mod(this.curve.q);
// x3 = 2 * y1 * z1 * (w^2 - 8 * x1 * y1^2 * z1) // x3 = 2 * y1 * z1 * (w^2 - 8 * x1 * y1^2 * z1)
var x3 = w.square().subtract(x1.shiftLeft(3).multiply(y1sqz1)).shiftLeft(1).multiply(y1z1).mod(this.curve.q); var x3 = w.square().subtract(x1.shiftLeft(3).multiply(y1sqz1)).shiftLeft(1).multiply(y1z1).mod(this.curve.q);
@ -205,6 +209,7 @@ function pointFpMultiply(k) {
// Compute this*j + x*k (simultaneous multiplication) // Compute this*j + x*k (simultaneous multiplication)
function pointFpMultiplyTwo(j,x,k) { function pointFpMultiplyTwo(j,x,k) {
var i; var i;
if (j.bitLength() > k.bitLength()) if (j.bitLength() > k.bitLength())
i = j.bitLength() - 1; i = j.bitLength() - 1;
else else
@ -410,6 +415,5 @@ ECPointFp.prototype.validate = function () {
return true; return true;
}; };
module.exports = ECCurveFp; module.exports = ECCurveFp;
module.exports.ECPointFp = ECPointFp; module.exports.ECPointFp = ECPointFp;

Loading…
Cancel
Save