diff --git a/.github/workflows/wide_integer_fuzzing.yml b/.github/workflows/wide_integer_fuzzing.yml index 7ab258f..ff2be9d 100644 --- a/.github/workflows/wide_integer_fuzzing.yml +++ b/.github/workflows/wide_integer_fuzzing.yml @@ -46,4 +46,4 @@ jobs: clang++ -std=c++20 -g -O2 -fsanitize=fuzzer -I. -I../boost-root test/fuzzing/test_fuzzing_${{ matrix.tcase }}.cpp -o test_fuzzing_${{ matrix.tcase }} echo "ls test_fuzzing_${{ matrix.tcase }}" ls -la test_fuzzing_${{ matrix.tcase }} - ./test_fuzzing_${{ matrix.tcase }} -max_total_time=240 -jobs=8 + ./test_fuzzing_${{ matrix.tcase }} -max_total_time=300 -jobs=8 diff --git a/test/fuzzing/test_fuzzing_prime.cpp b/test/fuzzing/test_fuzzing_prime.cpp index fd3ff36..898ce75 100644 --- a/test/fuzzing/test_fuzzing_prime.cpp +++ b/test/fuzzing/test_fuzzing_prime.cpp @@ -15,13 +15,10 @@ #include #include -#include #include #include #include #include -#include -#include namespace fuzzing { @@ -65,32 +62,30 @@ auto fuzzing::eval_prime(const std::uint8_t* data, std::size_t size) -> bool distribution_type distribution2; local_uint_type p0 { 0U }; + boost_uint_type pb { 0U }; // Import the random data into the prime candidate. import_bits ( p0, data, - data + size + data + size, + 8U ); - const bool miller_rabin_result_local { miller_rabin(p0, 25U, distribution2, generator2) }; - - auto from_string = - [](const local_uint_type& ui) - { - std::stringstream strm { }; - - strm << ui; - - return boost_uint_type { strm.str() }; - }; - - const boost_uint_type pb { std::move(from_string(p0)) }; + // Import the random data into the boost control prime candidate. + import_bits + ( + pb, + data, + data + size, + 8U + ); // Ensure that both uintwide_t as well as boost obtain // the same prime (or non-prime) result. + const bool miller_rabin_result_local { miller_rabin(p0, 25U, distribution2, generator2) }; const bool miller_rabin_result_boost { boost::multiprecision::miller_rabin_test(pb, 25U, generator2) }; const bool diff --git a/test/test_uintwide_t_spot_values.cpp b/test/test_uintwide_t_spot_values.cpp index 477d2a3..3b35719 100644 --- a/test/test_uintwide_t_spot_values.cpp +++ b/test/test_uintwide_t_spot_values.cpp @@ -5,13 +5,94 @@ // or copy at http://www.boost.org/LICENSE_1_0.txt) // +#include +#include + +#include + #include #include #include #include +#include +#include -#include -#include +namespace from_issue_429 +{ + auto test_uintwide_t_spot_values_from_issue_429() -> bool + { + #if defined(WIDE_INTEGER_NAMESPACE) + using local_uint_type = WIDE_INTEGER_NAMESPACE::math::wide_integer::uint256_t; + #else + using local_uint_type = ::math::wide_integer::uint256_t; + #endif + + using boost_uint_backend_type = + boost::multiprecision::cpp_int_backend(UINT32_C(256)), + static_cast(UINT32_C(256)), + boost::multiprecision::unsigned_magnitude>; + + using boost_uint_type = boost::multiprecision::number; + + + const std::vector + input + ( + { + 0x00, 0x00, 0x00, 0xff, + 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x21, 0x62, + 0xff, 0xff, 0xff, 0xff, + 0x21 + } + ); + + local_uint_type p0_local { }; + boost_uint_type p0_boost { }; + + // Import the data into the wide integer. + import_bits + ( + p0_local, + input.cbegin(), + input.cend(), + 8U + ); + + // Import the data into boost's cpp_int. + import_bits + ( + p0_boost, + input.cbegin(), + input.cend(), + 8U + ); + + std::stringstream strm_local { }; + std::stringstream strm_boost { }; + + strm_local << std::hex << p0_local; + strm_boost << std::hex << p0_boost; + + const std::string str_local { strm_local.str() }; + const std::string str_boost { strm_boost.str() }; + + const bool result_import_is_ok { str_local == str_boost }; + + std::vector export_local(input.size()); + std::vector export_boost(input.size()); + + export_bits(p0_local, export_local.begin(), 8U); + export_bits(p0_boost, export_boost.begin(), 8U); + + const bool result_export_is_ok { export_local == export_boost }; + + const bool result_import_export_is_ok { result_import_is_ok && result_export_is_ok }; + + return result_import_export_is_ok; + } +} // namespace from_issue_429 namespace from_issue_362 { @@ -651,6 +732,12 @@ auto local_test_spot_values::test() -> bool // NOLINT(readability-function-cogni { auto result_is_ok = true; + { + // See also: https://github.com/ckormanyos/wide-integer/issues/429 + + result_is_ok = (from_issue_429::test_uintwide_t_spot_values_from_issue_429() && result_is_ok); + } + { // See also: https://github.com/ckormanyos/wide-integer/issues/362