@@ -107,6 +107,18 @@ public: | |||||
throw LengthException(); | throw LengthException(); | ||||
return Block(data()+off, length); | 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? */ | /** Virtual destructor for SecureBlock. TODO: probably means vtable? Make bool? */ | ||||
inline virtual ~Block() {}; | inline virtual ~Block() {}; | ||||
@@ -215,6 +215,13 @@ static void test_ec() { | |||||
Point r = Point::from_hash(buffer); | Point r = Point::from_hash(buffer); | ||||
point_check(test,p,q,r,0,0,p,Point((decaf::SecureBuffer)p),"round-trip"); | 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,"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)+q,p,"correct sub"); | ||||
point_check(test,p,q,r,0,0,p+(q+r),(p+q)+r,"assoc add"); | point_check(test,p,q,r,0,0,p+(q+r),(p+q)+r,"assoc add"); | ||||