Browse Source

Fix the error loop.

I added a similar badrs function to python-ecdsa and compared the results.

The 1 badrs (aka forcing it to loop once) gave me a different value. It turns out you missed one of the `v = hmac_k(v)` steps during the loop.

Adding one extra `v = hmac_k(v)` in each loop makes it match up with python-ecdsa perfectly (I even tried up to badrs = 30 and it was fine.
patch-2
bip32JP 10 years ago
parent
commit
95bfb18849
  1. 1
      lib/crypto/ecdsa.js

1
lib/crypto/ecdsa.js

@ -100,6 +100,7 @@ ECDSA.prototype.deterministicK = function(badrs) {
for (var i = 0; i < badrs || !(T.lt(N) && T.gt(0)); i++) {
k = Hash.sha256hmac(Buffer.concat([v, new Buffer([0x00])]), k);
v = Hash.sha256hmac(v, k);
v = Hash.sha256hmac(v, k);
T = BN.fromBuffer(v);
}

Loading…
Cancel
Save