Files
mlkem-sync/.trellis/tasks/archive/2026-06/06-27-mlkem-top-tb/prd.md

1.3 KiB
Raw Blame History

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

  1. Python gen_vectors.py 解析 KAT 文件,生成 mlkem_top_input.hexmlkem_top_expected.hex
  2. 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)

  1. 复位
  2. KeyGen: d → verify pk, sk
  3. Encaps: msg → verify ct, ss
  4. 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