From d819a1006794103058dc07353cccf8c495e14cff Mon Sep 17 00:00:00 2001 From: bip32jp Date: Wed, 31 Dec 2014 22:33:22 +0900 Subject: [PATCH] Capture mouse movements for entropy --- index.html | 1 + js/coin.js | 5 +++-- js/coinbin.js | 26 ++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 61aa67a..c4f58bf 100644 --- a/index.html +++ b/index.html @@ -643,5 +643,6 @@ + diff --git a/js/coin.js b/js/coin.js index 2782227..fb58998 100644 --- a/js/coin.js +++ b/js/coin.js @@ -43,7 +43,7 @@ var x = window.location; x += (window.screen.height * window.screen.width * window.screen.colorDepth); x += coinjs.random(64); - x += (window.screen.availHeight * window.screen.availWidth * window.screen.pixelDepth); + x += (window.screen.availHeight * window.screen.availWidth * window.screen.pixelDepth); x += navigator.language; x += window.history.length; x += coinjs.random(64); @@ -54,9 +54,10 @@ var dateObj = new Date(); x += dateObj.getTimezoneOffset(); x += coinjs.random(64); + x += $("#entropybucket").html(); x += x+''+x; var r = x; - for(i=0;i<(x).length/16;i++){ + for(i=0;i<(x).length/25;i++){ r = Crypto.SHA256(r.concat(x)); } return r; diff --git a/js/coinbin.js b/js/coinbin.js index fa4718e..f39389e 100644 --- a/js/coinbin.js +++ b/js/coinbin.js @@ -813,4 +813,30 @@ $(document).ready(function() { $("#newKeysBtn").click(); validateOutputAmount(); + + /* capture mouse movement to add entropy */ + var IE = document.all?true:false // Boolean, is browser IE? + if (!IE) document.captureEvents(Event.MOUSEMOVE) + document.onmousemove = getMouseXY; + function getMouseXY(e) { + var tempX = 0; + var tempY = 0; + if (IE) { // If browser is IE + tempX = event.clientX + document.body.scrollLeft; + tempY = event.clientY + document.body.scrollTop; + } else { + tempX = e.pageX; + tempY = e.pageY; + }; + if (tempX < 0){tempX = 0}; + if (tempY < 0){tempY = 0}; + var xEnt = Crypto.util.bytesToHex([tempX]); + var yEnt = Crypto.util.bytesToHex([tempY]); + var addEnt = xEnt.concat(yEnt); + if ($("#entropybucket").html().indexOf(xEnt) == -1 && $("#entropybucket").html().indexOf(yEnt) == -1) { + $("#entropybucket").html(addEnt + $("#entropybucket").html()); + }; + if ($("#entropybucket").html().length > 128) {$("#entropybucket").html($("#entropybucket").html().slice(0, 128))}; + return true; + }; });