Helpers
Bindings for various helper functions. See the libsodium helpers docs for more information.
sodium_memcmp
var bool = sodium.sodium_memcmp(b1, b2)
Compares b1
with b2
, in constant-time for b1.length
.
b1
must be abuffer
b2
must be abuffer
and must beb1.length
bytes
Returns true
when equal, otherwise false
.
sodium_compare
var direction = sodium.sodium_compare(b1, b2)
Compares b1
with b2
, regarding either as little-endian encoded number.
b1
must be abuffer
b2
must be abuffer
and must beb1.length
bytes
Returns 1
, 0
, or -1
on whether b1
is greater than, equal to, or less than b2
. This is the same scheme as Array.prototype.sort
expect.
sodium_add
sodium.sodium_add(a, b)
Adds b
to a
(wrapping), regarding either as little-endian encoded number, and writing the result into a
.
a
must be abuffer
b
must be abuffer
and must bea.length
bytes
sodium_sub
sodium.sodium_sub(a, b)
Subtracts b
from a
(wrapping), regarding either as little-endian encoded number, and writing the result into a
.
a
must be abuffer
b
must be abuffer
and must bea.length
bytes
sodium_increment
sodium.sodium_increment(buf)
Increments buf
as a little-endian number. This operation is constant-time for the length of buf
.
buf
must be abuffer
sodium_is_zero
var bool = sodium.sodium_is_zero(buf, len)
Tests whether buf
is all zero for len
bytes. This operation is constant-time for len
.
len
must be an integer at mostbuf.length
Returns true
if all len
bytes are zero, otherwise false
.