Fixed fallback randomBytes for weak-crypto browsers..
This commit is contained in:
parent
33a1459505
commit
730ccd36b2
@ -6,10 +6,15 @@ var crypto = global.crypto || global.msCrypto;
|
|||||||
if (!crypto || !crypto.getRandomValues) {
|
if (!crypto || !crypto.getRandomValues) {
|
||||||
console.log('WARNING: Missing strong random number source; using weak randomBytes');
|
console.log('WARNING: Missing strong random number source; using weak randomBytes');
|
||||||
crypto = {
|
crypto = {
|
||||||
getRandomValues: function(length) {
|
getRandomValues: function(buffer) {
|
||||||
|
for (var round = 0; round < 20; round++) {
|
||||||
for (var i = 0; i < buffer.length; i++) {
|
for (var i = 0; i < buffer.length; i++) {
|
||||||
buffer[i] = parseInt(256 * Math.random());
|
if (round) {
|
||||||
|
buffer[i] ^= parseInt(256 * Math.random());
|
||||||
|
} else {
|
||||||
|
buffer[i] = parseInt(256 * Math.random());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
|
Loading…
Reference in New Issue
Block a user