diff --git a/lib/elliptic/curve/short.js b/lib/elliptic/curve/short.js index b631e7c..b263ecf 100644 --- a/lib/elliptic/curve/short.js +++ b/lib/elliptic/curve/short.js @@ -421,8 +421,9 @@ Point.prototype.getY = function getY() { Point.prototype.mul = function mul(k) { k = new BN(k, 16); - - if (this._hasDoubles(k)) + if (this.isInfinity()) + return this; + else if (this._hasDoubles(k)) return this.curve._fixedNafMul(this, k); else if (this.curve.endo) return this.curve._endoWnafMulAdd([ this ], [ k ]); diff --git a/test/curve-test.js b/test/curve-test.js index 2c6167d..fcfa84e 100644 --- a/test/curve-test.js +++ b/test/curve-test.js @@ -253,6 +253,13 @@ describe('Curve', function() { var neg2 = neg.neg(true); assert(p.eq(neg2)); }); + + it('should correctly handle scalar multiplication of zero', function() { + var curve = elliptic.curves.secp256k1.curve; + var p1 = curve.g.mul('0'); + var p2 = p1.mul('2'); + assert(p1.eq(p2)); + }); }); describe('Point codec', function () {