diff --git a/include/decaf.hxx b/include/decaf.hxx index 380d345..5ce71ce 100644 --- a/include/decaf.hxx +++ b/include/decaf.hxx @@ -102,7 +102,7 @@ public: inline Scalar(const decaf_448_scalar_t &t = decaf_448_scalar_zero) NOEXCEPT { decaf_448_scalar_copy(s,t); } /** @brief Copy constructor. */ - inline Scalar(const Scalar &x) NOEXCEPT { decaf_448_scalar_copy(s,x.s); } + inline Scalar(const Scalar &x) NOEXCEPT { *this = x; } /** @brief Construct from arbitrary-length little-endian byte sequence. */ inline explicit Scalar(const std::string &str) NOEXCEPT { *this = str; } @@ -408,6 +408,9 @@ public: /** @brief Multiply by s.inverse(). If s=0, maps to the identity. */ inline Point &operator/=(const Scalar &s) NOEXCEPT { return (*this) *= s.inverse(); } + /** @brief Validate / sanity check */ + inline bool validate() const NOEXCEPT { return !!decaf_448_point_valid(p); } + /** @brief Double-scalar multiply, equivalent to q*qs + r*rs but faster. */ static inline Point double_scalarmul ( const Point &q, const Scalar &qs, const Point &r, const Scalar &rs diff --git a/test/test_decaf.cxx b/test/test_decaf.cxx index 8ed6f4d..742e38e 100644 --- a/test/test_decaf.cxx +++ b/test/test_decaf.cxx @@ -95,13 +95,15 @@ static bool point_check( const Point &r, const char *name ) { - if (l == r) return true; + bool good = l==r; + if (!p.validate()) { good = false; printf(" p invalid\n"); } + if (!q.validate()) { good = false; printf(" q invalid\n"); } + if (!r.validate()) { good = false; printf(" r invalid\n"); } + if (!l.validate()) { good = false; printf(" l invalid\n"); } + if (good) return true; + test.fail(); printf(" %s", name); - if (!decaf_448_point_valid(p.p)) printf(" p invalid\n"); - if (!decaf_448_point_valid(q.p)) printf(" q invalid\n"); - if (!decaf_448_point_valid(r.p)) printf(" r invalid\n"); - if (!decaf_448_point_valid(l.p)) printf(" l invalid\n"); print("x", x); print("y", y); print("p", p);