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

randombit / botan / 5123321399

30 May 2023 04:06PM UTC coverage: 92.213% (+0.004%) from 92.209%
5123321399

Pull #3558

github

web-flow
Merge dd72f7389 into 057bcbc35
Pull Request #3558: Add braces around all if/else statements

75602 of 81986 relevant lines covered (92.21%)

11859779.3 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,316✔
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,316✔
28
      return;
×
29
   }
30

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

33
   if(blocks_required >= 0xFFFFFFFE) {
6,316✔
34
      throw Invalid_Argument("KDF2 maximum output length exceeeded");
×
35
   }
36

37
   uint32_t counter = 1;
6,316✔
38
   secure_vector<uint8_t> h;
6,316✔
39

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

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

52
      counter += 1;
12,669✔
53
      BOTAN_ASSERT_NOMSG(counter != 0);  // no overflow
18,985✔
54
   }
55
}
6,316✔
56

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