ecdsa: proper recovery param for canonical sigs

Fix: #59
This commit is contained in:
Fedor Indutny
2015-11-02 16:05:57 -05:00
parent f5bd12fa53
commit 1a05d7c67a
+6 -4
View File
@@ -134,13 +134,15 @@ EC.prototype.sign = function sign(msg, key, enc, options) {
if (s.cmpn(0) === 0)
continue;
// Use complement of `s`, if it is > `n / 2`
if (options.canonical && s.cmp(this.nh) > 0)
s = this.n.sub(s);
var recoveryParam = (kp.getY().isOdd() ? 1 : 0) |
(kpX.cmp(r) !== 0 ? 2 : 0);
// Use complement of `s`, if it is > `n / 2`
if (options.canonical && s.cmp(this.nh) > 0) {
s = this.n.sub(s);
recoveryParam ^= 1;
}
return new Signature({ r: r, s: s, recoveryParam: recoveryParam });
} while (true);
};