Hash the pad byte of K without a branch - #1283
Open
ejohnstown wants to merge 1 commit into
Open
ejohnstown wants to merge 1 commit into
ejohnstown wants to merge 1 commit into
Conversation
The MSB of the shared secret K decides whether its mpint encoding takes a 0 pad byte. CreateMpint now derives the pad with masks, and HashMpintHeader hashes the length and the optional pad as one update of LENGTH_SZ + kPad bytes: no branch on the pad in wolfSSH, and no zero-length update, which the SE050 and TI hash ports reject. - apply to DoKexDhReply, SendKexDhReply, and the in-tree GenerateKey - add wolfSSH_TestCreateMpint and a unit test of the pad, leading-zero, empty-input and NULL-argument cases Issue: F-8808
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The security-sensitive padded hashing path lacks known-answer test coverage.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Refactors shared-secret mpint hashing to avoid branching on the pad byte.
Changes:
- Adds branchless mpint header hashing.
- Updates key exchange and key derivation paths.
- Adds
CreateMpint()edge-case tests.
| File | Description |
|---|---|
src/internal.c |
Implements branchless pad handling and hashing. |
wolfssh/internal.h |
Exposes the internal test wrapper. |
tests/unit.c |
Tests mpint normalization and validation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| pad &= 1; | ||
| c32toa(sz + pad, hdr); | ||
| hdr[LENGTH_SZ] = 0; | ||
| return HashUpdate(hash, type, hdr, LENGTH_SZ + pad); |
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.

The MSB of the shared secret K decides whether its mpint encoding takes a 0 pad byte. The pad is now derived with masks and hashed with the length in a single update, with no branch on it in wolfSSH (F-8808).