| Crates.io | crypto_bastion |
| lib.rs | crypto_bastion |
| version | 0.1.0 |
| created_at | 2026-01-19 02:19:26.832914+00 |
| updated_at | 2026-01-19 02:19:26.832914+00 |
| description | Hardened post-quantum cryptographic primitives with zero-trust architecture |
| homepage | |
| repository | https://github.com/Guivernoir/veil-crypto |
| max_upload_size | |
| id | 2053558 |
| size | 184,752 |
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."
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.
Add to your Cargo.toml:
[dependencies]
crypto-bastion = "0.1.0"
use bastion::*;
fn main() -> Result<()> {
// Initialize 3-layer encryption (entry â relay â exit)
let encryptor = OnionEncryptor::new(
[1u8; 32], // entry node key
[2u8; 32], // relay node key
[3u8; 32], // exit node key
)?;
// Encrypt message through all layers
let ciphertext = encryptor.encrypt(b"Strategic intelligence")?;
// Decrypt at each node (keys consumed, preventing reuse)
let entry_dec = OnionDecryptor::new([1u8; 32])?;
let layer1 = entry_dec.decrypt(&ciphertext)?;
let relay_dec = OnionDecryptor::new([2u8; 32])?;
let layer2 = relay_dec.decrypt(&layer1)?;
let exit_dec = OnionDecryptor::new([3u8; 32])?;
let plaintext = exit_dec.decrypt(&layer2)?;
assert_eq!(&plaintext[..], b"Strategic intelligence");
Ok(())
}
use crypto_bastion::pqc::*;
fn secure_channel() -> Result<()> {
// Alice and Bob generate keypairs
let alice = HybridKeyExchange::new()?;
let bob = HybridKeyExchange::new()?;
// Alice encapsulates shared secret to Bob's public key
let (ciphertext, alice_key) = HybridKeyExchange::encapsulate(bob.public_key())?;
// Bob decapsulates to recover shared secret
let bob_key = bob.decapsulate(&ciphertext)?;
assert_eq!(alice_key, bob_key); // 64-byte shared secret
// Keys automatically zeroized when dropped
Ok(())
}
use crypto_bastion::pqc::*;
fn authenticated_message() -> Result<()> {
let keypair = SignatureKeypair::new()?;
let message = b"Execute Order 66";
// Sign message
let signature = keypair.sign(message)?;
// Verify signature (constant-time)
verify_signature(keypair.public_key(), message, &signature)?;
Ok(())
}
use crypto_bastion::constant_time::*;
fn secure_comparison() {
let secret = b"launch_codes_alpha_7";
let attempt = b"launch_codes_alpha_7";
// Constant-time equality (timing-attack resistant)
if ct_eq(secret, attempt) {
println!("Access granted");
}
// Verify buffer zeroization
let mut sensitive = vec![0x42u8; 1024];
ct_zeroize_verify(&mut sensitive).expect("Zeroization failed");
}
âââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â 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) â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââ
| 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 |
All cryptographic operations enforce timing constraints:
// Timing guard example
let _guard = TimingGuard::new("operation", MIN_TIME_NS);
// ... 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.
ZeroizeOnDropDual-context error system:
let err = CryptoError::decryption_failed("HMAC tag mismatch at offset 42");
// External display (safe for users)
println!("{}", err); // "Decryption operation failed"
// Internal context (security team only)
let internal = err.internal_context();
println!("{}", internal.details); // "HMAC tag mismatch at offset 42"
See SECURITY.md for comprehensive security documentation.
| 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.
Bastion includes comprehensive test coverage:
# Unit tests
cargo test
# Integration tests
cargo test --test integration_tests
# Property-based tests
cargo test --test property_tests
# Fuzzing (requires cargo-fuzz)
cargo fuzz run fuzz_onion_decrypt
cargo fuzz run fuzz_constant_time
cargo fuzz run fuzz_pqc_key_exchange
Access security metrics at runtime:
use bastion::METRICS;
use std::sync::atomic::Ordering;
let total = METRICS.total_operations.load(Ordering::Relaxed);
let failures = METRICS.failed_operations.load(Ordering::Relaxed);
let tampering = METRICS.tampering_detected.load(Ordering::Relaxed);
println!("Operations: {}, Failures: {}, Tampering: {}",
total, failures, tampering);
Contributions are welcome, particularly in:
Security Disclosure: Report vulnerabilities privately to strukturaenterprise@gmail.com
Dual-licensed under MIT or Apache 2.0, at your option.
Built on the shoulders of:
@software{bastion2026,
title = {Bastion: Hybrid Post-Quantum Cryptography},
year = {2026},
author = {Guilherme F. G. Santos},
url = {https://github.com/Guivernoir/Bastion}
}
"Security is a process, not a product. Bastion is both."