Use window.crypto.getRandomValues for added randomness.

The output of SecureRandom.nextBytes is XORed against the result of
window.crypto.getRandomValues before returning, if present.
This commit is contained in:
Chris Cowan 2013-11-16 04:07:05 -06:00
parent ef1d9614f1
commit 37987975a7

View file

@ -29,6 +29,15 @@
// ba: byte array
sr.prototype.nextBytes = function (ba) {
var i;
if (window.crypto && window.crypto.getRandomValues && window.Uint8Array) {
try {
var rvBytes = new Uint8Array(ba.length);
window.crypto.getRandomValues(rvBytes);
for (i = 0; i < ba.length; ++i)
ba[i] = sr.getByte() ^ rvBytes[i];
return;
} catch(e) {}
}
for (i = 0; i < ba.length; ++i) ba[i] = sr.getByte();
};