Bastion
Bastion is a hardened cryptographic crate focused on strict operational constraints:
- post-quantum primitives: ML-KEM-1024 and ML-DSA-87
- authenticated encryption: AES-256-GCM
- SHA-512 hashing
- zeroization of sensitive material
- bounded public API with timing-floor normalization
- runtime dependency-free (
[dependencies]is empty) - allocation-aware measurement workflow
Public API
Only these crate-level functions are public:
encryptdecryptencapsulatedecapsulatesignverifyhashcomparelayer_encryptlayer_decryptonioncut
Current signatures are buffer-oriented (caller provides output memory):
;
;
;
;
;
;
;
;
;
;
;
;
Install
[]
= "0.2"
Quick Start
Hash and Compare
use ;
let a = hash;
let b = hash;
assert!;
AES-256-GCM Encrypt
use encrypt;
let key = ;
let nonce = ;
let aad = b"context";
let pt = b"payload";
let mut ct = vec!;
let mut tag = ;
let n = encrypt?;
assert_eq!;
# Ok::
ML-KEM Encapsulation
use encapsulate;
let pk = vec!;
let mut ct = ;
let mut ss = ;
encapsulate?;
# Ok::
ML-DSA Signature
use sign;
let sk = vec!;
let msg = b"signed-message";
let mut sig = ;
sign?;
# Ok::
Layered Onion Encryption
Per-layer overhead is 6223 bytes. Required output size is:
plaintext.len() + (layers * 6223)
use onion;
let msg = b"onion-data";
let kem0 = vec!;
let kem1 = vec!;
let dsa0 = vec!;
let dsa1 = vec!;
let kem = ;
let dsa = ;
let mut out = vec!;
let packet_len = onion?;
assert_eq!;
# Ok::
Security and Engineering Constraints
- Secret material is zeroized in internal key/signing paths.
- Public API wrappers enforce timing floors.
compareis constant-time over equal-length slices.- Public API paths are allocation-aware; measurements are generated by
write_results. - Internal modules remain
pub(crate); no direct public key container exposure.
See SECURITY.md for the detailed model and verification process.
Verification Workflow
# Formatting and checks
# Benchmarks
# Allocation + memory + timing-spread report
# Fuzzing targets (cargo-fuzz + nightly)
Repository Layout
src/lib.rspublic API and hybrid orchestrationsrc/algos/aes256gcm/AES-GCM internalssrc/algos/mlkem1024/ML-KEM internalssrc/algos/mldsa87/ML-DSA internalssrc/constant_time.rsconstant-time helpers and timing guardsrc/zeroize.rszeroization primitivesexamples/usage and reporting toolsbenches/criterion benchmark suitesfuzz/libFuzzer targets
License
Licensed under MIT OR Apache-2.0.