throw if crypto_aead cannot validate, fix typo in crypto_verify

This commit is contained in:
Christophe Diederichs 2020-06-17 14:44:35 +02:00
parent e35adc6823
commit 56416de1d5
2 changed files with 4 additions and 4 deletions

View File

@ -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 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) { 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 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) { 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) { if (ret !== 0) {
m.fill(0) m.fill(0)
return -1 assert(false, 'could not verify data')
} }
crypto_stream_chacha20_ietf_xor_ic(m, c, npub, 1, k) crypto_stream_chacha20_ietf_xor_ic(m, c, npub, 1, k)

View File

@ -22,7 +22,7 @@ function crypto_verify_32(x, xi, y, yi) {
} }
function sodium_memcmp (a, b) { 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 return vn(a, 0, b, 0, a.byteLength) === 0
} }