From 74a1067746539bd52f4e8b7002e0a9c24e7db4f8 Mon Sep 17 00:00:00 2001 From: Emil Bay Date: Wed, 24 Jun 2020 14:55:46 +0200 Subject: [PATCH] Fix filling larger width TypedArrays --- randombytes.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/randombytes.js b/randombytes.js index d4dcc75..5bdb874 100644 --- a/randombytes.js +++ b/randombytes.js @@ -6,12 +6,12 @@ var randombytes = (function () { function browserBytes (out, n) { for (let i = 0; i < n; i += QUOTA) { - crypto.getRandomValues(out.subarray(i, i + Math.min(n - i, QUOTA))) + crypto.getRandomValues(new Uint8Array(out.buffer, i, Math.min(n - i, QUOTA))) } } function nodeBytes (out, n) { - out.set(crypto.randomBytes(n)) + new Uint8Array(out.buffer, 0, n).set(crypto.randomBytes(n)) } function noImpl () { @@ -36,5 +36,5 @@ Object.defineProperty(module.exports, 'randombytes', { module.exports.randombytes_buf = function (out) { assert(out, 'out must be given') - randombytes(out, out.length) + randombytes(out, out.byteLength) }