Skip to content

Commit 7ec66ff

Browse files
benediamondindutny
authored andcommitted
short: add infinity check before multiplying
1 parent ee7970b commit 7ec66ff

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/elliptic/curve/short.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,9 @@ Point.prototype.getY = function getY() {
421421

422422
Point.prototype.mul = function mul(k) {
423423
k = new BN(k, 16);
424-
425-
if (this._hasDoubles(k))
424+
if (this.isInfinity())
425+
return this;
426+
else if (this._hasDoubles(k))
426427
return this.curve._fixedNafMul(this, k);
427428
else if (this.curve.endo)
428429
return this.curve._endoWnafMulAdd([ this ], [ k ]);

test/curve-test.js

+7
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ describe('Curve', function() {
253253
var neg2 = neg.neg(true);
254254
assert(p.eq(neg2));
255255
});
256+
257+
it('should correctly handle scalar multiplication of zero', function() {
258+
var curve = elliptic.curves.secp256k1.curve;
259+
var p1 = curve.g.mul('0');
260+
var p2 = p1.mul('2');
261+
assert(p1.eq(p2));
262+
});
256263
});
257264

258265
describe('Point codec', function () {

0 commit comments

Comments
 (0)