Skip to content

Commit

Permalink
add tests for decaps type checks
Browse files Browse the repository at this point in the history
  • Loading branch information
GiacomoPope committed Aug 16, 2024
1 parent 83fcb7d commit 7965605
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/test_ml_kem.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,31 @@ def test_xof_failure(self):
def test_prf_failure(self):
self.assertRaises(ValueError, lambda: ML_KEM_512._prf(2, b"1", b"2"))

def test_decaps_ct_type_check_failure(self):
"""
Send a ciphertext of the wrong length
"""
ek, dk = ML_KEM_512.keygen()
K, c = ML_KEM_512.encaps(ek)
self.assertRaises(ValueError, lambda: ML_KEM_512.decaps(dk, b"1"))

def test_decaps_dk_type_check_failure(self):
"""
Send a ciphertext of the wrong length
"""
ek, dk = ML_KEM_512.keygen()
K, c = ML_KEM_512.encaps(ek)
self.assertRaises(ValueError, lambda: ML_KEM_512.decaps(b"1", c))

def test_decaps_hash_check_failure(self):
"""
Send a ciphertext of the wrong length
"""
ek, dk = ML_KEM_512.keygen()
K, c = ML_KEM_512.encaps(ek)
dk_bad = b"0" * len(dk)
self.assertRaises(ValueError, lambda: ML_KEM_512.decaps(dk_bad, c))


class TestML_KEM_KAT(unittest.TestCase):
"""
Expand Down

0 comments on commit 7965605

Please sign in to comment.