Botan: src/hash/par_hash/par_hash.cpp Source File

Botan 1.10.17

par_hash.cpp
Go to the documentation of this file.
1 /*
2 * Parallel
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #include <botan/par_hash.h>
9
10 namespace Botan {
11
12 /*
13 * Update the hash
14 */
15 void Parallel::add_data(const byte input[], size_t length)
16 {
17 for(size_t i = 0; i != hashes.size(); ++i)
18 hashes[i]->update(input, length);
19 }
20
21 /*
22 * Finalize the hash
23 */
24 void Parallel::final_result(byte hash[])
25 {
26 size_t offset = 0;
27 for(size_t i = 0; i != hashes.size(); ++i)
28 {
29 hashes[i]->final(hash + offset);
30 offset += hashes[i]->output_length();
31 }
32 }
33
34 /*
35 * Return output size
36 */
37 size_t Parallel::output_length() const
38 {
39 size_t sum = 0;
40 for(size_t i = 0; i != hashes.size(); ++i)
41 sum += hashes[i]->output_length();
42 return sum;
43 }
44
45 /*
46 * Return the name of this type
47 */
48 std::string Parallel::name() const
49 {
50 std::string hash_names;
51 for(size_t i = 0; i != hashes.size(); ++i)
52 {
53 if(i)
54 hash_names += ',';
55 hash_names += hashes[i]->name();
56 }
57 return "Parallel(" + hash_names + ")";
58 }
59
60 /*
61 * Return a clone of this object
62 */
63 HashFunction* Parallel::clone() const
64 {
65 std::vector<HashFunction*> hash_copies;
66 for(size_t i = 0; i != hashes.size(); ++i)
67 hash_copies.push_back(hashes[i]->clone());
68 return new Parallel(hash_copies);
69 }
70
71 /*
72 * Clear memory of sensitive data
73 */
74 void Parallel::clear()
75 {
76 for(size_t i = 0; i != hashes.size(); ++i)
77 hashes[i]->clear();
78 }
79
80 /*
81 * Parallel Constructor
82 */
83 Parallel::Parallel(const std::vector<HashFunction*>& hash_in) :
84 hashes(hash_in)
85 {
86 }
87
88 /*
89 * Parallel Destructor
90 */
91 Parallel::~Parallel()
92 {
93 for(size_t i = 0; i != hashes.size(); ++i)
94 delete hashes[i];
95 }
96
97 }
Botan::Parallel::Parallel
Parallel(const std::vector< HashFunction *> &hashes)
Definition: par_hash.cpp:83
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::Parallel::clear
void clear()
Definition: par_hash.cpp:74
Botan::Buffered_Computation::update
void update(const byte in[], size_t length)
Definition: buf_comp.h:33
Botan::Parallel::name
std::string name() const
Definition: par_hash.cpp:48
Botan
Definition: algo_base.h:14
Botan::Parallel::clone
HashFunction * clone() const
Definition: par_hash.cpp:63
Botan::HashFunction
Definition: hash.h:20
Botan::Parallel::~Parallel
~Parallel()
Definition: par_hash.cpp:91
Botan::Parallel::output_length
size_t output_length() const
Definition: par_hash.cpp:37