|
1 | 1 | # tests/test_crypto.py |
2 | 2 | """ |
3 | | -Tests for ML-KEM-1024 (Kyber) and ML-DSA-87 (Dilithium5). |
| 3 | +Tests for ML-KEM-1024, ML-DSA-87, Classic-McEliece-8192128f. |
4 | 4 | Covers: |
5 | 5 | - Key generation conformance to NIST spec |
6 | | -- Dilithium Signature generation and verification |
| 6 | +- Signature generation and verification |
7 | 7 | - OTP encryption using Kyber key exchange |
8 | 8 | - Hash chain tamper detection |
9 | 9 | """ |
10 | 10 |
|
11 | | -import pytest |
12 | 11 | from core.crypto import ( |
13 | 12 | generate_kem_keys, |
14 | 13 | generate_sign_keys, |
|
29 | 28 | ML_DSA_87_NAME, |
30 | 29 | ML_DSA_87_SK_LEN, |
31 | 30 | ML_DSA_87_PK_LEN, |
32 | | - ML_DSA_87_SIGN_LEN |
| 31 | + ML_DSA_87_SIGN_LEN, |
| 32 | + |
| 33 | + CLASSIC_MCELIECE_8_F_NAME, |
| 34 | + CLASSIC_MCELIECE_8_F_SK_LEN, |
| 35 | + CLASSIC_MCELIECE_8_F_PK_LEN, |
| 36 | + CLASSIC_MCELIECE_8_F_CT_LEN |
| 37 | + |
33 | 38 | ) |
34 | 39 | from core.trad_crypto import sha3_512 |
35 | 40 |
|
@@ -65,6 +70,26 @@ def test_mlkem_keygen_basic(): |
65 | 70 | seen_public_keys.add(public_key) |
66 | 71 |
|
67 | 72 |
|
| 73 | +def test_mceliece_keygen_basic(): |
| 74 | + """Validate ML-KEM-1024 key generation: uniqueness, type, and length.""" |
| 75 | + seen_private_keys = set() |
| 76 | + seen_public_keys = set() |
| 77 | + |
| 78 | + for _ in range(10): |
| 79 | + private_key, public_key = generate_kem_keys(CLASSIC_MCELIECE_8_F_NAME) |
| 80 | + |
| 81 | + assert private_key not in seen_private_keys, "Duplicate private key detected" |
| 82 | + assert public_key not in seen_public_keys, "Duplicate public key detected" |
| 83 | + |
| 84 | + assert private_key != public_key, "Private and public keys must differ" |
| 85 | + assert isinstance(private_key, bytes) and isinstance(public_key, bytes), "Keys must be bytes" |
| 86 | + assert len(private_key) == CLASSIC_MCELIECE_8_F_SK_LEN, "Private key length mismatch with spec" |
| 87 | + assert len(public_key) == CLASSIC_MCELIECE_8_F_PK_LEN,, "Public key length mismatch with spec" |
| 88 | + |
| 89 | + seen_private_keys.add(private_key) |
| 90 | + seen_public_keys.add(public_key) |
| 91 | + |
| 92 | + |
68 | 93 | def test_mldsa_keygen_basic(): |
69 | 94 | """Validate ML-DSA-87 key generation: uniqueness, type, and length.""" |
70 | 95 | seen_private_keys = set() |
|
0 commit comments