feat(mlkem_top): parameterize K in {2,3,4} (ML-KEM 512/768/1024)
Generalize KeyGen from K=2-hardcoded to compile-time parameter K:
- eta1 derived (3 for K=2, else 2); slot layout SLOT_S/E/T = K*K+{0,K,2K},
NUM_SLOTS = K*K+3K; SAW=5 slot-addr width.
- A-stage: explicit a_i/a_j row-major counters (slot = i*K+j) instead of
K=2 bit-tricks. C/N stages: parametric slot bases, 2K polys.
- M-stage: m_i/m_j widened to 3-bit (must reach K=4); slots i*K+j etc.
- E-stage: 2K polys, e_is_dk split, rho offset 384*K.
- H(ek): H_NBLK=ceil((EK_BYTES+1)/136), H_LAST padding generalized;
h_blk 4-bit. Byte mems sized EK_BYTES/DK_BYTES.
- Widen dbg_byte_idx_i to [10:0] (ek up to 1568B for K=4).
Parametric TB (tb_mlkem_kg_katK, KP generic + CASE plusarg). Verified
byte-exact vs NIST KAT:
K=2 (512): cases 0..4 ek 800B / dk 1632B
K=3 (768): cases 0..2 ek 1184B / dk 2400B (~36k cyc)
K=4 (1024): cases 0..2 ek 1568B / dk 3168B (~54k cyc)
run_tb.sh top runs all three parameter sets.
This commit is contained in:
@@ -1,16 +1,12 @@
|
||||
# xsim_run.tcl - Vivado XSIM for mlkem_top ML-KEM-512 KeyGen.
|
||||
# xsim_run.tcl - Vivado XSIM for mlkem_top ML-KEM KeyGen, all K in {2,3,4}.
|
||||
#
|
||||
# Compiles the full KeyGen datapath + all leaf modules, then runs the
|
||||
# end-to-end NIST KAT testbench for count=0..4 (each verifies ek==KAT.pk
|
||||
# 800B and dk==KAT.sk 1632B byte-exact).
|
||||
# Compiles the full KeyGen datapath + leaf modules, then runs the parametric
|
||||
# NIST KAT testbench for ML-KEM-512 (K=2), 768 (K=3), 1024 (K=4). Each case
|
||||
# verifies ek==KAT.pk and dk==KAT.sk byte-exact.
|
||||
#
|
||||
# Run from project root:
|
||||
# ./run_tb.sh top
|
||||
# (or: vivado-style step-by-step with the commands below)
|
||||
|
||||
# ================================================================
|
||||
# Step 1: Compile RTL sources (leaf modules + top)
|
||||
# ================================================================
|
||||
# ---- Step 1: compile RTL ----
|
||||
xvlog -sv --relax -i . sync_rtl/sha3/keccak_round.v
|
||||
xvlog -sv --relax -i . sync_rtl/sha3/keccak_core.v
|
||||
xvlog -sv --relax -i . sync_rtl/sha3/sha3_top.v
|
||||
@@ -25,21 +21,23 @@ xvlog -sv --relax -i . sync_rtl/poly_mul/poly_mul_zeta_rom.v
|
||||
xvlog -sv --relax -i . sync_rtl/poly_mul/poly_mul_sync.v
|
||||
xvlog -sv --relax -i . sync_rtl/top/mlkem_top.v
|
||||
|
||||
# ================================================================
|
||||
# Step 2: Compile KAT testbench (parameterized by +CASE=n)
|
||||
# ================================================================
|
||||
xvlog -sv --relax sync_rtl/top/TB/tb_mlkem_kg_katN_xsim.v
|
||||
# ---- Step 2: compile parametric KAT testbench ----
|
||||
xvlog -sv --relax sync_rtl/top/TB/tb_mlkem_kg_katK_xsim.v
|
||||
|
||||
# ================================================================
|
||||
# Step 3: Elaborate snapshot
|
||||
# ================================================================
|
||||
xelab tb_mlkem_kg_katN_xsim -s mlkem_kg_kat --timescale 1ns/1ps
|
||||
# ---- Step 3: elaborate one snapshot per K ----
|
||||
xelab tb_mlkem_kg_katK_xsim -generic_top KP=2 -s mlkem_kg_k2 --timescale 1ns/1ps
|
||||
xelab tb_mlkem_kg_katK_xsim -generic_top KP=3 -s mlkem_kg_k3 --timescale 1ns/1ps
|
||||
xelab tb_mlkem_kg_katK_xsim -generic_top KP=4 -s mlkem_kg_k4 --timescale 1ns/1ps
|
||||
|
||||
# ================================================================
|
||||
# Step 4: Run all 5 KAT cases (count=0..4)
|
||||
# ================================================================
|
||||
xsim mlkem_kg_kat -R -testplusarg CASE=0
|
||||
xsim mlkem_kg_kat -R -testplusarg CASE=1
|
||||
xsim mlkem_kg_kat -R -testplusarg CASE=2
|
||||
xsim mlkem_kg_kat -R -testplusarg CASE=3
|
||||
xsim mlkem_kg_kat -R -testplusarg CASE=4
|
||||
# ---- Step 4: run KAT cases (K=2: 0..4, K=3/4: 0..2) ----
|
||||
xsim mlkem_kg_k2 -R -testplusarg CASE=0
|
||||
xsim mlkem_kg_k2 -R -testplusarg CASE=1
|
||||
xsim mlkem_kg_k2 -R -testplusarg CASE=2
|
||||
xsim mlkem_kg_k2 -R -testplusarg CASE=3
|
||||
xsim mlkem_kg_k2 -R -testplusarg CASE=4
|
||||
xsim mlkem_kg_k3 -R -testplusarg CASE=0
|
||||
xsim mlkem_kg_k3 -R -testplusarg CASE=1
|
||||
xsim mlkem_kg_k3 -R -testplusarg CASE=2
|
||||
xsim mlkem_kg_k4 -R -testplusarg CASE=0
|
||||
xsim mlkem_kg_k4 -R -testplusarg CASE=1
|
||||
xsim mlkem_kg_k4 -R -testplusarg CASE=2
|
||||
|
||||
Reference in New Issue
Block a user