Skip to content

Commit

Permalink
short: add infinity check before multiplying
Browse files Browse the repository at this point in the history
  • Loading branch information
benediamond authored and indutny committed Sep 4, 2019
1 parent ee7970b commit 7ec66ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/elliptic/curve/short.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]);
Expand Down
7 changes: 7 additions & 0 deletions test/curve-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 7ec66ff

Please sign in to comment.