NaCl (Networking and Cryptography Library, pronounced "salt") is a public domain, high-speed software library for cryptography.[2]
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.[3][4] 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.[1]
Functions
Public-key cryptography
crypto_box, public-key authenticated encryption. Key agreement happens via X25519; encryption is done by Salsa20-Poly1305.[5]
crypto_verify, string comparison in constant time.[7]
Implementations
The reference implementation is written in C, often with several inline assembler. C++ is handled as a wrapper. A Python wrapper was planned,[8] but is not part of the latest (20110221) release. The home page, last updated 2016, mentions prototype wrappers.[2]
Libsodium is a 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 (NaCl had none). It is also "portable and cross-compilable".[11]
As libsodium can be dynamically linked, it serves as the basis for a number of bindings in languages such as Pharo,[12] Perl 5,[13] and Python.[14][15]
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 (140 symbols each).[19]
TweetNaCl has been used as the basis of ports including TweetNaCl.js[20] and TweetNaCl-Java.[21] It has also been rewritten in the SPARK Ada subset as SPARKNaCl, which the authors describe as "(unlike TweetNaCl) readable owing to the large number of explanatory comments and contracts in the code."[22]
Other implementations
dryoc — a pure-Rust cryptography library implementing the libsodium/NaCl API with support for protected memory.[23]
Monocypher — a rewrite of NaCl in C. Aims to have the speed of reference NaCl and the size of TweetNaCl.[24]
^Python Cryptographic Authority (18 January 2024). "pyca/pynacl". GitHub. PyNaCl is a Python binding to libsodium, which is a fork of the Networking and Cryptography library.