• 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

89.47
/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_BASE)
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_BASE)
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,446✔
28
         Test::Result result(kdf_name);
1,446✔
29

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

32
         if(!kdf) {
1,446✔
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,414✔
38
         const std::vector<uint8_t> secret = vars.get_req_bin("Secret");
1,414✔
39
         const std::vector<uint8_t> label = vars.get_opt_bin("Label");
1,414✔
40
         const std::vector<uint8_t> expected = vars.get_req_bin("Output");
1,414✔
41

42
         result.test_eq("name", kdf->name(), kdf_name);
2,828✔
43
         result.test_eq("derived key", kdf->derive_key(expected.size(), secret, salt, label), expected);
2,828✔
44

45
         if(expected.size() == 32) {
1,414✔
46
            const auto key = kdf->derive_key<32>(secret, salt, label);
26✔
47
            result.test_eq("derived key as array", Botan::secure_vector<uint8_t>{key.begin(), key.end()}, expected);
78✔
48
         }
49

50
         // Test that clone works
51
         auto clone = kdf->new_object();
1,414✔
52
         result.confirm("Clone has different pointer", kdf.get() != clone.get());
2,828✔
53
         result.test_eq("Clone has same name", kdf->name(), clone->name());
2,828✔
54

55
         return result;
1,414✔
56
      }
8,370✔
57
};
58

59
BOTAN_REGISTER_SMOKE_TEST("kdf", "kdf_kat", KDF_KAT_Tests);
60

61
#endif
62

63
#if defined(BOTAN_HAS_HKDF)
64
class HKDF_Expand_Label_Tests final : public Text_Based_Test {
×
65
   public:
66
      HKDF_Expand_Label_Tests() : Text_Based_Test("hkdf_label.vec", "Secret,Label,HashValue,Output") {}
2✔
67

68
      Test::Result run_one_test(const std::string& hash_name, const VarMap& vars) override {
4✔
69
         Test::Result result("HKDF-Expand-Label(" + hash_name + ")");
8✔
70

71
         const std::vector<uint8_t> secret = vars.get_req_bin("Secret");
4✔
72
         const std::vector<uint8_t> hashval = vars.get_req_bin("HashValue");
4✔
73
         const std::string label = vars.get_req_str("Label");
4✔
74
         const std::vector<uint8_t> expected = vars.get_req_bin("Output");
4✔
75

76
         auto hash = Botan::HashFunction::create(hash_name);
4✔
77

78
         if(!hash) {
4✔
79
            result.test_note("Skipping test due to missing hash");
×
80
            return result;
×
81
         }
82

83
         Botan::secure_vector<uint8_t> output =
4✔
84
            Botan::hkdf_expand_label(hash_name, secret, label, hashval, expected.size());
4✔
85

86
         result.test_eq("Output matches", output, expected);
8✔
87

88
         return result;
4✔
89
      }
20✔
90
};
91

92
BOTAN_REGISTER_TEST("kdf", "hkdf_expand_label", HKDF_Expand_Label_Tests);
93

94
#endif
95

96
}  // namespace
97

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

© 2025 Coveralls, Inc