Python bindings for post-quantum cryptography. Wraps well-tested Rust implementations of NIST-standardized and candidate KEM and signature schemes via PyO3/maturin. All variants live in a single compiled wheel.
pip install pqcryptoOr build from source:
pip install maturin pytest
maturin developThe Python API mirrors the Rust crate design: keygen, encaps, decaps
(KEM) and keygen, sign, verify (signatures).
from pqcrypto.kem.ml_kem_512 import keygen, encaps, decaps
from pqcrypto.kem.ml_kem_512 import PublicKey, SecretKey
pk, sk = keygen()
ct, ss = encaps(pk)
assert decaps(sk, ct) == ss
pk_obj = PublicKey(pk)
sk_obj = SecretKey(sk)
ct2, ss2 = pk_obj.encaps()
assert ss2 == sk_obj.decaps(ct2)from pqcrypto.sign.ml_dsa_44 import keygen, sign, verify
from pqcrypto.sign.ml_dsa_44 import PublicKey, SecretKey
pk, sk = keygen()
sig = sign(sk, b"message")
verify(pk, b"message", sig) # returns None; raises InvalidSignatureError if invalid
# FIPS 204/205 context string:
sig = sign(sk, b"message", b"my-context")
verify(pk, b"message", sig, b"my-context")
# HashML-DSA / HashSLH-DSA pre-hash mode:
from pqcrypto import HashAlgorithm
sig = sign(sk, b"message", hash_algorithm=HashAlgorithm.Sha256)
verify(pk, b"message", sig, hash_algorithm=HashAlgorithm.Sha256)
pk_obj = PublicKey(pk)
sk_obj = SecretKey(sk)
sig_obj = sk_obj.sign(b"message")
pk_obj.verify(b"message", sig_obj)from pqcrypto.kem.ml_kem_512 import PUBLIC_KEY_SIZE, SECRET_KEY_SIZE, CIPHERTEXT_SIZE, SHARED_SECRET_SIZE
from pqcrypto.sign.ml_dsa_44 import PUBLIC_KEY_SIZE, SECRET_KEY_SIZE, SIGNATURE_SIZEModules live in pqcrypto.kem (KEM) and pqcrypto.sign (signatures).
- ML-KEM (FIPS 203)
ml_kem_512,ml_kem_768,ml_kem_1024
- Classic McEliece
mceliece_348864mceliece_348864fmceliece_460896mceliece_460896fmceliece_6688128mceliece_6688128fmceliece_6960119mceliece_6960119fmceliece_8192128mceliece_8192128f
- SNTRUP
sntrup_653sntrup_761sntrup_857sntrup_953sntrup_1013sntrup_1277
- HQC (FIPS 207)
hqc_128,hqc_192,hqc_256
- ML-DSA (FIPS 204)
ml_dsa_44,ml_dsa_65,ml_dsa_87
- SLH-DSA (FIPS 205)
slh_dsa_sha2_128sslh_dsa_sha2_128fslh_dsa_sha2_192sslh_dsa_sha2_192fslh_dsa_sha2_256sslh_dsa_sha2_256fslh_dsa_shake_128sslh_dsa_shake_128fslh_dsa_shake_192sslh_dsa_shake_192fslh_dsa_shake_256sslh_dsa_shake_256f
The cryptographic implementations are provided by the backbone crates. These crates have not undergone a formal security audit; third-party review is recommended before production use. This Python wrapper is a thin shim — it validates key lengths, maps errors to Python exceptions, and provides idiomatic key objects.
Apache-2.0. See LICENSE.
