From 13fcad4d8e559ae8a7c3b899913e9751237e6056 Mon Sep 17 00:00:00 2001 From: Christophe Diederichs Date: Fri, 4 Sep 2020 15:53:02 +0200 Subject: [PATCH] crypto_verify return booleans --- crypto_aead.js | 2 +- crypto_verify.js | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/crypto_aead.js b/crypto_aead.js index 42f863f..a5be092 100644 --- a/crypto_aead.js +++ b/crypto_aead.js @@ -131,7 +131,7 @@ function crypto_aead_chacha20poly1305_ietf_decrypt_detached (m, nsec, c, mac, ad computed_mac.fill(0) slen.fill(0) - if (ret !== 0) { + if (!ret) { m.fill(0) throw new Error('could not verify data') } diff --git a/crypto_verify.js b/crypto_verify.js index f23ff3d..afa666d 100644 --- a/crypto_verify.js +++ b/crypto_verify.js @@ -1,7 +1,8 @@ /* eslint-disable camelcase */ module.exports = { crypto_verify_16, - crypto_verify_32 + crypto_verify_32, + crypto_verify_64 } function vn (x, xi, y, yi, n) { @@ -16,9 +17,13 @@ Object.defineProperty(module.exports, 'vn', { }) function crypto_verify_16 (x, xi, y, yi) { - return vn(x, xi, y, yi, 16) + return vn(x, xi, y, yi, 16) === 0 } function crypto_verify_32 (x, xi, y, yi) { - return vn(x, xi, y, yi, 32) + return vn(x, xi, y, yi, 32) === 0 +} + +function crypto_verify_64 (x, xi, y, yi) { + return vn(x, xi, y, yi, 64) === 0 }