A Post-Quantum Cryptography (PQC) enabled fork of libp2p-identity that provides quantum-resistant cryptographic identity support for libp2p networks.
- π‘οΈ Post-Quantum Security: Supports ML-DSA-87 (Dilithium Level 5) signatures
- π Multi-Algorithm Support: Ed25519, RSA, ECDSA, Secp256k1, and Dilithium
- π Drop-in Replacement: Compatible with existing libp2p-identity APIs
- π¦ Protocol Buffer Support: Seamless serialization/deserialization
- π― Peer ID Generation: Quantum-resistant peer identification
- π Comprehensive Logging: Emoji-enhanced debug logging for key operations
Add to your Cargo.toml:
[dependencies]
libp2p-identity = { package = "libp2p-identity", path = "../libp2p-identity-pqc" }
# or from git
libp2p-identity = { git = "https://github.com/Quantus-Network/libp2p-identity-pqc", package = "libp2p-identity" }use libp2p_identity::{Keypair, KeyType};
// Generate a quantum-resistant keypair
let keypair = Keypair::generate_dilithium();
println!("Generated keypair: {:?}", keypair.key_type());
// Sign a message
let message = b"Hello, Post-Quantum World!";
let signature = keypair.sign(message)?;
// Verify signature
let public_key = keypair.public();
let is_valid = public_key.verify(message, &signature);
assert!(is_valid);
// Generate PeerId
let peer_id = public_key.to_peer_id();
println!("Peer ID: {}", peer_id);| Algorithm | Emoji | Security Level | Quantum Resistant |
|---|---|---|---|
| Dilithium | π‘οΈ | Level 5 | β YES |
| Ed25519 | π | Classical | β No |
| RSA | ποΈ | Classical | β No |
| ECDSA | π | Classical | β No |
| Secp256k1 | π | Classical | β No |
This crate implements ML-DSA-87 (the NIST-standardized version of Dilithium Level 5), providing:
- Security Level: Equivalent to AES-256
- Signature Size: ~4,627 bytes
- Public Key Size: ~2,592 bytes
- Quantum Resistance: Secure against both classical and quantum attacks
With the advent of quantum computers, traditional cryptographic algorithms (RSA, ECDSA, etc.) will become vulnerable. Post-quantum cryptography provides security against both classical and quantum attacks, ensuring long-term security for your libp2p networks.
// Post-Quantum (recommended for new applications)
let pq_keypair = Keypair::generate_dilithium();
// Classical algorithms (for compatibility)
let ed25519_keypair = Keypair::generate_ed25519();
let ecdsa_keypair = Keypair::generate_ecdsa();
let secp256k1_keypair = Keypair::generate_secp256k1();// Load from bytes
let keypair = Keypair::ed25519_from_bytes(secret_bytes)?;
// Load RSA from PKCS8
let rsa_keypair = Keypair::rsa_from_pkcs8(&mut pkcs8_der)?;
// Load Secp256k1 from DER
let secp_keypair = Keypair::secp256k1_from_der(&mut der_bytes)?;// Encode keypair
let encoded = keypair.to_protobuf_encoding()?;
// Decode keypair
let decoded = Keypair::from_protobuf_encoding(&encoded)?;
// Encode public key
let pub_encoded = public_key.encode_protobuf();
// Decode public key
let pub_decoded = PublicKey::try_decode_protobuf(&pub_encoded)?;match keypair.key_type() {
KeyType::Dilithium => println!("π‘οΈ Quantum-resistant!"),
KeyType::Ed25519 => println!("π Classical Ed25519"),
KeyType::RSA => println!("ποΈ Classical RSA"),
KeyType::Ecdsa => println!("π Classical ECDSA"),
KeyType::Secp256k1 => println!("π Classical Secp256k1"),
}| Feature | Description | Default |
|---|---|---|
dilithium |
Post-Quantum Dilithium signatures | β |
ed25519 |
Ed25519 signatures | β |
rsa |
RSA signatures | β |
ecdsa |
ECDSA signatures | β |
secp256k1 |
Secp256k1 signatures | β |
peerid |
PeerId generation support | β |
rand |
Random key generation | β |
[dependencies]
libp2p-identity = {
package = "libp2p-identity",
path = "../libp2p-identity-pqc",
default-features = false,
features = ["dilithium", "ed25519", "peerid"]
}Run the test suite:
# All tests
cargo test
# Dilithium-specific tests
cargo test --test dilithium_test
# With logging (using the log crate)
RUST_LOG=libp2p-identity=debug cargo test -- --nocaptureComprehensive benchmarks are available to compare Dilithium performance with classical algorithms:
# Run all crypto benchmarks
cargo bench --bench crypto_operations
# Run specific benchmark groups
cargo bench --bench crypto_operations -- key_generation
cargo bench --bench crypto_operations -- signing
cargo bench --bench crypto_operations -- verification
cargo bench --bench crypto_operations -- dilithium_throughput
# Run PeerId benchmarks
cargo bench --bench peer_idπ For detailed benchmark results and analysis, see BENCHMARKS.md
| Operation | Dilithium π‘οΈ | Ed25519 π | ECDSA π | Notes |
|---|---|---|---|---|
| Key Generation | ~1-2ms | ~50ΞΌs | ~100ΞΌs | PQC has higher overhead |
| Signing | ~200-500ΞΌs | ~10-20ΞΌs | ~50-100ΞΌs | PQC optimized for security |
| Verification | ~100-200ΞΌs | ~30-50ΞΌs | ~200-300ΞΌs | PQC comparable to ECDSA |
| Signature Size | ~4,627 bytes | 64 bytes | ~71 bytes | PQC signatures are larger |
| Public Key Size | ~2,592 bytes | 32 bytes | ~33 bytes | PQC keys are larger |
The benchmark suite includes:
- π Key Generation: Time to generate new keypairs
- βοΈ Signing: Time to sign messages of various sizes
- β Verification: Time to verify signatures
- π Throughput: Operations per second for different message sizes
- π¦ Serialization: Protobuf encoding/decoding performance
- π PeerId Generation: Time to generate peer identifiers
- πΎ Memory Usage: Relative memory footprint comparison
Dilithium Advantages:
- β Quantum-resistant security
- β Strong mathematical foundation
- β NIST standardized (ML-DSA-87)
- β Reasonable verification performance
Dilithium Considerations:
β οΈ Larger signature and key sizesβ οΈ Higher computational overhead for key generationβ οΈ Slower signing compared to classical algorithms
- Replace the dependency in
Cargo.toml - No code changes required - it's a drop-in replacement
- Optionally start using Dilithium for new keypairs
// Support both classical and post-quantum
fn create_keypair(use_pqc: bool) -> Keypair {
if use_pqc {
Keypair::generate_dilithium() // π‘οΈ Quantum-resistant
} else {
Keypair::generate_ed25519() // π Classical
}
}- Algorithm: ML-DSA-87 (NIST FIPS 204)
- Implementation:
rusty-crystals-dilithium - Security: NIST Level 5 (256-bit quantum security)
- Key Sizes:
- Private: 4,896 bytes
- Public: 2,592 bytes
- Signature: ~4,627 bytes
Contributions are welcome! Please ensure:
- All tests pass:
cargo test - Code is formatted:
cargo fmt - No clippy warnings:
cargo clippy - Documentation is updated
Licensed under the MIT License. See LICENSE for details.
- Based on the original
libp2p-identitycrate - Post-quantum cryptography implementation via
rusty-crystals-dilithium - NIST for standardizing ML-DSA (Dilithium)
- NIST Post-Quantum Cryptography
- ML-DSA Standard (FIPS 204)
- libp2p Specifications
- Quantum Computing Threat Timeline
π‘οΈ Secure your libp2p networks against the quantum future! π‘οΈ