diff options
author | lloyd <[email protected]> | 2008-09-28 23:23:51 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-28 23:23:51 +0000 |
commit | a6f3801debb5239505ec2c9523a7fec5a9bbb070 (patch) | |
tree | 51adb7850c2fa18494743274b6767bd9abec957b /src/hash | |
parent | fda3e1b51fbb539e3689e23148be08783afe0e21 (diff) |
Move allocator code to secalloc/allocators module
Move paralle hash construction to par_hash module in hash directory
Diffstat (limited to 'src/hash')
-rw-r--r-- | src/hash/par_hash/modinfo.txt | 10 | ||||
-rw-r--r-- | src/hash/par_hash/par_hash.cpp | 102 | ||||
-rw-r--r-- | src/hash/par_hash/par_hash.h | 33 |
3 files changed, 145 insertions, 0 deletions
diff --git a/src/hash/par_hash/modinfo.txt b/src/hash/par_hash/modinfo.txt new file mode 100644 index 000000000..45716aac8 --- /dev/null +++ b/src/hash/par_hash/modinfo.txt @@ -0,0 +1,10 @@ +realname "Parallel Hash" + +define PARALLEL_HASH + +load_on auto + +<add> +par_hash.cpp +par_hash.h +</add> diff --git a/src/hash/par_hash/par_hash.cpp b/src/hash/par_hash/par_hash.cpp new file mode 100644 index 000000000..12786523f --- /dev/null +++ b/src/hash/par_hash/par_hash.cpp @@ -0,0 +1,102 @@ +/************************************************* +* Parallel Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include <botan/par_hash.h> +#include <botan/lookup.h> + +namespace Botan { + +namespace { + +/************************************************* +* Return the sum of the hash sizes * +*************************************************/ +u32bit sum_of_hash_lengths(const std::vector<std::string>& names) + { + u32bit sum = 0; + for(u32bit j = 0; j != names.size(); ++j) + sum += output_length_of(names[j]); + return sum; + } + +} + +/************************************************* +* Update the hash * +*************************************************/ +void Parallel::add_data(const byte input[], u32bit length) + { + for(u32bit j = 0; j != hashes.size(); ++j) + hashes[j]->update(input, length); + } + +/************************************************* +* Finalize the hash * +*************************************************/ +void Parallel::final_result(byte hash[]) + { + u32bit offset = 0; + for(u32bit j = 0; j != hashes.size(); ++j) + { + hashes[j]->final(hash + offset); + offset += hashes[j]->OUTPUT_LENGTH; + } + } + +/************************************************* +* Return the name of this type * +*************************************************/ +std::string Parallel::name() const + { + std::string hash_names; + for(u32bit j = 0; j != hashes.size(); ++j) + { + if(j) + hash_names += ','; + hash_names += hashes[j]->name(); + } + return "Parallel(" + hash_names + ")"; + } + +/************************************************* +* Return a clone of this object * +*************************************************/ +HashFunction* Parallel::clone() const + { + std::vector<std::string> names; + for(u32bit j = 0; j != hashes.size(); ++j) + names.push_back(hashes[j]->name()); + return new Parallel(names); + } + +/************************************************* +* Clear memory of sensitive data * +*************************************************/ +void Parallel::clear() throw() + { + for(u32bit j = 0; j != hashes.size(); ++j) + hashes[j]->clear(); + } + +/************************************************* +* Parallel Constructor * +*************************************************/ +Parallel::Parallel(const std::vector<std::string>& names) : + HashFunction(sum_of_hash_lengths(names)) + { + for(u32bit j = 0; j != names.size(); ++j) + hashes.push_back(get_hash(names[j])); + } + +/************************************************* +* Parallel Destructor * +*************************************************/ +Parallel::~Parallel() + { + for(u32bit j = 0; j != hashes.size(); ++j) + delete hashes[j]; + } + +} diff --git a/src/hash/par_hash/par_hash.h b/src/hash/par_hash/par_hash.h new file mode 100644 index 000000000..844a6fb50 --- /dev/null +++ b/src/hash/par_hash/par_hash.h @@ -0,0 +1,33 @@ +/************************************************* +* Parallel Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_PAR_HASH_H__ +#define BOTAN_PAR_HASH_H__ + +#include <botan/base.h> +#include <vector> + +namespace Botan { + +/************************************************* +* Parallel * +*************************************************/ +class BOTAN_DLL Parallel : public HashFunction + { + public: + void clear() throw(); + std::string name() const; + HashFunction* clone() const; + Parallel(const std::vector<std::string>&); + ~Parallel(); + private: + void add_data(const byte[], u32bit); + void final_result(byte[]); + std::vector<HashFunction*> hashes; + }; + +} + +#endif |