[otbn] Specify the OTBN side of the KMAC interface#30278
Conversation
008c1dd to
52e97b0
Compare
9e459fa to
94c3b1d
Compare
ed19225 to
1dad8a2
Compare
etterli
left a comment
There was a problem hiding this comment.
Thank you for the fast review @rswarbrick . Your feedback is incorporated.
| - In case of a timeout OTBN can either wait longer or abort the execution. | ||
| If the OTBN aborts, the interface starts a recovery operation, see error handling for more details. | ||
| - Write a message into `KMAC_DATA_S0` and `KMAC_DATA_S1` (share 0 and 1, respectively) and set the corresponding strobe in `KMAC_STRB`. | ||
| - All messages except the last one must be 32 bytes (256 bits) long, i.e., `KMAC_STRB = '1`. |
There was a problem hiding this comment.
I don't understand this question. What do you mean with 0x3f? There is no value which is 63.
| - The digest data always comes in a shared representation. | ||
| To recover the plaintext digest the values read from `KMAC_DATA_S0` and `KMAC_DATA_S1` must be XORed. | ||
| - Once both WSRs, `KMAC_DATA_S0` and `KMAC_DATA_S1`, have been read the interface clears `KMAC_STATUS.RSP_VALID` and the interface will accept the next digest part from the app interface. | ||
| (i.e., the `KMAC_STATUS.RSP_VALID` bit serves as back-pressure.) |
There was a problem hiding this comment.
The KMAC_STATUS.RSP_VALID bit shows the validity of the current response. But the hardware / interface uses it to drive the ready signal of the response channel. Obviously its inverted value; if it is cleared because the current response has been consumed then we can accept the next response.
1dad8a2 to
e1cb124
Compare
rswarbrick
left a comment
There was a problem hiding this comment.
Thank you for all the changes!
| - In case of a timeout OTBN can either wait longer or abort the execution. | ||
| If the OTBN aborts, the interface starts a recovery operation, see error handling for more details. | ||
| - Write a message into `KMAC_DATA_S0` and `KMAC_DATA_S1` (share 0 and 1, respectively) and set the corresponding strobe in `KMAC_STRB`. | ||
| - All messages except the last one must be 32 bytes (256 bits) long, i.e., `KMAC_STRB = '1`. |
There was a problem hiding this comment.
Damn! I meant to give the hex value that corresponds to '1, which I assumed had every bit set. Rather stupidly, I then calculated 2*32 - 1, rather than 2^32-1...
| If the OTBN aborts, the interface starts a recovery operation, see error handling for more details. | ||
| - Write a message into `KMAC_DATA_S0` and `KMAC_DATA_S1` (share 0 and 1, respectively) and set the corresponding strobe in `KMAC_STRB`. | ||
| - All messages except the last one must be 32 bytes (256 bits) long, i.e., `KMAC_STRB = '1`. | ||
| - The last message is allowed to be a partial message and it can be 1 to 32 bytes long. |
There was a problem hiding this comment.
Oh, good point! If we don't have a use for the feature, this seems perfectly sensible.
| - The digest data always comes in a shared representation. | ||
| To recover the plaintext digest the values read from `KMAC_DATA_S0` and `KMAC_DATA_S1` must be XORed. | ||
| - Once both WSRs, `KMAC_DATA_S0` and `KMAC_DATA_S1`, have been read the interface clears `KMAC_STATUS.RSP_VALID` and the interface will accept the next digest part from the app interface. | ||
| (i.e., the `KMAC_STATUS.RSP_VALID` bit serves as back-pressure.) |
There was a problem hiding this comment.
Oh, sorry! I think I've got confused.
At the moment, the text says "the interface clears KMAC_STATUS.RSP_VALID". Do you mean that the OTBN hardware notices that the two WSRs have been read, then clears the RSP_VALID flag? (That's what I took the text to mean)
Or do you mean that the SW should clear the RSP_VALID flag to accept the data? That would be a back-pressure signal, but I think the active party needs changing: maybe "the OTBN code clears" or something?
e1cb124 to
72d8f4c
Compare
etterli
left a comment
There was a problem hiding this comment.
Thank you @andrea-caforio for the questions. I have answered them and also redesigned the interface such that a process command is always required (a partial message no longer issues a process command).
f276e15 to
61acfdc
Compare
61acfdc to
5f41a7d
Compare
5f19c2e to
d875c5b
Compare
|
The latest version features:
|
5c24761 to
4ad932d
Compare
4ad932d to
4c5a43e
Compare
| - The session request is rejected because: | ||
| - The requested hashing configuration is invalid. | ||
| - System SW did not set `CFG_SHADOWED.entropy_ready` of the KMAC HWIP before OTBN SW is started. | ||
| - This error is reported with the first response after the `KMAC_CTRL.PROCESS` command. |
There was a problem hiding this comment.
Why do we only get this error after sending the PROCESS command? Already when sending the START command we should know whether the config is valid.
There was a problem hiding this comment.
Inside the KMAC the invalid config is detected immediately but the interface still goes to the "message absorb" phase. But no data is forwarded to the actual SHA3 core. I designed the interface this way because:
- For the static interface this behaviour is required for compatibility reasons. I wanted to keep the dynamic behaviour similar. I aggree, this is not a strong argument. We can relatively easily extend the dynamic interface such that it reports this after the START command. This extension is foreseen like the option to send a prefix.
- This behaviour simplifies the implementation of on application side. There is one state less to implement and verify. And we would need a way that OTBN SW can signal to the interface that it has checked the response. See also answer regarding why the CLOSE command is required.
- Knowing that the configuration was invalid directly after sending the configuration speeds up only the error case. Usually we can assume OTBN SW send a valid configuration and system SW did setup the KMAC properly. Having to check a response after the START command adds actually latency for the happy case.
I agree, delaying the error response until the full message has been sent is not the cleanest. However, I think this is acceptable. Does this clarify your question and do you accept it like this?
If not, I'm also happy to extend the app interface with such an immediate response.
There was a problem hiding this comment.
No, that's all perfect and reasonable. Thanks for explaining! Let's leave this one open for the future.
| - Can occur at any time when receiving digest data. | ||
| - See the KMAC HWIP documentation for error causes. | ||
|
|
||
| In case the polling times out, OTBN SW can either wait longer or abort the execution completely. |
There was a problem hiding this comment.
This sentence is ambiguous because it suggests that there is a hardware timeout. I don't think you need this sentence and can instead just say: If any of these errors happens, OTBN SW needs to abort the execution and system SW then has to take care of recovering the KMAC HWIP.
There was a problem hiding this comment.
The problem is that the 1st error (KMAC_STATUS.READY remains low after..) is non recoverable. And the interface can also not send any PRCOESS/DONE command. This error case happens only if the KMAC fails to accept a request. In this case, OTBN must abort the program execution and system SW must somehow start a recovery on the KMAC side. This is currently not yet supported by KMAC. But this feature then should somehow accept the pending requests such that the "recovery mode" of the OTBN side can end the session.
In contrast, if any of the other two errors occurs, OTBN SW can still end the session regularly (it must).
I will try to rewrite this distinction.
There was a problem hiding this comment.
The latest push now cleans up this section.
There was a problem hiding this comment.
Thanks, this section much clearer now!
My point regarding the timeout is that waiting even longer will not help. If the bit remains low for say more than 100 clock cycles, KMAC is dead. But I agree that this is different from the other two errors.
Question: why is it not sufficient to just perform the finish response handshake (IIRC a result of sending the DONE command) and then free the session?
Thanks, this is a lot simpler now and much easier to understand in my view. |
The flow is:
Now the problem is that the interface does not know when OTBN SW did read the RSP_ERROR flag. And thus it does not know when it can clear the RSP_VALID and all other error flags. And this is required to be ready for the next session. The CLOSE command is a clean way how OTBN SW can signal to the interface that it has read all flags and now longer needs the information. Note that once the finish response arrived, the session is fully terminated on the KMAC side. It is just a OTBN side problem. I thought about two approaches how to avoid a CLOSE command. But both have awkward consequences.
|
4c5a43e to
6ccdde2
Compare
|
Thanks @etterli for the latest updates including the reasoning of the DONE command. I wasn't aware that this is an OTBN-only thing (I thought you would send this also across to KMAC). But like you explained it, it makes sense. |
nasahlpa
left a comment
There was a problem hiding this comment.
Thanks Pascal - I had a look into the updates spec and it looks good to me.
This adapts the current simulator-only KMAC interface specification such that the new dynamic KMAC app interface can be used. Signed-off-by: Pascal Etterli <pascal.etterli@lowrisc.org>
6ccdde2 to
32a9840
Compare
|
Rebased on master to include the now merged KMAC interface implementation. |
|
It now also specifies that |
| This can be SHA3, SHAKE, cSHAKE, or KMAC. | ||
| See KMAC HWIP for encoding of values. | ||
| Note, cSHAKE uses prefix from KMAC HWIP CSRs (configured by SW), and KMAC always uses hard coded "KMAC" prefix. | ||
| 15-6: Reserved. Any write is ignored. Always reads as 0. |
There was a problem hiding this comment.
In theory all config bits would fit within 12 bits and we could use one ADDI to load the config. But to be prepared for eventual onehot encodings and for better SW code readability I chose a power of two offset. One instruction and one cycle more should not make the difference.
The last commit of this PR specifies the CSR/WSR based KMAC interface which OTBN SW can make use of to offload hashing operations.
Only the last commit is relevant. All other commits are part of #30141 (RTL of KMAC side of interface) or #30143 (required DV changes and RTL changes of IPs already using the app interface). Changes are expected for these PRs.