Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CSPRNG for private keys #246

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<div id="content" class="container">

<noscript class="alert alert-danger center-block"><span class="glyphicon glyphicon-exclamation-sign"></span> This page uses javascript, please enable it to continue!</noscript>
<div id="cryptoRandomStatus" class="alert alert-danger center-block hidden"><span class="glyphicon glyphicon-exclamation-sign"></span> This browser does not have a secure random number generator! Please use at your own risk!</div>

<div class="tab-content">
<div class="tab-pane tab-content active" id="home">
Expand Down
18 changes: 18 additions & 0 deletions js/coin.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,27 @@
};
}

/* generate crypto secure random numbers (should exist on most browsers) */
coinjs.randomBytesSafe = function(count){
var cry = window.crypto || window.msCrypto;
if (!cry) {
/* Display warning message for 30 seconds */
document.getElementById('cryptoRandomStatus').classList.remove("hidden");
setTimeout(function(){
document.getElementById('cryptoRandomStatus').classList.add("hidden");
}, 30000);

return '';
}
var buf = new Uint8Array(count);
cry.getRandomValues(buf);
return Crypto.util.bytesToHex(buf);
}

/* generate a new random private key */
coinjs.newPrivkey = function(){
var x = window.location;
x += coinjs.randomBytesSafe(32);
x += (window.screen.height * window.screen.width * window.screen.colorDepth);
x += coinjs.random(64);
x += (window.screen.availHeight * window.screen.availWidth * window.screen.pixelDepth);
Expand Down