Skip to content

Bound DH agree output and fix FFDHE size guard - #11930

Open
embhorn wants to merge 3 commits into
wolfSSL:masterfrom
embhorn:zd22715
Open

embhorn wants to merge 3 commits into
wolfSSL:masterfrom
embhorn:zd22715

Conversation

@embhorn

@embhorn embhorn commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Description

  • DhAgree() (src/internal.c): return BUFFER_E when agreeSz is smaller than the DH prime, before calling wc_DhAgree(). The sp_DhExp_ paths and the generic non-ct path write the full secret without checking the buffer.
  • wc_DhAgree(): behaviour unchanged. agreeSz is documented as output only, and callers such as hostap pass it uninitialized. The doxygen now states that the input size isn't checked, the buffer must hold the full prime, and wc_DhAgree_ct() is the variant that checks.
  • tfm.h / sp_int.h: check the largest FFDHE group against FP_MAX_BITS and SP_INT_BITS once those are final. The settings.h guard only ran when the size was set explicitly, so a defaulted FP_MAX_BITS (4096) with FFDHE-4096 built without error.

Fixes zd22715

Testing

  • New API test test_tls13_ffdhe_pms_too_small: a TLS 1.3 FFDHE-2048 handshake with the server's pre-master buffer one byte short fails with BUFFER_E. The test fails without the DhAgree() change.
  • wc_DhAgree() with agreeSz = 0 (the hostap pattern) succeeds again.
  • testwolfcrypt and unit.test pass for the default build and --enable-fastmath and --enable-all.
  • Compile checks: fastmath + FFDHE-4096 with the default FP_MAX_BITS now hits #error; SP_INT_DIGITS set too small for FFDHE-4096 hits #error; valid configs still build.

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@embhorn embhorn self-assigned this Oct 29, 2026
Copilot AI balanced review requested due to automatic review settings October 29, 2026 21:21

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

@embhorn

embhorn commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

Changes reviewed and approved by customer

@embhorn embhorn assigned wolfSSL-Bot and unassigned embhorn Oct 30, 2026
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