Coverage Report

Created: 2024-11-29 06:10

/src/botan/src/lib/hash/par_hash/par_hash.cpp
Line
Count
Source (jump to first uncovered line)
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/internal/par_hash.h>
9
10
#include <botan/internal/stl_util.h>
11
12
#include <sstream>
13
14
namespace Botan {
15
16
0
void Parallel::add_data(std::span<const uint8_t> input) {
17
0
   for(auto&& hash : m_hashes) {
18
0
      hash->update(input);
19
0
   }
20
0
}
21
22
0
void Parallel::final_result(std::span<uint8_t> output) {
23
0
   BufferStuffer out(output);
24
0
   for(auto&& hash : m_hashes) {
25
0
      hash->final(out.next(hash->output_length()));
26
0
   }
27
0
}
28
29
0
size_t Parallel::output_length() const {
30
0
   size_t sum = 0;
31
32
0
   for(auto&& hash : m_hashes) {
33
0
      sum += hash->output_length();
34
0
   }
35
0
   return sum;
36
0
}
37
38
0
std::string Parallel::name() const {
39
0
   std::ostringstream name;
40
41
0
   name << "Parallel(";
42
43
0
   for(size_t i = 0; i != m_hashes.size(); ++i) {
44
0
      if(i != 0) {
45
0
         name << ",";
46
0
      }
47
0
      name << m_hashes[i]->name();
48
0
   }
49
50
0
   name << ")";
51
52
0
   return name.str();
53
0
}
54
55
0
std::unique_ptr<HashFunction> Parallel::new_object() const {
56
0
   std::vector<std::unique_ptr<HashFunction>> hash_copies;
57
0
   hash_copies.reserve(m_hashes.size());
58
59
0
   for(auto&& hash : m_hashes) {
60
0
      hash_copies.push_back(std::unique_ptr<HashFunction>(hash->new_object()));
61
0
   }
62
63
0
   return std::make_unique<Parallel>(hash_copies);
64
0
}
65
66
0
std::unique_ptr<HashFunction> Parallel::copy_state() const {
67
0
   std::vector<std::unique_ptr<HashFunction>> hash_new_objects;
68
0
   hash_new_objects.reserve(m_hashes.size());
69
70
0
   for(const auto& hash : m_hashes) {
71
0
      hash_new_objects.push_back(hash->copy_state());
72
0
   }
73
74
0
   return std::make_unique<Parallel>(hash_new_objects);
75
0
}
76
77
0
void Parallel::clear() {
78
0
   for(auto&& hash : m_hashes) {
79
0
      hash->clear();
80
0
   }
81
0
}
82
83
0
Parallel::Parallel(std::vector<std::unique_ptr<HashFunction>>& hashes) {
84
0
   m_hashes.reserve(hashes.size());
85
0
   for(auto&& hash : hashes) {
86
0
      m_hashes.push_back(std::move(hash));
87
0
   }
88
0
}
89
90
}  // namespace Botan