Skip to content

Encrypt packets in-place#1787

Merged
Rob-Hague merged 1 commit intosshnet:developfrom
Rob-Hague:encryptinplace
May 5, 2026
Merged

Encrypt packets in-place#1787
Rob-Hague merged 1 commit intosshnet:developfrom
Rob-Hague:encryptinplace

Conversation

@Rob-Hague
Copy link
Copy Markdown
Collaborator

Support in-place encryption in the cipher types, then use it on the plaintext packets instead of allocating a new array each time. Removes 2 of 4 bytes allocated for each byte uploaded over SFTP.

For AES-CTR, supporting in-place encryption in this case means adding a persistent buffer for the keystream and encrypting in chunks. The performance difference is ~1-2% i.e. marginal versus one-shotting it. The variance is similar also for different choices of buffer size (here 4096 is used).

Support in-place encryption in the cipher types, then use it on the plaintext packets
instead of allocating a new array each time. Removes 2 of 4 bytes allocated for each
byte uploaded over SFTP.

For AES-CTR, supporting in-place encryption in this case means adding a persistent buffer
for the keystream and encrypting in chunks. The performance difference is ~1-2% i.e.
marginal versus one-shotting it. The variance is similar also for different choices of
buffer size (here 4096 is used).
Rob-Hague added a commit to Rob-Hague/SSH.NET that referenced this pull request Apr 27, 2026
PR#1752 added a persistent buffer into which to decrypt packets, rather than allocating
a new array for each packet. This was on the back of sshnet#1733 which added support in the
cipher types for decrypting into a given buffer, but for the case of AES-CTR, not into
the same buffer in-place. sshnet#1787 adds that missing support, meaning we can now decrypt
in-place and remove the plaintext buffer.
Rob-Hague added a commit to Rob-Hague/SSH.NET that referenced this pull request Apr 27, 2026
sshnet#1752 added a persistent buffer into which to decrypt packets, rather than allocating
a new array for each packet. This was on the back of sshnet#1733 which added support in the
cipher types for decrypting into a given buffer, but for the case of AES-CTR, not into
the same buffer in-place. sshnet#1787 adds that missing support, meaning we can now decrypt
in-place, and the plaintext buffer becomes unnecessary.
@Rob-Hague Rob-Hague merged commit 8ed8d38 into sshnet:develop May 5, 2026
6 checks passed
@Rob-Hague Rob-Hague deleted the encryptinplace branch May 5, 2026 10:57
@Rob-Hague
Copy link
Copy Markdown
Collaborator Author

Thanks

Rob-Hague added a commit to Rob-Hague/SSH.NET that referenced this pull request May 5, 2026
sshnet#1752 added a persistent buffer into which to decrypt packets, rather than allocating
a new array for each packet. This was on the back of sshnet#1733 which added support in the
cipher types for decrypting into a given buffer, but for the case of AES-CTR, not into
the same buffer in-place. sshnet#1787 adds that missing support, meaning we can now decrypt
in-place, and the plaintext buffer becomes unnecessary.
Rob-Hague added a commit that referenced this pull request May 5, 2026
#1752 added a persistent buffer into which to decrypt packets, rather than allocating
a new array for each packet. This was on the back of #1733 which added support in the
cipher types for decrypting into a given buffer, but for the case of AES-CTR, not into
the same buffer in-place. #1787 adds that missing support, meaning we can now decrypt
in-place, and the plaintext buffer becomes unnecessary.
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