1.3 KiB
1.3 KiB
mlkem_top KAT Testbench
Goal
编写 mlkem_top 的 KAT (Known Answer Test) testbench,使用 FIPS 203 标准测试向量验证 KeyGen/Encaps/Decaps 正确性。
Data Source
/home/fallensigh/Dev/ml-kem-r/test_data/kat_MLKEM_512.rsp
- 100 个测试向量 (count 0-99)
- 每个向量包含:d, z, msg, pk, sk, ct, ss
- NIST FIPS 203 标准格式
Requirements
- Python
gen_vectors.py解析 KAT 文件,生成mlkem_top_input.hex和mlkem_top_expected.hex - Verilog
tb_mlkem_top_xsim.v:- 读取输入向量 (d, z, msg)
- 驱动 KeyGen → 验证 pk, sk
- 驱动 Encaps → 验证 ct, ss
- 驱动 Decaps → 验证 ss
- 超时看门狗
- pass/fail 统计
Decisions
- 先用 ML-KEM-512 (k=2),后续扩展 768/1024
- 文件向量模式,遵循现有 TB 风格
- 自检模式:与 KAT 期望值逐个字节比较
Test Flow (per vector)
- 复位
- KeyGen: d → verify pk, sk
- Encaps: msg → verify ct, ss
- Decaps: ct → verify ss (output matches ss from encaps)
Acceptance Criteria
- 至少 count=0 的 KeyGen 通过
- 至少 count=0 的 Encaps 通过
- at least basic Decaps consistency
- xvlog 编译通过
- xsim 仿真通过
Out of Scope
- 全部 100 个向量(先做前 5 个)
- ct_n 无效密文测试
- ML-KEM-768/1024