Skip to content

Check SHE field widths in the software path only - #11279

Open
night1rider wants to merge 1 commit into
wolfSSL:masterfrom
night1rider:SHE-SoftwarePathValidation
Open

Check SHE field widths in the software path only#11279
night1rider wants to merge 1 commit into
wolfSSL:masterfrom
night1rider:SHE-SoftwarePathValidation

Conversation

@night1rider

Copy link
Copy Markdown
Contributor

A crypto callback builds the SHE messages itself and may use its own wider key numbering, so the software packing limits must not reject its values.

A crypto callback builds the SHE messages itself and may use its own wider
key numbering, so the software packing limits must not reject its values.
Copilot AI lite review requested due to automatic review settings August 25, 2026 23:08

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

This PR adjusts SHE message generation so packed-field width checks (counter/flags/key IDs) are enforced only on the software packing path, allowing crypto-callback implementations (e.g., secure elements/HSMs) to accept wider logical key numbering without being rejected up-front.

Changes:

  • Moved packed-field width validation in wc_SHE_GenerateM1M2M3() to occur only after the crypto-callback attempt (i.e., only for software path).
  • Moved packed-field width validation in wc_SHE_GenerateM4M5() to occur only after the crypto-callback attempt (i.e., only for software path).
Suppressed comments (2)

wolfcrypt/src/wc_she.c:705

  • As with M1/M2/M3 generation, the callback path can now accept key IDs beyond WC_SHE_KEY_ID_MAX, but the public header docs describe authKeyId/targetKeyId as 4-bit slot IDs. Consider updating the API documentation to clarify that the software path enforces packed-field widths, while callbacks may use their own key numbering/mapping.
    /* Only the software path packs these into M4, so the widths are
     * checked here.  A callback may use its own key numbering. */
    if (counter > WC_SHE_COUNTER_MAX ||

wolfcrypt/src/wc_she.c:708

  • There are existing tests that assert BAD_FUNC_ARG for out-of-range packed field widths on the software path, but no test appears to validate that the callback path bypasses these width checks (e.g., allowing authKeyId/targetKeyId > WC_SHE_KEY_ID_MAX when the callback succeeds). Adding a callback-path regression test would help ensure this behavioral contract remains intact.
    if (counter > WC_SHE_COUNTER_MAX ||
        authKeyId > WC_SHE_KEY_ID_MAX || targetKeyId > WC_SHE_KEY_ID_MAX) {
        return BAD_FUNC_ARG;
    }

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread wolfcrypt/src/wc_she.c
Comment on lines +522 to +524
/* Only the software path packs these into M1 and M2, so the widths
* are checked here. A callback may use its own key numbering. */
if (counter > WC_SHE_COUNTER_MAX || flags > WC_SHE_FLAGS_MAX ||
Comment thread wolfcrypt/src/wc_she.c
Comment on lines +524 to +527
if (counter > WC_SHE_COUNTER_MAX || flags > WC_SHE_FLAGS_MAX ||
authKeyId > WC_SHE_KEY_ID_MAX || targetKeyId > WC_SHE_KEY_ID_MAX) {
return BAD_FUNC_ARG;
}
@wolfSSL-Bot

Copy link
Copy Markdown

Can one of the admins verify this patch?

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