Repository navigation
crypto: no out-of-line calls on ChaCha20's per-message path (parity item 9, part) - #1015
Merged
Merged
Conversation
In the shipped profile every ChaCha20 message called out of line: - `features()` once per dispatch, several times per message; - the debug precondition check of `offset_from_unsigned` four times in the AVX state's construction, from `copy_from_slice` and `zip` over slice chunks. These are part of the per-message constant the track records on both benches (17 to 51 ns at 0 and 64 bytes). `initial` now builds the state by indexing, and `features()` inlines its cached load, leaving only the first read out of line and cold. The shipped x86-64 code of AEAD and OpenSSH seal, open and packet_length then calls neither on any instruction path; the remaining precondition calls are in the portable AES and GCM fallbacks, which no AES-NI machine runs. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PXEk8BBMDT8tXu4AnENB9Q
Collaborator
Author
Review of #1015, round 1 (head 74aa231, item 9 part)I read the commit, What was removedNothing safety-relevant.
Evidence
FindingsNo blockers. SUGGESTION
PR body (orchestrator): the base is d7f269d, not 81c1386. Verdict: LAND. |
Japabu
marked this pull request as ready for review
October 22, 2026 13:13
This was referenced Oct 22, 2026
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.
Based on main (d7f269d); independent of #1013 and #1014. One commit, 74aa231.
Problem
The track records a per-message constant on ChaCha20-Poly1305: 17–51 ns over ring at 0 and 64 bytes, on both benches. At #1000 on the T14, seal/0 was 1.18 and seal/64 1.12; on the AMD bench (probe fb93764) seal/0 was 1.26 and seal/64 1.34.
In
[profile.toyos](x86-64), every ChaCha20 message made out-of-line calls that do no work:arch::x86_64::features(), once per dispatch decision, several times per message;offset_from_unsigned's debug precondition check (runtime_ptr_ge) ininitial, the AVX paths' state construction, fromcopy_from_sliceandzipover slice chunks.What changes
initialbuilds the state by indexing.features()inlines its cached atomic load; only the first read stays out of line,#[cold].packet_lengthcall neither any more. The remaining precondition calls are in the portable AES and GCM fallbacks, which no AES-NI machine runs.This is part of item 9 (its C2 and C4 constant). The stitched AVX2 kernel (C1) is already on main. Open's keystream stitch (C1a) and the short-message reorganisation (C2) need bench iterations.
Checks
All at 74aa231. Logs: https://github.com/ToyOSOrg/evidence/tree/b82a36fafc5dcd508a202ef44fdd09e9c1272157/pr-1015/r1
cargo run -- --ci host: exit 0, 93 steps green.-D warnings) in the three CI forms, for the host and--target x86_64-apple-darwin: exit 0. Crate tests in the three forms: exit 0.x86_64-unknown-uefibuild: exit 0.cargo test -p toyos-crypto --features std,sign,wpa2,rustls-provider --release --target x86_64-apple-darwin(Rosetta): exit 0. Rosetta reports no AVX2, so this runs SSE and AES-NI paths only, notinitial.crypto_instrument_prints_its_table(QEMU x86_64): exit 0. The harness's CPU model has AVX2, and before timingcrypto_paritychecks ours against ring at every length from 0 to 1153 B, through this AVX2 path. That is the test that reachesinitial.initialproduces the same 16 words as before: SIGMA, the eight key words, two zero counter words, the two nonce words. Inspection settles that; no new test.Measurements
Readback staged at 74aa231 (
crypto_instrument,cryptocase; exit 2 = Staged). The rows to read are the ChaCha20-Poly1305 and OpenSSH ones at 0, 64 and 1024 B on both benches. I don't know how much of the constant these calls are; this run measures it.Risks
None known beyond the measurement still to come. GCM's 1 KiB shipped-profile loss on the T14 (G7) was not found here: the VAES and AES-NI kernels make no out-of-line call in either profile.
🤖 Generated with Claude Code
https://claude.ai/code/session_01PXEk8BBMDT8tXu4AnENB9Q