Hash Lab

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

APIUnderlying algorithm
crypto_generichashBLAKE2b
crypto_pwhashArgon2id
crypto_shorthashSipHash-2-4
crypto_kdfHKDF-SHA-512
crypto_authHMAC-SHA-512/256
crypto_signEd25519 (uses SHA-512 internally)
crypto_boxX25519 + XSalsa20-Poly1305

Why the opinionated style works

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

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.

References