From ffee53414f289b67ac3c4f9b2d84e79f8bca737d Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Fri, 4 Sep 2020 09:33:35 -0700 Subject: [PATCH] Fix problem when crypto_aead detached passed null Problem: In two cases the `if (ad === null)` conditions are meant to call a `_detached` method but accidentally call the non-detached counterpart. Solution: Call the corresponding function so that detached methods always call detached encryption or decryption. See-also: https://github.com/sodium-friends/sodium-javascript/issues/35 --- crypto_aead.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto_aead.js b/crypto_aead.js index 42f863f..85efa40 100644 --- a/crypto_aead.js +++ b/crypto_aead.js @@ -30,7 +30,7 @@ function crypto_aead_chacha20poly1305_ietf_encrypt (c, m, ad, nsec, npub, k) { } function crypto_aead_chacha20poly1305_ietf_encrypt_detached (c, mac, m, ad, nsec, npub, k) { - if (ad === null) return crypto_aead_chacha20poly1305_ietf_encrypt(c, mac, m, new Uint8Array(0), nsec, npub, k) + if (ad === null) return crypto_aead_chacha20poly1305_ietf_encrypt_detached(c, mac, m, new Uint8Array(0), nsec, npub, k) assert(c.byteLength === m.byteLength, 'ciphertext should be same length than message') assert(npub.byteLength === crypto_aead_chacha20poly1305_ietf_NPUBBYTES, @@ -91,7 +91,7 @@ function crypto_aead_chacha20poly1305_ietf_decrypt (m, nsec, c, ad, npub, k) { } function crypto_aead_chacha20poly1305_ietf_decrypt_detached (m, nsec, c, mac, ad, npub, k) { - if (ad === null) return crypto_aead_chacha20poly1305_ietf_decrypt(m, nsec, c, mac, new Uint8Array(0), npub, k) + if (ad === null) return crypto_aead_chacha20poly1305_ietf_decrypt_detached(m, nsec, c, mac, new Uint8Array(0), npub, k) assert(c.byteLength === m.byteLength, 'message should be same length than ciphertext') assert(npub.byteLength === crypto_aead_chacha20poly1305_ietf_NPUBBYTES,