From 29549dfd4142f88633db986e3c157ce3c4ef5a4e Mon Sep 17 00:00:00 2001 From: R Date: Mon, 23 Nov 2026 06:24:14 -0300 Subject: [PATCH 1/2] hash: the hasher turns MSVC's C4324 off for itself, since the trailing padding an aligned backend state needs is its intended layout libsodium's states are CRYPTO_ALIGN(16) or CRYPTO_ALIGN(64), so hasher is padded after its last member to that alignment, and no order of the members avoids it. MSVC for ARM64 reports that trailing padding as C4324 under /W4, which /WX makes an error, and stopped 14 tests (xof_sodium, digests_sodium, blake2b_sodium, capabilities, capabilities_botan, agreement_families, agreement_families_botan, allocation and their no-exceptions twins). MSVC for x64 reports only padding before an aligned member, never after the last one: a probe on the Windows VM, 14.3 and 14.5, gave both architectures the same layouts (448 bytes, alignment 64) and warned on ARM64 alone. The push and pop around the class template silence its instantiations and nothing else. --- include/webcpp/hash/digest.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/webcpp/hash/digest.hpp b/include/webcpp/hash/digest.hpp index 758c9b2..9b75f7a 100644 --- a/include/webcpp/hash/digest.hpp +++ b/include/webcpp/hash/digest.hpp @@ -734,6 +734,17 @@ template > return hashed; } +// MSVC's warning C4324 ("structure was padded due to alignment specifier") is off for the hasher +// alone. A backend's state may carry an alignment specifier (libsodium's are CRYPTO_ALIGN(16) or +// CRYPTO_ALIGN(64)), so the hasher is padded after its last member to a multiple of that +// alignment, as the state requires, and no order of the members avoids it: the padding is the +// intended layout. MSVC for ARM64 reports that trailing padding under /W4, which /WX makes an +// error; MSVC for x64 reports only padding before an aligned member, never after the last one, +// and so is silent here (14.3 and 14.5 alike, msvc-lane's probe of 2026-11-23). +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4324) +#endif /** A hash fed in pieces, with one result: `make`, `update` as often as the data comes, then `finish` once (spec 2.15). @@ -924,6 +935,9 @@ class hasher { bool keyed_ = false; // made with a key: update and finish hold the timing guard phase phase_ = phase::spent; }; +#ifdef _MSC_VER +#pragma warning(pop) +#endif } // namespace webcpp::hash From 5e5058949b531f048762936d8be27059268f4ff7 Mon Sep 17 00:00:00 2001 From: R Date: Mon, 23 Nov 2026 06:24:14 -0300 Subject: [PATCH 2/2] hash: the backends' canaries are declared constinit, which bugprone-dynamic-static-initializers reads, in place of four suppressions Each canary's declaration (BLAKE3, Botan, BearSSL, libsodium, and XKCP's, which carried no suppression) is a namespace-scope variable without an initialiser, which the check reports in a header as one that may be dynamically initialised. Its definition is a constant, so its initialisation is static; constinit on the declaration states it, as webcpp::crypto's canaries do (crypto 46a0df6). src/canary_botan.cpp, the one definition in C++, repeats constinit on its initialising declaration, as the standard asks. --- include/webcpp/hash/backends/bearssl.hpp | 6 +++--- include/webcpp/hash/backends/botan.hpp | 6 +++--- include/webcpp/hash/backends/sodium.hpp | 6 +++--- include/webcpp/hash/blake3.hpp | 6 +++--- include/webcpp/hash/keccak.hpp | 4 +++- src/canary_botan.cpp | 11 ++++++----- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/include/webcpp/hash/backends/bearssl.hpp b/include/webcpp/hash/backends/bearssl.hpp index 65bd945..961de3e 100644 --- a/include/webcpp/hash/backends/bearssl.hpp +++ b/include/webcpp/hash/backends/bearssl.hpp @@ -75,9 +75,9 @@ WEBCPP_HASH_DETAIL_BEARSSL_CONFIGURATION)) #endif -// A declaration: src/canary_bearssl.c defines it, constant, in /third_party//bearssl. -// NOLINTNEXTLINE(bugprone-dynamic-static-initializers) -extern "C" const char WEBCPP_HASH_DETAIL_BEARSSL_CANARY; +// A declaration: src/canary_bearssl.c defines it, constant, in /third_party//bearssl, so its +// initialisation is static, never dynamic; constinit, on this declaration, states it. +extern "C" constinit const char WEBCPP_HASH_DETAIL_BEARSSL_CANARY; namespace webcpp::hash::backends { diff --git a/include/webcpp/hash/backends/botan.hpp b/include/webcpp/hash/backends/botan.hpp index 5b0cdd6..c690ef3 100644 --- a/include/webcpp/hash/backends/botan.hpp +++ b/include/webcpp/hash/backends/botan.hpp @@ -110,9 +110,9 @@ WEBCPP_HASH_DETAIL_MISMATCH_VALUE(botan, WEBCPP_HASH_BOTAN_COMMIT, configured)) #endif -// A declaration: src/canary_botan.cpp defines it, constant, in /third_party//botan. -// NOLINTNEXTLINE(bugprone-dynamic-static-initializers) -extern "C" const char WEBCPP_HASH_DETAIL_BOTAN_CANARY; +// A declaration: src/canary_botan.cpp defines it, constant, in /third_party//botan, so its +// initialisation is static, never dynamic; constinit, on this declaration, states it. +extern "C" constinit const char WEBCPP_HASH_DETAIL_BOTAN_CANARY; namespace webcpp::hash { diff --git a/include/webcpp/hash/backends/sodium.hpp b/include/webcpp/hash/backends/sodium.hpp index e12dec9..f5f4e3d 100644 --- a/include/webcpp/hash/backends/sodium.hpp +++ b/include/webcpp/hash/backends/sodium.hpp @@ -109,9 +109,9 @@ WEBCPP_HASH_DETAIL_SODIUM_CONFIGURATION)) #endif -// A declaration: src/canary_sodium.c defines it, constant, in /third_party//sodium. -// NOLINTNEXTLINE(bugprone-dynamic-static-initializers) -extern "C" const char WEBCPP_HASH_DETAIL_SODIUM_CANARY; +// A declaration: src/canary_sodium.c defines it, constant, in /third_party//sodium, so its +// initialisation is static, never dynamic; constinit, on this declaration, states it. +extern "C" constinit const char WEBCPP_HASH_DETAIL_SODIUM_CANARY; namespace webcpp::hash { diff --git a/include/webcpp/hash/blake3.hpp b/include/webcpp/hash/blake3.hpp index e206945..79e4116 100644 --- a/include/webcpp/hash/blake3.hpp +++ b/include/webcpp/hash/blake3.hpp @@ -63,9 +63,9 @@ WEBCPP_HASH_DETAIL_BLAKE3_CONFIGURATION)) #endif -// A declaration: src/canary_blake3.c defines it, constant, in /third_party//blake3. -// NOLINTNEXTLINE(bugprone-dynamic-static-initializers) -extern "C" const char WEBCPP_HASH_DETAIL_BLAKE3_CANARY; +// A declaration: src/canary_blake3.c defines it, constant, in /third_party//blake3, so its +// initialisation is static, never dynamic; constinit, on this declaration, states it. +extern "C" constinit const char WEBCPP_HASH_DETAIL_BLAKE3_CANARY; namespace webcpp::hash { diff --git a/include/webcpp/hash/keccak.hpp b/include/webcpp/hash/keccak.hpp index 4d6ad5d..7757646 100644 --- a/include/webcpp/hash/keccak.hpp +++ b/include/webcpp/hash/keccak.hpp @@ -48,7 +48,9 @@ WEBCPP_HASH_DETAIL_XKCP_CONFIGURATION)) #endif -extern "C" const char WEBCPP_HASH_DETAIL_XKCP_CANARY; +// A declaration: src/canary_xkcp.c defines it, constant, in /third_party//xkcp, so its +// initialisation is static, never dynamic; constinit, on this declaration, states it. +extern "C" constinit const char WEBCPP_HASH_DETAIL_XKCP_CANARY; namespace webcpp::hash::detail { diff --git a/src/canary_botan.cpp b/src/canary_botan.cpp index 8f53bb3..f62a1a9 100644 --- a/src/canary_botan.cpp +++ b/src/canary_botan.cpp @@ -38,8 +38,9 @@ WEBCPP_HASH_DETAIL_MISMATCH_VALUE(botan, WEBCPP_HASH_BOTAN_COMMIT, WEBCPP_HASH_BOTAN_BUILT)) #endif -// The canary, constant, with C's linkage, as backends/botan.hpp declares it. -extern "C" const char WEBCPP_HASH_DETAIL_CANARY(botan, WEBCPP_HASH_BOTAN_COMMIT, - WEBCPP_HASH_BOTAN_BUILT); -extern "C" const char WEBCPP_HASH_DETAIL_CANARY(botan, WEBCPP_HASH_BOTAN_COMMIT, - WEBCPP_HASH_BOTAN_BUILT) = 0; +// The canary, constant, with C's linkage, as backends/botan.hpp declares it: constinit there, so +// constinit here too, on the initialising declaration, as the standard asks. +extern "C" constinit const char WEBCPP_HASH_DETAIL_CANARY(botan, WEBCPP_HASH_BOTAN_COMMIT, + WEBCPP_HASH_BOTAN_BUILT); +extern "C" constinit const char WEBCPP_HASH_DETAIL_CANARY(botan, WEBCPP_HASH_BOTAN_COMMIT, + WEBCPP_HASH_BOTAN_BUILT) = 0;