From 03f4390f20a3dfe4b8e30c4efc67e06944ea62a2 Mon Sep 17 00:00:00 2001 From: R Date: Wed, 2 Dec 2026 21:44:43 -0300 Subject: [PATCH 1/2] codecs: the test support includes before its replaced C allocation functions Clang's , which the x86 intrinsic headers include (Boost.URL's and Boost.JSON's ), redeclares posix_memalign without an exception specification. Clang accepts that only after a system header's declaration; after the test support's noexcept replacement it is an error, so every test that includes counting.hpp and then such a Boost header failed to compile with Clang on x86_64 Linux (the Clang 18 and Clang 22 lanes and the CI lint). --- test/support/counting.hpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/support/counting.hpp b/test/support/counting.hpp index 080b6fd..5ee6eba 100644 --- a/test/support/counting.hpp +++ b/test/support/counting.hpp @@ -6,7 +6,8 @@ // Copied from webcpp::secure's test/support/counting.hpp at 951401a, with its namespace // webcpp::secure::test renamed webcpp::codecs::test and its include guard renamed; nothing else -// differs, and the references below (spec section 8.5, N1) are secure's. codecs keeps its own +// differs (the include before the C library's replacements came later, to both), +// and the references below (spec section 8.5, N1) are secure's. codecs keeps its own // test support, as secure does, until webcpp::core holds it (the design's O5). // // Counts every allocation of the program that includes this header once (spec section 8.5): @@ -262,6 +263,14 @@ void __libc_free(void*); #define WEBCPP_TEST_C(name) __libc_##name // glibc declares these with __THROW, noexcept in C++11 and later: a replacement must match. #define WEBCPP_TEST_C_NOEXCEPT noexcept +// Clang's , which the x86 intrinsic headers include (, included by +// Boost.URL and Boost.JSON among others), redeclares posix_memalign without an exception +// specification. Clang accepts that redeclaration only when the declaration before it is a +// system header's (glibc's), so comes before the replacement below: included after +// it, it fails to compile ("'posix_memalign' is missing exception specification"). +#if __has_include() +#include +#endif #else #define WEBCPP_TEST_C(name) emscripten_builtin_##name // Emscripten's musl declares them without an exception specification. From 820a5f5e7e07eed6685e7e092ae5eba56fcccf33 Mon Sep 17 00:00:00 2001 From: R Date: Wed, 2 Dec 2026 22:20:10 -0300 Subject: [PATCH 2/2] codecs: dudect's base58 cases prepare their texts by the constant-time conversion The base58 cases encoded each class's text, unmeasured, by the public conversion, Bitcoin Core's, which exits its loops early by the bytes' values: the two classes left a different branch history before each measurement, which the measured secret operation, with no branch on the text, then read. On webcpp's main (run 46916884991, an Intel Xeon 6975P-C) base58_checksum_decode read |t| 33 to 45 in its three runs. A probe on six hosted runners (Intel Xeon 6975P-C, AMD EPYC 9V45 and 9V74), three runs each, read |t| up to 108 on the three base58 cases with that preparation and 1.3 to 4.0 with the constant-time conversion of a secure::secret<32>, which runs the same instructions for both classes, as every other case's preparation does; on an Apple M5 Max (Linux arm64 in Docker) base58_decode read 8.5 to 12.8 and then 1.4 to 2.5. The secret decode itself is unchanged: its x86-64 code has no branch on the text. --- 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 be08c05..12d57d0 100644 --- a/test/constant_time/dudect_test.cpp +++ b/test/constant_time/dudect_test.cpp @@ -299,7 +299,13 @@ void measure_base32_cases(test::case_results& results, test::case_selection cons * base58's cases, its secret operations: 32 bytes, 0xc0 then zeros for class 0 and random for * class 1, their two top bits set in both by the same instructions, so that every text is of one * length (44 characters, 50 with the tests' checksum) and decodes to 32 bytes; each text encoded - * unmeasured, by the public conversion of public bytes. + * unmeasured, by the constant-time conversion of a secure::secret<32>, which runs the same + * instructions for both classes. The public conversion, Bitcoin Core's, exits its loops early by + * the bytes' values, so that it left the two classes a different branch history before each + * measurement, which the measured operation, with no branch on the text, then read: on the hosted + * runners (an Intel Xeon 6975P-C, an AMD EPYC 9V45 and 9V74, 2026-12-03), base58's three cases + * read |t| up to 108 with it and 1.3 to 4.0 with the constant-time conversion, three runs on each + * of six runners; base58_checksum_decode had read 33 to 45 on webcpp's main (run 46916884991). */ void measure_base58_cases(test::case_results& results, test::case_selection const& selection) { std::uint8_t volatile byte_sink = 0; // keeps an operation from being optimised away @@ -307,14 +313,16 @@ void measure_base58_cases(test::case_results& results, test::case_selection cons std::array fixed_bytes{}; fixed_bytes[0] = 0xc0; std::array drawn_bytes{}; + secure::secret<32> encoded_key; std::array text{}; std::array checksummed_text{}; auto const prepare = [&](int which, auto& generator) { test::choose(which, generator, fixed_bytes, drawn_bytes); drawn_bytes[0] = static_cast(drawn_bytes[0] | 0xc0U); - static_cast(codecs::encode(formats::base58, drawn_bytes, std::span{text})); + std::ranges::copy(drawn_bytes, encoded_key.writable().begin()); + static_cast(codecs::encode(formats::base58, encoded_key, std::span{text})); static_cast( - codecs::encode(test::base58_with_checksum, drawn_bytes, std::span{checksummed_text})); + codecs::encode(test::base58_with_checksum, encoded_key, std::span{checksummed_text})); }; // base58 decode: the text of 0xc0 and zeros, against the text of random bytes.