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

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

12139530.51 hits per line

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

88.57
/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") {}
3✔
26

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

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

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

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

45
         // Test that clone works
46
         auto clone = kdf->new_object();
1,373✔
47
         result.confirm("Clone has different pointer", kdf.get() != clone.get());
2,746✔
48
         result.test_eq("Clone has same name", kdf->name(), clone->name());
4,033✔
49

50
         return result;
1,373✔
51
      }
8,148✔
52
};
53

54
BOTAN_REGISTER_SMOKE_TEST("kdf", "kdf_kat", KDF_KAT_Tests);
55

56
#endif
57

58
#if defined(BOTAN_HAS_HKDF)
59
class HKDF_Expand_Label_Tests final : public Text_Based_Test {
×
60
   public:
61
      HKDF_Expand_Label_Tests() : Text_Based_Test("hkdf_label.vec", "Secret,Label,HashValue,Output") {}
3✔
62

63
      Test::Result run_one_test(const std::string& hash_name, const VarMap& vars) override {
4✔
64
         Test::Result result("HKDF-Expand-Label(" + hash_name + ")");
4✔
65

66
         const std::vector<uint8_t> secret = vars.get_req_bin("Secret");
4✔
67
         const std::vector<uint8_t> hashval = vars.get_req_bin("HashValue");
4✔
68
         const std::string label = vars.get_req_str("Label");
4✔
69
         const std::vector<uint8_t> expected = vars.get_req_bin("Output");
4✔
70

71
         auto hash = Botan::HashFunction::create(hash_name);
4✔
72

73
         if(!hash) {
4✔
74
            result.test_note("Skipping test due to missing hash");
×
75
            return result;
×
76
         }
77

78
         Botan::secure_vector<uint8_t> output = Botan::hkdf_expand_label(
4✔
79
            hash_name, secret.data(), secret.size(), label, hashval.data(), hashval.size(), expected.size());
4✔
80

81
         result.test_eq("Output matches", output, expected);
4✔
82

83
         return result;
4✔
84
      }
24✔
85
};
86

87
BOTAN_REGISTER_TEST("kdf", "hkdf_expand_label", HKDF_Expand_Label_Tests);
88

89
#endif
90

91
}
92

93
}
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