aboutsummaryrefslogtreecommitdiff
path: root/src/js
diff options
context:
space:
mode:
authorIan Coleman <coleman.ian@gmail.com>2016-12-22 15:40:41 +1100
committerIan Coleman <coleman.ian@gmail.com>2016-12-22 15:40:41 +1100
commit9d33c8925dc07783e2cd819c91eee1144598fcf2 (patch)
tree9e38c1e63d500d4f641f6940c2165f677054e921 /src/js
parent0a1f0259d1cfe5217ca9c08f7fbd371a03703594 (diff)
downloadBIP39-9d33c8925dc07783e2cd819c91eee1144598fcf2.tar.gz
BIP39-9d33c8925dc07783e2cd819c91eee1144598fcf2.tar.zst
BIP39-9d33c8925dc07783e2cd819c91eee1144598fcf2.zip
Card entropy uses secure hashing when > 256 bits
Diffstat (limited to 'src/js')
-rw-r--r--src/js/entropy.js7
1 files changed, 2 insertions, 5 deletions
diff --git a/src/js/entropy.js b/src/js/entropy.js
index 24fc21a..a709c78 100644
--- a/src/js/entropy.js
+++ b/src/js/entropy.js
@@ -293,15 +293,12 @@ window.Entropy = new (function() {
293 // Create a normalized string of the selected cards 293 // Create a normalized string of the selected cards
294 var normalizedCards = cards.join("").toUpperCase(); 294 var normalizedCards = cards.join("").toUpperCase();
295 // Convert to binary using the SHA256 hash of the normalized cards. 295 // Convert to binary using the SHA256 hash of the normalized cards.
296 // If the number of bits is more than 256, multiple rounds of hashing 296 // If the number of bits is more than 256, multiple hashes
297 // are used until the required number of bits is reached. 297 // are used until the required number of bits is reached.
298 var entropyBin = ""; 298 var entropyBin = "";
299 var iterations = 0; 299 var iterations = 0;
300 while (entropyBin.length < numberOfBits) { 300 while (entropyBin.length < numberOfBits) {
301 var hashedCards = sjcl.hash.sha256.hash(normalizedCards); 301 var hashedCards = sjcl.hash.sha256.hash(normalizedCards + ":" + iterations);
302 for (var j=0; j<iterations; j++) {
303 hashedCards = sjcl.hash.sha256.hash(hashedCards);
304 }
305 var hashHex = sjcl.codec.hex.fromBits(hashedCards); 302 var hashHex = sjcl.codec.hex.fromBits(hashedCards);
306 for (var i=0; i<hashHex.length; i++) { 303 for (var i=0; i<hashHex.length; i++) {
307 var decimal = parseInt(hashHex[i], 16); 304 var decimal = parseInt(hashHex[i], 16);