From f7eeb957bb49a859b62f44fa2edd7fed54d20983 Mon Sep 17 00:00:00 2001 From: R Date: Fri, 20 Nov 2026 02:11:38 -0300 Subject: [PATCH] crypto: the Linux lint's findings in tests: the 64-bit and 32-bit message limits of box and secretbox as two static_asserts (bugprone-branch-clone on Linux, where both branches read alike), trailing commas in two of paths.hpp's initializer lists --- test/box_sodium_test.cpp | 4 ++-- test/constant_time/paths.hpp | 9 ++++++--- test/secretbox_sodium_test.cpp | 6 +++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/test/box_sodium_test.cpp b/test/box_sodium_test.cpp index ba05d7a8..058b10a2 100644 --- a/test/box_sodium_test.cpp +++ b/test/box_sodium_test.cpp @@ -83,8 +83,8 @@ static_assert(sealed_box::overhead == 48); // smaller, 2^32 - 17, as the Doc Comment says. static_assert(box::max_message_size == ~std::uint64_t{0} - 16 && box_xchacha::max_message_size == box::max_message_size); -static_assert(sizeof(std::size_t) == 8 ? box::max_message_size == crypto_box_MESSAGEBYTES_MAX - : crypto_box_MESSAGEBYTES_MAX == 0xffffffffU - 16); +static_assert(sizeof(std::size_t) != 8 || box::max_message_size == crypto_box_MESSAGEBYTES_MAX); +static_assert(sizeof(std::size_t) == 8 || crypto_box_MESSAGEBYTES_MAX == 0xffffffffU - 16); // Move-only: the precomputed key has one owner, which wipes it. static_assert(!std::is_copy_constructible_v && !std::is_copy_assignable_v); static_assert(std::is_nothrow_move_constructible_v && std::is_nothrow_move_assignable_v); diff --git a/test/constant_time/paths.hpp b/test/constant_time/paths.hpp index e5724a47..e7ae1894 100644 --- a/test/constant_time/paths.hpp +++ b/test/constant_time/paths.hpp @@ -521,8 +521,10 @@ int secp256k1_musig() { int const failures = check(carries_mark(bytes_of(own_nonce->secret_part)), "secp256k1's nonce_gen"); Checker::mark_public(bytes_of(own_nonce->public_part)); - std::array const nonces{own_nonce->public_part, - other_nonce->public_part}; + std::array const nonces{ + own_nonce->public_part, + other_nonce->public_part, + }; auto const nonce_sum = musig::nonce_aggregate(nonces, space); if (!nonce_sum) { return failures + check(false, "secp256k1's nonce_aggregate"); @@ -567,7 +569,8 @@ int secp256k1_silent_payments() { return check(false, "secp256k1's public keys for silent payments"); } std::array const recipients{ - silent_payments::recipient{.scan_key = *scan_key, .spend_key = *spend_key}}; + silent_payments::recipient{.scan_key = *scan_key, .spend_key = *spend_key}, + }; std::array outpoint{}; outpoint.fill(0x01); std::array const plain_inputs{&*input_pair}; diff --git a/test/secretbox_sodium_test.cpp b/test/secretbox_sodium_test.cpp index 4612d055..07fcb59c 100644 --- a/test/secretbox_sodium_test.cpp +++ b/test/secretbox_sodium_test.cpp @@ -58,9 +58,9 @@ static_assert(secretbox_xchacha::key_size == 32 && secretbox_xchacha::iv_size == static_assert(secretbox::max_message_size == ~std::uint64_t{0} - 16); // libsodium's own limit on a 64-bit target; on a 32-bit one libsodium's is the smaller, // 2^32 - 17, as the Doc Comment says. -static_assert(sizeof(std::size_t) == 8 - ? secretbox::max_message_size == crypto_secretbox_MESSAGEBYTES_MAX - : crypto_secretbox_MESSAGEBYTES_MAX == 0xffffffffU - 16); +static_assert(sizeof(std::size_t) != 8 || + secretbox::max_message_size == crypto_secretbox_MESSAGEBYTES_MAX); +static_assert(sizeof(std::size_t) == 8 || crypto_secretbox_MESSAGEBYTES_MAX == 0xffffffffU - 16); static_assert(secretbox::max_additional_data_size == 0 && secretbox_xchacha::max_additional_data_size == 0);