Ecosystem · Libraries
libsodium
libsodium is the modern, opinionated crypto library by Frank Denis. It descends from Daniel J. Bernstein’s NaCl (“networking and cryptography library”) and adds portability, packaging, and a clean API surface. The headline feature is the absence of choice: each primitive is one carefully-picked algorithm with sensible defaults.
What it picks for you
| API | Underlying algorithm |
|---|---|
crypto_generichash | BLAKE2b |
crypto_pwhash | Argon2id |
crypto_shorthash | SipHash-2-4 |
crypto_kdf | HKDF-SHA-512 |
crypto_auth | HMAC-SHA-512/256 |
crypto_sign | Ed25519 (uses SHA-512 internally) |
crypto_box | X25519 + XSalsa20-Poly1305 |
Why the opinionated style works
- No misuse opportunities, no nonce mode mistake, no IV confusion, no “raw SHA-256 of a key” footgun.
- Bindings everywhere , Python (pynacl), Node (sodium-native), Rust (sodiumoxide / dryoc), Go (gocrypt), PHP (built-in since 7.2), Erlang, Haskell, R, you name it.
- Strong defaults , the moderate / sensitive / interactive presets for password hashing match modern recommendations.
- Cross-platform , runs on Linux, macOS, Windows, iOS, Android, WebAssembly, microcontrollers.
A small example
#include <sodium.h>
unsigned char hash[crypto_generichash_BYTES];
crypto_generichash(hash, sizeof hash,
data, data_len,
NULL, 0); // unkeyed
crypto_generichash(hash, sizeof hash,
data, data_len,
key, sizeof key); // keyed (MAC)
// Password hash
char hashed[crypto_pwhash_STRBYTES];
crypto_pwhash_str(hashed, password, password_len,
crypto_pwhash_OPSLIMIT_MODERATE,
crypto_pwhash_MEMLIMIT_MODERATE);Where it is deployed
- Tox, Signal-adjacent messengers.
- Tor onion service v3 internals (with libsodium as a dependency).
- Bitcoin Core test infrastructure.
- Magic Wormhole (file transfer over PAKE).
- Many indie / open-source projects that did not want to wire up OpenSSL.
HACL*, when you want proofs
If you need formally-verified hashing code (proved correct in F*), the canonical project is HACL* / EverCrypt. Mozilla’s NSS integrates HACL* primitives for performance-critical paths.