From 43b272017cb35d2e61d04d67778f67bfa597218e Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 01:23:49 -0300 Subject: [PATCH 1/3] constant-time: the dudect judge prints the CPU it runs on, the host's, and repeats it in each warning A program under wasmtime cannot read the CPU and prints cpu="unavailable"; the judge, which runs on the host, reads /proc/cpuinfo (or macOS's brand string) as dudect.hpp's parse_cpuinfo does. --- test/constant_time/dudect_judge.py | 65 +++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/test/constant_time/dudect_judge.py b/test/constant_time/dudect_judge.py index 303550ef..5d00a985 100755 --- a/test/constant_time/dudect_judge.py +++ b/test/constant_time/dudect_judge.py @@ -11,7 +11,10 @@ Finds every DIR/**/dudect_*.output, which b2 wrote for a dudect program of the constant-time lane, prints each in a GitHub log group, and emits a warning annotation for every case whose |t|, -as printed, is 10 or more, with the case's evidence line. dudect_planted, whose high value is its +as printed, is 10 or more, with the case's evidence line. It first prints the CPU it runs on, the +host's, as `dudect host cpu="" microcode=` (read as dudect.hpp's `parse_cpuinfo` +reads it), and each warning repeats that line: a program under wasmtime cannot read the CPU, and +its own machine line says `unavailable`. dudect_planted, whose high value is its pass, and dudect_harness, a test of the harness with made-up values, are printed and never warned about. With --rerun, each judged case whose |t| is 10 or more is measured again in two fresh processes (the program's `--case `, which on wasip2 runs as `COMMAND .wasm @@ -24,6 +27,7 @@ from __future__ import annotations import argparse +import platform import re import shlex import subprocess @@ -39,6 +43,54 @@ NOT_MEASURING = ('dudect_planted', 'dudect_harness') +def parse_cpuinfo(text: str) -> tuple[str, str]: + """The CPU's model and microcode from the text of Linux's /proc/cpuinfo, as dudect.hpp's + `parse_cpuinfo` reads them: the first `model name` and `microcode` (x86); where there is no + `model name` (arm64), `arm64 implementer= part= variant= revision=` with the + fields found; `unavailable` for what the text does not hold. A double quote in the model + becomes a single one, a space or double quote in the microcode an underscore.""" + wanted = ('model name', 'microcode', 'CPU implementer', 'CPU part', 'CPU variant', + 'CPU revision') + found: dict[str, str] = {} + for line in text.splitlines(): + key, colon, value = line.partition(':') + key = key.rstrip(' \t\r') + if colon and key in wanted and key not in found: + value = value.strip(' \t\r') + if value: + found[key] = value + if 'model name' in found: + cpu = found['model name'] + elif 'CPU implementer' in found: + labels = ('implementer', 'part', 'variant', 'revision') + fields = [f'{label}={found[key]}' for label, key in zip(labels, wanted[2:]) + if key in found] + cpu = ' '.join(['arm64'] + fields) + else: + cpu = 'unavailable' + microcode = found.get('microcode', 'unavailable') + return cpu.replace('"', "'"), microcode.replace(' ', '_').replace('"', '_') + + +def host_line() -> str: + """The line naming the CPU this judge runs on: /proc/cpuinfo's on Linux, + `machdep.cpu.brand_string` on macOS with the microcode `unavailable`, `unavailable` + elsewhere.""" + cpu, microcode = 'unavailable', 'unavailable' + system = platform.system() + if system == 'Linux': + try: + cpu, microcode = parse_cpuinfo(Path('/proc/cpuinfo').read_text(errors='replace')) + except OSError: + pass + elif system == 'Darwin': + done = subprocess.run(['sysctl', '-n', 'machdep.cpu.brand_string'], capture_output=True, + text=True, check=False) + if done.returncode == 0 and done.stdout.strip(): + cpu = done.stdout.strip().replace('"', "'") + return f'dudect host cpu="{cpu}" microcode={microcode}' + + def annotation(text: str) -> str: """text as a workflow command's message: the characters it reserves escaped.""" return text.replace('%', '%25').replace('\r', '%0D').replace('\n', '%0A') @@ -80,8 +132,8 @@ def program_command(output: Path, target: str, launcher: str) -> list[str]: return [str(program)] -def judge(output: Path, target: str, rerun: bool, launcher: str) -> bool: - """Prints and judges one output; whether it passes.""" +def judge(output: Path, target: str, rerun: bool, launcher: str, host: str) -> bool: + """Prints and judges one output, host the line naming the judge's CPU; whether it passes.""" program = output.stem text = output.read_text(errors='replace') print(f'::group::{program} ({target})') @@ -98,7 +150,7 @@ def judge(output: Path, target: str, rerun: bool, launcher: str) -> bool: if not value >= THRESHOLD: continue title = f'dudect {program} {name} ({target})'.replace(':', '%3A').replace(',', '%2C') - print(f'::warning title={title}::{annotation(chr(10).join(shown))}') + print(f'::warning title={title}::{annotation(chr(10).join([*shown, host]))}') if not (rerun and judged): continue command = program_command(output, target, launcher) @@ -134,9 +186,12 @@ def main(argv: list[str]) -> int: if not outputs: print(f'dudect: no dudect_*.output under {arguments.bin}', file=sys.stderr) return 1 + host = host_line() + print(host) passed = True for output in outputs: - passed = judge(output, arguments.target, arguments.rerun, arguments.launcher) and passed + passed = judge(output, arguments.target, arguments.rerun, arguments.launcher, + host) and passed return 0 if passed else 1 From 0354adef2568dca418c78b40c03f046a9deeaace Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 01:30:54 -0300 Subject: [PATCH 2/3] test: BearSSL's ECDSA tests on every ordinary lane, so that a pinned BearSSL computing a signing nonce wrong fails every lane webcpporg/bearssl's 32381d6 dropped P-521's top nonce bits; only the lane c-suites ran test_crypto, and no CI run of it completed while that pin stood. bearssl_test_ecdsa runs ECDSA_i15 and ECDSA_i31 (RFC 6979's vectors, P-521's included) from upstream's test_crypto.c, unchanged; on 32381d6 it fails with "ECDSA KAT wrong signature value", on the current pin it passes (clang, gcc 15, wasip2, wasip3, Emscripten). --- test/c_suites/Jamfile | 13 +++++++++++++ test/c_suites/bearssl_bound.cpp | 32 +++++++++++++++++++++----------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/test/c_suites/Jamfile b/test/c_suites/Jamfile index e5ffd87f..7aee4fbe 100644 --- a/test/c_suites/Jamfile +++ b/test/c_suites/Jamfile @@ -33,6 +33,19 @@ webcpp.run bearssl_test_crypto : $(BEARSSL)/test/test_crypto.c bearssl_bound.cpp /third_party//bearssl-test-config main=bearssl_test_main off off ; +# BearSSL's ECDSA tests alone (ECDSA_i15 and ECDSA_i31: RFC 6979's vectors on +# P-256, P-384 and P-521, then random signatures), on every ordinary lane: a +# change of the pinned BearSSL that computes a signing nonce wrong fails every +# lane, not only c-suites. webcpporg/bearssl's 32381d6 (2026-11-21) computed +# P-521's nonce without its top bits, a bias that lattice attacks exploit. Only +# c-suites ran test_crypto, every CI run from the pin (2026-11-22) to +# 2026-12-02 was cancelled, and the bias was found on 2026-12-02 by a local run +# of c-suites. Both tests take about 7 s natively in a debug build. +webcpp.run bearssl_test_ecdsa : $(BEARSSL)/test/test_crypto.c bearssl_bound.cpp + : ecdsa /third_party//bearssl + /third_party//bearssl-test-config main=bearssl_test_main + off off ; + # ctaes's own test program (spec section 8.1): asserts, so NDEBUG stays off. It # is fast, so it is not in the lane c-suites: it runs on every ordinary lane, on # every compiler, which the lane's four toolsets would only repeat. diff --git a/test/c_suites/bearssl_bound.cpp b/test/c_suites/bearssl_bound.cpp index 00b96862..7278c3ac 100644 --- a/test/c_suites/bearssl_bound.cpp +++ b/test/c_suites/bearssl_bound.cpp @@ -4,17 +4,19 @@ // accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) -// The main of BearSSL's own test program (bearssl_test_crypto). Upstream's C cannot call -// webcpp::test::bound, and its main lists the tests and returns 0 for any argument but a test's -// name or "all", so a lane whose argument did not arrive would pass having run nothing. The Jamfile -// renames upstream's main to bearssl_test_main; this one runs it only for the argument "all", -// else fails. +// The main of BearSSL's own test programs (bearssl_test_crypto and bearssl_test_ecdsa). +// Upstream's C cannot call webcpp::test::bound, and its main lists the tests and returns 0 for any +// argument but a test's name or "all", so a lane whose argument did not arrive would pass having +// run nothing. The Jamfile renames upstream's main to bearssl_test_main; this one runs it for the +// argument "all" (every test, the lane c-suites) or "ecdsa" (ECDSA_i15 and ECDSA_i31, whose RFC +// 6979 vectors include P-521's, on every ordinary lane), else fails. // // The bound is re-armed at static initialisation, before main: node's default of 120 s is shorter // than the 88 tests, which take 116 s of CPU under Emscripten in a debug build (157 s on a loaded // machine, 126 s natively); 900 s leaves room for a slower machine. Natively it does nothing. #include +#include #include #include #include @@ -32,11 +34,19 @@ namespace { } // namespace int main(int argc, char** argv) { - if (argc != 2 || std::strcmp(argv[1], "all") != 0) { - // NOLINTNEXTLINE(cert-err33-c): the program fails either way; nothing to do if stderr fails - std::fputs("bearssl_test_crypto: the argument all did not arrive, so no test ran\n", - stderr); - return webcpp::test::exit_status(1); + if (argc == 2 && std::strcmp(argv[1], "all") == 0) { + return webcpp::test::exit_status(bearssl_test_main(argc, argv)); } - return webcpp::test::exit_status(bearssl_test_main(argc, argv)); + if (argc == 2 && std::strcmp(argv[1], "ecdsa") == 0) { + // Upstream's tests exit with a failure status at their first wrong value. Its main takes + // char*, so the names live in writable arrays. + std::array ecdsa_i15{"ECDSA_i15"}; + std::array ecdsa_i31{"ECDSA_i31"}; + std::array tests{argv[0], ecdsa_i15.data(), ecdsa_i31.data(), nullptr}; + return webcpp::test::exit_status(bearssl_test_main(3, tests.data())); + } + // NOLINTNEXTLINE(cert-err33-c): the program fails either way; nothing to do if stderr fails + std::fputs("bearssl_test: neither the argument all nor ecdsa arrived, so no test ran\n", + stderr); + return webcpp::test::exit_status(1); } From f1b1a593c4a67b35e79ece396f4b3c0066d68166 Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 01:44:55 -0300 Subject: [PATCH 3/3] constant-time: record where wasmtime's AMD-only leak lives, bitsliced AES as compiled for Zen 3 and Zen 4, so the unjudged WASI cases carry their cause --- test/constant_time/dudect_test.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/constant_time/dudect_test.cpp b/test/constant_time/dudect_test.cpp index 68284098..dd8183b9 100644 --- a/test/constant_time/dudect_test.cpp +++ b/test/constant_time/dudect_test.cpp @@ -58,9 +58,17 @@ constexpr std::size_t count = 2'000'000; * these cases follows the processor of the runner they run on, not the code measured, so a * verdict there would pass or fail with the machine drawn. On GitHub's hosted AMD EPYC 9V74, * wasip2 runs read |t| 30 to 150 on constant_time_equal and 11 to 12 on gcm_seal and - * ctaes_encrypt, failing pull requests and main that changed none of them. Every case is still - * measured and printed there, once (`measure_case`), so that its value stays in the log; the - * program then passes, and the CI's judge, which measures again only a case printed + * ctaes_encrypt, failing pull requests and main that changed none of them. Probed on 24 hosted + * runners (2026-12-05, wasmtime 50.0.1, all-zero key against a fixed 0x42 key, 3 rounds each): + * the leak is in bitsliced AES as wasmtime compiles it for AMD Zen 3 and Zen 4 alone. BearSSL's + * ct64 CTR (this backend's choice on wasm) read up to 6.3 on the 9V74 and its ct CTR up to 8.7, + * against A/A controls below 2.7; gcm_seal read up to 74 and ctaes_encrypt up to 12 on the 7763. + * The same code natively on the same processors, every GHASH (ctmul64, ctmul32, ctmul), a plain + * store and load by value, the Zen 5 9V45 and the Intel 8370C, 8573C and 6975P-C all read below + * 4.1; BearSSL's table AES, the probe's positive control, read 43 to 816. No constant-time AES of + * BearSSL is clean there, so no backend choice removes it; the harness is not its cause. Every + * case is still measured and printed there, once (`measure_case`), so that its value stays in the + * log; the program then passes, and the CI's judge, which measures again only a case printed * `judged=yes`, measures none of them again. * Natively every case is judged, as are memcheck's and MemorySanitizer's runs of the same code, * and dudect_sodium and dudect_secp256k1 keep their own verdicts under wasmtime.