enforce low S values on key signing, read BIP62 for details
This commit is contained in:
parent
100de8a9ba
commit
722e2efeae
@ -160,6 +160,11 @@ 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);
|
||||
// use only low S values according to BIP62
|
||||
var n_half = new bignum(n).div(2);
|
||||
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
Block a user