Skip to content

dh: reject generation controls wolfSSL cannot apply - #486

Merged
ColtonWilley merged 1 commit into
wolfSSL:masterfrom
yosuke-wolfssl:fix/f_12485
Oct 1, 2026
Merged

ColtonWilley merged 1 commit into
wolfSSL:masterfrom
yosuke-wolfssl:fix/f_12485

Conversation

@yosuke-wolfssl

@yosuke-wolfssl yosuke-wolfssl commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The DH generation context accepted DH_GENERATOR and DH_PRIV_LEN but never
read them, so a caller asking for a generator or a private-key length got
success and backend-default output. wolfCrypt cannot apply either:
wc_DhGenerateParams() derives g itself, and wc_DhGenerateKeyPair() takes
the private length from the group. Reachable from openssl dhparam -5,
genpkey -pkeyopt priv_len:N and EVP_PKEY_CTX_set_params(). An API contract
violation, not a crypto weakness. Closes 12485.

Fix (src/wp_dh_kmgmt.c)

Request Result
priv_len non-zero PROV_R_NOT_SUPPORTED at set-params (0 accepted)
generator < 2 PROV_R_INVALID_DATA at set-params
generator other than 2, parameter generation PROV_R_NOT_SUPPORTED
generator 2, parameter generation accepted, not applied (see below)
generator, named group or parameters key accepted only if the group's g matches

Both parameters stay in the settable list, so -pkeyopt and the
EVP_PKEY_CTX_set_dh_* helpers reach the provider and report its error.
README.md documents the refused requests under DH.

Limitation: openssl dhparam sends generator 2 whenever the user names
none, so 2 is accepted to keep openssl dhparam 2048 working, but wolfSSL
still derives its own g.

Tests

test_dh_pgen_controls covers both controls over parameter and key
generation, including the group-name and parameters-key paths.

Verification

  • Build clean; unit suite 234/234 pass.
  • test_dh_pgen_controls fails on master, where generator 5 and
    priv_len:256 are accepted and ignored.
  • openssl dhparam 2048 works; dhparam -5 fails with not supported.

@yosuke-wolfssl yosuke-wolfssl self-assigned this Sep 3, 2026
Copilot AI lite review requested due to automatic review settings September 3, 2026 05:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new DH control test can produce false-negatives by not asserting that setting a valid generator succeeds before expecting paramgen to fail.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR tightens the DH generation API contract by rejecting DH generation controls (DH_GENERATOR, DH_PRIV_LEN) that wolfSSL cannot actually honor, and adds unit coverage to ensure callers see deterministic failures instead of silent backend defaults.

Changes:

  • Reject non-zero DH_PRIV_LEN at set-params time with PROV_R_NOT_SUPPORTED.
  • Validate and enforce DH_GENERATOR behavior: reject invalid (<2), reject during parameter generation, and only accept during keygen when it matches the group/template generator.
  • Add unit tests covering generator/priv_len behavior across paramgen and keygen flows.
File summaries
File Description
test/unit.h Registers the new DH control test declaration.
test/unit.c Adds the new test case to the unit test table.
test/test_dh.c Adds coverage for DH generator and private-length controls across paramgen/keygen.
src/wp_dh_kmgmt.c Enforces rejection/acceptance rules for unsupported DH generation controls.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Lite

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

Comment thread test/test_dh.c Outdated
Comment thread src/wp_dh_kmgmt.c Outdated

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #486

Scan targets checked: wolfprovider-bugs, wolfprovider-src

Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Comment thread src/wp_dh_kmgmt.c Outdated
Comment thread src/wp_dh_kmgmt.c Outdated

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #486

Scan targets checked: wolfprovider-bugs, wolfprovider-src

Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Comment thread test/test_dh.c
Comment thread test/test_dh.c
- wp_dh_gen_set_params() reads DH_PRIV_LEN and DH_GENERATOR into
  locals: a non-zero length fails with PROV_R_NOT_SUPPORTED, a
  generator below 2 with PROV_R_INVALID_DATA, and ctx->generator is
  assigned only after that check.
- wp_dh_gen_parameters() fails before wc_DhGenerateParams() when a
  generator other than 2 was requested; wp_dh_gen_copy_parameters()
  fails when mp_cmp_d() against the group's g is not equal.
- wp_DhGenCtx drops privLen, and generator holds the caller's request
  with 0 meaning none, so wp_dh_gen_init() no longer sets it to 2.
- README.md describes the DH generator and private key length
  requests that are refused.
- test_dh_pgen_controls covers both controls over parameter and key
  generation, running the generator cases through the group-name and
  the parameters-key path.

Issue: F-12485

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #486

Scan targets checked: wolfprovider-src, wolfprovider-bugs
Coverage: 1 of 3 in-scope changed file(s) opened by the reviewer; not opened: test/test_dh.c, test/unit.c

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Lite

@wolfSSL-Fenrir-bot
wolfSSL-Fenrir-bot dismissed stale reviews from themself September 30, 2026 23:52

Fenrir's latest completed scan found no issues; clearing the prior automated change request.

@ColtonWilley
ColtonWilley merged commit 6245ca2 into wolfSSL:master Oct 1, 2026
82 checks passed
@yosuke-wolfssl
yosuke-wolfssl deleted the fix/f_12485 branch October 1, 2026 23:08
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.

5 participants