A pure Python implementation of ML-KEM (FIPS 203), built to understand the underlying mathematics and cryptography.
Validated against ACVP and C2SP test vectors for all three parameter sets (ML-KEM-512, ML-KEM-768, ML-KEM-1024).
Caution
This project is for educational purposes only. It is not hardened, not audited, and must not be used in real cryptographic applications.
git clone https://github.com/valentinfrm/pyber.git
cd pyber
uv synckeygen(): generate a keypair (ek, dk)keygen_checked(): generate a keypair (ek, dk) with fault attack resistanceencaps(ek): generate a key and ciphertext pair (key, c)decaps(dk, c): generate the symmetric key
from pyber.kem import keygen, keygen_checked, encaps, decaps
# Key generation (use keygen_checked() for fault attack resistance)
public_key, private_key = keygen()
# Encapsulation
symmetric_key, ciphertext = encaps(public_key)
# Decapsulation
symmetric_key_dec = decaps(private_key, ciphertext)
assert symmetric_key == symmetric_key_decFastest observed runtime over 20 runs on APPLE m1:
- FIPS 203 - ML-KEM Standard — NIST
- Kyber and Dilithium — Alfred Menezes, University of Waterloo
- Conceptual Review on Number Theoretic Transform and Comprehensive Review on Its Implementations
- kyber-py
