Skip to content

bench: ChaCha20-Poly1305 below 1 KiB and at 4 KiB; encrypt from two pieces - #1337

Merged
alex merged 1 commit into
mainfrom
claude/chacha20poly1305-bench-sizes
Oct 8, 2026
Merged

alex merged 1 commit into
mainfrom
claude/chacha20poly1305-bench-sizes

Conversation

@alex

@alex alex commented Oct 8, 2026

Copy link
Copy Markdown
Member

This comes out of the rustls provider analysis in #991. That provider seals TLS records with ChaCha20-Poly1305, and against aws-lc-rs on a Cascade Lake–class Xeon it is 0.58–0.84× as fast below 1 KiB. encrypt from two pieces (a TLS 1.3 record's shape) is also 3–7% slower than copying the pieces and calling encrypt_in_place. Neither shows in the benchmarks as they are: they measure 64 B, 1 KiB and 16 KiB only, and encrypt from a single piece. This PR changes only the benchmarks, so the PRs that follow are measured where it matters.

  • Every ChaCha20-Poly1305 group measures 16, 64, 256, 512, 768, 1024, 4096 and 16384 bytes.
  • chacha20poly1305-encrypt-out-of-place takes its plaintext in two pieces: size - 1 bytes of payload and the content type. aws-lc-rs runs seal_out_of_place_scatter with the content type as its extra_in; OpenSSL encrypts one buffer, as before.
  • New group chacha20poly1305-copy-encrypt-in-place: this library copying the two pieces into the output, then encrypt_in_place. It is what the provider does today, and encrypt should be no slower.

On a Sapphire Rapids–class machine (AVX-512 backend), encrypt is 5–9% slower than copy + encrypt_in_place at every size:

bytes encrypt (2 pieces) copy + encrypt_in_place
16 229 ns 212 ns
1024 872 ns 830 ns
16384 7.51 µs 6.86 µs

(Minimum of 41 interleaved samples each.)

🤖 Generated with Claude Code

https://claude.ai/code/session_01Ma2fA9rUTPXEEQjYyCMCRw


Generated by Claude Code

…ieces

The ChaCha20-Poly1305 groups measure 16, 64, 256, 512, 768, 1024, 4096
and 16384 bytes, where TLS records fall. Out-of-place encryption takes
its plaintext in two pieces, as a TLS 1.3 record's is (the payload and
the content type), with aws-lc-rs's seal_out_of_place_scatter taking the
last as its extra_in; and a new group measures copying the pieces into
the output and encrypting it in place, which encrypt should beat.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ma2fA9rUTPXEEQjYyCMCRw
@alex
alex added this pull request to the merge queue Oct 8, 2026
Merged via the queue into main with commit e10768f Oct 8, 2026
39 checks passed
@alex
alex deleted the claude/chacha20poly1305-bench-sizes branch October 8, 2026 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants