From 56416de1d5c6f0471076330d6ece3a0f5cf76bda Mon Sep 17 00:00:00 2001 From: Christophe Diederichs Date: Wed, 17 Jun 2020 14:44:35 +0200 Subject: [PATCH] throw if crypto_aead cannot validate, fix typo in crypto_verify --- crypto_aead.js | 6 +++--- crypto_verify.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crypto_aead.js b/crypto_aead.js index 774481a..d0bed22 100644 --- a/crypto_aead.js +++ b/crypto_aead.js @@ -28,7 +28,7 @@ function crypto_aead_chacha20poly1305_ietf_encrypt (c, m, ad, nsec, npub, k) { return m.length + crypto_aead_chacha20poly1305_ietf_ABYTES } - return ret + assert(false, 'could not encrypt data') } function crypto_aead_chacha20poly1305_ietf_encrypt_detached (c, mac, m, ad, nsec, npub, k) { @@ -95,7 +95,7 @@ function crypto_aead_chacha20poly1305_ietf_decrypt (m, nsec, c, ad, npub, k) { return c.length - crypto_aead_chacha20poly1305_ietf_ABYTES } - return ret + assert(false, 'could not verify data') } function crypto_aead_chacha20poly1305_ietf_decrypt_detached (m, nsec, c, mac, ad, npub, k) { @@ -143,7 +143,7 @@ function crypto_aead_chacha20poly1305_ietf_decrypt_detached (m, nsec, c, mac, ad if (ret !== 0) { m.fill(0) - return -1 + assert(false, 'could not verify data') } crypto_stream_chacha20_ietf_xor_ic(m, c, npub, 1, k) diff --git a/crypto_verify.js b/crypto_verify.js index 17db8b0..8dbd105 100644 --- a/crypto_verify.js +++ b/crypto_verify.js @@ -22,7 +22,7 @@ function crypto_verify_32(x, xi, y, yi) { } function sodium_memcmp (a, b) { - assert(a.byteLength = b.byteLength, 'buffers must be the same size') + assert(a.byteLength === b.byteLength, 'buffers must be the same size') return vn(a, 0, b, 0, a.byteLength) === 0 }