pq-msg

🔒 Overview
A Rust crate that combines multiple post-quantum cryptographic techniques to facilitate quantum-resistant end-to-end encrypted messaging. pq-msg serves as an abstraction layer over various cryptographic schemes to provide a comprehensive solution for secure communication in a post-quantum world.
🛠️ Cryptographic Foundation
| Component |
Implementation |
Purpose |
| Key Exchange |
ML-KEM (FIPS 203) |
Quantum-resistant key establishment |
| Symmetric Encryption |
XChaCha20Poly1305 |
Fast and secure data encryption |
| Message Authentication |
Falcon (FN-DSA, FIPS 206) |
Quantum-resistant digital signatures |
⚙️ Usage
use pq_msg::{
exchange::pair::KEMPair, messaging::MessageSession, messaging::create_nonce,
messaging::gen_session_id, signatures::keypair::SignerPair,
};
fn main() {
let alice_kem = KEMPair::create();
let alice_signer = SignerPair::create();
let bob_kem = KEMPair::create();
let bob_signer = SignerPair::create();
let base_nonce = create_nonce(&gen_session_id(), 0);
let (mut alice_session, ciphertext) = MessageSession::new_initiator(
alice_kem,
alice_signer.clone(),
base_nonce,
&bob_kem.to_bytes().unwrap().0, &bob_signer.to_bytes().unwrap().0, )
.unwrap();
let mut bob_session = MessageSession::new_responder(
bob_kem,
bob_signer.clone(),
base_nonce,
&ciphertext,
&alice_signer.to_bytes().unwrap().0, )
.unwrap();
let message = b"Hello, Bob! This is a secret message.";
let encrypted_message = alice_session.craft_message(message).unwrap();
let raw_message = bob_session.validate_message(&encrypted_message).unwrap();
let message_str = String::from_utf8_lossy(message);
let raw_message_str = String::from_utf8_lossy(&raw_message);
println!("[1] Alice's message: {}", message_str);
println!("[2] Bob's decrypted message: {}", raw_message_str);
let reply = b"Hello, Alice! I received your message safely.";
let encrypted_reply = bob_session.craft_message(reply).unwrap();
let raw_reply = alice_session.validate_message(&encrypted_reply).unwrap();
let reply_str = String::from_utf8_lossy(reply);
let raw_reply_str = String::from_utf8_lossy(&raw_reply);
println!("[3] Bob's reply: {}", reply_str);
println!("[4] Alice's decrypted reply: {}", raw_reply_str);
}
Run this example with:
cargo run --exampel full_exchange
⚠️ Important Notice
This library is currently in development and should be considered experimental.
Some of the cryptographic packages used have not been independently audited, and certain components are awaiting final standardization by NIST. Please refrain from using this in production environments and consider it for educational and research purposes until further notice.
📚 Documentation
For full documentation and examples, please visit docs.rs/pq-msg.
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📝 License
This project is licensed under the MIT/Apache-2.0 dual license.