Coverage Report

Created: 2021-11-25 09:31

/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
#include <botan/internal/parsing.h>
10
11
namespace Botan {
12
13
void Parallel::add_data(const uint8_t input[], size_t length)
14
0
   {
15
0
   for(auto&& hash : m_hashes)
16
0
       hash->update(input, length);
17
0
   }
18
19
void Parallel::final_result(uint8_t out[])
20
0
   {
21
0
   size_t offset = 0;
22
23
0
   for(auto&& hash : m_hashes)
24
0
      {
25
0
      hash->final(out + offset);
26
0
      offset += hash->output_length();
27
0
      }
28
0
   }
29
30
size_t Parallel::output_length() const
31
0
   {
32
0
   size_t sum = 0;
33
34
0
   for(auto&& hash : m_hashes)
35
0
      sum += hash->output_length();
36
0
   return sum;
37
0
   }
38
39
std::string Parallel::name() const
40
0
   {
41
0
   std::vector<std::string> names;
42
43
0
   for(auto&& hash : m_hashes)
44
0
      names.push_back(hash->name());
45
46
0
   return "Parallel(" + string_join(names, ',') + ")";
47
0
   }
48
49
std::unique_ptr<HashFunction> Parallel::new_object() const
50
0
   {
51
0
   std::vector<std::unique_ptr<HashFunction>> hash_copies;
52
53
0
   for(auto&& hash : m_hashes)
54
0
      hash_copies.push_back(std::unique_ptr<HashFunction>(hash->new_object()));
55
56
0
   return std::make_unique<Parallel>(hash_copies);
57
0
   }
58
59
std::unique_ptr<HashFunction> Parallel::copy_state() const
60
0
   {
61
0
   std::vector<std::unique_ptr<HashFunction>> hash_new_objects;
62
63
0
   for(const auto& hash : m_hashes)
64
0
      {
65
0
      hash_new_objects.push_back(hash->copy_state());
66
0
      }
67
68
0
   return std::make_unique<Parallel>(hash_new_objects);
69
0
   }
70
71
void Parallel::clear()
72
0
   {
73
0
   for(auto&& hash : m_hashes)
74
0
      hash->clear();
75
0
   }
76
77
Parallel::Parallel(std::vector<std::unique_ptr<HashFunction>>& hashes)
78
0
   {
79
0
   for(auto&& hash: hashes)
80
0
      {
81
0
      m_hashes.push_back(std::move(hash));
82
0
      }
83
0
   }
84
85
86
}