Coverage Report

Created: 2025-04-11 06:34

/src/botan/build/include/public/botan/buf_comp.h
Line
Count
Source (jump to first uncovered line)
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 {
23
   public:
24
      /**
25
      * @return length of the output of this function in bytes
26
      */
27
      virtual size_t output_length() const = 0;
28
29
      /**
30
      * Add new input to process.
31
      * @param in the input to process as a byte array
32
      * @param length of param in in bytes
33
      */
34
65.5k
      void update(const uint8_t in[], size_t length) { add_data({in, length}); }
35
36
      /**
37
      * Add new input to process.
38
      * @param in the input to process as a contiguous data range
39
      */
40
513k
      void update(std::span<const uint8_t> in) { add_data(in); }
41
42
      void update_be(uint16_t val);
43
      void update_be(uint32_t val);
44
      void update_be(uint64_t val);
45
46
      void update_le(uint16_t val);
47
      void update_le(uint32_t val);
48
      void update_le(uint64_t val);
49
50
      /**
51
      * Add new input to process.
52
      * @param str the input to process as a std::string_view. Will be interpreted
53
      * as a byte array based on the strings encoding.
54
      */
55
      void update(std::string_view str);
56
57
      /**
58
      * Process a single byte.
59
      * @param in the byte to process
60
      */
61
0
      void update(uint8_t in) { add_data({&in, 1}); }
62
63
      /**
64
      * Complete the computation and retrieve the
65
      * final result.
66
      * @param out The byte array to be filled with the result.
67
      * Must be of length output_length()
68
      */
69
6.01k
      void final(uint8_t out[]) { final_result({out, output_length()}); }
70
71
      /**
72
      * Complete the computation and retrieve the
73
      * final result as a container of your choice.
74
      * @return a contiguous container holding the result
75
      */
76
      template <concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
77
151k
      T final() {
78
151k
         T output(output_length());
79
151k
         final_result(output);
80
151k
         return output;
81
151k
      }
_ZN5Botan20Buffered_Computation5finalITkNS_8concepts21resizable_byte_bufferENSt3__16vectorIhNS_16secure_allocatorIhEEEEEET_v
Line
Count
Source
77
60.3k
      T final() {
78
60.3k
         T output(output_length());
79
60.3k
         final_result(output);
80
60.3k
         return output;
81
60.3k
      }
_ZN5Botan20Buffered_Computation5finalITkNS_8concepts21resizable_byte_bufferENSt3__16vectorIhNS3_9allocatorIhEEEEEET_v
Line
Count
Source
77
91.5k
      T final() {
78
91.5k
         T output(output_length());
79
91.5k
         final_result(output);
80
91.5k
         return output;
81
91.5k
      }
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
Unexecuted instantiation: _ZN5Botan20Buffered_Computation5finalITkNS_8concepts21resizable_byte_bufferENS_6StrongINSt3__16vectorIhNS4_9allocatorIhEEEENS_8LMOTS_K_EJEEEEET_v
82
83
91.5k
      std::vector<uint8_t> final_stdvec() { return final<std::vector<uint8_t>>(); }
84
85
      void final(std::span<uint8_t> out);
86
87
      template <concepts::resizable_byte_buffer T>
88
69.2k
      void final(T& out) {
89
69.2k
         out.resize(output_length());
90
69.2k
         final_result(out);
91
69.2k
      }
_ZN5Botan20Buffered_Computation5finalITkNS_8concepts21resizable_byte_bufferENSt3__16vectorIhNS_16secure_allocatorIhEEEEEEvRT_
Line
Count
Source
88
24.0k
      void final(T& out) {
89
24.0k
         out.resize(output_length());
90
24.0k
         final_result(out);
91
24.0k
      }
_ZN5Botan20Buffered_Computation5finalITkNS_8concepts21resizable_byte_bufferENSt3__16vectorIhNS3_9allocatorIhEEEEEEvRT_
Line
Count
Source
88
45.2k
      void final(T& out) {
89
45.2k
         out.resize(output_length());
90
45.2k
         final_result(out);
91
45.2k
      }
92
93
      /**
94
      * Update and finalize computation. Does the same as calling update()
95
      * and final() consecutively.
96
      * @param in the input to process as a byte array
97
      * @param length the length of the byte array
98
      * @result the result of the call to final()
99
      */
100
      template <concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
101
34.6k
      T process(const uint8_t in[], size_t length) {
102
34.6k
         update(in, length);
103
34.6k
         return final<T>();
104
34.6k
      }
105
106
      /**
107
      * Update and finalize computation. Does the same as calling update()
108
      * and final() consecutively.
109
      * @param in the input to process as a string
110
      * @result the result of the call to final()
111
      */
112
      template <concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
113
0
      T process(std::string_view in) {
114
0
         update(in);
115
0
         return final<T>();
116
0
      }
117
118
      /**
119
      * Update and finalize computation. Does the same as calling update()
120
      * and final() consecutively.
121
      * @param in the input to process as a contiguous container
122
      * @result the result of the call to final()
123
      */
124
      template <concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
125
24.0k
      T process(std::span<const uint8_t> in) {
126
24.0k
         update(in);
127
24.0k
         return final<T>();
128
24.0k
      }
_ZN5Botan20Buffered_Computation7processITkNS_8concepts21resizable_byte_bufferENSt3__16vectorIhNS_16secure_allocatorIhEEEEEET_NS3_4spanIKhLm18446744073709551615EEE
Line
Count
Source
125
24.0k
      T process(std::span<const uint8_t> in) {
126
24.0k
         update(in);
127
24.0k
         return final<T>();
128
24.0k
      }
Unexecuted instantiation: _ZN5Botan20Buffered_Computation7processITkNS_8concepts21resizable_byte_bufferENSt3__16vectorIhNS3_9allocatorIhEEEEEET_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
129
130
185k
      virtual ~Buffered_Computation() = default;
131
132
   private:
133
      /**
134
      * Add more data to the computation
135
      * @param input is an input buffer
136
      */
137
      virtual void add_data(std::span<const uint8_t> input) = 0;
138
139
      /**
140
      * Write the final output to out
141
      * @param out is an output buffer of output_length()
142
      */
143
      virtual void final_result(std::span<uint8_t> out) = 0;
144
};
145
146
}  // namespace Botan
147
148
#endif