Use webcrypto for whole seed initializing.
This commit is contained in:
parent
9861b3311b
commit
68ce15d078
2 changed files with 30 additions and 20 deletions
|
@ -1613,21 +1613,26 @@ if (typeof Crypto == "undefined" || !Crypto.util) {
|
||||||
if (sr.pool == null) {
|
if (sr.pool == null) {
|
||||||
sr.pool = new Array();
|
sr.pool = new Array();
|
||||||
sr.pptr = 0;
|
sr.pptr = 0;
|
||||||
var t;
|
|
||||||
|
// Use webcrypto if available
|
||||||
if (window.crypto && window.crypto.getRandomValues) {
|
if (window.crypto && window.crypto.getRandomValues) {
|
||||||
try {
|
try {
|
||||||
// Use webcrypto if available
|
var ua = new Uint8Array(sr.poolSize - sr.pptr);
|
||||||
var ua = new Uint8Array(32);
|
|
||||||
window.crypto.getRandomValues(ua);
|
window.crypto.getRandomValues(ua);
|
||||||
for (t = 0; t < 32; ++t)
|
var i = 0;
|
||||||
sr.pool[sr.pptr++] = ua[t];
|
while (sr.pptr < sr.poolSize) {
|
||||||
|
sr.pool[sr.pptr++] = ua[i++];
|
||||||
|
}
|
||||||
} catch (e) { alert(e); }
|
} catch (e) { alert(e); }
|
||||||
|
} else {
|
||||||
|
var t;
|
||||||
|
while (sr.pptr < sr.poolSize) { // extract some randomness from Math.random()
|
||||||
|
t = Math.floor(65536 * Math.random());
|
||||||
|
sr.pool[sr.pptr++] = t >>> 8;
|
||||||
|
sr.pool[sr.pptr++] = t & 255;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while (sr.pptr < sr.poolSize) { // extract some randomness from Math.random()
|
|
||||||
t = Math.floor(65536 * Math.random());
|
|
||||||
sr.pool[sr.pptr++] = t >>> 8;
|
|
||||||
sr.pool[sr.pptr++] = t & 255;
|
|
||||||
}
|
|
||||||
sr.pptr = 0;
|
sr.pptr = 0;
|
||||||
sr.seedTime();
|
sr.seedTime();
|
||||||
// entropy
|
// entropy
|
||||||
|
|
|
@ -126,21 +126,26 @@
|
||||||
if (sr.pool == null) {
|
if (sr.pool == null) {
|
||||||
sr.pool = new Array();
|
sr.pool = new Array();
|
||||||
sr.pptr = 0;
|
sr.pptr = 0;
|
||||||
var t;
|
|
||||||
|
// Use webcrypto if available
|
||||||
if (window.crypto && window.crypto.getRandomValues) {
|
if (window.crypto && window.crypto.getRandomValues) {
|
||||||
try {
|
try {
|
||||||
// Use webcrypto if available
|
var ua = new Uint8Array(sr.poolSize - sr.pptr);
|
||||||
var ua = new Uint8Array(32);
|
|
||||||
window.crypto.getRandomValues(ua);
|
window.crypto.getRandomValues(ua);
|
||||||
for (t = 0; t < 32; ++t)
|
var i = 0;
|
||||||
sr.pool[sr.pptr++] = ua[t];
|
while (sr.pptr < sr.poolSize) {
|
||||||
|
sr.pool[sr.pptr++] = ua[i++];
|
||||||
|
}
|
||||||
} catch (e) { alert(e); }
|
} catch (e) { alert(e); }
|
||||||
|
} else {
|
||||||
|
var t;
|
||||||
|
while (sr.pptr < sr.poolSize) { // extract some randomness from Math.random()
|
||||||
|
t = Math.floor(65536 * Math.random());
|
||||||
|
sr.pool[sr.pptr++] = t >>> 8;
|
||||||
|
sr.pool[sr.pptr++] = t & 255;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while (sr.pptr < sr.poolSize) { // extract some randomness from Math.random()
|
|
||||||
t = Math.floor(65536 * Math.random());
|
|
||||||
sr.pool[sr.pptr++] = t >>> 8;
|
|
||||||
sr.pool[sr.pptr++] = t & 255;
|
|
||||||
}
|
|
||||||
sr.pptr = 0;
|
sr.pptr = 0;
|
||||||
sr.seedTime();
|
sr.seedTime();
|
||||||
// entropy
|
// entropy
|
||||||
|
|
Loading…
Reference in a new issue