From fccefe3a97b5cfc0691ecb627a9d58db25bebdc8 Mon Sep 17 00:00:00 2001 From: Cheng Date: Sat, 26 Mar 2022 20:39:41 +1100 Subject: [PATCH] Visual studio became stuffier about template code, making it harder to use procedural code in templates. Cannot have a static_assert(false) in a template. Got into a tizzy about integer types, instead of cheerfully casting anything to anything. --- .gitmodules | 2 +- db_accessors.h | 6 ++++-- ristretto255.cpp | 8 ++++---- ristretto255.h | 7 +++++-- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.gitmodules b/.gitmodules index 71093de..a333793 100644 --- a/.gitmodules +++ b/.gitmodules @@ -8,4 +8,4 @@ ignore = dirty [submodule "mpir"] path = mpir - url = git://github.com/BrianGladman/mpir.git + url = https://github.com/BrianGladman/mpir.git diff --git a/db_accessors.h b/db_accessors.h index 393d695..94e3ef9 100644 --- a/db_accessors.h +++ b/db_accessors.h @@ -62,7 +62,8 @@ namespace ro { return sz; } else { - static_assert(false, "Don't know how to read this datatype from database"); + assert(false); + //, "Don't know how to read this datatype from database"); return null(); } } @@ -90,7 +91,8 @@ namespace ro { j = (*this)->Isqlite3_column_text(i); } else { - static_assert(false, "Don't know how to read this datatype from database"); + assert(false); + //, "Don't know how to read this datatype from database"); } return *this; } diff --git a/ristretto255.cpp b/ristretto255.cpp index dd4edf9..0e55c49 100644 --- a/ristretto255.cpp +++ b/ristretto255.cpp @@ -27,14 +27,14 @@ namespace ristretto255 { bool scalar::constant_time_required{ true }; bool point::constant_time_required{ true }; - constexpr scalar::scalar(int i) { + constexpr scalar::scalar(int64_t i) { if (i >= 0) { - auto k{ unsigned int(i) }; + auto k{ uint64_t(i) }; for (auto& j : blob) { j = k; k = k >> 8; } } - else{ + else { std::array absdata; - auto k{ unsigned int(-i) }; + auto k{ uint64_t(-i) }; for (auto& j : absdata) { j = k; k = k >> 8; } crypto_core_ristretto255_scalar_negate(&blob[0], &absdata[0]); } diff --git a/ristretto255.h b/ristretto255.h index 56898b5..d5e8711 100644 --- a/ristretto255.h +++ b/ristretto255.h @@ -653,7 +653,10 @@ namespace ristretto255 { ~scalar() = default; explicit constexpr scalar(std::array&& in) : blob{ in } {}; explicit constexpr scalar(std::array* in) :blob(*in) {}; - explicit constexpr scalar(int); + explicit constexpr scalar(int64_t); + explicit constexpr scalar(int i):scalar(int64_t(i)){} + explicit constexpr scalar(uint64_t k){ for (auto& j : blob) { j = k; k = k >> 8; } } + explicit constexpr scalar(unsigned int i) :scalar(uint64_t(i)) {} scalar(scalar&&) = default; // Move constructor scalar(const scalar&) = default; // Copy constructor scalar& operator=(scalar&&) = default; // Move assignment. @@ -705,7 +708,7 @@ namespace ristretto255 { return operator*(sclr.multiplicative_inverse()); } - scalar operator*(int i) const& { + scalar operator*(int64_t i) const& { return operator * (scalar(i)); }