oqs-safe
Architecture

oqs-safe v0.8.0
oqs-safe is a production-oriented Post-Quantum Cryptography (PQC) toolkit in Rust, built on top of [libOQS].
It provides safe, minimal abstractions for:
- Post-quantum key exchange (ML-KEM)
- Post-quantum signatures (ML-DSA)
- Hybrid cryptography (classical + PQC)
- Secure session key derivation
Zeroizes secrets • Safe newtypes • Hybrid-ready • Migration-focused
PQC Migration Audit CLI
oqs-safe includes an experimental CLI audit command for Rust projects that need post-quantum migration readiness checks.
The audit command scans Cargo.toml and Cargo.lock for known classical public-key cryptography dependencies and produces a migration readiness report.
Example output:
PQC Migration Readiness Report
Project: /path/to/project
Status: REVIEW_REQUIRED
Scanned files:
- /path/to/project/Cargo.toml
- /path/to/project/Cargo.lock
Findings:
- x25519-dalek
Category: classical-key-exchange
Severity: medium
Reason: X25519 is classical key exchange and should be hybridized for PQC migration.
Recommendation: Use hybrid X25519 + ML-KEM and bind the handshake transcript before deriving session keys.
JSON output is also supported:
CI usage:
A finding does not necessarily mean the project is insecure. It means the dependency should be reviewed for post-quantum migration readiness, crypto inventory, and future migration planning.
Features
Post-Quantum Algorithms
-
KEM:
- ML-KEM-512
- ML-KEM-768
- ML-KEM-1024
-
Signatures:
- ML-DSA-44
- ML-DSA-65
- ML-DSA-87
Hybrid Cryptography (NEW)
Supports hybrid key exchange combining:
- Classical cryptography: X25519
- Post-quantum cryptography: ML-KEM
This is the recommended real-world migration approach.
- HKDF-based secret derivation
- Domain separation
- Zeroized secrets
Secure Session Derivation (NEW)
SecureSessionabstraction- Derive symmetric keys from shared secrets
- Client/server key separation
Handshake Transcript Binding (Introduced in v0.6.0)
The hybrid handshake now binds session derivation to a transcript hash covering:
- selected KEM algorithm
- client X25519 public key
- client ML-KEM public key
- server X25519 public key
- ML-KEM ciphertext
This helps both sides derive the final session key from the same exchanged handshake messages.
Optional Handshake Serialization (Introduced in v0.6.0)
Enable the serialization feature to serialize and deserialize handshake messages:
= { = "0.8", = ["serialization"] }
Supported helpers:
- ClientHello::to_bytes()
- ClientHello::from_bytes()
- ServerHello::to_bytes()
- ServerHello::from_bytes()
Optional AEAD Secure Session Helpers (Introduced in v0.6.0)
Enable the aead feature to use ChaCha20Poly1305 helpers from SecureSession:
= { = "0.8", = ["aead"] }
Supported helpers:
- SecureSession::encrypt()
- SecureSession::decrypt()
The AEAD key is derived from the session master secret using HKDF with a dedicated label.
Authenticated Hybrid Handshake (Introduced in v0.7.0)
oqs-safe v0.7.0 includes an authenticated hybrid handshake example for post-quantum migration scenarios.
The example combines:
- X25519 classical key exchange
- ML-KEM post-quantum key exchange
- ML-DSA transcript signing and verification
- Transcript-bound hybrid secret derivation
- HKDF directional session keys
Run it with:
### ️ Backends
)
## Install
### 1. Add the crate
)
&& &&
&&
- Make oqs-safe find and load liboqs:
export LIBOQS_DIR="$HOME/.local/liboqs"
- macOS: ensure runtime linking finds liboqs.dylib:
export DYLD_FALLBACK_LIBRARY_PATH="$HOME/.local/liboqs/lib:${DYLD_FALLBACK_LIBRARY_PATH}"
- Optional: pkg-config:
export PKG_CONFIG_PATH="$HOME/.local/liboqs/lib/pkgconfig:${PKG_CONFIG_PATH}"
Quickstart
Hybrid Handshake API
oqs-safe v0.8.0 introduces a TLS-style hybrid handshake abstraction with transcript-bound session derivation.
The API combines:
- X25519 classical key exchange
- ML-KEM post-quantum encapsulation
- HKDF-based hybrid secret derivation
- Client/server session key separation
use ;
let mut client = new;
let client_hello = client.start_handshake?;
let mut server = new;
let server_hello = server.respond?;
let client_session = client.finish?;
let server_session = server.session?;
let = client_session.derive_client_server_keys;
let = server_session.derive_client_server_keys;
assert_eq!;
assert_eq!;
ML-KEM Key Exchange
use ;
let kem = new;
let = kem.keypair?;
let = kem.encapsulate?;
let ss2 = kem.decapsulate?;
assert_eq!;
ML-DSA Sign & Verify
use ;
let sig = new;
let = sig.keypair?;
let msg = b"hello pqc";
let signature = sig.sign?;
sig.verify?;
Hybrid X25519 + ML-KEM
cargo run --example hybrid_x25519_mlkem
- This demonstrates:
- Classical X25519 key exchange
- ML-KEM encapsulation
- HKDF-based hybrid secret derivation
Derive session keys
use SecureSession;
let session = new;
let = session.derive_client_server_keys;
Examples
- Mock backend:
- Real backend:
Testing
Security Notes
- Always derive keys via HKDF before use
- Hybrid handshake transcript binding is enabled in the handshake API
- Application-level identity authentication is still required
- Hybrid crypto does NOT replace authentication
- Secrets are zeroized on drop
- Avoid logging or serializing secrets
- This crate is not formally audited
Migration Guidance
- For real-world deployments:
- Use hybrid X25519 + ML-KEM
- Do NOT rely on PQC-only yet
- Add authentication (TLS, signatures, etc.)
- Protect against downgrade attacks
MSRV & License
- MSRV: Rust 1.70+:
License: MIT OR Apache-2.0
Acknowledgements
- Built on [libOQS] from the Open Quantum Safe project
- Designed for real-world PQC migration scenarios
Contributing
- Contributions welcome for:
- Additional PQC algorithms
- TLS-style handshake patterns
- HSM / enclave integrations
- Blockchain / wallet integrations