Check SHE field widths in the software path only - #11279
Open
night1rider wants to merge 1 commit into
Open
Conversation
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.
Contributor
There was a problem hiding this comment.
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 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 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; | ||
| } |
|
Can one of the admins verify this patch? |
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.
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.