Skip to main content

Python library for generating external μ (mu) values as specified by ML-DSA

Project description

mldsa-mu

A small Python library for generating external μ (mu) values as specified by ML-DSA (FIPS 204).

This library is intended for use in systems that need to compute μ outside of a full ML-DSA signing implementation (for example: KMS-style services, HSM adapters, or test tooling).


What is μ?

In ML-DSA, the value μ is defined as:

μ = SHAKE256(tr || M', 64)

where:

  • tr = SHAKE256(public_key, 64)
  • M' = 0x00 || len(context) || context || message

This library implements exactly that construction.


Features

  • Deterministic μ generation per FIPS 204
  • Supports optional domain-separation context
  • Utilities for extracting raw public keys from (base64) PKIX / SPKI encodings

Installation

pip install mldsa-mu

Usage

Example: generate μ from a raw public key

from mldsa_mu import generate

public_key = b"\x01" * 64
message = b"hello world"

mu = generate(public_key, message)
print(mu)

Example: generate μ with a domain-separation context

from mldsa_mu import generate

public_key = b"\x02" * 64
message = b"important message"
context = b"my-protocol-v1"

mu = generate(public_key, message, context=context)
print(mu)

Example: extract raw public key from DER-encoded PKIX (SPKI) and generate μ

from mldsa_mu import generate, public_key_from_pkix

with open("public_key.spki.der", "rb") as f:
    spki_der = f.read()

public_key = public_key_from_pkix(spki_der)

mu = generate(public_key, b"hello world")
print(mu)

Example: extract raw public key from base64-encoded PKIX (SPKI)

from mldsa_mu import generate, public_key_from_pkix_b64

spki_b64 = (
    "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A..."
)

public_key = public_key_from_pkix_b64(spki_b64)

mu = generate(public_key, b"hello world")
print(mu)

Development

Create (and remove if needed) the Hatch dev environment.

hatch env remove dev
hatch env create dev

Run tests: hatch run dev:fmt

Run code linting: hatch run dev:pytest

Run code type checking: hatch run dev:typing

License

mldsa-mu is distributed under the terms of the MIT license.


Python written by humans. English written by AI.

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_mu-1.0.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

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

mldsa_mu-1.0.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file mldsa_mu-1.0.0.tar.gz.

File metadata

  • Download URL: mldsa_mu-1.0.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.2 cpython/3.14.2 HTTPX/0.28.1

File hashes

Hashes for mldsa_mu-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a860c057023e50990607aa164a1f9a9f1cc2c55cad6efd30382f58dd0271ad89
MD5 829b74dbebaed129365e4f53aec3006d
BLAKE2b-256 8221c78c9ebd3025f623f3c21cc920ec01ac5b8143c474ad0dbf70fe18ddfe52

See more details on using hashes here.

File details

Details for the file mldsa_mu-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: mldsa_mu-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.2 cpython/3.14.2 HTTPX/0.28.1

File hashes

Hashes for mldsa_mu-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d0e6f5534744bbdaac9c2d91297a3ef92d559328e82dd9cca7708e8e3e762eb1
MD5 0028521b3bc92a2205f3a69abedf00a8
BLAKE2b-256 d6647364810b0a3edafdddd48cf3b86597f68d836cfc9850d76b9ca48ef38c0f

See more details on using hashes here.

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