Metadata-Version: 2.4
Name: mldsa
Version: 1.0.1
Summary: ML-DSA (FIPS 204) post-quantum signature verification (pure Python, no dependencies)
Author: Filippo Valsorda
License-Expression: CC0-1.0 OR 0BSD
License-File: LICENSE
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Topic :: Security :: Cryptography
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Typing :: Typed
Requires-Python: >=3.8
Project-URL: Homepage, https://github.com/FiloSottile/mldsa-py
Project-URL: Source, https://github.com/FiloSottile/mldsa-py
Project-URL: Issues, https://github.com/FiloSottile/mldsa-py/issues
Description-Content-Type: text/markdown

# 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.

```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.

```python
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](https://github.com/FiloSottile/mldsa-py/blob/main/src/mldsa/mldsa.py)
of less than 500 lines, with no dependencies.

It works with Python 3.8 and later.

<img width="1352" height="696" alt="mldsa-minimap-3col" src="https://github.com/user-attachments/assets/345f5e0f-2f97-478c-9a8d-5d1ad552dbaf" />

## Development

To run tests, use

```bash
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](https://github.com/C2SP/wycheproof).

To run benchmarks, use

```bash
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

```bash
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](https://creativecommons.org/publicdomain/zero/1.0/).

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.
