Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ot] hw/opentitan: ot_hmac: Restore correct msg_length with HMAC_EN #151

Merged
merged 1 commit into from
Mar 20, 2025

Conversation

AlexJones0
Copy link

Fixes a bug introduced to HMAC with the save/restore additions. All tests that can currently be run for HMAC are passing, except:

  • The hmac_kat tests, which require a test harness.
  • The 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.

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
commit 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.

This caused an error where, when saving and restoring context with
HMAC_EN=1, the hash length would be undercounted by a block and thus the
incorrect digest would be computed. This meant that save/restore and
streaming operations were not working properly with HMAC_EN.

This commit introduces the additional logic to fix this edge case.

Signed-off-by: Alex Jones <[email protected]>
Copy link

@rivos-eblot rivos-eblot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jwnrt jwnrt merged commit 68a8807 into lowRISC:ot-earlgrey-9.2.0 Mar 20, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants