Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions test/c_suites/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ webcpp.run bearssl_test_crypto : $(BEARSSL)/test/test_crypto.c bearssl_bound.cpp
<library>/third_party//bearssl-test-config <define>main=bearssl_test_main
<warnings>off <warnings-as-errors>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
: <testing.arg>ecdsa <library>/third_party//bearssl
<library>/third_party//bearssl-test-config <define>main=bearssl_test_main
<warnings>off <warnings-as-errors>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.
Expand Down
32 changes: 21 additions & 11 deletions test/c_suites/bearssl_bound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <webcpp/test/exit_status.hpp>

#include <array>
#include <chrono>
#include <cstdio>
#include <cstring>
Expand All @@ -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<char, 10> ecdsa_i15{"ECDSA_i15"};
std::array<char, 10> ecdsa_i31{"ECDSA_i31"};
std::array<char*, 4> 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);
}
65 changes: 60 additions & 5 deletions test/constant_time/dudect_judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="<model>" microcode=<value>` (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 <name>`, which on wasip2 runs as `COMMAND <program>.wasm
Expand All @@ -24,6 +27,7 @@
from __future__ import annotations

import argparse
import platform
import re
import shlex
import subprocess
Expand All @@ -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=<x> part=<x> variant=<x> revision=<x>` 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')
Expand Down Expand Up @@ -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})')
Expand All @@ -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)
Expand Down Expand Up @@ -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


Expand Down
14 changes: 11 additions & 3 deletions test/constant_time/dudect_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading