diff --git a/include/ack/bigint.hpp b/include/ack/bigint.hpp index a430307..708087a 100644 --- a/include/ack/bigint.hpp +++ b/include/ack/bigint.hpp @@ -864,7 +864,7 @@ namespace ack { size_t zn = xn; const bool success = z.buf_.alloc(zn); assert(success); - if (!success ) { + if ( !success ) { z.clear(); return; } @@ -1934,7 +1934,7 @@ namespace ack { static constexpr void shl(bigint& y, const bigint& x, std::size_t shift_bit) { size_t xn = x.size(); - size_t yn = xn + get_word_size_from_bitsize(shift_bit); /*(shift_bit + word_bit_size - 1) / word_bit_size;*/ + size_t yn = xn + bitsize_to_wordsize(shift_bit); /*(shift_bit + word_bit_size - 1) / word_bit_size;*/ [[maybe_unused]] const bool success = y.buf_.alloc(yn); assert(success); @@ -2529,7 +2529,7 @@ namespace ack { * The maximum size of a fixed_bigint can be 512 bits for all ECC & RSA operations. */ template - using fixed_bigint = bigint>; + using fixed_bigint = bigint>; template struct is_bigint : std::false_type {}; diff --git a/include/ack/buffer.hpp b/include/ack/buffer.hpp index 07393e5..a55c07e 100644 --- a/include/ack/buffer.hpp +++ b/include/ack/buffer.hpp @@ -60,7 +60,6 @@ namespace ack { private: buffer_base() = default; - friend derived_type; }; @@ -77,7 +76,7 @@ namespace ack { constexpr bool alloc(size_t n) { - if (n > N) { + if ( n > N ) { return false; } size_ = n; @@ -111,19 +110,19 @@ namespace ack { constexpr void swap(fixed_buffer& rhs) { - std::swap(data_, rhs.data_); - std::swap(size_, rhs.size_); + std::swap( data_, rhs.data_ ); + std::swap( size_, rhs.size_ ); } constexpr const T& operator[](size_t n) const { - check(n < size_, "fixed_buffer:operator[]: overflow"); + check( n < size_, "fixed_buffer:operator[]: overflow" ); return data_[n]; } constexpr T& operator[](size_t n) { - check(n < size_, "fixed_buffer:operator[]: overflow"); + check( n < size_, "fixed_buffer:operator[]: overflow" ); return data_[n]; } diff --git a/include/ack/types.hpp b/include/ack/types.hpp index 3c73477..342b688 100644 --- a/include/ack/types.hpp +++ b/include/ack/types.hpp @@ -27,7 +27,7 @@ namespace ack { using hash384 = eosio::fixed_bytes<48>; using hash512 = eosio::checksum512; - static constexpr size_t word_bit_size = sizeof(word_t) * 8; + inline constexpr size_t word_bit_size = sizeof(word_t) * 8; inline bytes make_bytes(const bytes_view& data) { return bytes{ data.begin(), data.end() }; diff --git a/include/ack/utils.hpp b/include/ack/utils.hpp index 3671ce2..2badeb1 100644 --- a/include/ack/utils.hpp +++ b/include/ack/utils.hpp @@ -88,7 +88,7 @@ namespace ack { * @param bitsize - the number of bits * @return the number of words needed to store the given number of bits */ - inline constexpr std::size_t get_word_size_from_bitsize(std::size_t bitsize) { + inline constexpr std::size_t bitsize_to_wordsize(std::size_t bitsize) { return (bitsize + word_bit_size - 1) / word_bit_size; } diff --git a/tests/include/ack/tests/utils_test.hpp b/tests/include/ack/tests/utils_test.hpp index 6284043..686ec93 100644 --- a/tests/include/ack/tests/utils_test.hpp +++ b/tests/include/ack/tests/utils_test.hpp @@ -17,53 +17,53 @@ namespace ack::tests { static_assert( sizeof( word_t ) == 4 ); // bitsize - REQUIRE_EQUAL( get_word_size_from_bitsize(0), 0 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(1), 1 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(8), 1 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(9), 1 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(16), 1 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(17), 1 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(24), 1 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(25), 1 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(31), 1 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(32), 1 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(33), 2 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(48), 2 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(49), 2 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(64), 2 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(65), 3 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(96), 3 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(97), 4 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(127), 4 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(128), 4 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(129), 5 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(160), 5 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(161), 6 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(192), 6 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(193), 7 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(224), 7 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(225), 8 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(255), 8 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(256), 8 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(257), 9 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(288), 9 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(289), 10 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(320), 10 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(321), 11 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(352), 11 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(353), 12 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(383), 12 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(384), 12 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(385), 13 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(416), 13 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(417), 14 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(448), 14 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(449), 15 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(480), 15 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(481), 16 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(511), 16 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(512), 16 ) - REQUIRE_EQUAL( get_word_size_from_bitsize(513), 17 ) + REQUIRE_EQUAL( bitsize_to_wordsize(0), 0 ) + REQUIRE_EQUAL( bitsize_to_wordsize(1), 1 ) + REQUIRE_EQUAL( bitsize_to_wordsize(8), 1 ) + REQUIRE_EQUAL( bitsize_to_wordsize(9), 1 ) + REQUIRE_EQUAL( bitsize_to_wordsize(16), 1 ) + REQUIRE_EQUAL( bitsize_to_wordsize(17), 1 ) + REQUIRE_EQUAL( bitsize_to_wordsize(24), 1 ) + REQUIRE_EQUAL( bitsize_to_wordsize(25), 1 ) + REQUIRE_EQUAL( bitsize_to_wordsize(31), 1 ) + REQUIRE_EQUAL( bitsize_to_wordsize(32), 1 ) + REQUIRE_EQUAL( bitsize_to_wordsize(33), 2 ) + REQUIRE_EQUAL( bitsize_to_wordsize(48), 2 ) + REQUIRE_EQUAL( bitsize_to_wordsize(49), 2 ) + REQUIRE_EQUAL( bitsize_to_wordsize(64), 2 ) + REQUIRE_EQUAL( bitsize_to_wordsize(65), 3 ) + REQUIRE_EQUAL( bitsize_to_wordsize(96), 3 ) + REQUIRE_EQUAL( bitsize_to_wordsize(97), 4 ) + REQUIRE_EQUAL( bitsize_to_wordsize(127), 4 ) + REQUIRE_EQUAL( bitsize_to_wordsize(128), 4 ) + REQUIRE_EQUAL( bitsize_to_wordsize(129), 5 ) + REQUIRE_EQUAL( bitsize_to_wordsize(160), 5 ) + REQUIRE_EQUAL( bitsize_to_wordsize(161), 6 ) + REQUIRE_EQUAL( bitsize_to_wordsize(192), 6 ) + REQUIRE_EQUAL( bitsize_to_wordsize(193), 7 ) + REQUIRE_EQUAL( bitsize_to_wordsize(224), 7 ) + REQUIRE_EQUAL( bitsize_to_wordsize(225), 8 ) + REQUIRE_EQUAL( bitsize_to_wordsize(255), 8 ) + REQUIRE_EQUAL( bitsize_to_wordsize(256), 8 ) + REQUIRE_EQUAL( bitsize_to_wordsize(257), 9 ) + REQUIRE_EQUAL( bitsize_to_wordsize(288), 9 ) + REQUIRE_EQUAL( bitsize_to_wordsize(289), 10 ) + REQUIRE_EQUAL( bitsize_to_wordsize(320), 10 ) + REQUIRE_EQUAL( bitsize_to_wordsize(321), 11 ) + REQUIRE_EQUAL( bitsize_to_wordsize(352), 11 ) + REQUIRE_EQUAL( bitsize_to_wordsize(353), 12 ) + REQUIRE_EQUAL( bitsize_to_wordsize(383), 12 ) + REQUIRE_EQUAL( bitsize_to_wordsize(384), 12 ) + REQUIRE_EQUAL( bitsize_to_wordsize(385), 13 ) + REQUIRE_EQUAL( bitsize_to_wordsize(416), 13 ) + REQUIRE_EQUAL( bitsize_to_wordsize(417), 14 ) + REQUIRE_EQUAL( bitsize_to_wordsize(448), 14 ) + REQUIRE_EQUAL( bitsize_to_wordsize(449), 15 ) + REQUIRE_EQUAL( bitsize_to_wordsize(480), 15 ) + REQUIRE_EQUAL( bitsize_to_wordsize(481), 16 ) + REQUIRE_EQUAL( bitsize_to_wordsize(511), 16 ) + REQUIRE_EQUAL( bitsize_to_wordsize(512), 16 ) + REQUIRE_EQUAL( bitsize_to_wordsize(513), 17 ) // char REQUIRE_EQUAL( get_word_size(0), 0 )