diff --git a/crypto3/libs/multiprecision/include/nil/crypto3/multiprecision/detail/big_int.hpp b/crypto3/libs/multiprecision/include/nil/crypto3/multiprecision/detail/big_int.hpp index f692ef1fb..21fcfafb8 100644 --- a/crypto3/libs/multiprecision/include/nil/crypto3/multiprecision/detail/big_int.hpp +++ b/crypto3/libs/multiprecision/include/nil/crypto3/multiprecision/detail/big_int.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include @@ -8,6 +7,8 @@ #include #include +#include + #include "nil/crypto3/multiprecision/detail/assert.hpp" #include "nil/crypto3/multiprecision/detail/big_uint/big_uint_impl.hpp" #include "nil/crypto3/multiprecision/detail/config.hpp" diff --git a/crypto3/libs/multiprecision/include/nil/crypto3/multiprecision/detail/big_uint/big_uint_impl.hpp b/crypto3/libs/multiprecision/include/nil/crypto3/multiprecision/detail/big_uint/big_uint_impl.hpp index 0ec75d040..90b43cda4 100644 --- a/crypto3/libs/multiprecision/include/nil/crypto3/multiprecision/detail/big_uint/big_uint_impl.hpp +++ b/crypto3/libs/multiprecision/include/nil/crypto3/multiprecision/detail/big_uint/big_uint_impl.hpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -19,9 +18,11 @@ #include #include +#include + #include "nil/crypto3/multiprecision/detail/assert.hpp" #include "nil/crypto3/multiprecision/detail/big_uint/arithmetic.hpp" -#include "nil/crypto3/multiprecision/detail/big_uint/parsing.hpp" +#include "nil/crypto3/multiprecision/detail/big_uint/parsing.hpp" // IWYU pragma: export #include "nil/crypto3/multiprecision/detail/big_uint/storage.hpp" #include "nil/crypto3/multiprecision/detail/big_uint/type_traits.hpp" // IWYU pragma: export #include "nil/crypto3/multiprecision/detail/config.hpp" diff --git a/crypto3/libs/multiprecision/include/nil/crypto3/multiprecision/detail/big_uint/ops/import_export.hpp b/crypto3/libs/multiprecision/include/nil/crypto3/multiprecision/detail/big_uint/ops/import_export.hpp index 3e9246065..8ea016d11 100644 --- a/crypto3/libs/multiprecision/include/nil/crypto3/multiprecision/detail/big_uint/ops/import_export.hpp +++ b/crypto3/libs/multiprecision/include/nil/crypto3/multiprecision/detail/big_uint/ops/import_export.hpp @@ -85,7 +85,7 @@ namespace nil::crypto3::multiprecision { bit_location = limb_bits - bit_location; NIL_CO3_MP_ASSERT( - !((bit_location < sizeof(bits) * CHAR_BIT) && (bits >>= bit_location))); + !((bit_location < sizeof(bits) * CHAR_BIT) && (bits >> bit_location))); } template diff --git a/crypto3/libs/multiprecision/include/nil/crypto3/multiprecision/miller_rabin.hpp b/crypto3/libs/multiprecision/include/nil/crypto3/multiprecision/miller_rabin.hpp index 4a1ca5ae4..555745e04 100644 --- a/crypto3/libs/multiprecision/include/nil/crypto3/multiprecision/miller_rabin.hpp +++ b/crypto3/libs/multiprecision/include/nil/crypto3/multiprecision/miller_rabin.hpp @@ -5,13 +5,15 @@ #pragma once -#include #include #include +#include #include #include #include +#include + #include "nil/crypto3/multiprecision/big_uint.hpp" #include "nil/crypto3/multiprecision/detail/assert.hpp" #include "nil/crypto3/multiprecision/integer.hpp" @@ -33,7 +35,9 @@ namespace nil::crypto3::multiprecision { for (std::size_t i = 0; i < sizeof(small_factors1) / sizeof(small_factors1[0]); ++i) { NIL_CO3_MP_ASSERT(pp1 % small_factors1[i] == 0); - if (m1 % small_factors1[i] == 0) return false; + if (m1 % small_factors1[i] == 0) { + return false; + } } constexpr std::uint32_t small_factors2[] = {29u, 31u, 37u, 41u, 43u, 47u}; @@ -43,7 +47,9 @@ namespace nil::crypto3::multiprecision { for (std::size_t i = 0; i < sizeof(small_factors2) / sizeof(small_factors2[0]); ++i) { NIL_CO3_MP_ASSERT(pp2 % small_factors2[i] == 0); - if (m1 % small_factors2[i] == 0) return false; + if (m1 % small_factors2[i] == 0) { + return false; + } } constexpr std::uint32_t small_factors3[] = {53u, 59u, 61u, 67u, 71u}; @@ -53,7 +59,9 @@ namespace nil::crypto3::multiprecision { for (std::size_t i = 0; i < sizeof(small_factors3) / sizeof(small_factors3[0]); ++i) { NIL_CO3_MP_ASSERT(pp3 % small_factors3[i] == 0); - if (m1 % small_factors3[i] == 0) return false; + if (m1 % small_factors3[i] == 0) { + return false; + } } constexpr std::uint32_t small_factors4[] = {73u, 79u, 83u, 89u, 97u}; @@ -63,7 +71,9 @@ namespace nil::crypto3::multiprecision { for (std::size_t i = 0; i < sizeof(small_factors4) / sizeof(small_factors4[0]); ++i) { NIL_CO3_MP_ASSERT(pp4 % small_factors4[i] == 0); - if (m1 % small_factors4[i] == 0) return false; + if (m1 % small_factors4[i] == 0) { + return false; + } } constexpr std::uint32_t small_factors5[6][4] = { @@ -76,12 +86,14 @@ namespace nil::crypto3::multiprecision { 181u * 191u * 193u * 197u, 199u * 211u * 223u * 227u}; - for (std::size_t k = 0; k < sizeof(pp5) / sizeof(*pp5); ++k) { + for (std::size_t k = 0; k < std::size(pp5); ++k) { m1 = integer_modulus(n, pp5[k]); for (std::size_t i = 0; i < 4; ++i) { NIL_CO3_MP_ASSERT(pp5[k] % small_factors5[k][i] == 0); - if (m1 % small_factors5[k][i] == 0) return false; + if (m1 % small_factors5[k][i] == 0) { + return false; + } } } return true; @@ -93,8 +105,10 @@ namespace nil::crypto3::multiprecision { 43u, 47u, 53u, 59u, 61u, 67u, 71u, 73u, 79u, 83u, 89u, 97u, 101u, 103u, 107u, 109u, 113u, 127u, 131u, 137u, 139u, 149u, 151u, 157u, 163u, 167u, 173u, 179u, 181u, 191u, 193u, 197u, 199u, 211u, 223u, 227u}; - for (std::size_t i = 0; i < sizeof(p) / sizeof(*p); ++i) { - if (n == p[i]) return true; + for (std::size_t i = 0; i < std::size(p); ++i) { + if (n == p[i]) { + return true; + } } return false; } @@ -105,11 +119,19 @@ namespace nil::crypto3::multiprecision { const I& n, std::size_t trials, Engine& gen) { using number_type = I; - if (n == 2) return true; // Trivial special case. - if (bit_test(n, 0) == 0) return false; // n is even - if (n <= 227) return detail::is_small_prime(static_cast(n)); + if (n == 2) { + return true; // Trivial special case. + } + if (bit_test(n, 0) == 0) { + return false; // n is even + } + if (n <= 227) { + return detail::is_small_prime(static_cast(n)); + } - if (!detail::check_small_factors(n)) return false; + if (!detail::check_small_factors(n)) { + return false; + } number_type nm1 = n - 1u; // @@ -118,7 +140,9 @@ namespace nil::crypto3::multiprecision { number_type q(228), x, y; // We know n is greater than this, as we've excluded small factors x = powm(q, nm1, n); - if (x != 1u) return false; + if (x != 1u) { + return false; + } q = n - 1u; std::size_t k = lsb(q); @@ -135,12 +159,18 @@ namespace nil::crypto3::multiprecision { y = powm(x, q, n); std::size_t j = 0; while (true) { - if (y == nm1) break; + if (y == nm1) { + break; + } if (y == 1) { - if (j == 0) break; + if (j == 0) { + break; + } return false; // test failed } - if (++j == k) return false; // failed + if (++j == k) { + return false; // failed + } y = powm(y, 2, n); } }