ML-DSA#
How to use the crypto_condor.primitives.MLDSA
module to test implementations of
MLDSA.
Test signing#
- crypto_condor.primitives.MLDSA.test_sign(sign, paramset)#
Tests a function that signs with ML-DSA.
Signs messages with the given function. As by default ML-DSA uses a “hedged”, pseudorandom procedure, the signature cannot be directly compared with the one included in the test vector. Instead, crypto-condor checks that the signature has the correct length and then verifies it is valid for the test vector public key and message using the reference implementation.
- Parameters:
- Returns:
A dictionary of results. It is empty if the internal decapsulation failed to run, or the implementation raised NotImplementedError.
- Return type:
Test signature verification#
- crypto_condor.primitives.MLDSA.test_verify(verify, paramset)#
Tests a function that verified ML-DSA signatures.
Verifies signatures with the given function. The test passes if valid signatures are accepted.
- Parameters:
- Returns:
A dictionary of results. It is empty if the internal decapsulation failed to run, or the implementation raised NotImplementedError.
- Return type:
Parameters#
- enum crypto_condor.primitives.MLDSA.Paramset(value)#
The parameter sets for ML-DSA.
- Member Type:
str
Valid values are as follows:
- ML_DSA_44 = <Paramset.ML_DSA_44: 'ML-DSA-44'>#
- ML_DSA_65 = <Paramset.ML_DSA_65: 'ML-DSA-65'>#
- ML_DSA_87 = <Paramset.ML_DSA_87: 'ML-DSA-87'>#
The
Enum
and its members also have the following methods:- property sk_size#
The secret key size of the parameter set in bytes.
- property pk_size#
The public key size of the parameter set in bytes.
- property sig_size#
The signature size of the parameter set in bytes.
- property dilithium#
The equivalent Dilithium parameter set.
Protocols#
- protocol crypto_condor.primitives.MLDSA.Sign#
Represents an ML-DSA signing function.
Classes that implement this protocol must have the following methods / attributes:
- __call__(sk, msg, ctx)#
Signs a message.
- Parameters:
sk (bytes) – The secret key to use.
msg (bytes) – The message to sign.
ctx (bytes) – The context string. Can be an empty bytestring.
- Returns:
The signature.
- Return type:
bytes
- protocol crypto_condor.primitives.MLDSA.Verify#
Represents an ML-DSA signature verification function.
Classes that implement this protocol must have the following methods / attributes:
- __call__(pk, msg, sig, ctx)#
Verifies an ML-DSA signature.
- Parameters:
pk (bytes) – The public key to use.
msg (bytes) – The message that was signed.
sig (bytes) – The signature to verify.
ctx (bytes) – The context string.
- Returns:
True if the signature is valid, False otherwise.
- Return type:
bool
Test vectors#
The following section describes the internal test vectors classes, which are protobuf Python classes.
Hint
The autodoc extension can’t properly document these clases so we include the
.proto
file to show the different fields each class has. IDEs should be able to
use the included .pyi
files to provide auto-completion and type checking.
- class crypto_condor.primitives.MLDSA.MldsaVectors#
Protobuf class that stores test vectors. See the description below.
syntax = "proto3";
package crypto_condor;
message MldsaTest{
// The test ID, unique in its set of vectors.
int32 id = 1;
// The type of test. One of: valid, invalid, acceptable.
string type = 2;
// A comment on the test.
string comment = 3;
// Flags that categorize this test.
repeated string flags = 4;
// The message to sign.
bytes msg = 5;
// The public key.
bytes pk = 6;
// The secret key.
bytes sk = 7;
// The signature.
bytes sig = 8;
// The context string.
bytes ctx = 9;
}
// A set of ML-DSA test vectors.
message MldsaVectors{
// The source of the test vectors.
string source = 1;
// Description of the source.
string source_desc = 2;
// The URL of the source.
string source_url = 3;
// Whether these are compliance test vectors or not.
bool compliance = 4;
// A dictionary of test flags and their description.
map<string, string> notes = 5;
// The ML-DSA parameter set.
string paramset = 6;
// The test vectors.
repeated MldsaTest tests = 7;
}