They are just a simplification of the secretbox API, thus it does
not provide any new functionality. But it helps mapping function
names to libsodium documentation.
sodium_init() will return 0 on success, -1 on failure, and 1 if sodium is
already loaded and initialized (which is not an error). In the case
where libsodium is already initialized and the system is restarted we
may return 1 from onload nif function resulting in a crash.
- change the call to sodium_init() to check for an error return (-1) and
return -1 explicitly in this case, otherwise always return zero at the
end of our onload function.
Turns out the interval we had in the
file were inverted and I was wrong
in an earlier commit. However, EQC
dutifully found the mistake, and it
is now corrected.
This is the same game as with the
generichash construction. We want
to protect it with a mutex so
different processes can safely do
work on the same resource.
While here, also move the _update
function onto the dirty scheduler.
It is by far the most expensive
operation, and why it wasn't there
in the first place is odd. This should
unblock the scheduler on long
sign-checks. It also move the
possible mutex block onto the
dirty scheduler thread, away from
the core schedulers, improving
latency in the system as a result.
While sodium is thread-safe, our
resources are not. Furthermore,
we might have an update call going
when someone decides to call
finalize and so on. It is not clever
to do so, but on the other hand
I want to protect against this.
While here, mark the mutexed
calls as dirty CPU. This avoids them
blocking the main scheduler and
only messes with the background
dirty threads, which is somewhat
more safe.
The consequence is that order
access to the resource is now
serialized. I don't think you should
do it, but it is now possible.
Since the chacha20poly1305 constructions were the IETF variants,
we renamed those so they follow the official library better. While
here, we also fixed the argument order of the files.
The order of parameters were in the wrong order. Make them equal
to the official order of libsodium.
While here, rename NONCEBYTES to NPUBBYTES so it reflects the
underlying names as well.
If we, for some reason, fail to the error-path, then binaries allocated
are not being released properly back to the erlang runtime. Fix this
in the usual fashion by using a stack of undo-operations, and thread
them via goto.