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