Add warning when custom entropy is low

This commit is contained in:
moneromooo-monero 2017-02-19 14:49:05 +00:00
parent c04a4e872b
commit 92c9e34701
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
2 changed files with 54 additions and 16 deletions

View file

@ -10741,9 +10741,10 @@ bC0zLjUsMjAuNGgtNkwyNDQuOCwzMTAuNkwyNDQuOCwzMTAuNnoiLz4KPC9nPgo8L3N2Zz4K">
<div class="row valign-wrapper">
<div class="col s4 right-align ">
<input class="btn orange" type="button" onclick="js:genwallet(null);"
value="Generate wallet" action=""/>
<p>Custom entropy (leave empty to use PRNG)</p>
<input type="text" value="" id="user_entropy_widget" />
value="Generate wallet" id="gen_with_custom_entropy_button" disabled="disabled" action=""/>
<p>Custom entropy for deterministic wallet (leave empty to use the browser's PRNG)</p>
<input type="text" value="" id="user_entropy_widget" oninput="js:checkEntropy();" />
<div style="color: red; display: none" id="user_entropy_warning_widget">WARNING: entropy is way too low for the wallet to be secure: aim for 256 bits (about a hundred dice throws)</div>
</div>
<div class="col s1 offset-s1"><h4>or</h4></div>
<div class="col s5 offset-s1">
@ -11093,6 +11094,43 @@ function genwallet_prefix()
}
}
function checkEntropy()
{
var good = true;
var button = document.getElementById("gen_with_custom_entropy_button")
var user_entropy_widget = document.getElementById("user_entropy_widget")
var user_entropy = user_entropy_widget.value;
var user_entropy_warning_widget = document.getElementById("user_entropy_warning_widget")
if (user_entropy.length === 0) {
good = false;
button.disabled = true
user_entropy_warning_widget.style.display = "none"
return
}
button.disabled = false
var count = new Int32Array(256);
for (var n = 0; n < 256; ++n)
count[n] = 0
for (var n = 0; n < user_entropy.length; ++n)
count[user_entropy.charCodeAt(n)]++;
var e = 0
for (var n = 0; n < 256; ++n) {
if (count[n] > 0) {
var p = count[n] / user_entropy.length
p *= Math.log(p) / Math.log(2)
e -= p
}
}
e *= user_entropy.length
if (e < 128)
good = false
if (good)
user_entropy_warning_widget.style.display = "none"
else
user_entropy_warning_widget.style.display = "block"
}
function toggle_qr()
{
address_qr_widget = document.getElementById("address_qr_widget");