aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/hash/par_hash/par_hash.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-01-10 03:41:59 +0000
committerlloyd <[email protected]>2014-01-10 03:41:59 +0000
commit6894dca64c04936d07048c0e8cbf7e25858548c3 (patch)
tree5d572bfde9fe667dab14e3f04b5285a85d8acd95 /src/lib/hash/par_hash/par_hash.cpp
parent9efa3be92442afb3d0b69890a36c7f122df18eda (diff)
Move lib into src
Diffstat (limited to 'src/lib/hash/par_hash/par_hash.cpp')
-rw-r--r--src/lib/hash/par_hash/par_hash.cpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/lib/hash/par_hash/par_hash.cpp b/src/lib/hash/par_hash/par_hash.cpp
new file mode 100644
index 000000000..df47780ef
--- /dev/null
+++ b/src/lib/hash/par_hash/par_hash.cpp
@@ -0,0 +1,100 @@
+/*
+* Parallel
+* (C) 1999-2009 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#include <botan/par_hash.h>
+#include <botan/parsing.h>
+
+namespace Botan {
+
+/*
+* Update the hash
+*/
+void Parallel::add_data(const byte input[], size_t length)
+ {
+ for(auto hash : hashes)
+ hash->update(input, length);
+ }
+
+/*
+* Finalize the hash
+*/
+void Parallel::final_result(byte out[])
+ {
+ u32bit offset = 0;
+
+ for(auto hash : hashes)
+ {
+ hash->final(out + offset);
+ offset += hash->output_length();
+ }
+ }
+
+/*
+* Return output size
+*/
+size_t Parallel::output_length() const
+ {
+ size_t sum = 0;
+
+ for(auto hash : hashes)
+ sum += hash->output_length();
+ return sum;
+ }
+
+/*
+* Return the name of this type
+*/
+std::string Parallel::name() const
+ {
+ std::vector<std::string> names;
+
+ for(auto hash : hashes)
+ names.push_back(hash->name());
+
+ return "Parallel(" + string_join(names, ',') + ")";
+ }
+
+/*
+* Return a clone of this object
+*/
+HashFunction* Parallel::clone() const
+ {
+ std::vector<HashFunction*> hash_copies;
+
+ for(auto hash : hashes)
+ hash_copies.push_back(hash->clone());
+
+ return new Parallel(hash_copies);
+ }
+
+/*
+* Clear memory of sensitive data
+*/
+void Parallel::clear()
+ {
+ for(auto hash : hashes)
+ hash->clear();
+ }
+
+/*
+* Parallel Constructor
+*/
+Parallel::Parallel(const std::vector<HashFunction*>& hash_in) :
+ hashes(hash_in)
+ {
+ }
+
+/*
+* Parallel Destructor
+*/
+Parallel::~Parallel()
+ {
+ for(auto hash : hashes)
+ delete hash;
+ }
+
+}