FIPS 204¶
MLDSA¶
- class fips.FIPS204.main.MLDSA(parameter)[source]¶
Bases:
objectMLDSA is a digital signature scheme based on CRYSTALS-DILITHIUM. It consists of three main algorithms: MLDSAKeyGen, MLDSASign and MLDSAVerify. The MLDSA scheme uses the Fiat-Shamir with Aborts construction.
This pure python implementation of the scheme is an educational resource and is not constructed with side channel attacks. This must not be used for real world application.
- Parameters:
parameter (dict[str, int])
- MLDSAKeyGen()[source]¶
Algorithm 1
Generates a public-private key pair.
- Return type:
tuple[bytes,bytes]- Returns:
public-keyThe public keybytestring.private-keyThe private keybytestring.
- MLDSAKeyGenInternal(seed)[source]¶
Algorithm 6
Generates a public-private key pair from a seed.
- Parameters:
seed (
bytes) – Input seed for deterministic results.- Return type:
tuple[bytes,bytes]- Returns:
public-keyThe public keybytestring.private-keyThe private keybytestring.
- Raises:
ValueError – If
seedis not32 byteslong.
- MLDSASign(secret_key, Message, ctx)[source]¶
Algorithm 2
Generates an ML-DSA signature.
- Parameters:
secret_key (
bytes) – The private keybytestring.Message (
str) – The message to be signed inbits.ctx (
bytes) – Context bytestring of lengthat most 255.
- Returns:
The generated ML-DSA signature as a bytestring.
- Return type:
bytes|None- Raises:
ValueError – If the message bit string has other than
0and1characters.ValueError – If the context length is
more than 255.
- MLDSASignInternal(secret_key, Message, input_seed)[source]¶
Algorithm 7
Deterministic algorithm to generate a signature for a formatted message M’.
- Parameters:
secret_key (
bytes) – The private keybytestring.Message (
str) – The message to be signed inbits.input_seed (
bytes) – A32-byterandom seed for signature generation.
- Returns:
The generated ML-DSA signature as a
bytestring.- Return type:
signature (
bytes)- Raises:
ValueError – If the input seed is not
32 bytes.ValueError – If the message has other than
0and1characters.
- MLDSAVerify(public_key, message, signature, ctx)[source]¶
Algorithm 3
Verifies a signature
rhofor a messageM.- Parameters:
public_key (
bytes) – The public keybytestring.message (
str) – The message inbits.signature (
bytes|None) – The signaturebytestring.ctx (
bytes) – Contextbytestringof lengthat most 255.
- Returns:
True if the signature is valid, False otherwise.
- Return type:
bool- Raises:
ValueError – If the public key or signature is invalid.
TypeError – If the context is not a
bytestring.
- MLDSAVerifyInternal(public_key, message, signature)[source]¶
Algorithm 8
Internal function to verify a signature
rhofor a formatted messageM'.- Parameters:
public_key (
bytes) – The public keybytestring.message (
str) – The message inbits.signature (
bytes) – The signaturebytestring.
- Returns:
True if the signature is valid, False otherwise.
- Return type:
bool- Raises:
ValueError – If the public key or signature is invalid.
TypeError – If the message is not a
bitstring.ValueError – If the message has other than
0and1characters.