opentitan icon indicating copy to clipboard operation
opentitan copied to clipboard

[kmac] ROM/OTP prefix issues

Open udinator opened this issue 5 years ago • 1 comments

Hi Eunchan,

I ran into the following bug relating to how the prefix values of ROM/OTP applications are handled:

Screenshot from 2021-04-27 17-05-07

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?

udinator avatar Apr 28 '21 00:04 udinator

Thanks Udi. I will look into this and revise the design

eunchan avatar Apr 28 '21 18:04 eunchan