diff --git a/bitaddress.org.html b/bitaddress.org.html index 586b20c..68832f5 100644 --- a/bitaddress.org.html +++ b/bitaddress.org.html @@ -1504,6 +1504,7 @@ if (typeof Crypto == "undefined" || !Crypto.util) { sr.state; sr.pool; sr.pptr; + sr.poolCopyOnInit; // Pool size must be a multiple of 4 and greater than 32. // An array of bytes the size of the pool will be passed to init() @@ -1533,8 +1534,9 @@ if (typeof Crypto == "undefined" || !Crypto.util) { sr.seedTime(); sr.state = sr.ArcFour(); // Plug in your RNG constructor here sr.state.init(sr.pool); + sr.poolCopyOnInit = []; for (sr.pptr = 0; sr.pptr < sr.pool.length; ++sr.pptr) - sr.pool[sr.pptr] = 0; + sr.poolCopyOnInit[sr.pptr] = sr.pool[sr.pptr]; sr.pptr = 0; } // TODO: allow reseeding after first request @@ -1543,13 +1545,17 @@ if (typeof Crypto == "undefined" || !Crypto.util) { // Mix in a 32-bit integer into the pool sr.seedInt = function (x) { - sr.pool[sr.pptr++] ^= x & 255; - sr.pool[sr.pptr++] ^= (x >> 8) & 255; - sr.pool[sr.pptr++] ^= (x >> 16) & 255; - sr.pool[sr.pptr++] ^= (x >> 24) & 255; - if (sr.pptr >= sr.poolSize) sr.pptr -= sr.poolSize; + sr.seedInt8(x); + sr.seedInt8((x >> 8)); + sr.seedInt8((x >> 16)); + sr.seedInt8((x >> 24)); } + // Mix in a 8-bit integer into the pool + sr.seedInt8 = function (x) { + sr.pool[sr.pptr++] ^= x & 255; + if (sr.pptr >= sr.poolSize) sr.pptr -= sr.poolSize; + } // Arcfour is a PRNG sr.ArcFour = function () { @@ -1597,11 +1603,14 @@ if (typeof Crypto == "undefined" || !Crypto.util) { sr.pool = new Array(); sr.pptr = 0; var t; - if (navigator.appName == "Netscape" && navigator.appVersion < "5" && window.crypto) { - // Extract entropy (256 bits) from NS4 RNG if available - var z = window.crypto.random(32); - for (t = 0; t < z.length; ++t) - sr.pool[sr.pptr++] = z.charCodeAt(t) & 255; + if (window.crypto && window.crypto.getRandomValues) { + try { + // Use webcrypto if available + var ua = new Uint8Array(32); + window.crypto.getRandomValues(ua); + for (t = 0; t < 32; ++t) + sr.pool[sr.pptr++] = ua[t]; + } catch (e) { alert(e); } } while (sr.pptr < sr.poolSize) { // extract some randomness from Math.random() t = Math.floor(65536 * Math.random()); @@ -1611,8 +1620,36 @@ if (typeof Crypto == "undefined" || !Crypto.util) { sr.pptr = 0; sr.seedTime(); // entropy - sr.seedInt(window.screenX); - sr.seedInt(window.screenY); + var entropyStr = ""; + // screen size and color depth: ~4.8 to ~5.4 bits + entropyStr += (window.screen.height * window.screen.width * window.screen.colorDepth); + entropyStr += (window.screen.availHeight * window.screen.availWidth * window.screen.pixelDepth); + // time zone offset: ~4 bits + var dateObj = new Date(); + var timeZoneOffset = dateObj.getTimezoneOffset(); + entropyStr += timeZoneOffset; + // user agent: ~8.3 to ~11.6 bits + entropyStr += navigator.userAgent; + // browser plugin details: ~16.2 to ~21.8 bits + var pluginsStr = ""; + for (var i = 0; i < navigator.plugins.length; i++) { + pluginsStr += navigator.plugins[i].name + " " + navigator.plugins[i].filename + " " + navigator.plugins[i].description + " " + navigator.plugins[i].version + ", "; + } + var mimeTypesStr = ""; + for (var i = 0; i < navigator.mimeTypes.length; i++) { + mimeTypesStr += navigator.mimeTypes[i].description + " " + navigator.mimeTypes[i].type + " " + navigator.mimeTypes[i].suffixes + ", "; + } + entropyStr += pluginsStr + mimeTypesStr; + // cookies and storage: 1 bit + entropyStr += navigator.cookieEnabled + typeof (sessionStorage) + typeof (localStorage); + + var entropyBytes = Crypto.SHA256(entropyStr, { asBytes: true }); + sr.seedInt8(entropyBytes[0]); + sr.seedInt8(entropyBytes[1]); + sr.seedInt8(entropyBytes[2]); + sr.seedInt8(entropyBytes[3]); + sr.seedInt8(entropyBytes[4]); + sr.seedInt8(entropyBytes[5]); } })(); @@ -5729,6 +5766,7 @@ body { font-family: Arial; } .answer { padding: 0 15px 10px 25px; text-align: left; display: none; font-size: 80%; } .faq { border: 0; border-top: 2px solid green; } +#seedpoolarea { display: none; } #keyarea { height: 250px; font-family: Arial; } #keyarea .pubaddress { float: none; display: block; padding: 0; height: auto; } #keyarea .label { text-decoration: none; } @@ -5891,6 +5929,7 @@ body { font-family: Arial; } #detailprivwif { width: 285px; word-wrap: break-word; } #detailprivwifcomp { width: 285px; word-wrap: break-word; text-align: right; } #detailarea .privqr .item { width: 285px; } + #seedpoolarea { display: none; } } @@ -5906,6 +5945,7 @@ body { font-family: Arial; }
Open Source JavaScript Client-Side Bitcoin Wallet Generator
+
Open Source JavaScript Client-Side Bitcoin Wallet Generator
+