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

randombit / botan / 27806188297

18 Jun 2026 04:12PM UTC coverage: 89.37% (-0.03%) from 89.397%
27806188297

push

github

web-flow
Merge pull request #5677 from randombit/jack/oid-names

Add OID::registered_name

111637 of 124915 relevant lines covered (89.37%)

10895907.86 hits per line

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

90.48
/src/tests/test_kdf.cpp
1
/*
2
* (C) 2014,2015 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "tests.h"
8

9
#if defined(BOTAN_HAS_KDF)
10
   #include <botan/kdf.h>
11
#endif
12

13
#if defined(BOTAN_HAS_HKDF)
14
   #include <botan/hash.h>
15
   #include <botan/internal/hkdf.h>
16
#endif
17

18
namespace Botan_Tests {
19

20
namespace {
21

22
#if defined(BOTAN_HAS_KDF)
23
class KDF_KAT_Tests final : public Text_Based_Test {
×
24
   public:
25
      KDF_KAT_Tests() : Text_Based_Test("kdf", "Secret,Output", "Salt,Label,IKM,XTS") {}
2✔
26

27
      Test::Result run_one_test(const std::string& kdf_name, const VarMap& vars) override {
1,623✔
28
         Test::Result result(kdf_name);
1,623✔
29

30
         auto kdf = Botan::KDF::create(kdf_name);
1,623✔
31

32
         if(!kdf) {
1,623✔
33
            result.note_missing(kdf_name);
32✔
34
            return result;
35
         }
36

37
         const std::vector<uint8_t> salt = vars.get_opt_bin("Salt");
1,591✔
38
         const std::vector<uint8_t> secret = vars.get_req_bin("Secret");
1,591✔
39
         const std::vector<uint8_t> label = vars.get_opt_bin("Label");
1,591✔
40
         const std::vector<uint8_t> expected = vars.get_req_bin("Output");
1,591✔
41

42
         result.test_str_eq("name", kdf->name(), kdf_name);
1,591✔
43
         result.test_bin_eq("derived key", kdf->derive_key(expected.size(), secret, salt, label), expected);
1,591✔
44

45
         if(expected.size() == 32) {
1,591✔
46
            const auto key = kdf->derive_key<32>(secret, salt, label);
26✔
47
            result.test_bin_eq("derived key as array", key, expected);
26✔
48
         }
49

50
         // Test using write-to-buffer variant
51
         std::vector<uint8_t> buf(expected.size() + 32, 0xFE);
1,591✔
52
         kdf->derive_key(std::span{buf}.first(expected.size()), secret, salt, label);
1,591✔
53
         result.test_bin_eq("derive key to buffer", std::span{buf}.first(expected.size()), expected);
1,591✔
54
         result.test_bin_eq("derive key to buffer (last)", std::span{buf}.last(32), std::vector<uint8_t>(32, 0xFE));
3,182✔
55

56
         // Test that clone works
57
         auto clone = kdf->new_object();
1,591✔
58
         result.test_is_true("Clone has different pointer", kdf.get() != clone.get());
1,591✔
59
         result.test_str_eq("Clone has same name", kdf->name(), clone->name());
1,591✔
60

61
         return result;
1,591✔
62
      }
15,796✔
63
};
64

65
BOTAN_REGISTER_SMOKE_TEST("kdf", "kdf_kat", KDF_KAT_Tests);
66

67
#endif
68

69
#if defined(BOTAN_HAS_HKDF)
70
class HKDF_Expand_Label_Tests final : public Text_Based_Test {
×
71
   public:
72
      HKDF_Expand_Label_Tests() : Text_Based_Test("hkdf_label.vec", "Secret,Label,HashValue,Output") {}
2✔
73

74
      Test::Result run_one_test(const std::string& hash_name, const VarMap& vars) override {
4✔
75
         Test::Result result("HKDF-Expand-Label(" + hash_name + ")");
12✔
76

77
         const std::vector<uint8_t> secret = vars.get_req_bin("Secret");
4✔
78
         const std::vector<uint8_t> hashval = vars.get_req_bin("HashValue");
4✔
79
         const std::string label = vars.get_req_str("Label");
4✔
80
         const std::vector<uint8_t> expected = vars.get_req_bin("Output");
4✔
81

82
         auto hash = Botan::HashFunction::create(hash_name);
4✔
83

84
         if(!hash) {
4✔
85
            result.test_note("Skipping test due to missing hash");
×
86
            return result;
×
87
         }
88

89
         Botan::secure_vector<uint8_t> output =
4✔
90
            Botan::hkdf_expand_label(hash_name, secret, label, hashval, expected.size());
4✔
91

92
         result.test_bin_eq("Output matches", output, expected);
4✔
93

94
         return result;
4✔
95
      }
20✔
96
};
97

98
BOTAN_REGISTER_TEST("kdf", "hkdf_expand_label", HKDF_Expand_Label_Tests);
99

100
#endif
101

102
}  // namespace
103

104
}  // namespace Botan_Tests
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