opentitan icon indicating copy to clipboard operation
opentitan copied to clipboard

[kmac] Write incorrect cmd from Idle state

Open udinator opened this issue 5 years ago • 3 comments

Hi Eunchan,

I'm seeing some odd behavior when I test an error case where I push an incorrect command from the Idle state (anything but CmdStart):

Screenshot from 2021-05-20 01-42-48

Here, I write CmdManualRun from the Idle state, and then kmac_app reports an ErrSwPushedWrongCmd and raises the error interrupt.

However, since in this test case I am not using the app interface, I'd expect that the ErrSha3SwControl error should be asserted from sha3 module instead (which checks for the exact same thing, but only applies to SW controlled hashing).

It looks like the error from kmac_app is incorrectly being thrown here due to this condition, which only checks that we are not using SelSw mux mode in kmac_app module.

As you can see in the waves, mux_sel is actually still remaining as SelNone here since we are sending an incorrect SW command - I think this condition needs to change to become: if (mux_sel != SelSw && mux_sel != SelNone) begin... or equivalent. WDYT?

udinator avatar May 20 '21 08:05 udinator

Thanks for finding this. I think this is also related to the other issue you and I talked before. The error handlings between KMAC and SHA logic are separated but shares similar error code structure. SHA3 does not care KMAC raising error or not but checks internally and report an error if not correct. KMAC also designed in similar way.

This is the condition that both error checkers catch the same condition. The reported error code from KMAC also makes sense as SW sends wrong command here. Even it is raised in kmac_app, it does not mean it can report an error when app interface is used. From the SW PoV, the report comes from KMAC HWIP. So, I think either way (choosing KMAC error vs choosing SHA error) is fine.

@moidx @cfrantz WDYT? Which one do you expect the SW to receive?

eunchan avatar May 25 '21 00:05 eunchan

Hm, I see, t makes sense that the SHA3 and KMAC errors can be separated.

My concern/question is now with what happens if SW sends an incorrect command after issuing CmdStart.

For example, say we issue CmdStart normally, which sends the kmac_app into StSw correctly.

However, we then issue CmdDone next - in this case the kmac_app will not detect this as an error because all it checks for is that the first SW command in every hash is a CmdStart, the SHA3 logic will report an error instead.

I may be wrong, but I remembered in a previous discussion we had decided that the ErrSwPushedMsgFifo error is solely meant to detect errors during application interface operation, and here it almost seems like that error is detecting an incorrect CmdStart by "mistake".

e.g. if I write incorrect CmdStart, it seems a bit odd to then expect a ErrSwPushedMsgFifo as we're not touching the msgfifo at all.

I guess I'm just wondering if it would be good to align these behaviors.

udinator avatar May 25 '21 16:05 udinator

adding @cindychip for visibility

udinator avatar Oct 08 '21 00:10 udinator