Skip to content

Commit

Permalink
Adding more tests for ML-DSA-44.
Browse files Browse the repository at this point in the history
  • Loading branch information
xvzcf committed Dec 5, 2024
1 parent 181a631 commit 29cb12b
Show file tree
Hide file tree
Showing 9 changed files with 2,961 additions and 11 deletions.
10 changes: 8 additions & 2 deletions tests/ml_dsa_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,15 @@ def sign(self, signing_key, message, randomness):
def verify(self, verification_key, message, signature):
if self.parameter_set == "44":
return self.ml_dsa.ml_dsa_44_verify(
verification_key, self.bytearray_to_ctype(message), len(message), signature
verification_key,
self.bytearray_to_ctype(message),
len(message),
signature,
)
elif self.parameter_set == "65":
return self.ml_dsa.ml_dsa_65_verify(
verification_key, self.bytearray_to_ctype(message), len(message), signature
verification_key,
self.bytearray_to_ctype(message),
len(message),
signature,
)
1,002 changes: 1,002 additions & 0 deletions tests/pqc/ml_dsa_44.json

Large diffs are not rendered by default.

100 changes: 100 additions & 0 deletions tests/pqc/ml_dsa_65.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion tests/test_accumulated_kats.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

@pytest.fixture()
def expected_final_hash(ml_dsa):
if ml_dsa.parameter_set == "65":
if ml_dsa.parameter_set == "44":
return "6a9b0e409516b34c706e2abaae5441b10baae85e98e3fafba5b25d864fe2b0aa"
elif ml_dsa.parameter_set == "65":
return "8fc42bd9a915e5d5b5b7be9d1f882034c80c55e1f1b61b37af670635e7db1b64"


Expand Down
2 changes: 1 addition & 1 deletion tests/test_nist_drbg_kats.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def kats(ml_dsa):
return json.load(kats_raw)


def test_against_kats(ml_dsa, kats):
def test_against_nist_drbg_kats(ml_dsa, kats):
for kat in kats:
# Test key generation.
key_generation_seed = bytearray.fromhex(kat["key_generation_seed"])
Expand Down
7 changes: 2 additions & 5 deletions tests/test_pqc_kats.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def kats(ml_dsa):
return json.load(kats_raw)


def test_against_kats(ml_dsa, kats):
def test_against_pqc_kats(ml_dsa, kats):
for kat in kats:
# Test key generation.
key_generation_seed = bytearray.fromhex(kat["key_generation_seed"])
Expand All @@ -34,9 +34,6 @@ def test_against_kats(ml_dsa, kats):

# Then signing.

# We append [0,0] to signal an empty domain separation context, see
# the comment in ml_dsa.jazz for as to why this is done here instead
# of there.
ctx = bytearray.fromhex(kat["context"])
message = bytearray([0, len(ctx)]) + ctx + bytearray.fromhex(kat["message"])

Expand All @@ -47,7 +44,7 @@ def test_against_kats(ml_dsa, kats):
sha3_256_hash_of_signature = hashlib.sha3_256(signature).digest()
assert sha3_256_hash_of_signature == bytes.fromhex(
(kat["sha3_256_hash_of_signature"])
)
), print("Failure at KAT number {}".format(kat["count"]))

# And lastly, verification.
verification_result = ml_dsa.verify(verification_key.raw, message, signature)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_wycheproof.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def verification_test_groups(ml_dsa):
return json.load(tests_raw)["testGroups"]


def test_signing(ml_dsa, signing_test_groups):
def test_wycheproof_sign(ml_dsa, signing_test_groups):
signing_seed = bytearray([0] * 32)

for test_group in signing_test_groups:
Expand Down Expand Up @@ -72,7 +72,7 @@ def test_signing(ml_dsa, signing_test_groups):
# wycheproof test file.


def test_verification(ml_dsa, verification_test_groups):
def test_wycheproof_verify(ml_dsa, verification_test_groups):
for test_group in verification_test_groups:
verification_key = bytearray.fromhex(test_group["publicKey"])
if len(verification_key) != ml_dsa.verification_key_size:
Expand Down
837 changes: 837 additions & 0 deletions tests/wycheproof/mldsa_44_standard_sign_test.json

Large diffs are not rendered by default.

1,006 changes: 1,006 additions & 0 deletions tests/wycheproof/mldsa_44_standard_verify_test.json

Large diffs are not rendered by default.

0 comments on commit 29cb12b

Please sign in to comment.