Skip to content

Conversation

@EpicEric
Copy link
Contributor

@EpicEric EpicEric commented Jun 26, 2025

Closes #532.

By switching the ChaCha20Poly1305, AES-GCM-128 and AES-GCM-256 ciphers from the RustCrypto implementation to ring's, my port forwarding benchmarks resulted in a substantial performance gain of an order of magnitude on my machine.

With current main With this PR
ChaCha20Poly1305 8s 18ms 662 ms
AES-GCM-128 6s 280ms 557ms
AES-GCM-256 6s 396ms 552ms

But results seem to vary depending on your hardware, where we see much smaller or no gains. On a different machine with limited memory and less CPU power (and a different benchmark):

With current main With this PR
ChaCha20Poly1305 660ms 654ms
AES-GCM-256 803ms 615ms

This implementation also changes the signature for the OpeningKey::open method to not split the tag from the cipher prematurely.

I have tested ChaCha20Poly1305 and AES-GCM-256 against the current release of russh and OpenSSH, but not AES-GCM-128, although I expect it to work the same.

@Eugeny
Copy link
Owner

Eugeny commented Jun 28, 2025

Thanks! I've added direct benchmarks for the ciphers and the GCM gains are just as dramatic on my side.

Out of curiousity, why did you decide to switch to ring from aws-lc? It seems that the general ecosystem trend is heading towards aws-lc (see rustls), especially given how it is FIPS certified.

@EpicEric
Copy link
Contributor Author

EpicEric commented Jun 28, 2025

We could switch to the aws-lc-rs implementations instead, I just wasn't able to figure out how to make it compile for Windows or WASM, so I went with ring for this PR.

@EpicEric EpicEric changed the title Use ring implementation for AEAD ciphers Use aws-lc-rs implementation for AEAD ciphers Jun 28, 2025
@EpicEric EpicEric changed the title Use aws-lc-rs implementation for AEAD ciphers Use aws-lc-rs/ring implementation for AEAD ciphers Jun 28, 2025
@EpicEric
Copy link
Contributor Author

EpicEric commented Jun 28, 2025

Given that WebAssembly doesn't seem to be a supported platform for aws-lc-rs, I've replaced the dependency with ring for the target.

Perhaps choosing between either package should be a feature flag in the same vein as rustls? EDIT: I've done just that.

@Eugeny
Copy link
Owner

Eugeny commented Jun 29, 2025

Looking great now 👍 👍

@Eugeny Eugeny merged commit c41d4f6 into Eugeny:main Jun 29, 2025
8 checks passed
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.

Implement faster AEAD ciphers

2 participants