1
0
mirror of synced 2024-11-15 02:37:40 +01:00

PseudoRandomNumberGenerator: support larger output than 65536 bytes

This commit is contained in:
MikeCAT 2022-11-17 20:24:54 +09:00
parent ed8bd34915
commit c04f409d23

View File

@ -52,8 +52,12 @@ class PseudoRandomNumberGenerator extends Operation {
let bytes;
if (isWorkerEnvironment() && self.crypto) {
bytes = self.crypto.getRandomValues(new Uint8Array(numBytes));
bytes = Utils.arrayBufferToStr(bytes.buffer);
bytes = new ArrayBuffer(numBytes);
const CHUNK_SIZE = 65536;
for (let i = 0; i < numBytes; i += CHUNK_SIZE) {
self.crypto.getRandomValues(new Uint8Array(bytes, i, Math.min(numBytes - i, CHUNK_SIZE)));
}
bytes = Utils.arrayBufferToStr(bytes);
} else {
bytes = forge.random.getBytesSync(numBytes);
}