Pluggable entropy framework for cryptographic applications with built-in quality testing, visualization, and interactive educational tools.
- π Trait-based Design: Any RNG can be plugged in via the
EntropySourcetrait - π¬ Quality Testing: NIST SP 800-22 tests, Shannon entropy, min-entropy calculations
- π Cryptographic Use: Stream cipher implementation using your entropy source
- π Real-time Visualization: egui-based GUI for interactive exploration
- β‘ Performance Benchmarks: Measure throughput and latency of entropy sources
- π Interactive Learning: Step-by-step visualizations of cryptographic operations
| Use Tab | Test Tab | Learn Tab |
|---|---|---|
| Stream cipher encryption | Quality metrics & NIST tests | Step-by-step XOR visualization |
cargo run --release# Basic usage
cargo run --example basic_usage
# Custom entropy source
cargo run --example custom_source
# Quality check with NIST tests
cargo run --example quality_checkEncrypt and decrypt data using the stream cipher with real-time keystream visualization.
Analyze entropy quality with:
- Shannon Entropy (bits/byte)
- Min-Entropy (conservative estimate)
- Chi-Square uniformity test
- NIST SP 800-22 statistical tests (Frequency, Runs, Longest Run, Serial, Chi-Square)
Measure entropy source performance:
- Throughput (MB/s)
- Latency per byte (Β΅s)
Interactive educational visualizations that teach cryptographic concepts step-by-step:
- XOR Cipher Visualization: See exactly how each character is encrypted
- Character β ASCII β Binary conversion
- Bit-by-bit XOR operation with color coding
- Keystream generation from entropy source
- Navigation controls (Previous/Next/Play/Pause)
- Adjustable animation speed
Perfect for understanding how stream ciphers actually work!
use entropy_forge::entropy::SystemEntropy;
use entropy_forge::crypto::StreamCipher;
let entropy = SystemEntropy::new();
let mut cipher = StreamCipher::new(entropy);
let plaintext = b"Hello, World!";
let ciphertext = cipher.process(plaintext);use entropy_forge::entropy::EntropySource;
struct MyRNG {
state: u64,
}
impl EntropySource for MyRNG {
fn fill_bytes(&mut self, dest: &mut [u8]) {
// Your RNG implementation here
for byte in dest.iter_mut() {
self.state = self.state.wrapping_mul(1103515245).wrapping_add(12345);
*byte = (self.state >> 24) as u8;
}
}
fn name(&self) -> &str {
"My Custom RNG"
}
}use entropy_forge::quality::QualityMetrics;
use entropy_forge::entropy::SystemEntropy;
let mut source = SystemEntropy::new();
let metrics = QualityMetrics::analyze(&mut source, 100_000);
println!("Shannon Entropy: {:.4} bits/byte", metrics.shannon_entropy);
println!("Min-Entropy: {:.4} bits/byte", metrics.min_entropy);
println!("Quality Score: {:.1}/100", metrics.overall_score());use entropy_forge::quality::NistTests;
use entropy_forge::entropy::{EntropySource, SystemEntropy};
let mut source = SystemEntropy::new();
let mut data = vec![0u8; 100_000];
source.fill_bytes(&mut data);
let results = NistTests::run_all_tests(&data);
for (name, p_value) in results {
println!("{}: {:.4} {}",
name,
p_value,
if p_value >= 0.01 { "β" } else { "β" }
);
}Entropy Forge is designed to work with any entropy source through a clean trait interface. Whether you're using:
- System RNG (
/dev/urandom,BCryptGenRandom, etc.) - Hardware RNG (TPM, RDRAND, etc.)
- Chaotic systems (Lorenz, RΓΆssler attractors, etc.)
- Quantum sources
- Custom implementations
The framework provides:
- Practical cryptographic use (stream ciphers, key derivation)
- Quality verification (statistical tests, entropy metrics)
- Performance measurement (throughput, latency benchmarks)
- Visual feedback (real-time GUI, state visualization)
- Educational tools (step-by-step algorithm breakdowns)
High-quality entropy sources (7.5+ bits/byte min-entropy) will show optimal performance across all metrics.
entropy-forge/
βββ src/
β βββ entropy/ # EntropySource trait + implementations
β βββ crypto/ # Stream cipher, key derivation
β βββ quality/ # Metrics, NIST tests
β βββ bench/ # Performance benchmarking
β βββ learn/ # Educational visualizations
β βββ viz/ # GUI components (egui)
βββ examples/ # Usage examples
βββ tests/ # Integration tests
The framework measures:
- Shannon Entropy: Average information content (max: 8.0 bits/byte)
- Min-Entropy: Conservative estimate based on most probable outcome
- Chi-Square: Tests uniformity of byte distribution
- NIST SP 800-22 Tests: Industry-standard randomness tests
- Frequency Test
- Runs Test
- Longest Run Test
- Serial Test
- Chi-Square Test
Typical results on modern hardware (example with System RNG):
- Throughput: 300-500 MB/s
- Latency: 2-3 Β΅s per byte
- Quality: 7.98+ bits/byte Shannon entropy
High-quality chaotic systems (e.g., RΓΆssler attractors) producing 7.5+ bits/byte entropy can be seamlessly integrated:
// Hypothetical example
struct ChaoticRNG {
// RΓΆssler system state...
}
impl EntropySource for ChaoticRNG {
fn fill_bytes(&mut self, dest: &mut [u8]) {
// Evolve chaotic system, extract bytes...
}
fn name(&self) -> &str {
"Chaotic RNG (RΓΆssler)"
}
}
// Use with Entropy Forge
let mut source = ChaoticRNG::new();
let metrics = QualityMetrics::analyze(&mut source, 1_000_000);
// Expect: ~7.75 bits/byte, excellent NIST scores
let mut cipher = StreamCipher::new(source);
// Now using chaotic entropy for cryptography!Contributions are welcome! Please feel free to submit a Pull Request. See CONTRIBUTING.md for guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
- NIST SP 800-22 for statistical test specifications
- The Rust community for excellent cryptographic libraries
- egui for the immediate-mode GUI framework
This is an educational and research tool. For production cryptographic applications, use well-vetted libraries and consult with security experts.
Made with π¦ Rust