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

randombit / botan / 12805544433

16 Jan 2025 09:08AM UTC coverage: 90.876% (-0.4%) from 91.245%
12805544433

Pull #4540

github

web-flow
Merge cc1ceff51 into 9b798efbb
Pull Request #4540: PKCS #11 Version 3.2 Support

93425 of 102805 relevant lines covered (90.88%)

11409241.89 hits per line

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

95.45
/src/lib/kdf/kdf1_iso18033/kdf1_iso18033.cpp
1
/*
2
* KDF1 from ISO 18033-2
3
* (C) 2016 Philipp Weber
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/kdf1_iso18033.h>
10

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

16
namespace Botan {
17

18
void KDF1_18033::perform_kdf(std::span<uint8_t> key,
892✔
19
                             std::span<const uint8_t> secret,
20
                             std::span<const uint8_t> salt,
21
                             std::span<const uint8_t> label) const {
22
   if(key.empty()) {
892✔
23
      return;
×
24
   }
25

26
   const auto hash_output_length = m_hash->output_length();
892✔
27
   const auto blocks_required = ceil_division<uint64_t /* for 32bit systems */>(key.size(), hash_output_length);
892✔
28

29
   // This KDF uses a 32-bit counter for the hash blocks, initialized at 0.
30
   // It will wrap around after 2^32 iterations which limits the theoretically
31
   // possible output to 2^32 blocks.
32
   BOTAN_ARG_CHECK(blocks_required <= 0xFFFFFFFF, "KDF1-18033 maximum output length exceeeded");
892✔
33

34
   BufferStuffer k(key);
892✔
35
   for(uint32_t counter = 0; !k.full(); ++counter) {
2,705✔
36
      m_hash->update(secret);
1,813✔
37
      m_hash->update_be(counter);
1,813✔
38
      m_hash->update(label);
1,813✔
39
      m_hash->update(salt);
1,813✔
40

41
      // Write straight into the output buffer, except if the hash output needs
42
      // a truncation in the final iteration.
43
      if(k.remaining_capacity() >= hash_output_length) {
1,813✔
44
         m_hash->final(k.next(hash_output_length));
1,234✔
45
      } else {
46
         const auto h = m_hash->final();
579✔
47
         k.append(std::span{h}.first(k.remaining_capacity()));
579✔
48
      }
579✔
49
   }
50
}
579✔
51

52
std::string KDF1_18033::name() const {
12✔
53
   return fmt("KDF1-18033({})", m_hash->name());
12✔
54
}
55

56
std::unique_ptr<KDF> KDF1_18033::new_object() const {
45✔
57
   return std::make_unique<KDF1_18033>(m_hash->new_object());
90✔
58
}
59

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

© 2025 Coveralls, Inc