Repository navigation
constant_time_equal reads 64-bit words, its accumulator a register - #4
Merged
Merged
Conversation
…ister crypto's constant-time lane on wasip2 failed on crypto#24 (run 47265884663): constant_time_equal read |t| 115.04, 120.80 and 146.54, on secure 44b1557, which webcpp's main still pins. Probes on hosted runners (2026-12-04, wasmtime 50.0.1) placed it on the AMD EPYC 9V74 alone, under wasmtime alone, and in the comparison's own reads, not in the harness: on six 9V74 runners the case read |t| 30 to 150 whatever the layout (the CI's offsets, 64-byte aligned, a cache line split at 1 or 8 bytes), for zeros or a nonzero pattern against random bytes, for a pair that differs only in its last or first byte against random bytes, and with the verdict discarded; its A/A control and a run that writes the classes' bytes without comparing them read 1 to 3. Natively, and on the Xeon 6975P-C, Platinum 8370C and 8573C, EPYC 7763 and 9V45, every variant read below 4. secure d7bbab4 (the accumulator a register through value_barrier, byte by byte) brought the 9V74 down to 5.5 to 10.0 in the probe and 2.4 to 9.9 in dudect_bearssl's case: below the threshold, not by much. Reading 64-bit words instead, the accumulator a register through value_barrier at each word, read 1.4 to 4.2 on three 9V74 runners (nine runs, its A/A control 1.2 to 2.9), and dudect_bearssl's case on this commit read 0.8 to 4.0 in eighteen runs on three 9V74 runners. The comparison now reads eight bytes of each sequence at a time through memcpy, at any alignment, ORs their XOR into a 64-bit register through constant_time::value_barrier, then the bytes past the last whole word one at a time, and folds the 64 bits into one byte before the branchless reduction. A test compares every length from 0 to 40 at every offset from 0 to 7 against each one-bit flip of every byte.
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.
constant_time_equalnow reads 8-byte words throughmemcpyat any alignment and ORs their XOR into a 64-bit register throughvalue_barrierat each word; the tail goes byte by byte and the 64 bits fold to one byte before the branchless reduction.Why: crypto's constant-time lane on wasip2 failed on crypto#24 (run 47265884663) and on webcpp main (run 47116123227) with
constant_time_equalat |t| 90 to 150. Probes on hosted runners placed it on AMD EPYC 9V74 hosts under wasmtime 50.0.1 alone, in the comparison's own reads (not the harness layout, the input pattern or the verdict); every other CPU and native read below 4. d7bbab4 (register accumulator, byte by byte) narrowed it to 5.5 to 10.0 on the 9V74; this commit reads 0.8 to 4.0 over 18 runs on three 9V74 runners.Tests: a new unit test covers every length 0 to 40 at every offset 0 to 7 against every one-bit flip. Local: wasip2 and native constant-time lanes pass, unit tests native/no-exceptions/wasip2, macOS clang-tidy and Linux lint clean.
🤖 Generated with Claude Code