1
0
forked from cheng/wallet

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.
This commit is contained in:
Cheng 2022-03-26 20:39:41 +11:00
parent 78a14309e5
commit fccefe3a97
No known key found for this signature in database
GPG Key ID: D51301E176B31828
4 changed files with 14 additions and 9 deletions

2
.gitmodules vendored
View File

@ -8,4 +8,4 @@
ignore = dirty ignore = dirty
[submodule "mpir"] [submodule "mpir"]
path = mpir path = mpir
url = git://github.com/BrianGladman/mpir.git url = https://github.com/BrianGladman/mpir.git

View File

@ -62,7 +62,8 @@ namespace ro {
return sz; return sz;
} }
else { 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(); return null();
} }
} }
@ -90,7 +91,8 @@ namespace ro {
j = (*this)->Isqlite3_column_text(i); j = (*this)->Isqlite3_column_text(i);
} }
else { 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; return *this;
} }

View File

@ -27,14 +27,14 @@ namespace ristretto255 {
bool scalar::constant_time_required{ true }; bool scalar::constant_time_required{ true };
bool point::constant_time_required{ true }; bool point::constant_time_required{ true };
constexpr scalar::scalar(int i) { constexpr scalar::scalar(int64_t i) {
if (i >= 0) { if (i >= 0) {
auto k{ unsigned int(i) }; auto k{ uint64_t(i) };
for (auto& j : blob) { j = k; k = k >> 8; } for (auto& j : blob) { j = k; k = k >> 8; }
} }
else{ else {
std::array<uint8_t, crypto_core_ristretto255_BYTES> absdata; std::array<uint8_t, crypto_core_ristretto255_BYTES> absdata;
auto k{ unsigned int(-i) }; auto k{ uint64_t(-i) };
for (auto& j : absdata) { j = k; k = k >> 8; } for (auto& j : absdata) { j = k; k = k >> 8; }
crypto_core_ristretto255_scalar_negate(&blob[0], &absdata[0]); crypto_core_ristretto255_scalar_negate(&blob[0], &absdata[0]);
} }

View File

@ -653,7 +653,10 @@ namespace ristretto255 {
~scalar() = default; ~scalar() = default;
explicit constexpr scalar(std::array<uint8_t, crypto_core_ristretto255_BYTES>&& in) : blob{ in } {}; explicit constexpr scalar(std::array<uint8_t, crypto_core_ristretto255_BYTES>&& in) : blob{ in } {};
explicit constexpr scalar(std::array<uint8_t, crypto_core_ristretto255_BYTES>* in) :blob(*in) {}; explicit constexpr scalar(std::array<uint8_t, crypto_core_ristretto255_BYTES>* 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(scalar&&) = default; // Move constructor
scalar(const scalar&) = default; // Copy constructor scalar(const scalar&) = default; // Copy constructor
scalar& operator=(scalar&&) = default; // Move assignment. scalar& operator=(scalar&&) = default; // Move assignment.
@ -705,7 +708,7 @@ namespace ristretto255 {
return operator*(sclr.multiplicative_inverse()); return operator*(sclr.multiplicative_inverse());
} }
scalar operator*(int i) const& { scalar operator*(int64_t i) const& {
return operator * (scalar(i)); return operator * (scalar(i));
} }