diff --git a/lib/elliptic/ec/index.js b/lib/elliptic/ec/index.js index b7fa666..d71d5df 100644 --- a/lib/elliptic/ec/index.js +++ b/lib/elliptic/ec/index.js @@ -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) {