/** * @file test_decaf.cxx * @author Mike Hamburg * * @copyright * Copyright (c) 2015 Cryptography Research, Inc. \n * Released under the MIT License. See LICENSE.txt for license information. * * @brief C++ tests, because that's easier. */ #include #include #include #include #include #include using namespace decaf; static const long NTESTS = 10; const char *undef_str = "Valgrind thinks this string is undefined."; const Block undef_block(undef_str); static inline void ignore(decaf_error_t x) { (void)x; } template struct Tests { typedef typename Group::Scalar Scalar; typedef typename Group::Point Point; typedef typename Group::Precomputed Precomputed; static void test_arithmetic() { SpongeRng rng(Block("test_arithmetic")); rng.stir(undef_block); Scalar x(rng),y(rng),z; uint8_t ser[Group::Scalar::SER_BYTES]; for (int i=0; i(ser))); (void)(p*y); (void)(p+q); (void)(p-q); (void)(-p); (void)(p.times_two()); (void)(p==q); (void)(p.debugging_torque()); //(void)(p.non_secret_combo_with_base(y,z)); // Should fail (void)(Precomputed(p)*y); p.dual_scalarmul(q,r,y,z); Group::Point::double_scalarmul(p,y,q,z); } } static void test_crypto() { SpongeRng rng(Block("test_crypto")); rng.stir(undef_block); for (int i=0; i sk1(rng); PrivateKey sk2(rng); SecureBuffer sig = sk1.sign(undef_block); //sk.pub().verify(undef_block,sig); would fail. FUTURE: ct version of this? /* TODO: shared_secret nothrow? have to test shared_secret... */ } } }; /* template */ int main(int argc, char **argv) { (void) argc; (void) argv; VALGRIND_MAKE_MEM_UNDEFINED(undef_str, strlen(undef_str)); printf("Testing %s:\n",IsoEd25519::name()); Tests::test_arithmetic(); Tests::test_elligator(); Tests::test_ec(); Tests::test_crypto(); printf("\n"); printf("Testing %s:\n", Ed448Goldilocks::name()); Tests::test_arithmetic(); Tests::test_elligator(); Tests::test_ec(); Tests::test_crypto(); return 0; }