Skip to content

secure: constant_time_equal in a register (wasm timing on EPYC 9V74); the page's title fits the site - #3

Merged
pinhopro merged 2 commits into
mainfrom
main-green-2
Dec 3, 2026
Merged

pinhopro merged 2 commits into
mainfrom
main-green-2

Conversation

@pinhopro

@pinhopro pinhopro commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Two fixes for failures on webcpp's main CI (run 47116123227).

1. constant_time_equal leaked on wasip2 on AMD EPYC 9V74.

crypto's constant-time lane on wasip2 read |t| 89.80, 104.33 and 119.54 for constant_time_equal.

Probe: sixteen hosted runners, the case built as crypto's dudect builds it, under wasmtime 50.0.1 and natively, in variants. Only on the 9V74 runners, and only under wasmtime:

variant 9V74 under wasmtime everywhere else
zeros vs random (the case) 70 to 117 0 to 4
the same without the guard leaks as above 0 to 4
differs only in the last byte vs nonzero leaks as above 0 to 4
equal random pair vs differs in last byte (results differ, values alike) 1 to 3 0 to 4
accumulator in a register through an empty asm 1 to 8 0 to 4

Cause: the volatile accumulator. On wasm it is a store and a load of linear memory at each byte, which wasmtime compiles to the host's. On that CPU, the round trip of a nonzero value took longer than that of zero.

Fix:

  • The accumulator is a register, passed through constant_time::value_barrier at each step.
  • On WebAssembly, value_barrier is now the empty asm statement, as on GCC and clang. WebAssembly has that statement: wasi-sdk 34 and Emscripten compile it at every width. Before, it fell back to the volatile round trip, which MSVC and MemorySanitizer still use.

Confirmed: with this change (probed at ef1d259, which differs from the final commit only by clang-format), the case read 0.9 to 2.9 under wasmtime on all five 9V74 runners (25 runs). It read 0.3 to 3.7 everywhere else. The old volatile form, kept in the same probe as a control, still read 52 to 91 there. The threshold is unchanged, and nothing is unjudged.

2. The page's title fits the site's 60 characters.

tools/ci/assemble.py refused "secure: side-channel and secret-in-memory primitives for C++ - webcpp" (69 characters), so the site never deployed. The new title is "secure: constant time and secrets in memory for C++" (60 with the suffix). I built the page locally with b2, and assemble.py's title check finds no fault.

Verified: secure's tests and examples natively (Apple Clang) and on wasip2 (wasmtime), and the lint.

🤖 Generated with Claude Code

The site's assembly (tools/ci/assemble.py) refuses a library page whose title, with " - webcpp",
is longer than 60 characters, so main's Site job (run 47116123227) never deployed: "secure:
side-channel and secret-in-memory primitives for C++ - webcpp" is 69. The heading is now
"secure: constant time and secrets in memory for C++" (60 with the suffix); the page's first
paragraph keeps the longer description.
@pinhopro pinhopro changed the title secure: the page's title fits the site's 60 characters secure: constant_time_equal in a register (wasm timing on EPYC 9V74); the page's title fits the site Dec 3, 2026
…is the asm statement on WebAssembly too

crypto's constant-time lane on wasip2 failed on webcpp's main (run 47116123227):
constant_time_equal read |t| 89.80, 104.33 and 119.54. A probe on sixteen hosted runners
(2026-12-03) built the case as crypto's dudect does, under wasmtime 50.0.1 and natively, in
variants. On all four AMD EPYC 9V74 runners and under wasmtime alone, three runs each, it read
|t| 70 to 117:
- zeros against random bytes (the case): over 10 on all four;
- the same with the guard removed: the same;
- a pair that differs only in its last byte against a nonzero pair: the same;
- an equal random pair against one that differs in its last byte, whose result differs while
  its values look alike: 1 to 3;
- the comparison with its accumulator in a register through an empty asm: 1 to 8.
Natively, and on every other runner model (Xeon 6975P-C, 6973P-C, Platinum 8573C, EPYC 7763
and 9V45), every variant read 0 to 4.

What leaked was the comparison's volatile accumulator. On wasm it is a store and a load of linear
memory at each byte, which wasmtime compiles to the host's, and on that CPU the round trip of a
nonzero value took longer than that of zero.

The accumulator is now a register, passed through constant_time::value_barrier at each step, so
the compiler still cannot know it has settled. On WebAssembly value_barrier is now the empty asm
statement it is on GCC and clang: WebAssembly has the statement too (wasi-sdk 34 and
Emscripten compile it at every width, as a local). Before, it fell back to the volatile round
trip, which MSVC and MemorySanitizer keep. The doc comments and the blocks and guard pages say so.

Confirmed on hosted runners, sixteen jobs, five runs of each case: with this change the case
read |t| 0.9 to 2.9 under wasmtime on all five AMD EPYC 9V74 runners (25 runs), and 0.3 to 3.7
everywhere else, natively and under wasmtime. The old volatile accumulator, kept in the same
probe as a control, still read 52 to 91 on those 9V74 runners under wasmtime.
@pinhopro
pinhopro merged commit d7bbab4 into main Dec 3, 2026
27 of 28 checks passed
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