opentitan icon indicating copy to clipboard operation
opentitan copied to clipboard

[kmac] switching entropy modes

Open udinator opened this issue 5 years ago • 11 comments

Hi Eunchan,

The small wave snippet shown below is from the start of a SHAKE128 test iteration, where I have just written the CFG CSR to switch from EDN to SW entropy - however, this happens in the middle of the EDN entropy refreshing request from the previously completed hash operation.

Screenshot from 2021-05-11 14-13-35

As you can see even though the mode_i detects that the new entropy mode is from SW, the state machine remains in the EDN states. This causes the first keccak round to block until EDN request returns, even though the SW entropy is immediately available.

Is there any requirement that entropy mode can only be switched from EDN to SW once a refreshing operation has completed, or is this an issue in the design?

Thanks, Udi

udinator avatar May 11 '21 21:05 udinator

I expected SW to configure any CFG register fields when the KMAC IP is in idle state. Currently, there's no way to exit from RandEdn except the timer expire.

eunchan avatar May 11 '21 21:05 eunchan

Maybe it is worth to check if Edn has a way to flush out current pending request? If not, I should consider adding emergency break from RandEdn by SW (not sure this is good idea or not). Or as a W/A, SW may set expire timer while in RandEdn state.

eunchan avatar May 11 '21 21:05 eunchan

This scenario is with all timers disabled - to me, it makes sense to short-circuit from RandEdn to RandSw, but I don't know if there would be any major security/functional issues with doing this.

udinator avatar May 11 '21 21:05 udinator

Maybe it is worth to check if Edn has a way to flush out current pending request?

I don't think this is possible given the current FSM design - it looks like we can only move from StRandEdn to either timer expiration, or entropy expansion.

udinator avatar May 11 '21 21:05 udinator

I don't think this is possible given the current FSM design - it looks like we can only move from StRandEdn to either timer expiration, or entropy expansion.

I assume "current FSM design" is the FSM in EDN IP?

In KMAC, yes you are right. only receiving ack from EDN or timer expire lets FSM move to the next state.

eunchan avatar May 11 '21 23:05 eunchan

I assume "current FSM design" is the FSM in EDN IP?

Sorry I should have been more clear - I mean the FSM in kmac_entropy.sv.

udinator avatar May 11 '21 23:05 udinator

I assume "current FSM design" is the FSM in EDN IP?

Sorry I should have been more clear - I mean the FSM in kmac_entropy.sv.

yeah right. KMAC has only the two options at this time. What I mentioned in the original comment was if the EDN IP has a way to flush in case of KMAC not receiving the response.

eunchan avatar May 11 '21 23:05 eunchan

ahh got it, sorry for confusion - I think that's a good idea.

even if the EDN can flush requests, shouldn't kmac_entropy still support exiting RandEdn states if a sudden switch is made to SW entropy? since even if the EDN can flush the request when KMAC goes into SwEntropy mode, I feel like keccak shouldn't have to wait until external module clears the spurious request - wdyt?

udinator avatar May 11 '21 23:05 udinator

I think, the expire timer is a way to achieve that. If there's any chance the SW need to switch to SW Entropy mode, they should set EDN timer in the initialization function.

If SW needs to switch to SW Entropy mode, it means somehow EDN has a chance to be stuck. That is what EDN Wait timer is made for.

eunchan avatar May 12 '21 00:05 eunchan

Hmm that makes sense, so SW entropy is sort of a backup for the EDN entropy. I'll update the existing tests accordingly until I implement the timer functionality in scoreboard. Thanks for the clarifications!

udinator avatar May 12 '21 16:05 udinator

adding @cindychip for visibility

udinator avatar Oct 08 '21 00:10 udinator