From 9962e481b8009d765122750cc90f3817918397bb Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Tue, 1 Sep 2020 14:43:17 -0700 Subject: [PATCH] Fix crypto_secretbox_detached Problem: When working on crypto_box_easy I noticed that the expected output only works when you use crypto_secretbox_detached from sodium-native. I think the MAC and message output are switched. Solution: Ensure that the MAC is the prefix, not the suffix. --- crypto_secretbox.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto_secretbox.js b/crypto_secretbox.js index 05fb264..5920286 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(0, msg.byteLength)) - mac.set(tmp.subarray(msg.byteLength)) + o.set(tmp.subarray(mac.byteLength)) + mac.set(tmp.subarray(0, mac.byteLength)) return true }