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

randombit / botan / 13073795340

31 Jan 2025 01:32PM UTC coverage: 91.224% (-0.009%) from 91.233%
13073795340

push

github

web-flow
Merge pull request #4617 from randombit/jack/fix-build-configs

Fix build/test errors caught by test_all_configs.py

94150 of 103208 relevant lines covered (91.22%)

11427437.8 hits per line

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

89.8
/src/tests/test_ecdh.cpp
1
/*
2
* (C) 2015,2016 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_ECDH)
10
   #include "test_pubkey.h"
11
   #include <botan/ecdh.h>
12
#endif
13

14
namespace Botan_Tests {
15

16
namespace {
17

18
#if defined(BOTAN_HAS_ECDH)
19

20
class ECDH_KAT_Tests final : public PK_Key_Agreement_Test {
21
   public:
22
      ECDH_KAT_Tests() : PK_Key_Agreement_Test("ECDH", "pubkey/ecdh.vec", "Secret,CounterKey,K", "KDF") {}
2✔
23

24
      std::string default_kdf(const VarMap& /*unused*/) const override { return "Raw"; }
156✔
25

26
      bool skip_this_test(const std::string& group_id, const VarMap&) override {
156✔
27
         return !Botan::EC_Group::supports_named_group(group_id);
156✔
28
      }
29

30
      std::unique_ptr<Botan::Private_Key> load_our_key(const std::string& group_id, const VarMap& vars) override {
156✔
31
         const auto group = Botan::EC_Group::from_name(group_id);
156✔
32
         const Botan::BigInt secret = vars.get_req_bn("Secret");
156✔
33
         return std::make_unique<Botan::ECDH_PrivateKey>(this->rng(), group, secret);
468✔
34
      }
156✔
35

36
      std::vector<uint8_t> load_their_key(const std::string& /*header*/, const VarMap& vars) override {
156✔
37
         return vars.get_req_bin("CounterKey");
312✔
38
      }
39
};
40

41
class ECDH_Keygen_Tests final : public PK_Key_Generation_Test {
×
42
   public:
43
      std::vector<std::string> keygen_params() const override {
1✔
44
         return {
1✔
45
            "secp256r1", "secp384r1", "secp521r1", "brainpool256r1", "brainpool384r1", "brainpool512r1", "frp256v1"};
1✔
46
      }
47

48
      std::string algo_name() const override { return "ECDH"; }
7✔
49

50
      std::unique_ptr<Botan::Public_Key> public_key_from_raw(std::string_view keygen_params,
7✔
51
                                                             std::string_view /* provider */,
52
                                                             std::span<const uint8_t> raw_pk) const override {
53
         const auto group = Botan::EC_Group(keygen_params);
7✔
54
         const auto public_key = Botan::EC_AffinePoint(group, raw_pk);
7✔
55
         return std::make_unique<Botan::ECDH_PublicKey>(group, public_key);
21✔
56
      }
7✔
57
};
58

59
class ECDH_AllGroups_Tests : public Test {
×
60
   public:
61
      std::vector<Test::Result> run() override {
1✔
62
         std::vector<Test::Result> results;
1✔
63

64
         for(const std::string& group_name : Botan::EC_Group::known_named_groups()) {
29✔
65
            Test::Result result("ECDH " + group_name);
28✔
66

67
            result.start_timer();
28✔
68

69
            const std::string kdf = "Raw";
28✔
70

71
            try {
28✔
72
               const auto group = Botan::EC_Group::from_name(group_name);
28✔
73

74
               for(size_t i = 0; i != 100; ++i) {
2,828✔
75
                  const Botan::ECDH_PrivateKey a_priv(rng(), group);
2,800✔
76
                  const auto a_pub = a_priv.public_value();
2,800✔
77

78
                  const Botan::ECDH_PrivateKey b_priv(rng(), group);
2,800✔
79
                  const auto b_pub = b_priv.public_value();
2,800✔
80

81
                  Botan::PK_Key_Agreement a_ka(a_priv, rng(), kdf);
2,800✔
82
                  const auto a_ss = a_ka.derive_key(0, b_pub);
2,800✔
83

84
                  Botan::PK_Key_Agreement b_ka(b_priv, rng(), kdf);
2,800✔
85
                  const auto b_ss = b_ka.derive_key(0, a_pub);
2,800✔
86

87
                  result.test_eq("Same shared secret", a_ss.bits_of(), b_ss.bits_of());
11,200✔
88
               }
11,200✔
89
            } catch(std::exception& e) {
28✔
90
               result.test_failure("Exception", e.what());
×
91
            }
×
92

93
            result.end_timer();
28✔
94

95
            results.push_back(result);
28✔
96
         }
28✔
97

98
         return results;
1✔
99
      }
×
100
};
101

102
BOTAN_REGISTER_TEST("pubkey", "ecdh_kat", ECDH_KAT_Tests);
103
BOTAN_REGISTER_TEST("pubkey", "ecdh_keygen", ECDH_Keygen_Tests);
104
BOTAN_REGISTER_TEST("pubkey", "ecdh_all_groups", ECDH_AllGroups_Tests);
105

106
#endif
107

108
}  // namespace
109

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