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.
This commit is contained in:
Christian Bundy 2020-09-01 14:43:17 -07:00
parent a40b363726
commit 9962e481b8

View File

@ -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
}