#ifndef CRC_DETAIL_2019_01_11_H #define CRC_DETAIL_2019_01_11_H #include #include #include #if(__cplusplus >= 201703L) namespace al::crypto::stream::crc::detail { #else namespace al { namespace crypto { namespace stream { namespace crc { namespace detail { #endif template struct crc_helper { using result_type = typename al::crypto::util::uint_type_helper::exact_unsigned_type; static auto reflect(result_type data) -> result_type { result_type reflected_result(0U); for(std::uint_fast8_t i = 0U; i < static_cast(NumberOfBits); ++i) { // Reflect the next LSB. const auto left_shift_amount = static_cast ( static_cast(NumberOfBits - 1U) - i ); const auto next_bit = static_cast ( static_cast(data) & static_cast(UINT8_C(0x01)) ); const auto next_reflected_bit = static_cast ( static_cast(next_bit) << left_shift_amount ); reflected_result = static_cast(reflected_result | next_reflected_bit); data = static_cast(data >> 1U); } return reflected_result; } static auto index(result_type local_crc, std::uint8_t x) -> std::uint8_t { return std::uint8_t(x ^ local_crc); } static auto shift(result_type local_crc) -> result_type { using local_value_type = typename al::crypto::util::uint_type_helper<(NumberOfBits <= 16) ? 16 : NumberOfBits>::exact_unsigned_type; return static_cast(local_value_type(local_crc) >> 8U); } }; template struct crc_helper { using local_result_type = typename al::crypto::util::uint_type_helper::exact_unsigned_type; static auto reflect(const local_result_type data) -> local_result_type { return data; } static auto index(const local_result_type local_crc, const std::uint8_t x) -> std::uint8_t { return std::uint8_t(x ^ (local_crc >> (std::numeric_limits::digits - 8))); } static auto shift(const local_result_type local_crc) -> local_result_type { using local_value_type = typename al::crypto::util::uint_type_helper<(NumberOfBits <= 16) ? 16 : NumberOfBits>::exact_unsigned_type; return local_result_type(local_value_type(local_crc) << 8U); } }; #if(__cplusplus >= 201703L) } // namespace al::crypto::stream::crc::detail #else } // namespace detail } // namespace crc } // namespace stream } // namespace crypto } // namespace al #endif #endif // CRC_DETAIL_2019_01_11_H