Skip to content

Conversation

gcsbt
Copy link
Contributor

@gcsbt gcsbt commented Sep 1, 2025

In the SSH 2.0 protocol, there are roughly three different Diffie-Hellman key exchange protocols:

  • The first one, simply called Diffie-Hellman Key Exchange, defined in RFC4253 § 8
  • The second one that use ECDH, defined in RFC6239 § 4
  • The last one, called Diffie-Hellman Group and Key Exchange, defined in RFC4419 § 3

The Diffie-Hellman key exhange protocol depends on the KEX algorithms that has been negociated during the Key Exchange Init stage.

This commit adds support for these three Diffie-Hellman key exchange protocols, by implementing a new API called SshKEX.

To use SshKEX, users must have retrieved the SshPacketKeyExchange from the client and the server. Then, SshKEX::init is called to initialize the KEX stage.

Later, depending on the type of the messages that come, SshKEX::parse_ssh_packet is called to feed the pending KEX stage.

Finally, the various sub-stages specific to each DH key exchange protocols are exposed through the SshKEX interface.

Tests have been added to ensure that these three protocols are well supported.

If the feature flag integers is enabled, some sub-stages may expose BigInt instead of the integers in raw format.

No copy or no memory allocation is used here.

Notes

To give credit where it's due, I'm not the author of this PR (which is preserved in the git commit).

I just rebased the original PR on master and fix a few warnings here and there.

thb-sb and others added 2 commits September 1, 2025 10:37
In the SSH 2.0 protocol, there are roughly three different Diffie-Hellman key exchange protocols:

 - The first one, simply called Diffie-Hellman Key Exchange, defined in [RFC4253 § 8](https://datatracker.ietf.org/doc/html/rfc4253#section-8)
 - The second one that use ECDH, defined in [RFC6239 § 4](https://datatracker.ietf.org/doc/html/rfc6239#section-4)
 - The last one, called Diffie-Hellman Group and Key Exchange, defined in [RFC4419 § 3](https://datatracker.ietf.org/doc/html/rfc4419#section-3)

The Diffie-Hellman key exhange protocol depends on the KEX algorithms that has been negociated
during the _Key Exchange Init_ stage.

This commit adds support for these three Diffie-Hellman key exchange protocols, by implementing
a new API called `SshKEX`.

To use `SshKEX`, users must have retrieved the `SshPacketKeyExchange`
from the client and the server. Then, `SshKEX::init` is called to initialize
the KEX stage.

Later, depending on the type of the messages that come, `SshKEX::parse_ssh_packet`
is called to feed the pending KEX stage.

Finally, the various sub-stages specific to each DH key exchange protocols are
exposed through the `SshKEX` interface.

Tests have been added to ensure that these three protocols are well supported.

If the feature flag `integers` is enabled, some sub-stages may expose `BigInt`
instead of the integers in raw format.

No copy or no memory allocation is used here.

Signed-off-by: gcsbt <[email protected]>
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.

1 participant