diff --git a/sync_rtl/top/TB/tb_mlkem_kg_katK_xsim.v b/sync_rtl/top/TB/tb_mlkem_kg_katK_xsim.v index dad77b5..d9e5699 100644 --- a/sync_rtl/top/TB/tb_mlkem_kg_katK_xsim.v +++ b/sync_rtl/top/TB/tb_mlkem_kg_katK_xsim.v @@ -32,9 +32,26 @@ module tb_mlkem_kg_katK_xsim; reg [255:0] zmem [0:0]; reg [7:0] ek_gold [0:EKB-1]; reg [7:0] dk_gold [0:DKB-1]; - integer c, i, errors, casenum; + reg [7:0] ek_got [0:EKB-1]; // ek bytes read back from DUT + reg [7:0] dk_got [0:DKB-1]; // dk bytes read back from DUT + integer c, i, errors, casenum, j; reg [8*80-1:0] tag, dfile, zfile, ekfile, dkfile; + // Dump a byte array as offset-prefixed hex, 32 bytes/line. + task dump_bytes(input [8*16-1:0] name, input integer n); + integer a, b; + begin + for (a = 0; a < n; a = a + 32) begin + $write(" %0s[%4d] ", name, a); + for (b = a; b < a+32 && b < n; b = b + 1) begin + if (name == "ek") $write("%02x", ek_got[b]); + else $write("%02x", dk_got[b]); + end + $write("\n"); + end + end + endtask + initial begin if (!$value$plusargs("CASE=%d", casenum)) casenum = 0; $sformat(tag, "k%0d", KP); @@ -49,6 +66,11 @@ module tb_mlkem_kg_katK_xsim; d_i = dmem[0]; z_i = zmem[0]; k_i = KP[2:0]; + // ---- show the KeyGen inputs (d, z seeds: 32 bytes each, MSB-first) ---- + $display("=== ML-KEM K=%0d KAT case %0d INPUTS ===", KP, casenum); + $write(" d = "); for (j = 0; j < 32; j = j + 1) $write("%02x", d_i[8*(31-j) +: 8]); $write("\n"); + $write(" z = "); for (j = 0; j < 32; j = j + 1) $write("%02x", z_i[8*(31-j) +: 8]); $write("\n"); + rst_n=0; repeat(4) @(posedge clk); rst_n=1; @(posedge clk); start_i=1; @(posedge clk); start_i=0; c=0; while(!done_o && c<2000000) begin @(posedge clk); c=c+1; end @@ -59,6 +81,7 @@ module tb_mlkem_kg_katK_xsim; dbg_byte_sel_i = 1'b0; for (i = 0; i < EKB; i = i + 1) begin dbg_byte_idx_i = i[10:0]; @(posedge clk); @(posedge clk); + ek_got[i] = dbg_byte_o; if (dbg_byte_o !== ek_gold[i]) begin if (errors < 8) $display(" EK[%0d] got=%02x exp=%02x", i, dbg_byte_o, ek_gold[i]); errors = errors + 1; @@ -66,11 +89,18 @@ module tb_mlkem_kg_katK_xsim; end for (i = 0; i < DKB; i = i + 1) begin dbg_dk_idx_i = i[11:0]; @(posedge clk); @(posedge clk); + dk_got[i] = dbg_dk_o; if (dbg_dk_o !== dk_gold[i]) begin if (errors < 8) $display(" DK[%0d] got=%02x exp=%02x", i, dbg_dk_o, dk_gold[i]); errors = errors + 1; end end + + // ---- show the KeyGen outputs (ek, dk byte strings read from DUT) ---- + $display("=== ML-KEM K=%0d KAT case %0d OUTPUTS ===", KP, casenum); + $display(" ek (%0d bytes):", EKB); dump_bytes("ek", EKB); + $display(" dk (%0d bytes):", DKB); dump_bytes("dk", DKB); + if (errors == 0) $display("K=%0d CASE %0d PASS: ek (%0dB)==pk, dk (%0dB)==sk", KP, casenum, EKB, DKB); else $display("K=%0d CASE %0d FAIL: %0d mismatches", KP, casenum, errors); $finish;