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
10namespace Botan {
11
12/*
13* Update the hash
14*/
15void 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*/
24void 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*/
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*/
48std::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*/
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*/
75 {
76 for(size_t i = 0; i != hashes.size(); ++i)
77 hashes[i]->clear();
78 }
79
80/*
81* Parallel Constructor
82*/
83Parallel::Parallel(const std::vector<HashFunction*>& hash_in) :
84 hashes(hash_in)
85 {
86 }
87
88/*
89* Parallel Destructor
90*/
92 {
93 for(size_t i = 0; i != hashes.size(); ++i)
94 delete hashes[i];
95 }
96
97}
void update(const byte in[], size_t length)
Definition buf_comp.h:33
HashFunction * clone() const
Definition par_hash.cpp:63
std::string name() const
Definition par_hash.cpp:48
size_t output_length() const
Definition par_hash.cpp:37
Parallel(const std::vector< HashFunction * > &hashes)
Definition par_hash.cpp:83