Skip to main content

ML-DSA (FIPS 204) post-quantum signature verification (pure Python, no dependencies)

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mldsa-1.0.1.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mldsa-1.0.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file mldsa-1.0.1.tar.gz.

File metadata

  • Download URL: mldsa-1.0.1.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for mldsa-1.0.1.tar.gz
Algorithm Hash digest
SHA256 005a296d138448d9210a1f36bdc3190d30a19595f1bbf2b92aa537049d797a31
MD5 0e6b91df82e178666adce7f0c938df5d
BLAKE2b-256 029c252742c41fb96632e42d17ee790de522c628bc6b7124a3d1d9672950a3e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for mldsa-1.0.1.tar.gz:

Publisher: publish-to-pypi.yml on FiloSottile/mldsa-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mldsa-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: mldsa-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for mldsa-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cad0a75124c5a6f4c1efe0e013039e9b0a1a86a9bb8ec5a75d6cf71a45ce08f9
MD5 a4cf1ac172c8b44e35dbfd9f5e34c5da
BLAKE2b-256 ee1247c2ce5d1c133fbdb50d24c8fc10cd7a5f4000a6f57888565514051a97fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for mldsa-1.0.1-py3-none-any.whl:

Publisher: publish-to-pypi.yml on FiloSottile/mldsa-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page