fips204 Python module
This Python module provides an implementation of FIPS 204, the Module-Lattice-based Digital Signature Standard.
The underlying mechanism is intended to offer "post-quantum" data integrity, authenticity, and non-repudiation.
Example
The following example shows using the standard ML-DSA algorithm to sign a message:
from fips204 import ML_DSA_65
(public_key, private_key) = ML_DSA_65.keygen()
message = b"this is a test"
context = b""
sig = private_key.sign(message, context)
assert(public_key.verify(sig, message, context))
Key generation can also be done deterministically, by passing a
SEED_SIZE-byte seed to keygen:
from fips204 import ML_DSA_65, Seed
seed1 = Seed() # Generate a random seed
(pub, priv) = ML_DSA_65.keygen(seed1)
seed2 = Seed(b'\x00'*ML_DSA_65.SEED_SIZE) # This seed is clearly not a secret!
(pub, priv) = ML_DSA_65.keygen(seed2)
public keys, private keys, and seeds can all
be serialized by accessing them as bytes, and deserialized by
initializing them with the appropriate size bytes object.
A signature itself is already just a bytes object.
A serialization example:
from fips204 import ML_DSA_65, Seed
seed = Seed()
(pub,priv) = ML_DSA_65.keygen(seed)
with open('pub.bin', 'wb') as f:
f.write(bytes(pub))
with open('priv.bin', 'wb') as f:
f.write(bytes(priv))
with open('seed.bin', 'wb') as f:
f.write(bytes(seed))
A deserialization example, followed by use:
import fips204
with open('priv.bin', 'rb') as f:
privdata = f.read()
context = b'abc'
priv = fips204.PrivateKey(privdata)
with open('msg', 'rb') as m:
with open ('msg.sig', 'wb') as s:
s.write(priv.sign(m.read(), context))
The expected sizes (in bytes) of the different objects in each
parameter set can be accessed with PUBKEY_SIZE, PRIVKEY_SIZE, SIG_SIZE,
SEED_SIZE:
from fips204 import ML_DSA_65
print(f"ML-DSA-65 Signature size (in bytes) is {ML_DSA_65.SIG_SIZE}")
Implementation Notes
This is a wrapper around libfips204, built from the Rust fips204-ffi crate.
If that library is not installed in the expected path for libraries on
your system, importing this module will fail. For in-tree tests, set
FIPS204_PYTHON_TESTING_LIBRARY to the built libfips204.so (libfips204.dylib on macOS).
On macOS, Python searches DYLD_LIBRARY_PATH, then ~/lib, /usr/local/lib, /lib and
/usr/lib, so a library installed elsewhere, such as MacPorts' /opt/local/lib or
Homebrew's /opt/homebrew/lib, also needs FIPS204_PYTHON_TESTING_LIBRARY.
The NIST tests under test/ read vectors from ../../tests/nist_vectors in a source checkout,
or from the directory named by FIPS204_NIST_VECTORS. The published fips204 crate includes
the keyGen vectors, under tests/nist_vectors/.
This module should have reasonable type annotations and docstrings for the public interface. If you discover a problem with type annotations, or see a way that this kind of documentation could be improved, please report it!
See Also
Bug Reporting
Please report issues at https://github.com/integritychain/fips204/issues
Metadata
Release files for fips204 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fips204-0.5.0.tar.gz | 7.3 kB | Without provenance | Details for fips204-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fips204-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for fips204-0.5.0-py3-none-any.whl |
Total release size: 15.5 kB
Release files / fips204-0.5.0.tar.gz
| Download URL | fips204-0.5.0.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a9e19bf8d0b7f5be8d24b94476b84dd1b3fc5a15a1ab4f1e3457131ee20bd7c8
|
|
BLAKE2b-256 checksum How to use checksums |
0d27984a1829230448bdbb14a9089ea8367610d694d2f04dbf3e319dc7fa3a9b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Release files / fips204-0.5.0-py3-none-any.whl
| Download URL | fips204-0.5.0-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d027bbedba6e2659b22ea25ae4c27ed128423e4d2424d9f1acb4a85857049697
|
|
BLAKE2b-256 checksum How to use checksums |
da5ed86980554b4cbb8959f9e3e223dd7ac76daca25bdf28358631569ffa0d9f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Security for fips204 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.