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
14 changes: 11 additions & 3 deletions test/constant_time/dudect_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,22 +299,30 @@ 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
char volatile character_sink = 0;
std::array<std::uint8_t, 32> fixed_bytes{};
fixed_bytes[0] = 0xc0;
std::array<std::uint8_t, 32> drawn_bytes{};
secure::secret<32> encoded_key;
std::array<char, 44> text{};
std::array<char, 50> checksummed_text{};
auto const prepare = [&]<bool Control>(int which, auto& generator) {
test::choose<Control>(which, generator, fixed_bytes, drawn_bytes);
drawn_bytes[0] = static_cast<std::uint8_t>(drawn_bytes[0] | 0xc0U);
static_cast<void>(codecs::encode(formats::base58, drawn_bytes, std::span{text}));
std::ranges::copy(drawn_bytes, encoded_key.writable().begin());
static_cast<void>(codecs::encode(formats::base58, encoded_key, std::span{text}));
static_cast<void>(
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.
Expand Down
11 changes: 10 additions & 1 deletion test/support/counting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <mm_malloc.h> 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):
Expand Down Expand Up @@ -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 <mm_malloc.h>, which the x86 intrinsic headers include (<emmintrin.h>, 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 <mm_malloc.h> comes before the replacement below: included after
// it, it fails to compile ("'posix_memalign' is missing exception specification").
#if __has_include(<mm_malloc.h>)
#include <mm_malloc.h>
#endif
#else
#define WEBCPP_TEST_C(name) emscripten_builtin_##name
// Emscripten's musl declares them without an exception specification.
Expand Down