diff --git a/include/decaf_255.hxx b/include/decaf_255.hxx index 23ea568..828fb47 100644 --- a/include/decaf_255.hxx +++ b/include/decaf_255.hxx @@ -107,6 +107,18 @@ public: throw LengthException(); return Block(data()+off, length); } + + /* Content-wise comparison; constant-time if they are the same length. + * FIXME: is it wise to have a content-wise compare on objects that may be mutable? + */ + inline decaf_bool_t operator==(const Block &b) const NOEXCEPT { + return ~(*this != b); + } + + inline decaf_bool_t operator!=(const Block &b) const NOEXCEPT { + if (b.size() != size()) return true; + return ~decaf_memeq(b,*this,size()); + } /** Virtual destructor for SecureBlock. TODO: probably means vtable? Make bool? */ inline virtual ~Block() {}; diff --git a/test/test_decaf.cxx b/test/test_decaf.cxx index bc83ea2..6ad23e8 100644 --- a/test/test_decaf.cxx +++ b/test/test_decaf.cxx @@ -215,6 +215,13 @@ static void test_ec() { Point r = Point::from_hash(buffer); point_check(test,p,q,r,0,0,p,Point((decaf::SecureBuffer)p),"round-trip"); + Point pp = p; + (pp).debugging_torque_in_place(); + if (decaf::SecureBuffer(pp) != decaf::SecureBuffer(p)) { + test.fail(); + printf("Fail torque seq test\n"); + } + point_check(test,p,q,r,0,0,p,pp,"torque eq"); point_check(test,p,q,r,0,0,p+q,q+p,"commute add"); point_check(test,p,q,r,0,0,(p-q)+q,p,"correct sub"); point_check(test,p,q,r,0,0,p+(q+r),(p+q)+r,"assoc add");