Expand description
§Rust bindings for libsodium
This crate provides safe, ergonomic Rust bindings for the libsodium cryptographic library. It offers a comprehensive set of cryptographic primitives with a focus on usability, security, and performance.
§Features
- Complete Coverage: Implements the entire libsodium API in Rust
- Memory Safety: Ensures secure memory handling with automatic clearing of sensitive data
- Type Safety: Leverages Rust’s type system to prevent misuse of cryptographic primitives
- Flexible APIs: Uses
AsRef
trait for parameters, allowing for more ergonomic function calls - Extensive Testing: Comprehensive test suite covering all functionality
- Minimal Dependencies: Uses only a small set of carefully selected dependencies beyond libsodium itself
§Getting Started
Before using any cryptographic functions, you must initialize the library:
use libsodium_rs::ensure_init;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize libsodium
ensure_init()?;
// Now you can use the cryptographic functions
Ok(())
}
§Available Modules
crypto_aead
: Authenticated Encryption with Associated Data (AEAD)crypto_auth
: Secret-key message authenticationcrypto_box
: Public-key authenticated encryptioncrypto_core
: Core cryptographic operationscrypto_generichash
: Cryptographic hash functions (BLAKE2b)crypto_hash
: Traditional cryptographic hash functions (SHA-256, SHA-512)crypto_kdf
: Key derivation functionscrypto_kx
: Key exchangecrypto_pwhash
: Password hashing and key derivationcrypto_scalarmult
: Elliptic curve operationscrypto_secretbox
: Secret-key authenticated encryptioncrypto_secretstream
: Secret-key authenticated encryption for streamscrypto_shorthash
: Short-input hash functions (SipHash)crypto_sign
: Public-key signaturescrypto_stream
: Stream ciphersrandom
: Secure random number generationutils
: Utility functionsversion
: Library version information
Modules§
- crypto_
aead - Authenticated Encryption with Associated Data (AEAD)
- crypto_
auth - Secret-Key Authentication
- crypto_
box - Public-Key Cryptography
- crypto_
core - Core Cryptographic Operations
- crypto_
generichash - Generic Hash Function (BLAKE2b)
- crypto_
hash - Cryptographic Hashing Functions
- crypto_
kdf - Key Derivation Functions
- crypto_
kx - Key Exchange
- crypto_
onetimeauth - One-Time Authentication (Poly1305)
- crypto_
pwhash - Password Hashing (Argon2)
- crypto_
scalarmult - Scalar Multiplication Operations
- crypto_
secretbox - Secret-key Authenticated Encryption
- crypto_
secretstream - Secret Stream Encryption
- crypto_
shorthash - Short-Input Hash Function (SipHash-2-4)
- crypto_
sign - Digital Signatures
- crypto_
stream - Stream Ciphers
- crypto_
verify - Constant-Time Verification Functions
- random
- Secure Random Number Generation
- utils
- Cryptographic Utilities
- version
- Version Information
Enums§
- Sodium
Error - Error type for libsodium operations
Functions§
- ensure_
init - Ensures libsodium is initialized
Type Aliases§
- Result
- Result type for sodium operations