Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

par_hash.cpp
Go to the documentation of this file.
1 /*
2 * Parallel Hash
3 * (C) 1999-2009 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #include <botan/par_hash.h>
9 #include <botan/parsing.h>
10
11 namespace Botan {
12
13 void Parallel::add_data(const uint8_t input[], size_t length)
14 {
15 for(auto&& hash : m_hashes)
16 hash->update(input, length);
17 }
18
19 void Parallel::final_result(uint8_t out[])
20 {
21 uint32_t offset = 0;
22
23 for(auto&& hash : m_hashes)
24 {
25 hash->final(out + offset);
26 offset += hash->output_length();
27 }
28 }
29
30 size_t Parallel::output_length() const
31 {
32 size_t sum = 0;
33
34 for(auto&& hash : m_hashes)
35 sum += hash->output_length();
36 return sum;
37 }
38
39 std::string Parallel::name() const
40 {
41 std::vector<std::string> names;
42
43 for(auto&& hash : m_hashes)
44 names.push_back(hash->name());
45
46 return "Parallel(" + string_join(names, ',') + ")";
47 }
48
49 HashFunction* Parallel::clone() const
50 {
51 std::vector<std::unique_ptr<HashFunction>> hash_copies;
52
53 for(auto&& hash : m_hashes)
54 hash_copies.push_back(std::unique_ptr<HashFunction>(hash->clone()));
55
56 return new Parallel(hash_copies);
57 }
58
59 void Parallel::clear()
60 {
61 for(auto&& hash : m_hashes)
62 hash->clear();
63 }
64
65 Parallel::Parallel(std::vector<std::unique_ptr<HashFunction>>& h)
66 {
67 for(size_t i = 0; i != h.size(); ++i)
68 {
69 m_hashes.push_back(std::unique_ptr<HashFunction>(h[i].release()));
70 }
71 }
72
73
74 }
Botan::string_join
std::string string_join(const std::vector< std::string > &strs, char delim)
Definition: parsing.cpp:172
Botan::Parallel::clone
HashFunction * clone() const override
Definition: par_hash.cpp:49
Botan::Parallel::output_length
size_t output_length() const override
Definition: par_hash.cpp:30
Botan::Parallel::clear
void clear() override
Definition: par_hash.cpp:59
Botan
Definition: alg_id.cpp:13
Botan::HashFunction
Definition: hash.h:19
Botan::Parallel::name
std::string name() const override
Definition: par_hash.cpp:39
Botan::Parallel
Definition: par_hash.h:19
hash
MechanismType hash
Definition: p11_mechanism.cpp:63