rustcrypt
Macro-first encryption and obfuscation library for Rust. Protect your source code from reverse engineering with compile-time string obfuscation, automatic struct encryption, and control flow obfuscation powered by procedural macros.
Features
- Compile-time string obfuscation
- Automatic struct encryption via derive
- Control flow obfuscation
- Multiple encryption layers
- Zero runtime dependencies
- Rustfuscator-inspired API
Quick Start
Add to your Cargo.toml:
[]
= "0.3.0-beta.1"
Basic Usage
use ;
API Reference
String Obfuscation Macros
obfuscate_string!
Obfuscates a string literal at compile time.
use obfuscate_string;
let secret = obfuscate_string!;
obfuscate_bytes!
Obfuscates a byte string literal at compile time.
use obfuscate_bytes;
let secret_bytes = obfuscate_bytes!;
Control Flow Obfuscation
obfuscate_flow!
Inserts opaque control flow to make reverse engineering more difficult.
use obfuscate_flow;
obfuscate_flow!;
obfuscate_flow!;
Automatic Struct Encryption
#[derive(Obfuscate)]
Automatically generates encrypted versions of structs.
use Obfuscate;
let config = new_clear;
let clear_config = config.get_clear;
Supported field types:
String/&stru32,u64i32,i64bool
Legacy Compile-Time Macros
The original compile-time macros are still available:
use ;
let s = obf_lit!;
let b = obf_lit_bytes!;
let c = obf_lit_cstr!;
let = obf_lit_array!;
Architecture
Rustcrypt is built as a workspace with specialized crates:
rustcrypt/
├── rustcrypt-core/ # Core encryption and obfuscation functionality
├── rustcrypt-macros/ # Function-like procedural macros
├── rustcrypt-derive/ # Derive macros for automatic struct encryption
├── rustcrypt-ct-macros/ # Compile-time literal obfuscation macros
└── examples/ # Usage examples
How It Works
- Compile-time encryption
- Runtime decryption
- Zero runtime cost
- Memory safety
Examples
Basic String Obfuscation
use obfuscate_string;
Complex Struct Encryption
use Obfuscate;
Layered Protection
use ;
Advanced Usage
Custom Encryption Layers
use ;
let crypto = with_config?;
let encrypted = crypto.hide?;
let decrypted = crypto.reveal?;
Stack-Based Secrets
use ;
let crypto = new?;
let stack_secret: = crypto.hide_stack?;
Additional Macros
use ;
let _b = obfuscate_bytes!;
let _c = obfuscate_cstr!;
let _arr = obfuscate_bytes_array!;
let _cb = obfuscate_const_bytes!;
obfuscate_flow_heavy!;
let _x = if obfuscate_branch! else ;
let _y: u32 = obfuscate_select!;
obfuscate_loop!;
Security Considerations
- Not a silver bullet: Obfuscation increases complexity but doesn't guarantee security
- Combine with other techniques: Use with binary stripping, anti-debugging, etc.
- Key management: Ensure proper key derivation and storage
- Memory safety: All secrets are zeroized when dropped
Performance
- Zero runtime overhead: All obfuscation happens at compile time
- Minimal binary size increase: Only encrypted data is added
- Fast decryption: Optimized for runtime performance
- Memory efficient: Automatic cleanup of sensitive data
Requirements
- Rust 1.70+
- No external dependencies for basic usage
- Optional features for advanced functionality
Contributing
Contributions are welcome! Please see our Contributing Guide for details.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Inspired by rustfuscator
- Built on top of proven cryptographic libraries
- Community feedback and contributions