From ba160cca345c6cdc6b043d800aa63a596631bc21 Mon Sep 17 00:00:00 2001 From: FallenSigh Date: Sat, 11 Jul 2026 19:47:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=A4=E4=B8=AA=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=A7=8D=E5=AD=90=E7=9A=84=E6=9C=80=E5=90=8E=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E7=9F=A9=E9=98=B5=E5=A4=9A=E9=A1=B9=E5=BC=8F=20A[1][1]=20?= =?UTF-8?q?=E9=83=BD=E6=81=B0=E5=A5=BD=E5=9C=A8=E7=AC=AC=203=20=E4=B8=AA?= =?UTF-8?q?=20SHAKE=20rate=20block=20=E7=9A=84=E6=9C=80=E5=90=8E=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=203-byte=20group=EF=BC=88=E7=AC=AC=20168=20=E7=BB=84?= =?UTF-8?q?=EF=BC=89=E4=BA=A7=E5=87=BA=E7=AC=AC=20256=20=E4=B8=AA=E7=B3=BB?= =?UTF-8?q?=E6=95=B0=E3=80=82=E5=BD=93=E5=89=8D=20RTL=20=E5=9C=A8=E8=AF=A5?= =?UTF-8?q?=20=20=20=E7=B3=BB=E6=95=B0=E5=B7=B2=E7=BB=8F=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E5=90=8E=E4=BB=8D=E5=90=AF=E5=8A=A8=E4=B8=80=E6=AC=A1=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E7=9A=84=20Keccak=20=E9=87=8D=E6=8E=92=EF=BC=9B?= =?UTF-8?q?=E9=A1=B6=E5=B1=82=E9=9A=8F=E5=8D=B3=E5=88=87=E6=8D=A2=E5=88=B0?= =?UTF-8?q?=20CBD=20=E9=98=B6=E6=AE=B5=EF=BC=8C=E5=85=B1=E4=BA=AB=20core?= =?UTF-8?q?=20=E7=9A=84=E8=BF=99=E4=BB=BD=E6=97=A7=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E8=A2=AB=20CBD=20=E5=BD=93=E6=88=90=E8=87=AA=E5=B7=B1=E7=9A=84?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E6=8E=A5=E6=94=B6=EF=BC=8C=E6=89=80=E4=BB=A5?= =?UTF-8?q?=E5=90=8E=E7=BB=AD=20KeyGen=20=E5=85=A8=E9=94=99=E3=80=82?= =?UTF-8?q?=E6=88=91=E8=A6=81=E5=9C=A8=E4=B8=A4=E4=B8=AA=20=20=20SampleNTT?= =?UTF-8?q?=20=E5=8F=98=E4=BD=93=E4=B8=AD=E9=98=BB=E6=AD=A2=E2=80=9C?= =?UTF-8?q?=E7=AC=AC=20256=20=E4=B8=AA=E7=B3=BB=E6=95=B0=E5=B7=B2=E7=BB=8F?= =?UTF-8?q?=E6=98=AF=E6=9C=AC=E7=BB=84=20d2=E2=80=9D=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E9=87=8D=E6=8E=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sync_rtl/sample_ntt/sample_ntt_sync.v | 6 +++++- sync_rtl/sample_ntt/sample_ntt_sync_shared.v | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/sync_rtl/sample_ntt/sample_ntt_sync.v b/sync_rtl/sample_ntt/sample_ntt_sync.v index 62539fe..afc1658 100644 --- a/sync_rtl/sample_ntt/sample_ntt_sync.v +++ b/sync_rtl/sample_ntt/sample_ntt_sync.v @@ -210,6 +210,10 @@ module sample_ntt_sync #(parameter K = 4) ( // d2 rejected, no longer need coefficients, or d2 was just accepted out. wire grp_done = (state_r == ST_SQUEEZE) && (sq_phase_r == 2'd2) && (!d2_acc_r || !need_more || (valid_o_r && ready_i)); + // `need_more` observes the registered counter before the final d2 + // handshake increments it. Detect that boundary explicitly so a full + // rate block does not launch an unnecessary final re-permutation. + wire completes_output = valid_o_r && ready_i && (coeff_cnt_r == 9'd255); // ================================================================ // FSM: state_next (combinational) @@ -235,7 +239,7 @@ module sample_ntt_sync #(parameter K = 4) ( // next group in this block, re-permute (block exhausted), or // finish. if (grp_done) begin - if (!need_more) + if (!need_more || completes_output) state_next = ST_DONE; else if (grp_ptr_r < GRP_MAX) state_next = ST_SQUEEZE; // next group, no re-permute diff --git a/sync_rtl/sample_ntt/sample_ntt_sync_shared.v b/sync_rtl/sample_ntt/sample_ntt_sync_shared.v index 9896ba2..43944a4 100644 --- a/sync_rtl/sample_ntt/sample_ntt_sync_shared.v +++ b/sync_rtl/sample_ntt/sample_ntt_sync_shared.v @@ -224,6 +224,10 @@ module sample_ntt_sync_shared #(parameter K = 4) ( // d2 rejected, no longer need coefficients, or d2 was just accepted out. wire grp_done = (state_r == ST_SQUEEZE) && (sq_phase_r == 2'd2) && (!d2_acc_r || !need_more || (valid_o_r && ready_i)); + // `need_more` observes the registered counter before the final d2 + // handshake increments it. Detect that boundary explicitly so a full + // rate block does not launch an unnecessary final re-permutation. + wire completes_output = valid_o_r && ready_i && (coeff_cnt_r == 9'd255); // ================================================================ // FSM: state_next (combinational) @@ -249,7 +253,7 @@ module sample_ntt_sync_shared #(parameter K = 4) ( // next group in this block, re-permute (block exhausted), or // finish. if (grp_done) begin - if (!need_more) + if (!need_more || completes_output) state_next = ST_DONE; else if (grp_ptr_r < GRP_MAX) state_next = ST_SQUEEZE; // next group, no re-permute