Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Library:Libsodium

From ReverseEngineering.wiki
Library
Developer Frank Denis (jedisct1) and contributors
License ISC
Website https://libsodium.org
On this wiki Facts · Code · Notes · Topics

Portable NaCl-derived crypto library in C (ISC license): crypto_box, secretbox, sign (Ed25519), generichash (BLAKE2b), pwhash (Argon2id); identified by sodium_version_string, the crypto_ naming scheme and fixed-size macros.

Overview

libsodium offers a small, hard-to-misuse API: sodium_init, crypto_secretbox_easy, crypto_box_*, crypto_sign_*, crypto_generichash, crypto_pwhash, randombytes_buf. It is linked into many games and messengers. See Technique:Identifying cryptographic libraries and Technique:Identifying cryptographic constants (Salsa20/ChaCha constant "expand 32-byte k").

Identification

  • Version: sodium_version_string() returns SODIUM_VERSION_STRING (configure.ac says 1.0.23 on master; latest tag seen: 1.0.22); sodium_library_version_major() / _minor() return the ABI numbers (configure.ac: major 30, minor 0 on master); sodium_library_minimal() tells whether the minimal build was used (src/libsodium/sodium/version.c). Fact:Libsodium/identification/Version functions.
  • Exports: public functions start with crypto_, sodium_ or randombytes_; per-primitive variants carry the algorithm in the name, e.g. crypto_box_curve25519xsalsa20poly1305_*. The *_PRIMITIVE macros give default algorithms: secretbox "xsalsa20poly1305", box "curve25519xsalsa20poly1305", sign "ed25519", generichash "blake2b", pwhash "argon2id,argon2i" (Fact:Libsodium/enum/Primitive and size constants).
  • Password hash prefix: crypto_pwhash_str output starts with "$argon2id$" (crypto_pwhash_argon2id_STRPREFIX).
  • Sizes: secretbox key 32, nonce 24, MAC 16; box public/secret key 32, nonce 24, MAC 16; XChaCha20-Poly1305-IETF key 32, nonce 24, tag 16, so a sealed blob is message length plus 16.

Code & repositories

  • https://github.com/jedisct1/libsodium @ 60b751cd14418fae2d17e6f1003e43622b3e5a25 · license: ISC (declared by the contributor; GitHub's detector did not recognize LICENSE)
    libsodium source: configure.ac, src/libsodium/sodium/version.c and the crypto_*.h headers.
    Tested on: source read, not run: Source read at this commit; not built. · checked 2026-10-18; last activity 2026-10-15; Note: the latest release ships binaries; the wiki links only the source, never the binaries

Pitfalls

  • Unverified: whether sodium_version_string survives in typical static builds with section garbage collection.
  • sodium_init selects CPU-specific code at run time, so several implementations of one primitive can coexist in the binary.