You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
588 B
25 lines
588 B
var SecureRandom = function() {};
|
|
|
|
/* secure random bytes that sometimes throws an error due to lack of entropy */
|
|
SecureRandom.getRandomBuffer = function() {};
|
|
|
|
/* insecure random bytes, but it never fails */
|
|
SecureRandom.getPseudoRandomBuffer = function(size) {
|
|
var b32 = 0x100000000;
|
|
var b = new Buffer(size);
|
|
|
|
for (var i = 0; i <= size; i++) {
|
|
var j = Math.floor(i / 4);
|
|
var k = i - j * 4;
|
|
if (k == 0) {
|
|
r = Math.random() * b32;
|
|
b[i] = r & 0xff;
|
|
} else {
|
|
b[i] = (r = r >>> 8) & 0xff;
|
|
}
|
|
}
|
|
|
|
return b;
|
|
};
|
|
|
|
module.exports = (SecureRandom);
|
|
|