latticearc
Post-quantum cryptography library for Rust with unified API.
Why LatticeArc?
| Manual Implementation | LatticeArc |
|---|---|
| ~50 lines for hybrid signing | 2 lines |
| Manage 4 separate key vectors | Single SignedData struct |
| Research NIST parameter sets | UseCase::* auto-selects |
| Manual memory zeroization | Automatic via Zeroize |
Overview
LatticeArc provides post-quantum cryptographic primitives implementing NIST FIPS 203-206 standards:
- ML-KEM (FIPS 203) - Key encapsulation
- ML-DSA (FIPS 204) - Digital signatures
- SLH-DSA (FIPS 205) - Hash-based signatures
- FN-DSA (FIPS 206) - Lattice signatures
- Hybrid encryption - PQC + classical for defense-in-depth
- TLS 1.3 - Post-quantum TLS integration
Unified API
LatticeArc uses a consistent builder pattern across all APIs:
// Crypto operations use CryptoConfig
new
.use_case
.session
// TLS configuration uses TlsConfig
new
.use_case
.with_fallback
Both APIs share the same intuitive pattern:
::new()creates defaults.use_case()selects algorithm by scenario.security_level()selects algorithm by security level
Quick Start
Add to your Cargo.toml:
[]
= "0.4"
Digital Signatures
use ;
// Generate signing keypair (defaults: ML-DSA-65 + Ed25519)
let config = new;
let = generate_signing_keypair?;
// Sign
let signed = sign_with_key?;
// Verify
let is_valid = verify?;
Encryption
use ;
let key = ; // 256-bit key
let config = new.force_scheme;
let encrypted = encrypt?;
let decrypted = decrypt?;
With Use Case Selection
use ;
// Library auto-selects optimal algorithm
let config = new.use_case;
let = generate_signing_keypair?;
let signed = sign_with_key?;
With Security Level
use ;
// Maximum security (ML-DSA-87 + Ed25519)
let config = new.security_level;
let = generate_signing_keypair?;
let signed = sign_with_key?;
Key Generation
use generate_keypair;
// Generate Ed25519 keypair
let = generate_keypair?;
Hybrid Encryption
use ;
// Generate hybrid keypair (ML-KEM-768 + X25519)
let = generate_hybrid_keypair?;
// Encrypt using hybrid KEM (ML-KEM + X25519 + HKDF + AES-256-GCM)
let encrypted = encrypt?;
// Decrypt
let plaintext = decrypt?;
Hybrid Signatures
use ;
// Generate hybrid signing keypair (ML-DSA-65 + Ed25519)
let = generate_hybrid_signing_keypair?;
// Sign (both ML-DSA and Ed25519)
let signature = sign_hybrid?;
// Verify (both must pass)
let valid = verify_hybrid_signature?;
With Zero Trust Session
For high-security environments with session-based verification:
use ;
// Establish verified session
let = generate_keypair?;
let session = establish?;
// Operations with session verification
let config = new.session;
let = generate_signing_keypair?;
let signed = sign_with_key?;
let is_valid = verify?;
Post-Quantum TLS
Native PQ key exchange via rustls 0.23.37+ (no extra dependencies):
use ;
use SecurityLevel;
// Default: Hybrid mode (X25519MLKEM768 with X25519 fallback)
let config = new;
// By use case
let config = new.use_case;
// By security level
let config = new.security_level;
Available key exchange groups: X25519MLKEM768 (hybrid, default), SECP256R1MLKEM768 (hybrid), MLKEM768 (PQ-only), MLKEM1024 (PQ-only), X25519 (classical fallback).
Low-Level Primitives
For direct access to NIST algorithms:
use ;
use OsRng;
let mut rng = OsRng;
let = generate_keypair?;
let = encapsulate?;
let recovered = decapsulate?;
Included Features
All features are included by default:
- Post-quantum KEM (ML-KEM-512/768/1024)
- Post-quantum signatures (ML-DSA, SLH-DSA, FN-DSA)
- Hybrid encryption (PQC + classical)
- Zero-knowledge proofs (Schnorr, Pedersen)
- TLS 1.3 integration
- Use case-based scheme selection
- Portable key format (JSON + CBOR) with UseCase/SecurityLevel-first design
Key Serialization
Keys are serialized using the LatticeArc Portable Key (LPK) format — dual JSON + CBOR
encoding identified by use case or security level. See docs/KEY_FORMAT.md.
use ;
// Generate → wrap → serialize → deserialize → use
let = generate_hybrid_keypair?;
let =
from_hybrid_kem_keypair?;
// JSON for files/REST, CBOR for wire/storage
let json = portable_pk.to_json?;
let cbor = portable_pk.to_cbor?;
// Reconstruct for crypto operations
let restored_pk = from_json?.to_hybrid_public_key?;
Algorithm Selection
By Use Case
| Use Case | Encryption | Signatures |
|---|---|---|
SecureMessaging |
ML-KEM-768 + AES-256-GCM | ML-DSA-65 + Ed25519 |
FileStorage |
ML-KEM-1024 + AES-256-GCM | ML-DSA-87 + Ed25519 |
FinancialTransactions |
ML-KEM-768 + AES-256-GCM | ML-DSA-65 + Ed25519 |
IoTDevice |
ML-KEM-512 + AES-256-GCM | ML-DSA-44 + Ed25519 |
By Security Level
| Level | Mode | Encryption | Signatures |
|---|---|---|---|
Quantum |
PQ-only | ML-KEM-1024 + AES-256-GCM | ML-DSA-87 |
Maximum |
Hybrid | ML-KEM-1024 + AES-256-GCM | ML-DSA-87 + Ed25519 |
High (default) |
Hybrid | ML-KEM-768 + AES-256-GCM | ML-DSA-65 + Ed25519 |
Standard |
Hybrid | ML-KEM-512 + AES-256-GCM | ML-DSA-44 + Ed25519 |
For complete security level documentation, see the API Reference.
Runnable Examples
The latticearc crate includes comprehensive examples:
basic_encryption.rs- Simple symmetric encryption with AES-256-GCMdigital_signatures.rs- Digital signatures with ML-DSA and hybrid modeshybrid_encryption.rs- Hybrid encryption (ML-KEM + X25519 + HKDF)post_quantum_signatures.rs- Post-quantum signature schemescomplete_secure_workflow.rs- End-to-end secure workflow with Zero Trustzero_knowledge_proofs.rs- Zero-knowledge proof demonstrations
Run an example with:
Security
- No unsafe code
- Constant-time operations
- Automatic secret zeroization
- CAVP test vector validation
Documentation
License
Apache-2.0
Contributing
See CONTRIBUTING.md in the repository root.