OpenADP Rust SDK
A complete Rust implementation of the OpenADP (Open Advanced Data Protection) distributed secret sharing system, designed to protect against nation-state attacks.
Features
- Ed25519 elliptic curve operations with point compression/decompression
- Shamir secret sharing with threshold recovery
- Noise-NK protocol for secure server communication
- JSON-RPC 2.0 API with multi-server support
- Cross-language compatibility with Go and Python implementations
- High-level key generation API for file encryption
- Simple ocrypt API for password hashing replacement
- Automatic server discovery from registry
- Load balancing across multiple servers
- Guess limiting and rate limiting protection
- Two-phase commit backup refresh
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
= { = "1.0", = ["full"] }
Quick Start
High-Level Key Generation API
use ;
async
Simple Ocrypt API (Password Hashing Replacement)
Replace bcrypt, scrypt, Argon2, or PBKDF2 with distributed threshold cryptography:
use ;
async
Core Components
Cryptographic Operations
use ;
// Hash-to-point function H(uid, did, bid, pin)
let point = hash_to_point?;
// Compress point to 32 bytes
let compressed = point_compress?;
// Derive encryption key from point
let key = derive_enc_key?;
Client Communication
use ;
// Basic client (no encryption)
let client = new;
client.ping.await?;
// Encrypted client with Noise-NK
let public_key = Some?;
let mut encrypted_client = new;
// Get server information
let info = encrypted_client.get_server_info.await?;
println!;
Server Discovery
use ;
// Get servers from default registry
let servers = get_servers.await?;
// Use custom registry
let servers = get_servers.await?;
// Discover with fallback
let servers = discover_servers.await?; // Falls back to hardcoded servers
Use Cases
1. API Key Protection
Replace database storage of API keys with distributed protection:
// Instead of storing API keys in database:
// database.store("user123", "stripe_key", "sk_live_...");
// Use OpenADP distributed protection:
let metadata = register.await?;
database.store;
// Recovery:
let metadata = database.get;
let = recover.await?;
2. File Encryption
Generate encryption keys with distributed backup:
let servers = get_servers.await?;
let result = generate_encryption_key.await?;
// Use key for AES-256-GCM file encryption
let key = result.encryption_key.unwrap;
encrypt_file?;
3. Private Key Protection
Protect Ed25519/RSA private keys:
let private_key = generate_ed25519_key;
let metadata = register.await?;
// Later: recover for signing
let = recover.await?;
let signing_key = from_bytes?;
4. Database Encryption
Protect database master keys:
let master_key = generate_random_key;
let metadata = register.await?;
// Store metadata in secure configuration
config.set;
Architecture
Distributed Secret Sharing
- Secret Generation: Random 256-bit secret
s - Point Computation:
U = H(uid, did, bid, pin) - Shamir Sharing: Split
sintonshares withtthreshold - Server Registration: Store shares
(i, s_i, U)on distributed servers - Key Derivation: Final key =
derive_key(s * U)
Threshold Recovery
- Point Computation:
U = H(uid, did, bid, pin) - Share Recovery: Retrieve
tshares from servers - Secret Reconstruction: Lagrange interpolation to recover
s - Key Derivation: Compute final key from
s * U
Security Properties
- Nation-state resistant: Requires compromise of
t-of-nservers - Guess limiting: Wrong PIN attempts tracked across all servers
- Forward security: Backup refresh changes all server state
- No single point of failure: Distributed across multiple jurisdictions
Error Handling
use ;
match register.await
Testing
Run the test suite:
Run examples:
# Basic usage
# API key protection
# Full OpenADP demo
Cross-Language Compatibility
The Rust SDK is fully compatible with:
- Go SDK:
../ocrypt(separate git repository) - Python SDK:
../python/openadp/ - JavaScript SDK:
../javascript/openadp/
All implementations use the same:
- Cryptographic primitives (Ed25519, SHA-256, HKDF)
- JSON-RPC 2.0 protocol
- Server registry format
- Metadata structure
Production Deployment
Server Configuration
// Use custom server registry for production
let servers = get_servers.await?;
// Or specify servers directly
let servers = vec!;
Security Considerations
- Server Selection: Use servers in different jurisdictions
- Threshold Setting: Recommend
t = ⌊n/2⌋ + 1fornservers - Guess Limits: Use low limits (3-10) for production secrets
- Backup Refresh: Implement automatic refresh on recovery
- Key Rotation: Periodically re-register secrets with new backup IDs
Monitoring
// Monitor server health
for server in &servers
// Check remaining guesses
let = recover.await?;
if remaining < 3
Contributing
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass:
cargo test - Submit a pull request
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.
Security
For security issues, please email security@openadp.org instead of using the issue tracker.