Crate libsodium_rs

Source
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

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§

SodiumError
Error type for libsodium operations

Functions§

ensure_init
Ensures libsodium is initialized

Type Aliases§

Result
Result type for sodium operations