Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mldsa-py

pip install mldsa

This is a pure-Python production implementation of ML-DSA (FIPS 204) post-quantum signature verification.

It does not provide key or signature generation, because secrets can't be handled in constant-time in Python.

from mldsa import VerificationKey, VerificationError

vk = VerificationKey(verification_key_bytes)

try:
    vk.verify(signature, message)
except VerificationError:
    print("invalid signature!")

The parameter set (ML-DSA-44, ML-DSA-65, or ML-DSA-87) is inferred from the verification key size, or it can be specified explicitly.

from mldsa import ParameterSet, VerificationKey

vk = VerificationKey(verification_key_bytes, parameters=ParameterSet.ML_DSA_87)
vk.verify(signature, message, context=b"example.com/foo token")

The non-test code is a single-file module of less than 500 lines, with no dependencies.

It works with Python 3.8 and later.

mldsa-minimap-3col

Development

To run tests, use

uv run ruff check
uv run ruff format --check
uv run ty check
uv run pytest
go install github.com/FiloSottile/mostly-harmless/muzoo@latest
muzoo -mutations tests/testdata/mutations test -- uv run pytest -x

This project uses tests from Wycheproof.

To run benchmarks, use

uv run tests/bench_mldsa.py

The output is in the format of Go benchmarks, and matches the sub-benchmarks of BenchmarkVerify in crypto/mldsa, so the two can be compared with

go test -run=^$ -bench=BenchmarkVerify -cpu=1 -count=10 crypto/mldsa | tee go.txt
uv run tests/bench_mldsa.py -count=10 | tee py.txt
benchstat -ignore=goos,goarch,pkg,cpu go.txt py.txt

License

This work is marked CC0 1.0 Universal. To view a copy of this mark, visit creativecommons.org.

Alternatively, you may use this source code under the terms of the 0BSD license that can be found in the LICENSE file. In short, you can do whatever you want with this code.

About

Pure-Python ML-DSA (FIPS 204) signature verification. Python 3.8+, zero dependencies, public domain, single file, 350 lines.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

19 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages