diff --git a/introspection_of_standard_C_types.h b/introspection_of_standard_C_types.h index 6f82b9b..f00822d 100644 --- a/introspection_of_standard_C_types.h +++ b/introspection_of_standard_C_types.h @@ -25,7 +25,12 @@ namespace ro { template ,std::make_unsigned>::type>> constexpr U iabs(T i) { - if constexpr (is_standard_signed_integer)return U(abs(i)); + if constexpr (is_standard_signed_integer) { + U j; + if (i < 0)j = -i; + else j = i; + return j; + } else return i; } diff --git a/ristretto255.h b/ristretto255.h index 23bb41e..d0374ee 100644 --- a/ristretto255.h +++ b/ristretto255.h @@ -654,11 +654,12 @@ namespace ristretto255 { explicit constexpr scalar(std::array&& in) : blob{ in } {}; explicit constexpr scalar(std::array* in) :blob(*in) {}; explicit constexpr scalar(uintmax_t k){ for (auto& j : blob) { j = k; k = k >> 8; } } - template , uintmax_t>> - explicit constexpr scalar(T i) :scalar(U(ro::iabs(i))) { - if constexpr (ro::is_standard_signed_integer) { - if (i < 0) crypto_core_ristretto255_scalar_negate(&blob[0], &blob[0]); - } + template + explicit constexpr scalar(std::enable_if_t < ro::is_standard_unsigned_integer, T> i) :scalar(uintmax_t(i)) {} + template , uintmax_t>> + explicit constexpr scalar(T i) : scalar(U(ro::iabs(i))) { + static_assert (ro::is_standard_signed_integer); + if (i < 0) crypto_core_ristretto255_scalar_negate(&blob[0], &blob[0]); } scalar(scalar&&) = default; // Move constructor scalar(const scalar&) = default; // Copy constructor