Python bindings for leanXMSS and leanSPHINCS post-quantum signatures and their leanVM aggregation
Actively maintained. Last release 4 days ago, commits in 23 of the last 26 weeks. A safe choice.
pip install py-lean-pqREADME as published on PyPI with version 0.19.2.
py-lean-pq
Python bindings for the leanXMSS and leanSPHINCS post-quantum signatures, their aggregation into one proof, and the consensus VRF tree.
Install
pip install py-lean-pq==0.19.2
Python 3.11 or newer. Wheels for Linux x86_64 and aarch64 (glibc, musl), macOS arm64 and Windows x86_64; x86_64 needs AVX2 and PCLMULQDQ.
Sign and verify
import py_lean_pq as lpq
message = b"\x42" * 32
xmss_key = lpq.XmssSecretKey.from_seed(b"\x01" * 32) # or XmssSecretKey.generate()
xmss_sig = xmss_key.sign(message, 7) # at leaf index 7
lpq.xmss_verify(xmss_key.public_key, message, xmss_sig) # raises LeanPqError if invalid
sphincs_key = lpq.SphincsSecretKey.from_seed(b"\x02" * 32)
sphincs_sig = sphincs_key.sign(message)
lpq.sphincs_verify(sphincs_key.public_key, message, sphincs_sig)
- Public keys and messages are 32 bytes; signatures are 2404 (leanXMSS) or 7740 (leanSPHINCS) bytes.
- leanXMSS is stateful: a key has
2^32leaf indices, and must never sign two messages at the same one. Persist a high-water leaf index next to the key and advance it before publishing a signature.prepare(leaf_index)builds a leaf's signing state ahead of time, andset_bottom_tree_cache_size(size)sets how many recently used bottom trees the key keeps, 8 by default. - leanSPHINCS is stateless and deterministic; a key signs at most
2^30messages. to_bytes()is the key's 32-byte seed, which is secret;from_bytesrestores the key.cache_to_bytes()returns the key's trees, which are not secret;XmssSecretKey.from_cache_bytes(seed, public_key, cache)loads the key from them instead of rebuilding them, checking them against the public key.- Failures raise
LeanPqError, inputs of the wrong lengthValueError. Every call that signs, verifies or aggregates releases the GIL.
Aggregate
leaf = lpq.aggregate(
xmss=[(xmss_key.public_key, message, xmss_sig)],
sphincs=[(sphincs_key.public_key, message, sphincs_sig)],
)
root = lpq.aggregate(children=[leaf])
proof = root.to_bytes()
received = lpq.Aggregate.from_bytes(proof, root.xmss_claims, root.sphincs_claims)
- verifies raw signatures before proving and takes at most 16 children. The result proves the union of their claims, or with or exactly those claims, in any order, each one the inputs cover; an omitted list means none.