rust-bitcoin-unsafe-fast/chacha20_poly1305/src
merge-script 35a49993c8
Merge rust-bitcoin/rust-bitcoin#4083: Improve chacha20 cipher performance
1ca55ac77d chacha20_poly1305: inline simd functions (Nick Johnson)
30920c4d84 chacha20_poly1305: drop mutable requirement (Nick Johnson)
415945cd2b chacha20_poly1305: avoid duplicate block work (Nick Johnson)
33dc1b95fa chacha20_poly1305: swap tuple for array (Nick Johnson)
dadd1d7224 chacha20_poly1305: remove alignment (Nick Johnson)
36d45bf360 chacha20_poly1305: remove mod operator (Nick Johnson)

Pull request description:

  Inspired by JeremiahR's new benchmark on the chacha20 module, I dug in and found a few tweaks (and a larger refactor) which help a lot with performance.

  The tweaks are broken down by commit. One of the relatively fruitful ones (5% increase) was refactoring the U32x4's rotation methods to use hardcoded matches instead of the mod operator. Others saw more modest performance gains.

  The big change though was to *not* calculate two blocks for each keystream call (oops). I refactored the logic to handle the offset state (which is technically not required for BIP324, but as seen here, can be confusing to not have) and now we always calculate just the required amount of a keystream. This about doubles the performance.

  For the curious, the SIMD performance isn't very impressive at this point, just a modest increase. But I have some hope that the experimental core library U32x4 will bring a nice bump (it is implemented with some unsafe hacking) and be an easy refactor.

ACKs for top commit:
  apoelstra:
    ACK 1ca55ac77db698f3816d8b7ed4051ddb5a579a29; successfully ran local tests
  tcharding:
    ACK 1ca55ac77d

Tree-SHA512: 8db1c6144d172775164859ffd0d97021f90d9123d06b5cccde21800aec4dcea75a5753d547933288ae233caf82e92849f894fb7019537d188baf10fbf7019684
2025-05-15 12:47:00 +00:00
..
benches.rs 2025-02-23 automated rustfmt nightly 2025-02-23 01:21:34 +00:00
chacha20.rs Merge rust-bitcoin/rust-bitcoin#4083: Improve chacha20 cipher performance 2025-05-15 12:47:00 +00:00
lib.rs Merge rust-bitcoin/rust-bitcoin#4083: Improve chacha20 cipher performance 2025-05-15 12:47:00 +00:00
poly1305.rs fix duplicate poly1305.rs 2025-05-07 12:57:11 +03:00