๐ฆ CrabGraph
A safe, ergonomic, and high-performance cryptographic library for Rust, built on top of audited primitives from the RustCrypto ecosystem and other trusted sources.
โ ๏ธ Security Notice
This library is NOT yet audited by third-party cryptographic experts. While it uses audited primitives (RustCrypto, dalek-cryptography), mistakes in composition can still lead to vulnerabilities. DO NOT use in production without a professional security audit.
Note: The optional rsa-support feature has a known vulnerability (RUSTSEC-2023-0071 - Marvin timing attack). Use Ed25519/X25519 instead.
For security issues, please see SECURITY.md.
โจ Features
- ๐ Authenticated Encryption (AEAD): AES-GCM, ChaCha20-Poly1305
- ๏ฟฝ Streaming Encryption: Process large files chunk-by-chunk with STREAM construction
- ๏ฟฝ๐ Key Derivation: PBKDF2, Argon2, HKDF
- โ๏ธ Digital Signatures: Ed25519, (optional: RSA-PSS)
- ๐ค Key Exchange: X25519 (Elliptic Curve Diffie-Hellman)
- ๐ Message Authentication: HMAC (SHA-256, SHA-512)
- #๏ธโฃ Hashing: SHA-256, SHA-512, (optional: SHA-3, BLAKE2)
- ๐ Optional RSA Support: RSA-OAEP encryption & RSA-PSS signatures (โ ๏ธ opt-in only, not recommended)
- ๐ฒ Secure Random: Cryptographically secure RNG wrapper
- ๐งน Memory Safety: Automatic zeroization of sensitive data
- ๐ Interoperability: Helpers for CryptoJS compatibility
- ๐ Performance: Zero-copy operations, hardware acceleration support
- ๐ฆ No-std Support: Core functionality available in embedded contexts
๐ Live Demo
Experience CrabGraph's cryptographic capabilities directly in your browser. This interactive demo showcases real-world usage of the library compiled to WebAssembly, demonstrating encryption, key derivation, and signing operations with zero installation required.
๐ Quick Start
Add to your Cargo.toml:
[]
= "0.3.1"
Authenticated Encryption (AES-GCM)
use ;
Key Derivation (Argon2)
use ;
Digital Signatures (Ed25519)
use ;
Serialization (Serde)
use ;
Streaming Encryption for Large Files
use ;
See examples/serde_example.rs for JSON, TOML, and binary serialization examples.
HMAC Authentication
use ;
๐ Documentation
โก Performance
CrabGraph delivers excellent performance with minimal overhead over raw primitives:
| Operation | Speed | Throughput |
|---|---|---|
| AES-256-GCM Encrypt (1KB) | ~0.95 ฮผs | ~1,079 MB/s |
| ChaCha20-Poly1305 Encrypt (1KB) | ~2.7 ฮผs | ~378 MB/s |
| Ed25519 Sign | ~16 ฮผs | ~62,500 ops/sec |
| Ed25519 Verify | ~47 ฮผs | ~21,277 ops/sec |
| Argon2id KDF (32B) | ~11 ms | Intentionally slow (security) |
๐ Full benchmark results: ariajsarkar.github.io/crabgraph-bench
Benchmarks run on modern hardware with AES-NI. Your results may vary.
๐๏ธ Architecture
CrabGraph is built on these audited cryptographic libraries:
- RustCrypto:
aes-gcm,chacha20poly1305,sha2,hmac,pbkdf2,hkdf - dalek-cryptography:
ed25519-dalek,x25519-dalek - Argon2: Official Rust bindings to the Argon2 reference implementation
๐ฏ Design Principles
- Safe by Default: AEAD modes, proper nonce handling, automatic secret zeroization
- No Footguns: High-level API hides complexity; low-level access requires opt-in
- Audited Primitives: Never implements crypto from scratch
- Performance: Zero-copy, hardware acceleration, minimal allocations
- Ergonomic: Builder patterns, clear error messages, comprehensive docs
- Interoperable: Helpers for common JS library compatibility
๐งช Testing & Quality
# Run all tests
# Run benchmarks
# Run fuzzing (requires cargo-fuzz)
# Security audit
๐ง Feature Flags
default: Enablesstdsupportstd: Standard library support (enabled by default)alloc: Allocation support without full stdno_std: Embedded/bare-metal supportextended-hashes: SHA-3 and BLAKE2 supportrsa-support: RSA encryption/signatures (โ ๏ธ NOT enabled by default - opt-in only, has known vulnerability RUSTSEC-2023-0071)serde-support: Serialization for keys and ciphertextszero-copy:bytescrate integration for high-performance scenarioswasm: WebAssembly support (โ ๏ธ Temporarily unavailable in v0.3.3 - see CHANGELOG for details)
Enabling RSA Support
RSA is not included by default due to security concerns. To use RSA:
[]
= { = "0.2", = ["rsa-support"] }
โ ๏ธ Security Warning: RSA has a known timing attack vulnerability (RUSTSEC-2023-0071). Use Ed25519 for signatures and X25519+AEAD for encryption unless RSA is specifically required for legacy compatibility.
๐ค Contributing
Contributions are welcome! Please read CONTRIBUTING.md and our Code of Conduct.
๐ License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
๐ Acknowledgments
Built on the shoulders of giants:
- RustCrypto team
- dalek-cryptography contributors
- Argon2 reference implementation authors
โ ๏ธ Disclaimer
This software is provided "as is", without warranty of any kind. See LICENSE files for details.
IMPORTANT: Cryptography is hard. This library has not undergone a formal security audit. Use at your own risk, especially in production environments. Always consult with security professionals for critical applications.