[ot] hw/opentitan: ot_hmac: Restore correct msg_length with HMAC_EN #151
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes a bug introduced to HMAC with the save/restore additions. All tests that can currently be run for HMAC are passing, except:
hmac_kat
tests, which require a test harness.clkmgr_off_hmac_trans_test
, which is reliant on other blocks (e.g. clkmgr).hmac_multistream_functest
, which this PR aims to address to get the HMAC as functional as possible.HMAC can operate either with HMAC_EN, using HMAC algorithms, or without, using standard SHA algorithms. The HMAC algorithms introduce additional logic surrounding a key, and inner and outer padding. Relevant to this PR is that when computing HMAC, we first process a block of inner padding XORed with the key. This means that the message length reported to software in the MSG_LENGTH register diverges from the message length reported by the tomcrypt cryptographic library's state. Specifically, with HMAC_EN=1, it undercounts by a block. See relevant RTL.
This caused an error where, when saving and restoring context with HMAC_EN=1, the hash length would be undercounted by a block, leading to different hash computations. This meant that save/restore and streaming operations were not working properly with HMAC_EN.
This PR introduces additional logic to fix this edge case. All existing HMAC tests appear to continue to pass, and the
hmac_multistream_functest
is now passing with this change.