Merge pull request #33 from AgentME/rng
Use window.crypto.getRandomValues for added OS-supplied randomness
This commit is contained in:
commit
0f19ca3974
1 changed files with 9 additions and 0 deletions
|
@ -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();
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue