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

randombit / botan / 5230455705

10 Jun 2023 02:30PM UTC coverage: 91.715% (-0.03%) from 91.746%
5230455705

push

github

randombit
Merge GH #3584 Change clang-format AllowShortFunctionsOnASingleLine config from All to Inline

77182 of 84154 relevant lines covered (91.72%)

11975295.43 hits per line

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

92.0
/src/lib/kdf/kdf2/kdf2.cpp
1
/*
2
* KDF2
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/kdf2.h>
9

10
#include <botan/exceptn.h>
11
#include <botan/internal/fmt.h>
12

13
namespace Botan {
14

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

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

23
void KDF2::kdf(uint8_t key[],
6,322✔
24
               size_t key_len,
25
               const uint8_t secret[],
26
               size_t secret_len,
27
               const uint8_t salt[],
28
               size_t salt_len,
29
               const uint8_t label[],
30
               size_t label_len) const {
31
   if(key_len == 0) {
6,322✔
32
      return;
×
33
   }
34

35
   const size_t blocks_required = key_len / m_hash->output_length();
6,322✔
36

37
   if(blocks_required >= 0xFFFFFFFE) {
6,322✔
38
      throw Invalid_Argument("KDF2 maximum output length exceeeded");
×
39
   }
40

41
   uint32_t counter = 1;
6,322✔
42
   secure_vector<uint8_t> h;
6,322✔
43

44
   size_t offset = 0;
6,322✔
45
   while(offset != key_len) {
6,322✔
46
      m_hash->update(secret, secret_len);
12,683✔
47
      m_hash->update_be(counter);
12,683✔
48
      m_hash->update(label, label_len);
12,683✔
49
      m_hash->update(salt, salt_len);
12,683✔
50
      m_hash->final(h);
12,683✔
51

52
      const size_t added = std::min(h.size(), key_len - offset);
12,683✔
53
      copy_mem(&key[offset], h.data(), added);
12,683✔
54
      offset += added;
12,683✔
55

56
      counter += 1;
12,683✔
57
      BOTAN_ASSERT_NOMSG(counter != 0);  // no overflow
19,005✔
58
   }
59
}
6,322✔
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