Bastion
Enterprise-grade post-quantum cryptographic library with military-grade operational security.
"In cryptography, as in chess, the amateur focuses on tactics. The professional studies strategy."
Overview
Bastion is a hardened cryptographic library implementing post-quantum algorithms with comprehensive security controls. Unlike conventional crypto libraries that stop at correctness, Bastion enforces operational security through constant-time execution, dual-context error handling, comprehensive audit logging, and STRIDE threat model coverage.
Key Features
- ðĄïļ Post-Quantum Security: ML-KEM-1024 (Kyber) and ML-DSA-87 (Dilithium) - NIST standardized
- âąïļ Constant-Time Operations: Timing guards enforce execution bounds, preventing side-channel attacks
- ð Dual-Context Errors: Internal debugging context + external opacity (no information leakage)
- ð STRIDE Coverage: Comprehensive threat model mitigation with audit classification
- ð Memory Safety: Automatic zeroization with cryptographic verification
- ðĶ Rate Limiting: Built-in DoS protection (1000 ops/sec symmetric, 100 ops/sec PQC)
- ð Audit Logging: GDPR-compliant security event tracking
- ðŊ No-Clone Architecture: Single-owner semantics prevent memory bloat and side channels
- ð§ą Onion Routing: 3-layer encryption for anonymous communication
Installation
Add to your Cargo.toml:
[]
= "0.1.0"
Quick Start
Onion Encryption (3-Layer)
use *;
Post-Quantum Key Exchange
use *;
Digital Signatures
use *;
Constant-Time Operations
use *;
Architecture
âââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â Application Layer â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â Crypto Operations â
â âĒ AES-256-GCM (authenticated encryption) â
â âĒ ML-KEM-1024 (post-quantum key exchange) â
â âĒ ML-DSA-87 (post-quantum signatures) â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â Hardened Standard â
â âĒ Constant-time primitives â
â âĒ Dual-context error handling â
â âĒ Comprehensive audit logging â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â Security Enforcement â
â âĒ Rate limiting (DoS protection) â
â âĒ Memory zeroization (verified) â
â âĒ Timing guards (side-channel protection) â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Security Model
STRIDE Threat Coverage
| Threat | Mitigation |
|---|---|
| Spoofing | Post-quantum signatures (ML-DSA-87) |
| Tampering | Authenticated encryption (AES-256-GCM) |
| Repudiation | Comprehensive audit logging |
| Information Disclosure | Opaque errors, memory zeroization |
| Denial of Service | Rate limiting (1000/sec symmetric, 100/sec PQC) |
| Elevation of Privilege | Immutable keys, least privilege |
Constant-Time Guarantees
All cryptographic operations enforce timing constraints:
// Timing guard example
let _guard = new;
// ... cryptographic operation ...
_guard.verify?; // Fails if too fast or too slow
Operations that complete too quickly indicate potential side-channel attacks. Violations are logged to METRICS.timing_violations.
Memory Safety
- Automatic Zeroization: All sensitive data (keys, plaintexts) use
ZeroizeOnDrop - Verified Erasure: Cryptographic verification ensures zeroization succeeded
- No-Clone Architecture: Keys cannot be cloned, preventing accidental duplication
Error Handling
Dual-context error system:
let err = decryption_failed;
// External display (safe for users)
println!; // "Decryption operation failed"
// Internal context (security team only)
let internal = err.internal_context;
println!; // "HMAC tag mismatch at offset 42"
See SECURITY.md for comprehensive security documentation.
Compliance
GDPR
- Data minimization (no PII in errors)
- Purpose limitation (keys only for crypto)
- Storage limitation (automatic zeroization)
- Right to erasure (verified zeroization)
NIST Cybersecurity Framework
- Identify: Comprehensive threat model (STRIDE)
- Protect: Defense-in-depth (rate limiting, constant-time)
- Detect: Audit logging, timing violation detection
- Respond: Dual-context errors for incident response
- Recover: Graceful degradation, no panic on errors
Performance Characteristics
| Operation | Rate Limit | Typical Latency |
|---|---|---|
| AES-256-GCM Encrypt | 1000/sec | ~5 Ξs |
| AES-256-GCM Decrypt | 1000/sec | ~5 Ξs |
| ML-KEM Encapsulate | 100/sec | ~50 Ξs |
| ML-KEM Decapsulate | 100/sec | ~60 Ξs |
| ML-DSA Sign | 100/sec | ~200 Ξs |
| ML-DSA Verify | 100/sec | ~100 Ξs |
Note: Benchmarks are planned for future releases.
Testing
Bastion includes comprehensive test coverage:
# Unit tests
# Integration tests
# Property-based tests
# Fuzzing (requires cargo-fuzz)
Test Categories
- Unit Tests: Individual function correctness
- Integration Tests: Complete workflows, concurrency, error propagation
- Property Tests: Cryptographic invariants (proptest)
- Fuzz Tests: Malformed inputs, boundary conditions
Audit Metrics
Access security metrics at runtime:
use METRICS;
use Ordering;
let total = METRICS.total_operations.load;
let failures = METRICS.failed_operations.load;
let tampering = METRICS.tampering_detected.load;
println!;
Future Work
Planned Features
- Benchmarking Suite: Comprehensive performance measurements across platforms
- Hardware Acceleration: AES-NI, AVX2 optimizations
- Extended PQC: Additional NIST finalists (BIKE, HQC)
- Threshold Cryptography: Multi-party computation primitives
- HSM Integration: Hardware security module support
Research Areas
- Formal Verification: Coq/Lean proofs of constant-time properties
- Side-Channel Analysis: Power analysis resistance validation
- Quantum-Safe Hybrid: X25519 + ML-KEM composition
Contributing
Contributions are welcome, particularly in:
- Security audits and vulnerability reports
- Performance optimizations (with constant-time preservation)
- Additional test coverage
- Documentation improvements
Security Disclosure: Report vulnerabilities privately to strukturaenterprise@gmail.com
License
Dual-licensed under MIT or Apache 2.0, at your option.
Acknowledgments
Built on the shoulders of:
- pqc_kyber: ML-KEM-1024 implementation
- pqc_dilithium: ML-DSA-87 implementation
- aes-gcm: Authenticated encryption
- subtle: Constant-time primitives
- zeroize: Memory erasure
Citation
"Security is a process, not a product. Bastion is both."