Repository navigation
perf(noise_sv2): use rust-bitcoin's chacha20-poly1305 for the AEAD - #2506
Open
rustaceanrob wants to merge 1 commit into
Open
rustaceanrob wants to merge 1 commit into
rustaceanrob wants to merge 1 commit into
Conversation
Our `chacha20-poly1305` implementation in `rust-bitcoin` has recently added multi-block SIMD support for both ChaCha20 and Poly1305. Performance is now better for all the roundtrip benchmarks due to a setup cost somewhere within RustCrypto's implementation (I am not as familiar with their implementation and cannot allude to why). This adds a wrapper class for `ChaCha20Poly1305` that uses the existing zeroize crate to clear memory on drop. Some additional message parsing is done when decrypting to extract the tag. Otherwise it is a simple replacement. A sanity check test that the wrapper is working is added as well. The `aead` crate is preserved to avoid a breaking change, but this can also be removed in a `3.0.0` with a simple new type. Considering Stratum already depends on `rust-bitcoin`, this allows for a consolidation of organizations Stratum depends on for maintenance. The tag check is done in constant time, same behavior as RustCrypto. Ryzen 7 7700, median of 3 runs: | Benchmark | RustCrypto | rust-bitcoin | Change | |-----------------------------------|------------|--------------|--------| | transport/roundtrip/64B | 4.70 us | 781 ns | -83% | | transport/roundtrip/256B | 4.83 us | 1.17 us | -76% | | transport/roundtrip/1024B | 6.12 us | 2.07 us | -66% | | transport/roundtrip/4096B | 11.89 us | 7.03 us | -41% | | noise/encode_only | 1.79 us | 407 ns | -77% | | encoder/noise/transport | 1.80 us | 396 ns | -78% | | handshake/handshake | 215.9 us | 211.9 us | -2% | Constant time equality check: https://github.com/rust-bitcoin/rust-bitcoin/blob/master/chacha20_poly1305/src/lib.rs#L147
Member
|
cc @bit-aloo |
Member
|
Damn!! rust-bitcoin's implementation is faster than rustcrypto 😆 I will have a look at this PR soon! |
bit-aloo
self-requested a review
November 16, 2026 17:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Our
chacha20-poly1305implementation inrust-bitcoinhas recently added multi-block SIMD support for both ChaCha20 and Poly1305. Performance is now better for all the roundtrip benchmarks due to a setup cost somewhere within RustCrypto's implementation (I am not as familiar with their implementation and cannot allude to why).This adds a wrapper class for
ChaCha20Poly1305that uses the existing zeroize crate to clear memory on drop. Some additional message parsing is done when decrypting to extract the tag. Otherwise it is a simple replacement. A sanity check test that the wrapper is working is added as well.The
aeadcrate is preserved to avoid a breaking change, but this can also be removed in a3.0.0with a simple new type. Considering Stratum already depends onrust-bitcoin, this allows for a consolidation of organizations Stratum depends on for maintenance.The tag check is done in constant time, same behavior as RustCrypto.
Ryzen 7 7700, median of 3 runs:
Constant time equality check: https://github.com/rust-bitcoin/rust-bitcoin/blob/master/chacha20_poly1305/src/lib.rs#L147