Skip to content

crypto: ssh2_dh_key_pair() reject group_order <= 0, where missing - #2154

Closed
vszakats wants to merge 2 commits into
libssh2:masterfrom
vszakats:dh3
Closed

vszakats wants to merge 2 commits into
libssh2:masterfrom
vszakats:dh3

Conversation

@vszakats

@vszakats vszakats commented Jun 30, 2026 •

Copy link
Copy Markdown
Member

As already done in WinCNG, but for negative only.

Follow-up to 5a96f49 #879

@vszakats vszakats changed the title crypto: ssh2_dh_key_pair() reject negative group_order, where missing crypto: ssh2_dh_key_pair() reject negative group_order, where missing Jun 30, 2026
@vszakats
vszakats requested a review from Copilot June 30, 2026 12:06

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.

Pull request overview

This PR aligns multiple crypto backends by adding an explicit guard in ssh2_dh_key_pair() to reject negative group_order values (matching the WinCNG behavior introduced previously), preventing negative sizes from flowing into DH private exponent generation.

Changes:

  • Add group_order < 0 early-return guards in DH keypair generation across OS/400 QC3, OpenSSL, mbedTLS, and libgcrypt backends.
  • Minor expression parenthesization in OpenSSL/libgcrypt DH exponent bit-length calculation.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/os400qc3.c Adds negative group_order rejection in OS/400 QC3 DH keypair routine.
src/openssl.c Adds negative group_order rejection and tweaks the DH exponent bit-length expression.
src/mbedtls.c Adds negative group_order rejection in mbedTLS DH keypair routine.
src/libgcrypt.c Adds negative group_order rejection and tweaks the DH exponent bit-length expression.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/openssl.c Resolved
Comment thread src/libgcrypt.c Resolved
Comment thread src/os400qc3.c Resolved
Comment thread src/mbedtls.c Resolved
@vszakats vszakats changed the title crypto: ssh2_dh_key_pair() reject negative group_order, where missing crypto: ssh2_dh_key_pair() reject negative/zero group_order, where missing Jun 30, 2026
@vszakats vszakats changed the title crypto: ssh2_dh_key_pair() reject negative/zero group_order, where missing crypto: ssh2_dh_key_pair() reject group_order <= 0, where missing Jun 30, 2026
@vszakats
vszakats requested a review from Copilot June 30, 2026 12:40

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

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.

2 participants