mirror of
https://github.com/dmuth/diceware.git
synced 2024-11-21 08:26:29 -05:00
Added check for crypto into getRandomValue().
This commit is contained in:
parent
5cb69f140f
commit
61fb6fa227
1 changed files with 14 additions and 3 deletions
17
main.js
17
main.js
|
@ -29,9 +29,20 @@ Diceware.getRandomValue = function(max) {
|
|||
return(NaN);
|
||||
}
|
||||
|
||||
var a = new Uint32Array(1);
|
||||
window.crypto.getRandomValues(a);
|
||||
retval = (a[0] % max);
|
||||
if (Diceware.i_can_has_good_crypto()) {
|
||||
var a = new Uint32Array(1);
|
||||
window.crypto.getRandomValues(a);
|
||||
retval = (a[0] % max);
|
||||
|
||||
} else {
|
||||
//
|
||||
// Fall back to something way less secure. The user has already
|
||||
// been warned.
|
||||
//
|
||||
retval = Math.floor(Math.random() * max);
|
||||
|
||||
}
|
||||
|
||||
|
||||
return(retval);
|
||||
|
||||
|
|
Loading…
Reference in a new issue