Coverage Report

Created: 2026-12-01 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/Botan-3.13.0/build/include/public/botan/buf_comp.h
Line
Count
Source
1
/*
2
* Buffered Computation
3
* (C) 1999-2007 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#ifndef BOTAN_BUFFERED_COMPUTATION_H_
9
#define BOTAN_BUFFERED_COMPUTATION_H_
10
11
#include <botan/concepts.h>
12
#include <botan/secmem.h>
13
#include <span>
14
#include <string_view>
15
16
namespace Botan {
17
18
/**
19
* This class represents any kind of computation which uses an internal
20
* state, such as hash functions or MACs
21
*/
22
class BOTAN_PUBLIC_API(2, 0) Buffered_Computation /* NOLINT(*special-member-functions) */ {
23
   public:
24
      /**
25
      * Return the output length of this function
26
      * @return length of the output of this function in bytes
27
      */
28
      virtual size_t output_length() const = 0;
29
30
      /**
31
      * Add new input to process.
32
      * @param in the input to process as a byte array
33
      * @param length of param in in bytes
34
      */
35
612M
      void update(const uint8_t in[], size_t length) { add_data({in, length}); }
36
37
      /**
38
      * Add new input to process.
39
      * @param in the input to process as a contiguous data range
40
      */
41
17.1M
      void update(std::span<const uint8_t> in) { add_data(in); }
42
43
      /**
44
      * Add new input to process, encoded as a big-endian integer
45
      * @param val the value to process
46
      */
47
      void update_be(uint16_t val);
48
49
      /**
50
      * Add new input to process, encoded as a big-endian integer
51
      * @param val the value to process
52
      */
53
      void update_be(uint32_t val);
54
55
      /**
56
      * Add new input to process, encoded as a big-endian integer
57
      * @param val the value to process
58
      */
59
      void update_be(uint64_t val);
60
61
      /**
62
      * Add new input to process, encoded as a little-endian integer
63
      * @param val the value to process
64
      */
65
      void update_le(uint16_t val);
66
67
      /**
68
      * Add new input to process, encoded as a little-endian integer
69
      * @param val the value to process
70
      */
71
      void update_le(uint32_t val);
72
73
      /**
74
      * Add new input to process, encoded as a little-endian integer
75
      * @param val the value to process
76
      */
77
      void update_le(uint64_t val);
78
79
      /**
80
      * Add new input to process.
81
      * @param str the input to process as a std::string_view. Will be interpreted
82
      * as a byte array based on the strings encoding.
83
      */
84
      void update(std::string_view str);
85
86
      /**
87
      * Process a single byte.
88
      * @param in the byte to process
89
      */
90
12.0M
      void update(uint8_t in) { add_data({&in, 1}); }
91
92
      /**
93
      * Complete the computation and retrieve the final result.
94
      * @param out The byte array to be filled with the result, which
95
      * must be of length output_length()
96
      */
97
1.78M
      void final(uint8_t out[]) { final_result({out, output_length()}); }
98
99
      /**
100
      * Complete the computation and retrieve the final result as a container.
101
      * @return a contiguous container holding the result
102
      */
103
      template <concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
104
1.12M
      T final() {
105
1.12M
         T output(output_length());
106
1.12M
         final_result(output);
107
1.12M
         return output;
108
1.12M
      }
_ZN5Botan20Buffered_Computation5finalITkNS_8concepts21resizable_byte_bufferENSt3__16vectorIhNS3_9allocatorIhEEEEEET_v
Line
Count
Source
104
156k
      T final() {
105
156k
         T output(output_length());
106
156k
         final_result(output);
107
156k
         return output;
108
156k
      }
_ZN5Botan20Buffered_Computation5finalITkNS_8concepts21resizable_byte_bufferENSt3__16vectorIhNS_16secure_allocatorIhEEEEEET_v
Line
Count
Source
104
970k
      T final() {
105
970k
         T output(output_length());
106
970k
         final_result(output);
107
970k
         return output;
108
970k
      }
Unexecuted instantiation: _ZN5Botan20Buffered_Computation5finalITkNS_8concepts21resizable_byte_bufferENS_6StrongINSt3__16vectorIhNS_16secure_allocatorIhEEEENS_13KyberMessage_EJEEEEET_v
Unexecuted instantiation: _ZN5Botan20Buffered_Computation5finalITkNS_8concepts21resizable_byte_bufferENS_6StrongINSt3__16vectorIhNS4_9allocatorIhEEEENS_22KyberHashedCiphertext_EJEEEEET_v
Unexecuted instantiation: _ZN5Botan20Buffered_Computation5finalITkNS_8concepts21resizable_byte_bufferENS_6StrongINSt3__16vectorIhNS4_9allocatorIhEEEENS_21KyberHashedPublicKey_EJEEEEET_v
Unexecuted instantiation: _ZN5Botan20Buffered_Computation5finalITkNS_8concepts21resizable_byte_bufferENS_6StrongINSt3__16vectorIhNS_16secure_allocatorIhEEEENS_18KyberSharedSecret_EJEEEEET_v
109
110
      /**
111
      * Complete the computation and retrieve the final result
112
      * @return a std::vector holding the result
113
      */
114
133k
      std::vector<uint8_t> final_stdvec() { return final<std::vector<uint8_t>>(); }
115
116
      /**
117
      * Complete the computation and retrieve the final result
118
      * @param out the buffer to write the result to, must be output_length() bytes
119
      */
120
      void final(std::span<uint8_t> out);
121
122
      /**
123
      * Complete the computation and retrieve the final result
124
      * @param out a container which is resized to hold the result
125
      */
126
      template <concepts::resizable_byte_buffer T>
127
1.96M
      void final(T& out) {
128
1.96M
         out.resize(output_length());
129
1.96M
         final_result(out);
130
1.96M
      }
_ZN5Botan20Buffered_Computation5finalITkNS_8concepts21resizable_byte_bufferENSt3__16vectorIhNS_16secure_allocatorIhEEEEEEvRT_
Line
Count
Source
127
1.96M
      void final(T& out) {
128
1.96M
         out.resize(output_length());
129
1.96M
         final_result(out);
130
1.96M
      }
Unexecuted instantiation: _ZN5Botan20Buffered_Computation5finalITkNS_8concepts21resizable_byte_bufferENSt3__16vectorIhNS3_9allocatorIhEEEEEEvRT_
131
132
      /**
133
      * Update and finalize computation. Does the same as calling update()
134
      * and final() consecutively.
135
      * @param in the input to process as a byte array
136
      * @param length the length of the byte array
137
      * @result the result of the call to final()
138
      */
139
      template <concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
140
      T process(const uint8_t in[], size_t length) {
141
         update(in, length);
142
         return final<T>();
143
      }
144
145
      /**
146
      * Update and finalize computation. Does the same as calling update()
147
      * and final() consecutively.
148
      * @param in the input to process as a string
149
      * @result the result of the call to final()
150
      */
151
      template <concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
152
      T process(std::string_view in) {
153
         update(in);
154
         return final<T>();
155
      }
156
157
      /**
158
      * Update and finalize computation. Does the same as calling update()
159
      * and final() consecutively.
160
      * @param in the input to process as a contiguous container
161
      * @result the result of the call to final()
162
      */
163
      template <concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
164
0
      T process(std::span<const uint8_t> in) {
165
0
         update(in);
166
0
         return final<T>();
167
0
      }
Unexecuted instantiation: _ZN5Botan20Buffered_Computation7processITkNS_8concepts21resizable_byte_bufferENSt3__16vectorIhNS_16secure_allocatorIhEEEEEET_NS3_4spanIKhLm18446744073709551615EEE
Unexecuted instantiation: _ZN5Botan20Buffered_Computation7processITkNS_8concepts21resizable_byte_bufferENS_6StrongINSt3__16vectorIhNS_16secure_allocatorIhEEEENS_13KyberMessage_EJEEEEET_NS4_4spanIKhLm18446744073709551615EEE
Unexecuted instantiation: _ZN5Botan20Buffered_Computation7processITkNS_8concepts21resizable_byte_bufferENS_6StrongINSt3__16vectorIhNS4_9allocatorIhEEEENS_22KyberHashedCiphertext_EJEEEEET_NS4_4spanIKhLm18446744073709551615EEE
Unexecuted instantiation: _ZN5Botan20Buffered_Computation7processITkNS_8concepts21resizable_byte_bufferENS_6StrongINSt3__16vectorIhNS4_9allocatorIhEEEENS_21KyberHashedPublicKey_EJEEEEET_NS4_4spanIKhLm18446744073709551615EEE
168
169
1.56M
      virtual ~Buffered_Computation() = default;
170
171
   private:
172
      /**
173
      * Add more data to the computation
174
      * @param input is an input buffer
175
      */
176
      virtual void add_data(std::span<const uint8_t> input) = 0;
177
178
      /**
179
      * Write the final output to out
180
      * @param out is an output buffer of output_length()
181
      */
182
      virtual void final_result(std::span<uint8_t> out) = 0;
183
};
184
185
}  // namespace Botan
186
187
#endif