Skip to content

Conversation

Rob-Hague
Copy link
Collaborator

When the key exchange produces less key material than is needed for the cipher or hmac algorithms, there is an iterative procedure to produce more.

For example, a SHA-1 key exchange algorithm produces 20 bytes of key material. A SHA-256 hmac uses a 32 byte key, so one iteration of the procedure produces another 20 bytes of key material for a total of 40 which is sufficient for the hmac key.

The library works correctly in such cases of one iteration, but the logic is wrong if more than one iteration is needed. In #1660, the connection uses a SHA-1 kex algorithm with a SHA-512 hmac (64 byte key), requiring 3 iterations of the extension procedure and resulting in an error upon connection.

This change fixes the logic to use the output of the previous iteration per the spec.

closes #1660

When the key exchange produces less key material than is needed for the cipher or hmac
algorithms, there is an iterative procedure to produce more.

For example, a SHA-1 key exchange algorithm produces 20 bytes of key material.
A SHA-256 hmac uses a 32 byte key, so one iteration of the procedure produces another
20 bytes of key material for a total of 40 which is sufficient for the hmac key.

The library works correctly in such cases of one iteration, but the logic is wrong if
more than one iteration is needed. In sshnet#1660, the connection uses a SHA-1 kex algorithm
with a SHA-512 hmac (64 byte key), requiring 3 iterations of the extension procedure and
resulting in an error upon connection.

This change fixes the logic to use the output of the previous iteration per the spec.

closes sshnet#1660
@Rob-Hague Rob-Hague merged commit b199467 into sshnet:develop Aug 17, 2025
4 checks passed
@Rob-Hague Rob-Hague deleted the keyextension branch August 17, 2025 21:49
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.

SshConnectionException: MAC Error when using only hmac-sha2-512 with .NET 8 and SSH.NET 2024.1.0
3 participants