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. 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.