• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 19012754211

02 Nov 2025 01:10PM UTC coverage: 90.677% (+0.006%) from 90.671%
19012754211

push

github

web-flow
Merge pull request #5137 from randombit/jack/clang-tidy-includes

Remove various unused includes flagged by clang-tidy misc-include-cleaner

100457 of 110786 relevant lines covered (90.68%)

12189873.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.65
/src/lib/kdf/kdf2/kdf2.cpp
1
/*
2
* KDF2
3
* (C) 1999-2007 Jack Lloyd
4
* (C) 2024      René Meusel, Rohde & Schwarz Cybersecurity
5
*
6
* Botan is released under the Simplified BSD License (see license.txt)
7
*/
8

9
#include <botan/internal/kdf2.h>
10

11
#include <botan/internal/bit_ops.h>
12
#include <botan/internal/fmt.h>
13
#include <botan/internal/stl_util.h>
14

15
namespace Botan {
16

17
std::string KDF2::name() const {
240✔
18
   return fmt("KDF2({})", m_hash->name());
240✔
19
}
20

21
std::unique_ptr<KDF> KDF2::new_object() const {
119✔
22
   return std::make_unique<KDF2>(m_hash->new_object());
238✔
23
}
24

25
void KDF2::perform_kdf(std::span<uint8_t> key,
6,351✔
26
                       std::span<const uint8_t> secret,
27
                       std::span<const uint8_t> salt,
28
                       std::span<const uint8_t> label) const {
29
   if(key.empty()) {
6,351✔
30
      return;
×
31
   }
32

33
   const size_t hash_output_length = m_hash->output_length();
6,351✔
34
   const auto blocks_required = ceil_division<uint64_t /* for 32bit systems */>(key.size(), hash_output_length);
6,351✔
35

36
   // This KDF uses a 32-bit counter for the hash blocks, initialized at 1.
37
   // It will wrap around after 2^32 - 1 iterations limiting the theoretically
38
   // possible output to 2^32 - 1 blocks.
39
   BOTAN_ARG_CHECK(blocks_required <= 0xFFFFFFFE, "KDF2 maximum output length exceeded");
6,351✔
40

41
   BufferStuffer k(key);
6,351✔
42
   for(uint32_t counter = 1; !k.full(); ++counter) {
19,085✔
43
      BOTAN_ASSERT_NOMSG(counter != 0);  // no overflow
12,734✔
44

45
      m_hash->update(secret);
12,734✔
46
      m_hash->update_be(counter);
12,734✔
47
      m_hash->update(label);
12,734✔
48
      m_hash->update(salt);
12,734✔
49

50
      // Write straight into the output buffer, except if the hash output needs
51
      // a truncation in the final iteration.
52
      if(k.remaining_capacity() >= hash_output_length) {
12,734✔
53
         m_hash->final(k.next(hash_output_length));
11,916✔
54
      } else {
55
         const auto h = m_hash->final();
818✔
56
         k.append(std::span{h}.first(k.remaining_capacity()));
818✔
57
      }
818✔
58
   }
59
}
818✔
60

61
}  // namespace Botan
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc