Skip to content

Commit

Permalink
ec: speedup ec.recoverPubKey
Browse files Browse the repository at this point in the history
PR-URL: #104
Reviewed-By: Fedor Indutny <fedor@indutny.com>
  • Loading branch information
fanatid authored and indutny committed Sep 15, 2016
1 parent ab93810 commit f3edfe5
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/elliptic/ec/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,13 @@ EC.prototype.recoverPubKey = function(msg, signature, j, enc) {
else
r = this.curve.pointFromX(r, isYOdd);

var eNeg = n.sub(e);
var rInv = signature.r.invm(n);
var s1 = n.sub(e).mul(rInv).umod(n);
var s2 = s.mul(rInv).umod(n);

// 1.6.1 Compute Q = r^-1 (sR - eG)
// Q = r^-1 (sR + -eG)
var rInv = signature.r.invm(n);
return this.g.mulAdd(eNeg, r, s).mul(rInv);
return this.g.mulAdd(s1, r, s2);
};

EC.prototype.getKeyRecoveryParam = function(e, signature, Q, enc) {
Expand Down

0 comments on commit f3edfe5

Please sign in to comment.