diff options
author | lloyd <[email protected]> | 2014-01-10 03:41:59 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-01-10 03:41:59 +0000 |
commit | 6894dca64c04936d07048c0e8cbf7e25858548c3 (patch) | |
tree | 5d572bfde9fe667dab14e3f04b5285a85d8acd95 /src/lib/hash/par_hash | |
parent | 9efa3be92442afb3d0b69890a36c7f122df18eda (diff) |
Move lib into src
Diffstat (limited to 'src/lib/hash/par_hash')
-rw-r--r-- | src/lib/hash/par_hash/info.txt | 1 | ||||
-rw-r--r-- | src/lib/hash/par_hash/par_hash.cpp | 100 | ||||
-rw-r--r-- | src/lib/hash/par_hash/par_hash.h | 41 |
3 files changed, 142 insertions, 0 deletions
diff --git a/src/lib/hash/par_hash/info.txt b/src/lib/hash/par_hash/info.txt new file mode 100644 index 000000000..4f559b545 --- /dev/null +++ b/src/lib/hash/par_hash/info.txt @@ -0,0 +1 @@ +define PARALLEL_HASH 20131128 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; + } + +} diff --git a/src/lib/hash/par_hash/par_hash.h b/src/lib/hash/par_hash/par_hash.h new file mode 100644 index 000000000..4f5395c23 --- /dev/null +++ b/src/lib/hash/par_hash/par_hash.h @@ -0,0 +1,41 @@ +/* +* Parallel Hash +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_PARALLEL_HASH_H__ +#define BOTAN_PARALLEL_HASH_H__ + +#include <botan/hash.h> +#include <vector> + +namespace Botan { + +/** +* Parallel Hashes +*/ +class BOTAN_DLL Parallel : public HashFunction + { + public: + void clear(); + std::string name() const; + HashFunction* clone() const; + + size_t output_length() const; + + /** + * @param hashes a set of hashes to compute in parallel + */ + Parallel(const std::vector<HashFunction*>& hashes); + ~Parallel(); + private: + void add_data(const byte[], size_t); + void final_result(byte[]); + std::vector<HashFunction*> hashes; + }; + +} + +#endif |