Skip to content

Align HsmHashAlgo discriminants with Crypto Engine encoding - #676

Open
Aakash Sasidharan (asasidharan) wants to merge 1 commit into
Azure:mainfrom
asasidharan:asasidharan-mrvl/align-hsmhashalgo-discriminants
Open

Align HsmHashAlgo discriminants with Crypto Engine encoding#676
Aakash Sasidharan (asasidharan) wants to merge 1 commit into
Azure:mainfrom
asasidharan:asasidharan-mrvl/align-hsmhashalgo-discriminants

Conversation

@asasidharan

Copy link
Copy Markdown

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.

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 AI lite review requested due to automatic review settings August 27, 2026 08:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 u32 discriminants on HsmHashAlgo variants (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.
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.

2 participants