LibSignal Rust
A complete Rust implementation of the Signal messaging protocol, providing secure end-to-end encryption for messaging applications. This library offers full protocol compatibility with Signal's cryptographic primitives while leveraging Rust's safety and performance benefits.
Features
- End-to-End Encryption: Full Signal protocol implementation with Perfect Forward Secrecy.
- Double Ratchet Algorithm: Advanced key management for secure message chains.
- Industry-Standard Cryptography: Curve25519 key agreement, Ed25519 signatures, AES-256-CBC encryption, HMAC-SHA256 authentication.
- Multiple Message Types: Supports WhisperMessage, PreKeyWhisperMessage, and KeyExchangeMessage.
- Protocol Buffer Integration: Complete protobuf serialization/deserialization.
- Session Management: Automatic session initialization, key rotation, and state persistence.
- Memory Safe: Leverages Rust's ownership model to prevent security vulnerabilities.
- Zero-Copy Operations: Efficient message processing with minimal allocations.
- Async/Await Support: Modern asynchronous programming patterns throughout.
- Comprehensive API: Easy-to-use interfaces for session management and message encryption.
- Rich Error Handling: Detailed error types and proper error propagation.
- Extensive Testing: Full test coverage for cryptographic, session, and protocol buffer components.
Quick Start
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Basic Usage
use ;
use Arc;
async
Core Components
SessionCipher
The main interface for encrypting and decrypting messages:
use ;
// Encrypt a message
let message = b"Secret message";
let encrypted: CiphertextMessage = cipher.encrypt.await?;
// Decrypt a message
let decrypted: = cipher.decrypt.await?;
let original_message = Stringfrom_utf8?;
SessionBuilder
Manages session initialization and key exchange:
use ;
// Create session builder
let remote_address = new?;
let builder = new;
// Initialize outgoing session
let device = Device ;
builder.init_outgoing.await?;
Key Generation
Generate cryptographic keys for your application:
use ;
// Generate identity key pair
let identity_keys = generate_identity_key_pair;
// Generate pre-keys
let pre_key = generate_pre_key;
let signed_pre_key = generate_signed_pre_key?;
// Generate signing key pair for Ed25519 signatures
let signing_keys = generate_signing_key_pair;
Storage Implementation
Implement the SessionStorage trait to provide persistence:
use ;
use async_trait;
Protocol Buffer Messages
The library uses protocol buffers for message serialization:
use Message;
use ;
// Decode a received message
let whisper_msg = decode?;
println!;
// Encode a message for transmission
let encoded = whisper_msg.encode_to_vec;
Testing
Run the comprehensive test suite:
# Run all tests
# Run specific test categories
Advanced Usage
Custom Message Processing
use ;
// Direct cryptographic operations
let key = b"32-byte-encryption-key-here!!!!!!";
let iv = b"16-byte-iv-here!";
let plaintext = b"Hello World";
let ciphertext = encrypt?;
let decrypted = decrypt?;
// ECDH key agreement
let alice_keys = generate_key_pair;
let bob_keys = generate_key_pair;
let shared_secret = calculate_agreement?;
Error Handling
The library provides detailed error types for different failure scenarios:
use ;
match cipher.decrypt.await
Architecture
Security Design
- Memory Safe: All cryptographic operations use Rust's ownership system to prevent buffer overflows and use-after-free vulnerabilities
- Constant-Time Operations: Uses libraries designed to resist timing attacks
- Forward Secrecy: Automatic key rotation ensures past messages remain secure even if current keys are compromised
Protocol Compatibility
- Signal Protocol v3: Full compatibility with Signal's current protocol version
- Cross-Platform: Generated protocol buffers ensure compatibility with other Signal implementations
- Standard Cryptography: Uses widely-audited cryptographic libraries
Documentation
We will be creating comprehensive and clear documentation soon. For now, check out our documentation on the rust registry.
- API Documentation - Complete API reference
Contributing
Contributions are welcome! Please read our contributing guidelines and ensure all tests pass:
License
MIT License
Copyright (c) 2025 DitzDev
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.