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

randombit / botan / 5111374265

29 May 2023 11:19AM UTC coverage: 92.227% (+0.5%) from 91.723%
5111374265

push

github

randombit
Next release will be 3.1.0. Update release notes

75588 of 81959 relevant lines covered (92.23%)

11886470.91 hits per line

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

91.3
/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 { return fmt("KDF2({})", m_hash->name()); }
240✔
16

17
std::unique_ptr<KDF> KDF2::new_object() const { return std::make_unique<KDF2>(m_hash->new_object()); }
119✔
18

19
void KDF2::kdf(uint8_t key[],
6,328✔
20
               size_t key_len,
21
               const uint8_t secret[],
22
               size_t secret_len,
23
               const uint8_t salt[],
24
               size_t salt_len,
25
               const uint8_t label[],
26
               size_t label_len) const {
27
   if(key_len == 0)
6,328✔
28
      return;
×
29

30
   const size_t blocks_required = key_len / m_hash->output_length();
6,328✔
31

32
   if(blocks_required >= 0xFFFFFFFE)
6,328✔
33
      throw Invalid_Argument("KDF2 maximum output length exceeeded");
×
34

35
   uint32_t counter = 1;
6,328✔
36
   secure_vector<uint8_t> h;
6,328✔
37

38
   size_t offset = 0;
6,328✔
39
   while(offset != key_len) {
6,328✔
40
      m_hash->update(secret, secret_len);
12,689✔
41
      m_hash->update_be(counter);
12,689✔
42
      m_hash->update(label, label_len);
12,689✔
43
      m_hash->update(salt, salt_len);
12,689✔
44
      m_hash->final(h);
12,689✔
45

46
      const size_t added = std::min(h.size(), key_len - offset);
12,689✔
47
      copy_mem(&key[offset], h.data(), added);
12,689✔
48
      offset += added;
12,689✔
49

50
      counter += 1;
12,689✔
51
      BOTAN_ASSERT_NOMSG(counter != 0);  // no overflow
19,017✔
52
   }
53
}
6,328✔
54

55
}  // 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