From 533bf0d711d8cd5d7a9c202ca856e4b8c9d97352 Mon Sep 17 00:00:00 2001 From: R Date: Fri, 4 Dec 2026 05:40:48 -0300 Subject: [PATCH 1/2] hash: max and min in parentheses in every header, so that a bare before them compiles A bare defines the macros min and max for the whole program. detail/limits.hpp's std::numeric_limits::max() then stopped MSVC with C2589 in any program that included webcpp::hash's KDF headers after it: crypto's HPKE, which calls hkdf over pieces, met it in crypto's windows_h_before test on MSVC 14.3. Every header now writes (std::numeric_limits::max)() and (std::min)(a, b), as crypto's do, and the test windows_h includes every public header after a bare , with every backend linked, and calls HKDF over spans and over pieces. --- include/webcpp/hash/backends/bearssl.hpp | 4 +- include/webcpp/hash/backends/botan.hpp | 6 +-- include/webcpp/hash/backends/hash2.hpp | 8 ++-- include/webcpp/hash/backends/openssl.hpp | 8 ++-- include/webcpp/hash/backends/sodium.hpp | 4 +- include/webcpp/hash/backends/webcrypto.hpp | 3 +- include/webcpp/hash/detail/engines.hpp | 4 +- include/webcpp/hash/detail/limits.hpp | 6 +-- include/webcpp/hash/keccak.hpp | 2 +- include/webcpp/hash/scrypt.hpp | 2 +- test/Jamfile | 7 +++ test/windows_h_test.cpp | 53 ++++++++++++++++++++++ 12 files changed, 84 insertions(+), 23 deletions(-) create mode 100644 test/windows_h_test.cpp diff --git a/include/webcpp/hash/backends/bearssl.hpp b/include/webcpp/hash/backends/bearssl.hpp index 0721245..d662674 100644 --- a/include/webcpp/hash/backends/bearssl.hpp +++ b/include/webcpp/hash/backends/bearssl.hpp @@ -493,7 +493,7 @@ struct hkdf_pieces_engine { /** The most bytes of one update. */ static constexpr std::uint64_t slice_max = hkdf_pieces_slice; - static_assert(slice_max <= std::numeric_limits::max(), + static_assert(slice_max <= (std::numeric_limits::max)(), "br_hmac_update takes every slice's length"); /** @@ -570,7 +570,7 @@ struct hkdf_pieces_engine { secure::erase_secret(std::span(&mac_context, 1)); if (call_succeeded) { std::size_t const copied_count = - std::min(t_block.size(), output_key_material.size() - written_count); + (std::min)(t_block.size(), output_key_material.size() - written_count); std::copy_n(t_block.data(), copied_count, output_key_material.data() + written_count); written_count += copied_count; diff --git a/include/webcpp/hash/backends/botan.hpp b/include/webcpp/hash/backends/botan.hpp index 5683bd9..bb13d8e 100644 --- a/include/webcpp/hash/backends/botan.hpp +++ b/include/webcpp/hash/backends/botan.hpp @@ -154,7 +154,7 @@ struct backend_limits { /** PBKDF2's output. */ static constexpr std::uint64_t pbkdf2_output = no_limit; /** PBKDF2's iteration count, a `size_t` of Botan's (`PBKDF2_Family::from_params`). */ - static constexpr std::uint64_t pbkdf2_iterations = std::numeric_limits::max(); + static constexpr std::uint64_t pbkdf2_iterations = (std::numeric_limits::max)(); /** Argon2id's password. */ static constexpr std::uint64_t argon2id_password = no_limit; /** Argon2id's salt. */ @@ -1354,7 +1354,7 @@ struct hkdf_pieces_engine { /** The most bytes of one update. */ static constexpr std::uint64_t slice_max = hkdf_pieces_slice; - static_assert(slice_max <= std::numeric_limits::max(), + static_assert(slice_max <= (std::numeric_limits::max)(), "Botan's update takes every slice's length"); /** @@ -1443,7 +1443,7 @@ struct hkdf_pieces_engine { mac_instance.update(static_cast(block_counter)); mac_instance.final(std::span(t_block.data(), t_block.size())); std::size_t const copied_count = - std::min(t_block.size(), output_key_material.size() - written_count); + (std::min)(t_block.size(), output_key_material.size() - written_count); std::copy_n(t_block.data(), copied_count, output_key_material.data() + written_count); written_count += copied_count; diff --git a/include/webcpp/hash/backends/hash2.hpp b/include/webcpp/hash/backends/hash2.hpp index 8974d88..a0c0224 100644 --- a/include/webcpp/hash/backends/hash2.hpp +++ b/include/webcpp/hash/backends/hash2.hpp @@ -115,7 +115,7 @@ struct hkdf_engine { t_block = mac_state.result(); secure::erase_secret(std::span(&mac_state, 1)); const std::size_t copied_count = - std::min(t_block.size(), output_key_material.size() - written_count); + (std::min)(t_block.size(), output_key_material.size() - written_count); std::memcpy(output_key_material.data() + written_count, t_block.data(), copied_count); written_count += copied_count; } @@ -220,7 +220,7 @@ struct hkdf_pieces_engine { t_block = mac_state.result(); secure::erase_secret(std::span(&mac_state, 1)); const std::size_t copied_count = - std::min(t_block.size(), output_key_material.size() - written_count); + (std::min)(t_block.size(), output_key_material.size() - written_count); std::memcpy(output_key_material.data() + written_count, t_block.data(), copied_count); written_count += copied_count; } @@ -293,7 +293,7 @@ struct pbkdf2_engine { } secure::erase_secret(std::span(&mac_state, 1)); const std::size_t copied_count = - std::min(t_block.size(), output_bytes.size() - written_count); + (std::min)(t_block.size(), output_bytes.size() - written_count); std::memcpy(output_bytes.data() + written_count, t_block.data(), copied_count); written_count += copied_count; } @@ -343,7 +343,7 @@ struct hash2_digest_engine : full_engine { state& digest_state, std::span output_bytes) noexcept { while (!output_bytes.empty()) { auto result_bytes = digest_state.result(); - auto const taken_size = std::min(output_bytes.size(), result_bytes.size()); + auto const taken_size = (std::min)(output_bytes.size(), result_bytes.size()); std::memcpy(output_bytes.data(), result_bytes.data(), taken_size); secure::erase_secret(std::span(&result_bytes, 1)); output_bytes = output_bytes.subspan(taken_size); diff --git a/include/webcpp/hash/backends/openssl.hpp b/include/webcpp/hash/backends/openssl.hpp index 958508e..80de8f5 100644 --- a/include/webcpp/hash/backends/openssl.hpp +++ b/include/webcpp/hash/backends/openssl.hpp @@ -665,7 +665,7 @@ struct hkdf_pieces_engine { /** The most bytes of one update. */ static constexpr std::uint64_t slice_max = hkdf_pieces_slice; - static_assert(slice_max <= std::numeric_limits::max(), + static_assert(slice_max <= (std::numeric_limits::max)(), "EVP_MAC_update takes every slice's length"); /** @@ -787,7 +787,7 @@ struct hkdf_pieces_engine { EVP_MAC_CTX_free(block_context); if (call_succeeded) { std::size_t const copied_count = - std::min(t_block.size(), output_key_material.size() - written_count); + (std::min)(t_block.size(), output_key_material.size() - written_count); std::copy_n(t_block.data(), copied_count, output_key_material.data() + written_count); written_count += copied_count; @@ -853,7 +853,7 @@ struct pbkdf2_engine { 1 KiB, a `size_t` (4,194,303 KiB on wasm32, where a larger m overflows it). */ inline constexpr std::uint32_t openssl_argon2_max_memory_kibibytes = static_cast( - std::min(0xffffffffULL, std::numeric_limits::max() / 1024)); + std::min(0xffffffffULL, (std::numeric_limits::max)() / 1024)); /** One Argon2 of OpenSSL, version 0x13 (its default), with one thread: OpenSSL's Argon2 runs its @@ -1028,7 +1028,7 @@ struct scrypt_engine { std::span output_bytes, std::span password_bytes, std::span salt_bytes, std::uint64_t cost_n, std::uint32_t block_size_r, std::uint32_t parallelism_p) noexcept { - std::uint64_t memory_limit = std::numeric_limits::max(); + std::uint64_t memory_limit = (std::numeric_limits::max)(); std::array ossl_params{ openssl_octets("pass", password_bytes), openssl_octets("salt", salt_bytes), diff --git a/include/webcpp/hash/backends/sodium.hpp b/include/webcpp/hash/backends/sodium.hpp index 6e76c27..f1a641d 100644 --- a/include/webcpp/hash/backends/sodium.hpp +++ b/include/webcpp/hash/backends/sodium.hpp @@ -411,7 +411,7 @@ struct sodium_hkdf_pieces_engine { /** The most bytes of one update. */ static constexpr std::uint64_t slice_max = hkdf_pieces_slice; - static_assert(slice_max <= std::numeric_limits::max(), + static_assert(slice_max <= (std::numeric_limits::max)(), "libsodium's _update takes every slice's length"); /** @@ -495,7 +495,7 @@ struct sodium_hkdf_pieces_engine { secure::erase_secret(std::span(&mac_state, 1)); if (call_succeeded) { std::size_t const copied_count = - std::min(t_block.size(), output_key_material.size() - written_count); + (std::min)(t_block.size(), output_key_material.size() - written_count); std::copy_n(t_block.data(), copied_count, output_key_material.data() + written_count); written_count += copied_count; diff --git a/include/webcpp/hash/backends/webcrypto.hpp b/include/webcpp/hash/backends/webcrypto.hpp index 1662fd3..6b0d277 100644 --- a/include/webcpp/hash/backends/webcrypto.hpp +++ b/include/webcpp/hash/backends/webcrypto.hpp @@ -1027,7 +1027,8 @@ class webcrypto_hmac_hkdf_operation { return; } webcrypto_secret tag_secret(uint8_array(promise_value)); - std::size_t const block_size = std::min(request_.digest_length, output_.size() - written_); + std::size_t const block_size = + (std::min)(request_.digest_length, output_.size() - written_); copy(tag_secret.bytes(), written_, block_size); written_ += block_size; if (written_ == output_.size()) { diff --git a/include/webcpp/hash/detail/engines.hpp b/include/webcpp/hash/detail/engines.hpp index 4edc30a..a1c1b37 100644 --- a/include/webcpp/hash/detail/engines.hpp +++ b/include/webcpp/hash/detail/engines.hpp @@ -85,7 +85,7 @@ template struct mac_traits; /** No limit beyond the spec's own: the largest 64-bit size. */ -inline constexpr std::uint64_t no_limit = std::numeric_limits::max(); +inline constexpr std::uint64_t no_limit = (std::numeric_limits::max)(); /** The longest input and output a backend's C library takes, in bytes, where its interface holds a @@ -207,7 +207,7 @@ static_assert(hkdf_pieces_slice_seam >= 1, @ref for_each_slice requires. */ template -inline constexpr std::uint64_t hkdf_pieces_update_max = std::numeric_limits::max(); +inline constexpr std::uint64_t hkdf_pieces_update_max = (std::numeric_limits::max)(); /** The most bytes an engine of HKDF over pieces on `Backend` hands its HMAC in one update: the diff --git a/include/webcpp/hash/detail/limits.hpp b/include/webcpp/hash/detail/limits.hpp index f924383..d895ee7 100644 --- a/include/webcpp/hash/detail/limits.hpp +++ b/include/webcpp/hash/detail/limits.hpp @@ -42,7 +42,7 @@ inline constexpr std::uint64_t sp800_185_max_bytes = WEBCPP_HASH_DETAIL_TEST_SP8 (`input_too_long` for a string, `invalid_key_size` for a KMAC key, `invalid_output_size` for an output). The test seam `WEBCPP_HASH_DETAIL_TEST_SP800_185_MAX_BYTES` lowers it. */ -inline constexpr std::uint64_t sp800_185_max_bytes = std::numeric_limits::max() / 8; +inline constexpr std::uint64_t sp800_185_max_bytes = (std::numeric_limits::max)() / 8; #endif #ifdef WEBCPP_HASH_DETAIL_TEST_KANGAROOTWELVE_MAX_BYTES @@ -60,9 +60,9 @@ inline constexpr std::uint64_t kangarootwelve_max_bytes = */ inline constexpr std::uint64_t kangarootwelve_max_bytes = sizeof(std::size_t) < sizeof(std::uint64_t) - ? (std::uint64_t{std::numeric_limits::max()} * 8192) - + ? (std::uint64_t{(std::numeric_limits::max)()} * 8192) - (sizeof(std::size_t) + 1) - : std::numeric_limits::max(); + : (std::numeric_limits::max)(); #endif /** The byte @ref nonnull points at for an empty span: a constant, never written. */ diff --git a/include/webcpp/hash/keccak.hpp b/include/webcpp/hash/keccak.hpp index 7757646..2d9c1b5 100644 --- a/include/webcpp/hash/keccak.hpp +++ b/include/webcpp/hash/keccak.hpp @@ -158,7 +158,7 @@ inline void keccak_256::update(unsigned char const* input_data, std::size_t inpu return; } if (m_ > 0) { - std::size_t const absorbed_count = std::min(input_size, block_size - m_); + std::size_t const absorbed_count = (std::min)(input_size, block_size - m_); webcpp_hash_xkcp_add_bytes(state_.data(), input_data, m_, absorbed_count); input_data += absorbed_count; input_size -= absorbed_count; diff --git a/include/webcpp/hash/scrypt.hpp b/include/webcpp/hash/scrypt.hpp index 8d77764..ea0c39b 100644 --- a/include/webcpp/hash/scrypt.hpp +++ b/include/webcpp/hash/scrypt.hpp @@ -108,7 +108,7 @@ template } // 128 r (N + p) bytes must fit size_t: N + p cannot wrap, N being at most 2^63. constexpr std::uint64_t block_bytes_count = 128; - constexpr std::uint64_t size_max = std::numeric_limits::max(); + constexpr std::uint64_t size_max = (std::numeric_limits::max)(); if (exceeds(cost_n + parallelism_p, size_max / block_bytes_count / block_size_r)) { return error::invalid_parameters; } diff --git a/test/Jamfile b/test/Jamfile index 19e6fcb..3153465 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -877,6 +877,13 @@ hash-run user_globals : user_globals_test.cpp @botan-native-with-exceptions msvc:/bigobj : native ; +# A bare before every public header: no header's max or min is +# expanded as the macro (MSVC's C2589 otherwise), with every backend linked. +hash-run windows_h : windows_h_test.cpp + : /webcpp/hash//openssl /third_party//bearssl + /third_party//sodium + : native ; + build-project messages ; # The canaries at link time, each C library's absence and another commit of diff --git a/test/windows_h_test.cpp b/test/windows_h_test.cpp new file mode 100644 index 0000000..8c29ffe --- /dev/null +++ b/test/windows_h_test.cpp @@ -0,0 +1,53 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// A bare (no NOMINMAX, no WIN32_LEAN_AND_MEAN) before every public header of hash, +// every backend's included, and max and min used as functions after them. A bare +// defines the macros min and max for the whole program, which is what its author asked for: every +// header writes `(std::numeric_limits::max)()` and `(std::min)(a, b)`, which no macro expands. +// Before that, a header that wrote `std::numeric_limits::max()` (detail/limits.hpp) stopped +// MSVC with C2589 where crypto's HPKE included webcpp::hash's HKDF after . Elsewhere +// than Windows the program is the headers and the calls alone. + +#ifdef _WIN32 +#include +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +int main() { + // HKDF over pieces and over spans, on its default backend, which reach detail/limits.hpp. + std::array output{}; + std::array const salt{1, 2, 3, 4}; + std::array const input{5, 6, 7, 8, 9, 10, 11, 12}; + BOOST_TEST(webcpp::hash::hkdf(output, salt, + std::span(input), + std::span(salt)) + .has_value()); + std::array pieces_output{}; + std::span const whole_input(input); + std::span const info(salt); + BOOST_TEST(webcpp::hash::hkdf( + pieces_output, salt, {whole_input.first(3), whole_input.subspan(3)}, + webcpp::hash::byte_pieces{info}) + .has_value()); + BOOST_TEST(output == pieces_output); + // The program's own max and min, the macros' or the standard's, still work in parentheses. + BOOST_TEST_EQ((std::max)(1, 2), 2); + return webcpp::test::exit_status(boost::report_errors()); +} From 8875c22f5ab43f7b5a1b5f8a67149f7a654914b3 Mon Sep 17 00:00:00 2001 From: R Date: Fri, 4 Dec 2026 06:38:36 -0300 Subject: [PATCH 2/2] hash: the types' maxima as SIZE_MAX, UINT64_MAX and ULLONG_MAX clang-tidy's readability-redundant-parentheses reports (std::numeric_limits::max)(), the form the previous commit used against 's max macro. The and constants name the same values, and no macro expands them. --- include/webcpp/hash/backends/bearssl.hpp | 4 +--- include/webcpp/hash/backends/botan.hpp | 6 ++---- include/webcpp/hash/backends/openssl.hpp | 10 ++++------ include/webcpp/hash/backends/sodium.hpp | 5 ++--- include/webcpp/hash/detail/engines.hpp | 5 ++--- include/webcpp/hash/detail/limits.hpp | 8 +++----- include/webcpp/hash/scrypt.hpp | 3 +-- 7 files changed, 15 insertions(+), 26 deletions(-) diff --git a/include/webcpp/hash/backends/bearssl.hpp b/include/webcpp/hash/backends/bearssl.hpp index d662674..8c13c23 100644 --- a/include/webcpp/hash/backends/bearssl.hpp +++ b/include/webcpp/hash/backends/bearssl.hpp @@ -54,7 +54,6 @@ #include #include #include -#include #include #ifdef WEBCPP_HASH_BEARSSL_CANARY_CONFIGURATION @@ -493,8 +492,7 @@ struct hkdf_pieces_engine { /** The most bytes of one update. */ static constexpr std::uint64_t slice_max = hkdf_pieces_slice; - static_assert(slice_max <= (std::numeric_limits::max)(), - "br_hmac_update takes every slice's length"); + static_assert(slice_max <= SIZE_MAX, "br_hmac_update takes every slice's length"); /** Feeds every byte of `input_pieces` to `mac_context`, in slices of at most @ref slice_max bytes. diff --git a/include/webcpp/hash/backends/botan.hpp b/include/webcpp/hash/backends/botan.hpp index bb13d8e..c6647f6 100644 --- a/include/webcpp/hash/backends/botan.hpp +++ b/include/webcpp/hash/backends/botan.hpp @@ -92,7 +92,6 @@ #include #include #include -#include #include #include #include @@ -154,7 +153,7 @@ struct backend_limits { /** PBKDF2's output. */ static constexpr std::uint64_t pbkdf2_output = no_limit; /** PBKDF2's iteration count, a `size_t` of Botan's (`PBKDF2_Family::from_params`). */ - static constexpr std::uint64_t pbkdf2_iterations = (std::numeric_limits::max)(); + static constexpr std::uint64_t pbkdf2_iterations = SIZE_MAX; /** Argon2id's password. */ static constexpr std::uint64_t argon2id_password = no_limit; /** Argon2id's salt. */ @@ -1354,8 +1353,7 @@ struct hkdf_pieces_engine { /** The most bytes of one update. */ static constexpr std::uint64_t slice_max = hkdf_pieces_slice; - static_assert(slice_max <= (std::numeric_limits::max)(), - "Botan's update takes every slice's length"); + static_assert(slice_max <= SIZE_MAX, "Botan's update takes every slice's length"); /** Makes Botan's HMAC over the hmac's hash, "HMAC()", into `mac_object`; Botan throws diff --git a/include/webcpp/hash/backends/openssl.hpp b/include/webcpp/hash/backends/openssl.hpp index 80de8f5..a625b4d 100644 --- a/include/webcpp/hash/backends/openssl.hpp +++ b/include/webcpp/hash/backends/openssl.hpp @@ -98,7 +98,6 @@ #include #include #include -#include #include #include #include @@ -665,8 +664,7 @@ struct hkdf_pieces_engine { /** The most bytes of one update. */ static constexpr std::uint64_t slice_max = hkdf_pieces_slice; - static_assert(slice_max <= (std::numeric_limits::max)(), - "EVP_MAC_update takes every slice's length"); + static_assert(slice_max <= SIZE_MAX, "EVP_MAC_update takes every slice's length"); /** A context of `mac_algorithm` keyed by `key_bytes` with the hmac's digest (`EVP_MAC_CTX_new`, @@ -852,8 +850,8 @@ struct pbkdf2_engine { The most memory OpenSSL's Argon2 takes, in KiB: m is a `uint32_t`, and the memory, m blocks of 1 KiB, a `size_t` (4,194,303 KiB on wasm32, where a larger m overflows it). */ -inline constexpr std::uint32_t openssl_argon2_max_memory_kibibytes = static_cast( - std::min(0xffffffffULL, (std::numeric_limits::max)() / 1024)); +inline constexpr std::uint32_t openssl_argon2_max_memory_kibibytes = + static_cast(std::min(0xffffffffULL, SIZE_MAX / 1024)); /** One Argon2 of OpenSSL, version 0x13 (its default), with one thread: OpenSSL's Argon2 runs its @@ -1028,7 +1026,7 @@ struct scrypt_engine { std::span output_bytes, std::span password_bytes, std::span salt_bytes, std::uint64_t cost_n, std::uint32_t block_size_r, std::uint32_t parallelism_p) noexcept { - std::uint64_t memory_limit = (std::numeric_limits::max)(); + std::uint64_t memory_limit = UINT64_MAX; std::array ossl_params{ openssl_octets("pass", password_bytes), openssl_octets("salt", salt_bytes), diff --git a/include/webcpp/hash/backends/sodium.hpp b/include/webcpp/hash/backends/sodium.hpp index f1a641d..c9cb5f9 100644 --- a/include/webcpp/hash/backends/sodium.hpp +++ b/include/webcpp/hash/backends/sodium.hpp @@ -89,9 +89,9 @@ #include #include #include +#include #include #include -#include #include #ifdef WEBCPP_HASH_SODIUM_CANARY_CONFIGURATION @@ -411,8 +411,7 @@ struct sodium_hkdf_pieces_engine { /** The most bytes of one update. */ static constexpr std::uint64_t slice_max = hkdf_pieces_slice; - static_assert(slice_max <= (std::numeric_limits::max)(), - "libsodium's _update takes every slice's length"); + static_assert(slice_max <= ULLONG_MAX, "libsodium's _update takes every slice's length"); /** Feeds every byte of `input_pieces` to `mac_state`, in slices of at most @ref slice_max bytes. diff --git a/include/webcpp/hash/detail/engines.hpp b/include/webcpp/hash/detail/engines.hpp index a1c1b37..f02aa7a 100644 --- a/include/webcpp/hash/detail/engines.hpp +++ b/include/webcpp/hash/detail/engines.hpp @@ -19,7 +19,6 @@ #include #include -#include #include #include #include @@ -85,7 +84,7 @@ template struct mac_traits; /** No limit beyond the spec's own: the largest 64-bit size. */ -inline constexpr std::uint64_t no_limit = (std::numeric_limits::max)(); +inline constexpr std::uint64_t no_limit = UINT64_MAX; /** The longest input and output a backend's C library takes, in bytes, where its interface holds a @@ -207,7 +206,7 @@ static_assert(hkdf_pieces_slice_seam >= 1, @ref for_each_slice requires. */ template -inline constexpr std::uint64_t hkdf_pieces_update_max = (std::numeric_limits::max)(); +inline constexpr std::uint64_t hkdf_pieces_update_max = SIZE_MAX; /** The most bytes an engine of HKDF over pieces on `Backend` hands its HMAC in one update: the diff --git a/include/webcpp/hash/detail/limits.hpp b/include/webcpp/hash/detail/limits.hpp index d895ee7..48c3f43 100644 --- a/include/webcpp/hash/detail/limits.hpp +++ b/include/webcpp/hash/detail/limits.hpp @@ -11,7 +11,6 @@ #include #include -#include #include namespace webcpp::hash::detail { @@ -42,7 +41,7 @@ inline constexpr std::uint64_t sp800_185_max_bytes = WEBCPP_HASH_DETAIL_TEST_SP8 (`input_too_long` for a string, `invalid_key_size` for a KMAC key, `invalid_output_size` for an output). The test seam `WEBCPP_HASH_DETAIL_TEST_SP800_185_MAX_BYTES` lowers it. */ -inline constexpr std::uint64_t sp800_185_max_bytes = (std::numeric_limits::max)() / 8; +inline constexpr std::uint64_t sp800_185_max_bytes = SIZE_MAX / 8; #endif #ifdef WEBCPP_HASH_DETAIL_TEST_KANGAROOTWELVE_MAX_BYTES @@ -60,9 +59,8 @@ inline constexpr std::uint64_t kangarootwelve_max_bytes = */ inline constexpr std::uint64_t kangarootwelve_max_bytes = sizeof(std::size_t) < sizeof(std::uint64_t) - ? (std::uint64_t{(std::numeric_limits::max)()} * 8192) - - (sizeof(std::size_t) + 1) - : (std::numeric_limits::max)(); + ? (std::uint64_t{SIZE_MAX} * 8192) - (sizeof(std::size_t) + 1) + : UINT64_MAX; #endif /** The byte @ref nonnull points at for an empty span: a constant, never written. */ diff --git a/include/webcpp/hash/scrypt.hpp b/include/webcpp/hash/scrypt.hpp index ea0c39b..a7804c3 100644 --- a/include/webcpp/hash/scrypt.hpp +++ b/include/webcpp/hash/scrypt.hpp @@ -46,7 +46,6 @@ #include #include -#include #include namespace webcpp::hash { @@ -108,7 +107,7 @@ template } // 128 r (N + p) bytes must fit size_t: N + p cannot wrap, N being at most 2^63. constexpr std::uint64_t block_bytes_count = 128; - constexpr std::uint64_t size_max = (std::numeric_limits::max)(); + constexpr std::uint64_t size_max = SIZE_MAX; if (exceeds(cost_n + parallelism_p, size_max / block_bytes_count / block_size_r)) { return error::invalid_parameters; }