Merge pull request #727 from thoatbk/master
enforce low S values on key signing
This commit is contained in:
commit
0d238f1165
|
@ -160,6 +160,12 @@ Key.sign = function(hash, priv, k) {
|
|||
var Q = Point.multiply(G, k);
|
||||
var r = Q.x.mod(n);
|
||||
var s = k.invm(n).mul(e.add(d.mul(r))).mod(n);
|
||||
//enforce low s
|
||||
//see BIP 62, "low S values in signatures"
|
||||
var n_half = bignum.fromBuffer(new Buffer("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0", 'hex'), {size: 32});
|
||||
if (s.cmp(n_half) > 0) {
|
||||
s = new bignum(n).sub(s);
|
||||
}
|
||||
} while (r.cmp(new bignum(0)) <= 0 || s.cmp(new bignum(0)) <= 0);
|
||||
|
||||
return {r: r, s: s};
|
||||
|
|
Loading…
Reference in New Issue