Align HsmHashAlgo discriminants with Crypto Engine encoding - #676
Open
Aakash Sasidharan (asasidharan) wants to merge 1 commit into
Open
Conversation
Set explicit u32 discriminants (Sha1=2, Sha256=4, Sha384=5, Sha512=6) on fw/pal/traits::HsmHashAlgo to match the crypto engine's encoding field. No behavior change: HsmHashAlgo is only ever matched by variant name today (no numeric cast or TryFrom relies on the old sequential 0..3 values), so existing PALs (Uno's explicit From<HsmHashAlgo> for ShaMode, and the OpenSSL/CNG-backed std PAL) are unaffected.
Copilot started reviewing on behalf of
Aakash Sasidharan (asasidharan)
August 27, 2026 08:14
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the PAL-traits hash algorithm enum to use explicit u32 discriminants that align with an underlying crypto engine encoding, enabling direct numeric mapping where applicable.
Changes:
- Set explicit
u32discriminants onHsmHashAlgovariants (Sha1=2, Sha256=4, Sha384=5, Sha512=6). - Expanded the enum’s documentation to describe the intended hardware-encoding alignment and PAL boundary behavior.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+21
to
+27
| /// Discriminant values are `u32` and are fixed to match the CPT crypto | ||
| /// hardware's MAC-Select field encoding (`PARAM2[3:0]`; see | ||
| /// `fw/crates/crypto/hash/src/pal/cpt.rs` in tiger-collab). A CPT-backed PAL | ||
| /// can therefore cast `algo as u32` directly into `mac_select` with no | ||
| /// translation table. Platforms whose hardware uses a different encoding | ||
| /// (e.g. the Uno SHA engine's `ShaMode`) still perform an explicit | ||
| /// `From<HsmHashAlgo>` match at the PAL boundary. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Set explicit u32 discriminants (Sha1=2, Sha256=4, Sha384=5, Sha512=6) on fw/pal/traits::HsmHashAlgo to match the crypto engine's encoding field.
No behavior change: HsmHashAlgo is only ever matched by variant name today (no numeric cast or TryFrom relies on the old sequential 0..3 values), so existing PALs (Uno's explicit From for ShaMode, and the OpenSSL/CNG-backed std PAL) are unaffected.