From f3edfe59c7aa574e9e96f951d70bc0fdd9872cdd Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Wed, 14 Sep 2016 13:41:34 +0300 Subject: [PATCH] ec: speedup ec.recoverPubKey PR-URL: https://github.com/indutny/elliptic/pull/104 Reviewed-By: Fedor Indutny --- lib/elliptic/ec/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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) {