Coverage Report

Created: 2025-06-10 06:14

/src/botan/src/lib/pk_pad/mgf1/mgf1.cpp
Line
Count
Source
1
/*
2
* MGF1
3
* (C) 1999-2007 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#include <botan/internal/mgf1.h>
9
10
#include <botan/hash.h>
11
#include <botan/mem_ops.h>
12
#include <algorithm>
13
14
namespace Botan {
15
16
56
void mgf1_mask(HashFunction& hash, const uint8_t in[], size_t in_len, uint8_t out[], size_t out_len) {
17
56
   uint32_t counter = 0;
18
19
56
   std::vector<uint8_t> buffer(hash.output_length());
20
720
   while(out_len) {
21
664
      hash.update(in, in_len);
22
664
      hash.update_be(counter);
23
664
      hash.final(buffer.data());
24
25
664
      const size_t xored = std::min<size_t>(buffer.size(), out_len);
26
664
      xor_buf(out, buffer.data(), xored);
27
664
      out += xored;
28
664
      out_len -= xored;
29
30
664
      ++counter;
31
664
   }
32
56
}
33
34
}  // namespace Botan