Merge pull request #33 from AgentME/rng

Use window.crypto.getRandomValues for added OS-supplied randomness
This commit is contained in:
pointbiz 2013-12-15 19:01:27 -08:00
commit 0f19ca3974

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();
};