Skip to content

Fix key material extension during key exchange #1689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

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
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
1 participant