From 95bfb188490ae519ef18a224a92d6e49d38493eb Mon Sep 17 00:00:00 2001 From: bip32JP Date: Fri, 2 Jan 2015 15:32:33 +0900 Subject: [PATCH] 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. --- lib/crypto/ecdsa.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/crypto/ecdsa.js b/lib/crypto/ecdsa.js index 9ab220d..42fa774 100644 --- a/lib/crypto/ecdsa.js +++ b/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); }