From 5b3cae1f328ffe00a111c511e1281f6c9fb796f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Wed, 2 Jul 2014 21:23:39 +0200 Subject: [PATCH] SecureRandom: /!\ throw an alert if the PRNG is used is initialized when the entropy collection using the mouse is not done. --- index.html | 9 +++++++++ src/ninja.misc.js | 14 +++++++++----- src/securerandom.js | 5 +++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 56e5012..58ff3c8 100644 --- a/index.html +++ b/index.html @@ -1543,6 +1543,11 @@ if (typeof Crypto == "undefined" || !Crypto.util) { } sr.getByte = function () { + if(!ninja.seeder.isDone()) { + alert("Premature initialisation of the random generator. Something is really wrong, do not generate wallets."); + return NaN; + } + if (sr.state == null) { sr.seedTime(); sr.state = sr.ArcFour(); // Plug in your RNG constructor here @@ -10703,6 +10708,10 @@ ninja.publicKey = { lastInputTime: new Date().getTime(), seedPoints: [], + isDone: function() { + return ninja.seeder.seedCount >= ninja.seeder.seedLimit; + }, + // seed function exists to wait for mouse movement to add more entropy before generating an address seed: function (evt) { if (!evt) var evt = window.event; diff --git a/src/ninja.misc.js b/src/ninja.misc.js index 7aeeba1..f4e206f 100644 --- a/src/ninja.misc.js +++ b/src/ninja.misc.js @@ -13,14 +13,18 @@ lastInputTime: new Date().getTime(), seedPoints: [], + isDone: function() { + return ninja.seeder.seedCount >= ninja.seeder.seedLimit; + }, + // seed function exists to wait for mouse movement to add more entropy before generating an address seed: function (evt) { if (!evt) var evt = window.event; var timeStamp = new Date().getTime(); - // seeding is over now we generate and display the address + // seeding is over now we generate and display the address if (ninja.seeder.seedCount == ninja.seeder.seedLimit) { ninja.seeder.seedCount++; - ninja.wallets.singlewallet.open(); + ninja.wallets.singlewallet.open(); document.getElementById("generate").style.display = "none"; document.getElementById("menu").style.visibility = "visible"; ninja.seeder.removePoints(); @@ -42,7 +46,7 @@ // seeding is over now we generate and display the address if (ninja.seeder.seedCount == ninja.seeder.seedLimit) { ninja.seeder.seedCount++; - ninja.wallets.singlewallet.open(); + ninja.wallets.singlewallet.open(); document.getElementById("generate").style.display = "none"; document.getElementById("menu").style.visibility = "visible"; ninja.seeder.removePoints(); @@ -63,8 +67,8 @@ showPool: function () { var poolHex = Crypto.util.bytesToHex(SecureRandom.pool); - document.getElementById("seedpool").innerHTML = poolHex; - document.getElementById("seedpooldisplay").innerHTML = poolHex; + document.getElementById("seedpool").innerHTML = poolHex; + document.getElementById("seedpooldisplay").innerHTML = poolHex; document.getElementById("mousemovelimit").innerHTML = (ninja.seeder.seedLimit - ninja.seeder.seedCount); }, diff --git a/src/securerandom.js b/src/securerandom.js index 3b6f172..278450a 100644 --- a/src/securerandom.js +++ b/src/securerandom.js @@ -52,6 +52,11 @@ } sr.getByte = function () { + if(!ninja.seeder.isDone()) { + alert("Premature initialisation of the random generator. Something is really wrong, do not generate wallets."); + return NaN; + } + if (sr.state == null) { sr.seedTime(); sr.state = sr.ArcFour(); // Plug in your RNG constructor here