Skip to content

ChaCha20-Poly1305: compute the Poly1305 key block once - #56

Merged
david415 merged 1 commit into
mainfrom
chachapoly-speed
Oct 27, 2026
Merged

david415 merged 1 commit into
mainfrom
chachapoly-speed

Conversation

@david415

Copy link
Copy Markdown
Member

`tagOf` built the 32-byte one-time Poly1305 key as `Vector.ofFn fun i => (block key n 0)[i]!`, and the compiled code ran the ChaCha20 block for every byte: 32 blocks per seal or open. Binding the block once removes about 100 µs from every call. That fixed cost dominated small messages such as QUIC packets: huh over lean_quic seals and opens one ChaCha20-Poly1305 packet per datagram.

encrypt before after
64 B 131 µs 27 µs
1200 B 383 µs ~250 µs

The "before" column comes from a probe in lean_quic, the "after" column from the new `chacha20-poly1305 encrypt 64B/1200B` benchmarks added here.

No proof unfolds `tagOf`'s body, so nothing else changes. `make test` passes, including 316/316 Wycheproof ChaCha20-Poly1305 vectors.

The rest of the per-packet cost is mostly Poly1305 over `Nat`, about 170 µs per KiB. That is for a separate PR.

@david415
david415 merged commit 37c2ae1 into main Oct 27, 2026
3 checks passed
@david415
david415 deleted the chachapoly-speed branch October 27, 2026 13:48
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.

1 participant