libsodium (libsodium v3.0.1)

View Source

libsodium bindings for Erlang and Elixir.

Each libsodium namespace is exposed by its own module, named after the C prefix: crypto_box_easy() is libsodium_crypto_box:easy/4. Functions accept and return binaries and integers, raise badarg for invalid argument types or lengths, and return libsodium's integer status (usually -1) when an operation such as decryption or verification fails.

Streaming and precomputed APIs use opaque native states (each module's state() type). Operations return new states and never modify their arguments, so a state can be reused or shared between processes, but it cannot be serialized or used with another module's functions.

All modules call libsodium_nif directly; starting the application is not required. Long-running operations move to dirty schedulers and streaming updates yield, so calls never block a normal scheduler for long.

Secret-key cryptography

ModuleDescription
libsodium_crypto_aead_aegis128lAEGIS-128L
libsodium_crypto_aead_aegis256AEGIS-256
libsodium_crypto_aead_aes256gcmAES256-GCM
libsodium_crypto_aead_chacha20poly1305ChaCha20-Poly1305
libsodium_crypto_aead_xchacha20poly1305XChaCha20-Poly1305
libsodium_crypto_authSecret-key authentication
libsodium_crypto_auth_hmacsha256HMAC-SHA-256
libsodium_crypto_auth_hmacsha512HMAC-SHA-512
libsodium_crypto_auth_hmacsha512256HMAC-SHA-512-256
libsodium_crypto_ipcryptIP address encryption
libsodium_crypto_secretboxSecret-key authenticated encryption
libsodium_crypto_secretbox_xchacha20poly1305XChaCha20-Poly1305 secret box
libsodium_crypto_secretbox_xsalsa20poly1305XSalsa20-Poly1305 secret box
libsodium_crypto_secretstream_xchacha20poly1305Encrypted streams

Public-key cryptography

ModuleDescription
libsodium_crypto_boxPublic-key authenticated encryption
libsodium_crypto_box_curve25519xchacha20poly1305X25519-XChaCha20-Poly1305 box
libsodium_crypto_box_curve25519xsalsa20poly1305X25519-XSalsa20-Poly1305 box
libsodium_crypto_kemKey encapsulation
libsodium_crypto_kem_mlkem768ML-KEM-768 key encapsulation
libsodium_crypto_kem_xwingX-Wing key encapsulation
libsodium_crypto_kxKey exchange
libsodium_crypto_signPublic-key signatures
libsodium_crypto_sign_ed25519Ed25519 signatures
libsodium_crypto_sign_ed25519phEd25519ph signatures

Hashing

ModuleDescription
libsodium_crypto_generichashGeneric hashing
libsodium_crypto_generichash_blake2bBLAKE2b
libsodium_crypto_hashHashing (SHA-512)
libsodium_crypto_hash_sha256SHA-256
libsodium_crypto_hash_sha3256SHA3-256
libsodium_crypto_hash_sha3512SHA3-512
libsodium_crypto_hash_sha512SHA-512
libsodium_crypto_shorthashShort-input hashing
libsodium_crypto_shorthash_siphash24SipHash-2-4
libsodium_crypto_shorthash_siphashx24SipHash-2-4 (128-bit)
libsodium_crypto_xof_shake128SHAKE128 extendable-output function
libsodium_crypto_xof_shake256SHAKE256 extendable-output function
libsodium_crypto_xof_turboshake128TurboSHAKE128 extendable-output function
libsodium_crypto_xof_turboshake256TurboSHAKE256 extendable-output function

Password hashing

ModuleDescription
libsodium_crypto_pwhashPassword hashing
libsodium_crypto_pwhash_argon2iArgon2i password hashing
libsodium_crypto_pwhash_argon2idArgon2id password hashing
libsodium_crypto_pwhash_scryptsalsa208sha256Scrypt password hashing

Key derivation

ModuleDescription
libsodium_crypto_kdfKey derivation
libsodium_crypto_kdf_blake2bBLAKE2b key derivation
libsodium_crypto_kdf_hkdf_sha256HKDF-SHA-256
libsodium_crypto_kdf_hkdf_sha512HKDF-SHA-512

Advanced

ModuleDescription
libsodium_crypto_core_ed25519Edwards25519 arithmetic
libsodium_crypto_core_hchacha20HChaCha20 core
libsodium_crypto_core_hsalsa20HSalsa20 core
libsodium_crypto_core_keccak1600Keccak-f[1600] permutation
libsodium_crypto_core_ristretto255Ristretto255 arithmetic
libsodium_crypto_core_salsa20Salsa20 core
libsodium_crypto_core_salsa2012Salsa20/12 core
libsodium_crypto_onetimeauthOne-time authentication
libsodium_crypto_onetimeauth_poly1305Poly1305
libsodium_crypto_scalarmultPoint multiplication
libsodium_crypto_scalarmult_curve25519X25519 point multiplication
libsodium_crypto_scalarmult_ed25519Ed25519 point multiplication
libsodium_crypto_scalarmult_ristretto255Ristretto255 point multiplication
libsodium_crypto_streamStream cipher
libsodium_crypto_stream_chacha20ChaCha20 stream cipher
libsodium_crypto_stream_salsa20Salsa20 stream cipher
libsodium_crypto_stream_salsa2012Salsa20/12 stream cipher
libsodium_crypto_stream_xchacha20XChaCha20 stream cipher
libsodium_crypto_stream_xsalsa20XSalsa20 stream cipher
libsodium_crypto_verify_1616-byte comparison
libsodium_crypto_verify_3232-byte comparison
libsodium_crypto_verify_6464-byte comparison

Helpers

ModuleDescription
libsodium_randombytesRandom data
libsodium_runtimeCPU features
libsodium_utilsHelpers
libsodium_versionLibrary version

Summary

Application API

Start the libsodium application and its dependencies.

Deprecated API

Equivalent to call(Namespace, Function, {}).

Call the native function for Namespace and Function with the elements of Arguments, as the port driver did. For example, call(crypto_box, keypair, {}) calls libsodium_nif:crypto_box_keypair/0.

Application API

start()

-spec start() -> Result when Result :: {ok, [atom()]} | {error, term()}.

Start the libsodium application and its dependencies.

The native library loads on first use, so this is optional.

{ok, _Started} = libsodium:start().

Deprecated API

call(Namespace, Function)

This function is deprecated. libsodium:call/2 is deprecated; call the namespace module, such as libsodium_crypto_box, instead.
-spec call(Namespace, Function) -> Result
              when Namespace :: atom(), Function :: atom(), Result :: dynamic().

Equivalent to call(Namespace, Function, {}).

call(Namespace, Function, Arguments)

This function is deprecated. libsodium:call/3 is deprecated; call the namespace module, such as libsodium_crypto_box, instead.
-spec call(Namespace, Function, Arguments) -> Result
              when Namespace :: atom(), Function :: atom(), Arguments :: tuple(), Result :: dynamic().

Call the native function for Namespace and Function with the elements of Arguments, as the port driver did. For example, call(crypto_box, keypair, {}) calls libsodium_nif:crypto_box_keypair/0.

Unknown functions raise undef.