[kmac] ROM/OTP prefix issues
Hi Eunchan,
I ran into the following bug relating to how the prefix values of ROM/OTP applications are handled:

This test is driving a request through the OTP app interface of 5-bytes total of data - meaning that the first transaction sent will assert the last signal.
The kmac_app state machine transitions then to StAppMsg for single cycle as last signal is high in the very first transaction (this transition happens at the location of the yellow marker).
Additionally, the sha3_prefix_o output changes to the value of AppCfg[i].Prefix at the marker as well (this is some arbitrary value that I've added locally).
sha3pad logic starts processing this (correct) output prefix value from the app parameter and outputs the first 64-bit block on the next cycle.
However, in kmac_app, we set sha3_prefix_o to AppCfg[i].Prefix only when we're in StAppMsg state - in this scenario only a single cycle.
This 1 cycle is not long enough for sha3pad to slice the entire prefix and thus one cycle later kmac_app sets sha3_prefix_o back to the default value of CSR.prefix fields, this is reflected in the waves.
This causes sha3pad to basically take slices from two different "full" prefix values which corrupts the final prefix value, eventually ending up in a digest mismatch.
To fix this issue, I think this section in kmac_app:
StAppMsg: begin
// Check app intf cfg
for (int unsigned i = 0 ; i < NumAppIntf ; i++) begin
if (app_id == i) begin
if (AppCfg[i].PrefixMode == 1'b 0) begin
sha3_prefix_o = reg_prefix_i;
end else begin
sha3_prefix_o = AppCfg[i].Prefix;
end
end
end
end
needs to change to not make outputting the static prefix value last for as only as long as we're in StAppMsg.
WDYT?
Thanks Udi. I will look into this and revise the design