From 7951ccec7dc12b8cb5767cfa0612f02973813304 Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Thu, 3 Sep 2020 09:31:09 -0700 Subject: [PATCH] Fix line order to ensure that prefix is set first This should make it more clear that the MAC is a prefix, which is written first, which is especially important since it's so easy to accidentally have backward. --- crypto_secretbox.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto_secretbox.js b/crypto_secretbox.js index 9d52d43..7d74cb0 100644 --- a/crypto_secretbox.js +++ b/crypto_secretbox.js @@ -69,8 +69,8 @@ function crypto_secretbox_detached (o, mac, msg, n, k) { const tmp = new Uint8Array(msg.byteLength + mac.byteLength) crypto_secretbox_easy(tmp, msg, n, k) - o.set(tmp.subarray(mac.byteLength)) mac.set(tmp.subarray(0, mac.byteLength)) + o.set(tmp.subarray(mac.byteLength)) return true } @@ -81,8 +81,8 @@ function crypto_secretbox_open_detached (msg, o, mac, n, k) { assert(k.byteLength === crypto_secretbox_KEYBYTES, "k must be 'crypto_secretbox_KEYBYTES' bytes") const tmp = new Uint8Array(o.byteLength + mac.byteLength) - tmp.set(o, mac.byteLength) tmp.set(mac) + tmp.set(o, mac.byteLength) return crypto_secretbox_open_easy(msg, tmp, n, k) }