diff options
author | Jack Lloyd <[email protected]> | 2016-07-21 11:30:37 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-07-21 11:30:37 -0400 |
commit | b4da573fc1c241a6badc83f4ec166cbdd5c70c5c (patch) | |
tree | cd91fd6cd3ebdffd2e1705dbb7c233b6cded5570 /src/tests | |
parent | f7fb8241947de7df08acd87423738edc39e15421 (diff) | |
parent | 8f53d3f6efd1419e8feac027035fc8d407e1e75f (diff) |
Merge GH #548 Parallel hash tests, fix memory leak
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/data/hash/parallel.vec | 4 | ||||
-rw-r--r-- | src/tests/test_hash.cpp | 97 |
2 files changed, 100 insertions, 1 deletions
diff --git a/src/tests/data/hash/parallel.vec b/src/tests/data/hash/parallel.vec index 8fd62a76b..544ecc0b8 100644 --- a/src/tests/data/hash/parallel.vec +++ b/src/tests/data/hash/parallel.vec @@ -9,3 +9,7 @@ Out = 0CC175B9C0F1B6A831C399E26977266186F7E437FAA5A7FCE15D1DDCB9EAEAEA377667B8 In = Out = DA39A3EE5E6B4B0D3255BFEF95601890AFD80709CDF26213A150DC3ECB610F18F6B38B463293AC630C13F0245F92BBB1766E16167A4E58492DDE73F3 +[Parallel(SHA-256,SHA-512)] +In = +Out = E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855CF83E1357EEFB8BDF1542850D66D8007D620E4050B5715DC83F4A921D36CE9CE47D0D13C5D85F2B0FF8318D2877EEC2F63B931BD47417A81A538327AF927DA3E + diff --git a/src/tests/test_hash.cpp b/src/tests/test_hash.cpp index be7156411..811e95727 100644 --- a/src/tests/test_hash.cpp +++ b/src/tests/test_hash.cpp @@ -8,6 +8,10 @@ #include <botan/hash.h> +#if defined (BOTAN_HAS_PARALLEL_HASH) + #include <botan/par_hash.h> +#endif + namespace Botan_Tests { namespace { @@ -28,7 +32,7 @@ class Hash_Function_Tests : public Text_Based_Test if(providers.empty()) { - result.note_missing("block cipher " + algo); + result.note_missing("hash " + algo); return result; } @@ -71,6 +75,97 @@ class Hash_Function_Tests : public Text_Based_Test BOTAN_REGISTER_TEST("hash", Hash_Function_Tests); +#if defined(BOTAN_HAS_PARALLEL_HASH) + +Test::Result test_clone() + { + Test::Result result("Parallel hash"); + + std::string algo = "Parallel(MD5,SHA-160)"; + std::unique_ptr<Botan::HashFunction> hash(Botan::HashFunction::create(algo)); + + if(!hash) + { + result.note_missing(algo); + return result; + } + + hash->update(""); + result.test_eq("Parallel hashing", hash->final(), "D41D8CD98F00B204E9800998ECF8427EDA39A3EE5E" + "6B4B0D3255BFEF95601890AFD80709"); + + std::unique_ptr<Botan::HashFunction> hash_clone(hash->clone()); + + hash_clone->clear(); + hash_clone->update(""); + result.test_eq("Parallel hashing (clone)", hash_clone->final(), "D41D8CD98F00B204E9800998ECF8427" + "EDA39A3EE5E6B4B0D3255BFEF95601890AFD80709"); + + return result; + } + +Test::Result test_ctor() + { + Test::Result result("Parallel hash"); + + std::unique_ptr<Botan::HashFunction> sha256(Botan::HashFunction::create("SHA-256")); + if(!sha256) + { + result.note_missing("SHA-256"); + return result; + } + + std::unique_ptr<Botan::HashFunction> sha512(Botan::HashFunction::create("SHA-512")); + if(!sha512) + { + result.note_missing("SHA-512"); + return result; + } + + std::vector<Botan::HashFunction*> hashes = { sha256.get(), sha512.get() }; + Botan::Parallel par_hash(hashes); + + par_hash.update(""); + result.test_eq("Parallel hashing", par_hash.final(), "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B" + "934CA495991B7852B855CF83E1357EEFB8BDF1542850D66D8007D620E4050B5715DC83F4A921D36CE9C" + "E47D0D13C5D85F2B0FF8318D2877EEC2F63B931BD47417A81A538327AF927DA3E"); + + return result; + } + +class Parallel_Hash_Tests : public Test + { + public: + std::vector<Test::Result> run() override + { + std::vector<Test::Result> results; + + std::vector<std::function<Test::Result()>> fns = + { + test_clone, + test_ctor + }; + + for(size_t i = 0; i != fns.size(); ++i) + { + try + { + results.push_back(fns[ i ]()); + } + catch(std::exception& e) + { + results.push_back(Test::Result::Failure("Parallel hash tests " + std::to_string(i), e.what())); + } + } + + return results; + } + }; + +BOTAN_REGISTER_TEST("par_hash", Parallel_Hash_Tests); + +#endif + } } |