added: sodium_is_zero

This commit is contained in:
Christophe Diederichs 2020-06-17 13:19:05 +02:00
parent b7a0d1f2e5
commit ec9cac17d0

View File

@ -3,7 +3,8 @@ const assert = require('nanoassert')
module.exports = { module.exports = {
crypto_verify_16, crypto_verify_16,
crypto_verify_32, crypto_verify_32,
sodium_memcmp sodium_memcmp,
sodium_is_zero
} }
function vn (x, xi, y, yi, n) { function vn (x, xi, y, yi, n) {
@ -25,3 +26,9 @@ function sodium_memcmp (a, b) {
return vn(a, 0, b, 0, a.byteLength) === 0 return vn(a, 0, b, 0, a.byteLength) === 0
} }
function sodium_is_zero = function (arr) {
var d = 0
for (let i = 0; i < arr.length; i++) d |= arr[i]
return d === 0
}