Browse Source

point validation in hxx

master
Mike Hamburg 9 years ago
parent
commit
3c2152abea
2 changed files with 11 additions and 6 deletions
  1. +4
    -1
      include/decaf.hxx
  2. +7
    -5
      test/test_decaf.cxx

+ 4
- 1
include/decaf.hxx View File

@@ -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


+ 7
- 5
test/test_decaf.cxx View File

@@ -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);


Loading…
Cancel
Save