NaCl (software)


NaCl is a public domain, high-speed software library for cryptography.
NaCl was created by the mathematician and programmer Daniel J. Bernstein, who is best known for the creation of qmail and Curve25519. The core team also includes Tanja Lange and Peter Schwabe. The main goal while creating NaCl, according to the team's 2011 paper, was to "avoid various types of cryptographic disasters suffered by previous cryptographic libraries". The team does so by safer designs that avoid issues such as side-channel leakage and loss of randomness, by being performant enough that safety features do not get disabled by the user, and by picking better cryptographic primitives. The high-level "box" API is designed to encourage the use of authenticated encryption.

Functions

Public-key cryptography

Secret-key cryptography

Low-level functions

Implementations

The reference implementation is written in C, often incorporating inline assembly routines. C++ support is implemented as a wrapper. A Python wrapper was planned, but is not part of the latest release. The home page, last updated in 2016, mentions prototype wrappers.
The reference NaCl implementation has a variety of programming language bindings, such as PHP and Tcl.

Libsodium

Libsodium is an API-compatible fork of reference NaCl created in 2013. It is "installable and packageable", or in other words can be compiled into a dynamic library and installed as a software package thanks to the addition of build files. It is also "portable and cross-compilable".
As libsodium can be dynamically linked, it serves as the basis for a number of bindings in languages such as Squeak, Pharo, Perl 5, and Python.
libsodium also extends the NaCl API with new algorithms and new classes of functions.

TweetNaCl

In 2013, the NaCl team and three others released TweetNaCl, a condensed implementation of NaCl's 25 functions that fits in the size of 100 tweets.
TweetNaCl has been used as the basis of ports including TweetNaCl.js and TweetNaCl-Java. It has also been rewritten in the SPARK Ada subset as SPARKNaCl, which the authors describe as " readable owing to the large number of explanatory comments and contracts in the code."

Other implementations

  • RustCrypto - a popular set of pure-Rust crypto libraries that includes an NaCl compatibility layer.
  • dryoc — a pure-Rust cryptography library implementing the libsodium/NaCl API with support for protected memory.
  • Monocypher — a rewrite of NaCl in C. Aims to have the speed of reference NaCl and the size of TweetNaCl.