A Python implementation of the ML-KEM (Kyber-based Module-Lattice Key Encapsulation Mechanism) algorithm as standardized in NIST FIPS 203.
- Complete ML-KEM Implementation: All three variants (512, 768, 1024) following official NIST FIPS 203 specification
- Secure Messaging CLI: Real-time encrypted chat using ML-KEM for key exchange and AES-GCM for message encryption
- Performance Tools: Comprehensive benchmarking and correctness/CCA-resistance verification
- Modular Design: Clean separation of KEM operations, PKE primitives, and utility functions
git clone https://github.com/Preterno/ml-kem.git
cd ml-kem
pip install -r requirements.txt
python test.py # Verify installation- Python 3.8 or higher
- Dependencies listed in
requirements.txt
git clone https://github.com/Preterno/ml-kem.git
cd ml-kem
pip install -r requirements.txtfrom pke.params import ML_KEM_512, ML_KEM_768, ML_KEM_1024
from kem.keygen import ml_kem_keygen
from kem.encapsulate import ml_kem_encaps
from kem.decapsulate import ml_kem_decaps
# Choose ML-KEM variant
params = ML_KEM_768
# Generate key pair
ek, dk = ml_kem_keygen(params) # ek = encapsulation key, dk = decapsulation key
# Encapsulate (sender side)
K, ct = ml_kem_encaps(ek, params) # K = shared secret, ct = ciphertext
# Decapsulate (receiver side)
K_prime = ml_kem_decaps(dk, ct, params)
assert K == K_prime # Shared secrets should matchTo verify correctness and CCA security:
python test.pyTo measure performance of ML-KEM operations:
python benchmark_mlkem.pyLaunch the encrypted chat application:
- Start the server:
python chat/server.py- Connect with client:
python chat/client.pyThe client and server perform ML-KEM-768 key exchange and use AES-GCM for encrypted messaging.
.
├── kem/ # ML-KEM logic (keygen, encaps, decaps)
├── pke/ # Kyber PKE primitives
├── utils/ # Support utilities (hashing, polynomials, etc.)
├── chat/ # CLI chat app using ML-KEM + AES
├── benchmark_mlkem.py
├── test.py
├── requirements.txt
| Variant | KeyGen | Encaps | Decaps | Full Cycle | Public Key Size |
|---|---|---|---|---|---|
| ML-KEM-512 | 13.13 ms | 15.20 ms | 40.00 ms | 53.04 ms | 800 bytes |
| ML-KEM-768 | 19.57 ms | 22.85 ms | 59.28 ms | 78.63 ms | 1,184 bytes |
| ML-KEM-1024 | 28.00 ms | 32.68 ms | 84.03 ms | 115.77 ms | 1,568 bytes |
| Variant | KeyGen | Encaps | Decaps | Full Cycle |
|---|---|---|---|---|
| ML-KEM-512 | 76.2 ops/sec | 65.8 ops/sec | 25.0 ops/sec | 18.9 ops/sec |
| ML-KEM-768 | 51.1 ops/sec | 43.8 ops/sec | 16.9 ops/sec | 12.7 ops/sec |
| ML-KEM-1024 | 35.7 ops/sec | 30.6 ops/sec | 11.9 ops/sec | 8.6 ops/sec |
Note: Benchmarks may vary depending on hardware and system configuration. Run
python benchmark_mlkem.pyfor your specific environment.
This project is for educational and research use only. It has not undergone security audits and is not intended for production or security-critical deployments.