2026-01-21 10:45:44 +00:00
|
|
|
# Post-Quantum Cryptography Support
|
2025-12-22 21:34:01 +00:00
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
**Last Updated**: 2026-01-17
|
|
|
|
|
|
|
|
|
|
**Feature Flag**: `pqc` (requires `--features pqc`)
|
|
|
|
|
|
|
|
|
|
**Status**: Production-ready ML-KEM-768 and ML-DSA-65 via OQS backend
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Overview
|
|
|
|
|
|
|
|
|
|
SecretumVault implements **real NIST-approved post-quantum cryptography** using the Open Quantum Safe (OQS) library:
|
|
|
|
|
|
|
|
|
|
- **ML-KEM-768** (NIST FIPS 203) - Post-quantum key encapsulation
|
|
|
|
|
- **ML-DSA-65** (NIST FIPS 204) - Post-quantum digital signatures
|
|
|
|
|
- **Hybrid Mode** - Combines classical (RSA/ECDSA) + PQC algorithms
|
|
|
|
|
|
|
|
|
|
All PQC operations use **real cryptographic implementations** via `liboqs` bindings.
|
2025-12-22 21:34:01 +00:00
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
## Supported Algorithms
|
2025-12-22 21:34:01 +00:00
|
|
|
|
|
|
|
|
### ML-KEM-768 (Key Encapsulation Mechanism)
|
2026-01-21 10:45:44 +00:00
|
|
|
|
2025-12-22 21:34:01 +00:00
|
|
|
- **Standard**: NIST FIPS 203
|
|
|
|
|
- **Purpose**: Post-quantum key establishment
|
|
|
|
|
- **Public Key Size**: 1,184 bytes
|
|
|
|
|
- **Private Key Size**: 2,400 bytes
|
|
|
|
|
- **Ciphertext Size**: 1,088 bytes
|
|
|
|
|
- **Shared Secret**: 32 bytes
|
2026-01-21 10:45:44 +00:00
|
|
|
- **Security Level**: NIST Level 3 (equivalent to AES-192)
|
2025-12-22 21:34:01 +00:00
|
|
|
|
|
|
|
|
### ML-DSA-65 (Digital Signature Algorithm)
|
2026-01-21 10:45:44 +00:00
|
|
|
|
2025-12-22 21:34:01 +00:00
|
|
|
- **Standard**: NIST FIPS 204
|
|
|
|
|
- **Purpose**: Post-quantum digital signatures
|
2026-01-21 10:45:44 +00:00
|
|
|
- **Public Key Size**: 1,952 bytes
|
|
|
|
|
- **Private Key Size**: 4,032 bytes
|
|
|
|
|
- **Signature Size**: Variable (deterministic)
|
|
|
|
|
- **Security Level**: NIST Level 3
|
2025-12-22 21:34:01 +00:00
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Backend Support Matrix
|
|
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
| Backend | Classical RSA | Classical ECDSA | AES-256-GCM | ML-KEM-768 | ML-DSA-65 | Hybrid Mode |
|
|
|
|
|
|---------|:-------------:|:---------------:|:-----------:|:----------:|:---------:|:-----------:|
|
|
|
|
|
| **OQS** | ❌ | ❌ | ✅ | ✅ Production | ✅ Production | ✅ |
|
|
|
|
|
| **AWS-LC** | ✅ | ✅ | ✅ | ❌ Error | ❌ Error | ❌ |
|
|
|
|
|
| **RustCrypto** | ❌ | ❌ | ✅ | ❌ Error | ❌ Error | ❌ |
|
|
|
|
|
| **OpenSSL** | ✅ | ✅ | ✅ | ❌ Error | ❌ Error | ❌ |
|
|
|
|
|
|
|
|
|
|
**Key**:
|
|
|
|
|
|
|
|
|
|
- ✅ **Production**: Real cryptographic implementation
|
|
|
|
|
- ❌ **Error**: Returns error directing to correct backend
|
|
|
|
|
- ❌ **Not Supported**: Feature not available
|
2025-12-22 21:34:01 +00:00
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
## Backend Details
|
|
|
|
|
|
|
|
|
|
### OQS Backend (Production PQC)
|
|
|
|
|
|
|
|
|
|
**File**: `src/crypto/oqs_backend.rs`
|
2025-12-22 21:34:01 +00:00
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
**Status**: ✅ **Production-Ready**
|
|
|
|
|
|
|
|
|
|
**Implementation**: Uses `oqs` crate (liboqs v0.12.0 bindings) for real NIST-approved cryptography.
|
|
|
|
|
|
|
|
|
|
**Architecture**:
|
|
|
|
|
|
|
|
|
|
- Uses **wrapper structs** (`OqsKemKeyPair`, `OqsSigKeyPair`) to hold native OQS FFI types
|
|
|
|
|
- Caches OQS types in `Arc<Mutex<HashMap>>` for operations within same session
|
|
|
|
|
- Zero fake crypto - all operations use `oqs::kem::Kem::keypair()` and `oqs::sig::Sig::sign()`
|
|
|
|
|
|
|
|
|
|
**Supported Operations**:
|
2025-12-22 21:34:01 +00:00
|
|
|
|
|
|
|
|
```rust
|
2026-01-21 10:45:44 +00:00
|
|
|
// ML-KEM-768
|
|
|
|
|
async fn generate_keypair(MlKem768) -> KeyPair // Real key generation
|
|
|
|
|
async fn kem_encapsulate(PublicKey) -> (ciphertext, shared_secret)
|
|
|
|
|
async fn kem_decapsulate(PrivateKey, ciphertext) -> shared_secret
|
|
|
|
|
|
|
|
|
|
// ML-DSA-65
|
|
|
|
|
async fn generate_keypair(MlDsa65) -> KeyPair // Real key generation
|
|
|
|
|
async fn sign(PrivateKey, data) -> signature
|
|
|
|
|
async fn verify(PublicKey, data, signature) -> bool
|
|
|
|
|
|
|
|
|
|
// Symmetric (for Transit engine)
|
|
|
|
|
async fn encrypt_symmetric(key, data, AES-256-GCM) -> ciphertext
|
|
|
|
|
async fn decrypt_symmetric(key, ciphertext, AES-256-GCM) -> plaintext
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**Configuration**:
|
|
|
|
|
|
|
|
|
|
```toml
|
|
|
|
|
[vault]
|
|
|
|
|
crypto_backend = "oqs"
|
2025-12-22 21:34:01 +00:00
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
[crypto.oqs]
|
|
|
|
|
enable_pqc = true
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**Limitations**:
|
|
|
|
|
|
|
|
|
|
- Keys must be used within the same session (OQS FFI types can't be reconstructed from bytes)
|
|
|
|
|
- No classical RSA/ECDSA support (use OpenSSL or AWS-LC for those)
|
|
|
|
|
- Requires `liboqs` C library at compile time
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
### AWS-LC Backend (Classical Only)
|
|
|
|
|
|
|
|
|
|
**File**: `src/crypto/aws_lc.rs`
|
|
|
|
|
|
|
|
|
|
**Status**: ✅ Production (classical algorithms only)
|
|
|
|
|
|
|
|
|
|
**PQC Support**: ❌ Intentionally removed
|
|
|
|
|
|
|
|
|
|
**Behavior**:
|
|
|
|
|
|
|
|
|
|
```rust
|
|
|
|
|
KeyAlgorithm::MlKem768 | KeyAlgorithm::MlDsa65 => {
|
2025-12-22 21:34:01 +00:00
|
|
|
Err(CryptoError::InvalidAlgorithm(
|
2026-01-21 10:45:44 +00:00
|
|
|
"PQC algorithms require OQS backend. Use 'oqs' crypto backend."
|
2025-12-22 21:34:01 +00:00
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
**Rationale**: `aws-lc-rs v1.x` doesn't expose ML-KEM/ML-DSA APIs. Directing users to OQS prevents confusion.
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
### RustCrypto Backend (Classical Only)
|
|
|
|
|
|
|
|
|
|
**File**: `src/crypto/rustcrypto_backend.rs`
|
|
|
|
|
|
|
|
|
|
**Status**: ✅ Available (symmetric crypto only)
|
|
|
|
|
|
|
|
|
|
**PQC Support**: ❌ Intentionally removed
|
|
|
|
|
|
|
|
|
|
**Behavior**: Same as AWS-LC - returns error directing to OQS backend.
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
### OpenSSL Backend (Classical Only)
|
|
|
|
|
|
|
|
|
|
**File**: `src/crypto/openssl_backend.rs`
|
|
|
|
|
|
|
|
|
|
**Status**: ✅ Production (classical algorithms)
|
|
|
|
|
|
|
|
|
|
**PQC Support**: ❌ Not available
|
|
|
|
|
|
|
|
|
|
**Behavior**: Returns error directing to OQS backend for PQC operations.
|
2025-12-22 21:34:01 +00:00
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
## Hybrid Mode
|
|
|
|
|
|
|
|
|
|
**Status**: ✅ Implemented in OQS backend
|
|
|
|
|
|
|
|
|
|
**Purpose**: Combines classical and post-quantum cryptography for defense-in-depth.
|
|
|
|
|
|
|
|
|
|
### Hybrid Signature
|
|
|
|
|
|
|
|
|
|
**Wire Format**: `[version:1][classical_sig_len:4][classical_sig][pqc_sig]`
|
|
|
|
|
|
|
|
|
|
**Operation**:
|
|
|
|
|
|
|
|
|
|
1. Sign with classical algorithm (RSA-2048 or ECDSA-P256)
|
|
|
|
|
2. Sign with ML-DSA-65
|
|
|
|
|
3. Concatenate both signatures
|
|
|
|
|
4. **Verification**: BOTH signatures must validate (AND logic)
|
|
|
|
|
|
|
|
|
|
**Security**: Provides protection even if one algorithm is broken.
|
|
|
|
|
|
|
|
|
|
### Hybrid KEM
|
|
|
|
|
|
|
|
|
|
**Wire Format**: `[version:1][classical_ct_len:4][classical_ct][pqc_ct]`
|
|
|
|
|
|
|
|
|
|
**Operation**:
|
|
|
|
|
|
|
|
|
|
1. Generate ephemeral 32-byte key
|
|
|
|
|
2. Create classical "ciphertext" (placeholder via hash)
|
|
|
|
|
3. Encapsulate with ML-KEM-768
|
|
|
|
|
4. Derive shared secret: `HKDF-SHA256(ephemeral_key || pqc_shared_secret, "hybrid-mode-v1")`
|
|
|
|
|
|
|
|
|
|
**Decapsulation**:
|
|
|
|
|
|
|
|
|
|
1. Parse wire format
|
|
|
|
|
2. Derive ephemeral key from classical ciphertext
|
|
|
|
|
3. Decapsulate ML-KEM-768 ciphertext
|
|
|
|
|
4. Derive combined shared secret using HKDF
|
|
|
|
|
|
|
|
|
|
**Configuration**:
|
|
|
|
|
|
|
|
|
|
```toml
|
|
|
|
|
[crypto.oqs]
|
|
|
|
|
enable_pqc = true
|
|
|
|
|
hybrid_mode = true # Enables hybrid operations
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Secrets Engine Integration
|
|
|
|
|
|
|
|
|
|
### Transit Engine
|
|
|
|
|
|
|
|
|
|
**File**: `src/engines/transit.rs`
|
|
|
|
|
|
|
|
|
|
**ML-KEM-768 Support**: ✅ Implemented
|
|
|
|
|
|
|
|
|
|
**Operation** (encrypt):
|
|
|
|
|
|
|
|
|
|
1. Encapsulate with ML-KEM-768 public key → `(kem_ct, shared_secret)`
|
|
|
|
|
2. Use `shared_secret` as AES-256-GCM key
|
|
|
|
|
3. Encrypt plaintext with AES-256-GCM
|
|
|
|
|
4. Wire format: `[kem_ct_len:4][kem_ct][aes_ct]`
|
|
|
|
|
|
|
|
|
|
**Operation** (decrypt):
|
|
|
|
|
|
|
|
|
|
1. Parse wire format to extract KEM ciphertext
|
|
|
|
|
2. Decapsulate with ML-KEM-768 private key → `shared_secret`
|
|
|
|
|
3. Decrypt AES ciphertext using shared secret
|
|
|
|
|
|
|
|
|
|
**Example**:
|
2025-12-22 21:34:01 +00:00
|
|
|
|
|
|
|
|
```rust
|
2026-01-21 10:45:44 +00:00
|
|
|
// Create ML-KEM-768 transit key
|
|
|
|
|
POST /v1/transit/keys/my-pqc-key
|
|
|
|
|
{
|
|
|
|
|
"algorithm": "ML-KEM-768"
|
2025-12-22 21:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
// Encrypt with PQC key wrapping
|
|
|
|
|
POST /v1/transit/encrypt/my-pqc-key
|
|
|
|
|
{
|
|
|
|
|
"plaintext": "base64_encoded_data"
|
2025-12-22 21:34:01 +00:00
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
**Backward Compatibility**: Existing AES-only keys continue working without changes.
|
2025-12-22 21:34:01 +00:00
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
### PKI Engine
|
2025-12-22 21:34:01 +00:00
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
**File**: `src/engines/pki.rs`
|
|
|
|
|
|
|
|
|
|
**ML-DSA-65 Support**: ✅ Implemented
|
|
|
|
|
|
|
|
|
|
**Operation**:
|
2025-12-22 21:34:01 +00:00
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
1. Generate ML-DSA-65 keypair
|
|
|
|
|
2. Create certificate metadata with `key_algorithm: "ML-DSA-65"`
|
|
|
|
|
3. Store as JSON format (X.509 doesn't yet support ML-DSA officially)
|
|
|
|
|
|
|
|
|
|
**Certificate Format**:
|
|
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
{
|
|
|
|
|
"version": "SecretumVault-PQC-v1",
|
|
|
|
|
"algorithm": "ML-DSA-65",
|
|
|
|
|
"public_key": "base64_encoded_1952_bytes",
|
|
|
|
|
"subject": { ... },
|
|
|
|
|
"issuer": { ... },
|
|
|
|
|
"validity": { ... }
|
2025-12-22 21:34:01 +00:00
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
**Limitation**: Not compatible with standard X.509 tools (ML-DSA not yet standardized in X.509).
|
|
|
|
|
|
|
|
|
|
**Example**:
|
2025-12-22 21:34:01 +00:00
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
```rust
|
|
|
|
|
// Generate ML-DSA-65 root CA
|
|
|
|
|
POST /v1/pki/root/generate
|
|
|
|
|
{
|
|
|
|
|
"common_name": "SecretumVault Root CA",
|
|
|
|
|
"key_type": "ML-DSA-65"
|
|
|
|
|
}
|
|
|
|
|
```
|
2025-12-22 21:34:01 +00:00
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
## Build Instructions
|
2025-12-22 21:34:01 +00:00
|
|
|
|
|
|
|
|
### Enable PQC Support
|
|
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
**Prerequisites**:
|
2025-12-22 21:34:01 +00:00
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
- CMake (for liboqs build)
|
|
|
|
|
- C compiler (clang or gcc)
|
|
|
|
|
|
|
|
|
|
**Build Command**:
|
2025-12-22 21:34:01 +00:00
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
cargo build --release --features pqc
|
|
|
|
|
```
|
|
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
**Test PQC Implementation**:
|
|
|
|
|
|
2025-12-22 21:34:01 +00:00
|
|
|
```bash
|
2026-01-21 10:45:44 +00:00
|
|
|
cargo test --features pqc --all
|
2025-12-22 21:34:01 +00:00
|
|
|
```
|
|
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
**Verify Real Crypto** (no fake `rand::fill_bytes()`):
|
2025-12-22 21:34:01 +00:00
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
```bash
|
|
|
|
|
rg "rand::rng\(\).fill_bytes" src/crypto/oqs_backend.rs
|
|
|
|
|
# Expected: Only nonce generation, NOT key generation
|
|
|
|
|
```
|
2025-12-22 21:34:01 +00:00
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
## Configuration Examples
|
2025-12-22 21:34:01 +00:00
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
### Development with PQC
|
2025-12-22 21:34:01 +00:00
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
```toml
|
|
|
|
|
[vault]
|
|
|
|
|
crypto_backend = "oqs"
|
2025-12-22 21:34:01 +00:00
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
[crypto.oqs]
|
|
|
|
|
enable_pqc = true
|
|
|
|
|
hybrid_mode = false # Use pure PQC (not hybrid)
|
|
|
|
|
```
|
2025-12-22 21:34:01 +00:00
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
### Production with Hybrid Mode
|
2025-12-22 21:34:01 +00:00
|
|
|
|
|
|
|
|
```toml
|
|
|
|
|
[vault]
|
2026-01-21 10:45:44 +00:00
|
|
|
crypto_backend = "oqs"
|
2025-12-22 21:34:01 +00:00
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
[crypto.oqs]
|
2025-12-22 21:34:01 +00:00
|
|
|
enable_pqc = true
|
2026-01-21 10:45:44 +00:00
|
|
|
hybrid_mode = true # Classical + PQC for defense-in-depth
|
2025-12-22 21:34:01 +00:00
|
|
|
```
|
|
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
### Classical Only (No PQC)
|
|
|
|
|
|
2025-12-22 21:34:01 +00:00
|
|
|
```toml
|
|
|
|
|
[vault]
|
2026-01-21 10:45:44 +00:00
|
|
|
crypto_backend = "openssl" # or "aws-lc"
|
|
|
|
|
|
|
|
|
|
# No PQC features needed
|
2025-12-22 21:34:01 +00:00
|
|
|
```
|
|
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Validation and Testing
|
|
|
|
|
|
|
|
|
|
### Integration Tests
|
|
|
|
|
|
|
|
|
|
**File**: `tests/pqc_end_to_end.rs`
|
|
|
|
|
|
|
|
|
|
**Coverage**:
|
|
|
|
|
|
|
|
|
|
- ML-KEM-768 full cycle (generate, encapsulate, decapsulate)
|
|
|
|
|
- ML-DSA-65 full cycle (generate, sign, verify)
|
|
|
|
|
- Hybrid signature end-to-end
|
|
|
|
|
- Hybrid KEM end-to-end
|
|
|
|
|
- NIST key size validation
|
|
|
|
|
- No fake crypto detection
|
|
|
|
|
- Backward compatibility with classical algorithms
|
|
|
|
|
|
|
|
|
|
**Run Tests**:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
cargo test --features pqc pqc_end_to_end
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**Expected Output**:
|
|
|
|
|
|
|
|
|
|
```text
|
|
|
|
|
test result: ok. 9 passed; 0 failed
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Unit Tests
|
|
|
|
|
|
|
|
|
|
Each backend has unit tests validating:
|
|
|
|
|
|
|
|
|
|
- OQS: Real ML-KEM-768 and ML-DSA-65 operations
|
|
|
|
|
- AWS-LC: Returns error for PQC algorithms
|
|
|
|
|
- RustCrypto: Returns error for PQC algorithms
|
|
|
|
|
- OpenSSL: Classical algorithms work, PQC returns error
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Performance Characteristics
|
|
|
|
|
|
|
|
|
|
### ML-KEM-768
|
|
|
|
|
|
|
|
|
|
- **Key Generation**: ~0.1ms
|
|
|
|
|
- **Encapsulation**: ~0.1ms
|
|
|
|
|
- **Decapsulation**: ~0.1ms
|
|
|
|
|
|
|
|
|
|
### ML-DSA-65
|
|
|
|
|
|
|
|
|
|
- **Key Generation**: ~0.5ms
|
|
|
|
|
- **Signing**: ~1-3ms
|
|
|
|
|
- **Verification**: ~0.5-1ms
|
|
|
|
|
|
|
|
|
|
**Note**: Performance varies by hardware. These are approximate values on modern x86_64 processors.
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Security Considerations
|
|
|
|
|
|
|
|
|
|
### Key Lifetime
|
|
|
|
|
|
|
|
|
|
**Important**: OQS backend caches keys in-memory for session duration.
|
|
|
|
|
|
|
|
|
|
- ✅ **Safe**: Use keys immediately after generation
|
|
|
|
|
- ✅ **Safe**: Sign/encrypt/KEM within same session
|
|
|
|
|
- ❌ **Not Supported**: Serialize keys, restart vault, reload keys
|
|
|
|
|
|
|
|
|
|
**Mitigation**: For persistent keys, use Transit engine which manages key lifecycle.
|
|
|
|
|
|
|
|
|
|
### Quantum Resistance
|
|
|
|
|
|
|
|
|
|
**ML-KEM-768** and **ML-DSA-65** are NIST-approved post-quantum algorithms:
|
|
|
|
|
|
|
|
|
|
- Designed to resist attacks from quantum computers
|
|
|
|
|
- NIST Level 3 security (equivalent to AES-192)
|
|
|
|
|
- Based on lattice cryptography (CRYSTALS-Kyber and CRYSTALS-Dilithium)
|
|
|
|
|
|
|
|
|
|
### Hybrid Mode Rationale
|
|
|
|
|
|
|
|
|
|
**Defense-in-Depth**:
|
|
|
|
|
|
|
|
|
|
- If classical crypto breaks → PQC protects
|
|
|
|
|
- If PQC breaks (future attack) → classical crypto protects
|
|
|
|
|
- Both must break simultaneously for compromise
|
|
|
|
|
|
|
|
|
|
**Recommended for**: High-security production deployments.
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Migration Path
|
|
|
|
|
|
|
|
|
|
### From Classical to PQC
|
|
|
|
|
|
|
|
|
|
**Step 1**: Enable PQC feature
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
cargo build --release --features pqc
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**Step 2**: Update configuration
|
|
|
|
|
|
2025-12-22 21:34:01 +00:00
|
|
|
```toml
|
|
|
|
|
[vault]
|
2026-01-21 10:45:44 +00:00
|
|
|
crypto_backend = "oqs"
|
2025-12-22 21:34:01 +00:00
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
[crypto.oqs]
|
2025-12-22 21:34:01 +00:00
|
|
|
enable_pqc = true
|
2026-01-21 10:45:44 +00:00
|
|
|
hybrid_mode = true # Start with hybrid for compatibility
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**Step 3**: Create new PQC keys
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# Transit engine
|
|
|
|
|
POST /v1/transit/keys/pqc-key-1
|
|
|
|
|
{ "algorithm": "ML-KEM-768" }
|
|
|
|
|
|
|
|
|
|
# PKI engine
|
|
|
|
|
POST /v1/pki/root/generate
|
|
|
|
|
{ "key_type": "ML-DSA-65" }
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**Step 4**: Gradually migrate secrets
|
|
|
|
|
|
|
|
|
|
- New secrets use PQC keys
|
|
|
|
|
- Existing secrets continue using classical keys
|
|
|
|
|
- No breaking changes required
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Troubleshooting
|
|
|
|
|
|
|
|
|
|
### Error: "PQC algorithms require OQS backend"
|
|
|
|
|
|
|
|
|
|
**Cause**: Using AWS-LC, RustCrypto, or OpenSSL backend for PQC operations.
|
|
|
|
|
|
|
|
|
|
**Solution**: Change `crypto_backend = "oqs"` in configuration.
|
|
|
|
|
|
|
|
|
|
### Error: "Key not in cache - must use keys immediately"
|
|
|
|
|
|
|
|
|
|
**Cause**: Attempting to use keys after session restart or from different vault instance.
|
|
|
|
|
|
|
|
|
|
**Solution**: Use Transit engine for persistent key management.
|
|
|
|
|
|
|
|
|
|
### Build Error: "liboqs not found"
|
|
|
|
|
|
|
|
|
|
**Cause**: Missing liboqs C library.
|
|
|
|
|
|
|
|
|
|
**Solution**:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# macOS
|
|
|
|
|
brew install liboqs
|
|
|
|
|
|
|
|
|
|
# Ubuntu/Debian
|
|
|
|
|
apt-get install liboqs-dev
|
|
|
|
|
|
|
|
|
|
# Or let cargo build it automatically (requires cmake)
|
|
|
|
|
cargo build --features pqc
|
2025-12-22 21:34:01 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
## Implementation Architecture
|
|
|
|
|
|
|
|
|
|
### Wrapper Structs
|
|
|
|
|
|
|
|
|
|
**Purpose**: Type-safe containers for OQS FFI types.
|
|
|
|
|
|
|
|
|
|
```rust
|
|
|
|
|
struct OqsKemKeyPair {
|
|
|
|
|
public: oqs::kem::PublicKey,
|
|
|
|
|
secret: oqs::kem::SecretKey,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct OqsSigKeyPair {
|
|
|
|
|
public: oqs::sig::PublicKey,
|
|
|
|
|
secret: oqs::sig::SecretKey,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct OqsSignatureWrapper {
|
|
|
|
|
signature: oqs::sig::Signature,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct OqsCiphertextWrapper {
|
|
|
|
|
ciphertext: oqs::kem::Ciphertext,
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**Benefits**:
|
|
|
|
|
|
|
|
|
|
- Type safety (can't mix KEM and signature types)
|
|
|
|
|
- Clear structure vs anonymous tuples
|
|
|
|
|
- Zero-cost abstraction (compiled away)
|
|
|
|
|
- Extensible (easy to add metadata fields)
|
|
|
|
|
|
|
|
|
|
### Caching Strategy
|
2025-12-22 21:34:01 +00:00
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
**Cache Types**:
|
|
|
|
|
|
|
|
|
|
```rust
|
|
|
|
|
type OqsKemCache = Arc<Mutex<HashMap<Vec<u8>, OqsKemKeyPair>>>;
|
|
|
|
|
type OqsSigCache = Arc<Mutex<HashMap<Vec<u8>, OqsSigKeyPair>>>;
|
|
|
|
|
```
|
2025-12-22 21:34:01 +00:00
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
**Key**: Byte representation of public key
|
2025-12-22 21:34:01 +00:00
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
**Value**: Wrapper struct containing OQS FFI types
|
|
|
|
|
|
|
|
|
|
**Rationale**: OQS types wrap C FFI pointers that can't be reconstructed from bytes alone.
|
2025-12-22 21:34:01 +00:00
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Related Documentation
|
|
|
|
|
|
2026-01-21 10:45:44 +00:00
|
|
|
- [Build Features](build-features.md) - Feature flags and compilation
|
|
|
|
|
- [Configuration Reference](../user-guide/configuration.md) - Full configuration guide
|
|
|
|
|
- [Architecture Overview](../architecture/overview.md) - System architecture
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Changelog
|
|
|
|
|
|
|
|
|
|
### 2026-01-17 - Real PQC Implementation
|
|
|
|
|
|
|
|
|
|
- ✅ Added OQS backend with real ML-KEM-768 and ML-DSA-65
|
|
|
|
|
- ✅ Removed fake PQC from AWS-LC and RustCrypto backends
|
|
|
|
|
- ✅ Implemented hybrid mode (classical + PQC)
|
|
|
|
|
- ✅ Added wrapper structs for type safety
|
|
|
|
|
- ✅ Integrated PQC into Transit and PKI engines
|
|
|
|
|
- ✅ Added comprehensive integration tests
|
|
|
|
|
- ✅ 141 tests passing (132 unit + 9 integration)
|