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

randombit / botan / 5134090420

31 May 2023 03:12PM UTC coverage: 91.721% (-0.3%) from 91.995%
5134090420

push

github

randombit
Merge GH #3565 Disable noisy/pointless pylint warnings

76048 of 82912 relevant lines covered (91.72%)

11755290.1 hits per line

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

80.0
/src/tests/unit_ecdh.cpp
1
/*
2
* ECDH tests
3
*
4
* (C) 2007 Manuel Hartl (hartl@flexsecure.de)
5
*     2008 Jack Lloyd
6
*
7
* Botan is released under the Simplified BSD License (see license.txt)
8
*/
9

10
#include "tests.h"
11

12
#if defined(BOTAN_HAS_ECDH)
13
   #include <botan/ecdh.h>
14
   #include <botan/pubkey.h>
15
#endif
16

17
namespace Botan_Tests {
18

19
namespace {
20

21
#if defined(BOTAN_HAS_ECDH)
22
class ECDH_Unit_Tests final : public Test {
×
23
   public:
24
      std::vector<Test::Result> run() override {
1✔
25
         std::vector<Test::Result> results;
1✔
26

27
         results.push_back(test_ecdh_normal_derivation());
2✔
28

29
         return results;
1✔
30
      }
×
31

32
   private:
33
      static Test::Result test_ecdh_normal_derivation() {
1✔
34
         Test::Result result("ECDH key exchange");
1✔
35

36
         std::vector<std::string> params = {"secp256r1", "secp384r1", "secp521r1", "brainpool256r1"};
5✔
37

38
         for(const auto& param : params) {
5✔
39
            try {
4✔
40
               Botan::EC_Group dom_pars(param);
4✔
41
               Botan::ECDH_PrivateKey private_a(Test::rng(), dom_pars);
4✔
42
               Botan::ECDH_PrivateKey private_b(Test::rng(), dom_pars);
4✔
43

44
               Botan::PK_Key_Agreement ka(private_a, Test::rng(), "KDF2(SHA-512)");
4✔
45
               Botan::PK_Key_Agreement kb(private_b, Test::rng(), "KDF2(SHA-512)");
4✔
46

47
               Botan::SymmetricKey alice_key = ka.derive_key(32, private_b.public_value());
8✔
48
               Botan::SymmetricKey bob_key = kb.derive_key(32, private_a.public_value());
8✔
49

50
               if(!result.test_eq("same derived key", alice_key.bits_of(), bob_key.bits_of())) {
20✔
51
                  result.test_note("Keys where " + alice_key.to_string() + " and " + bob_key.to_string());
×
52
               }
53
            } catch(Botan::Lookup_Error& e) {
8✔
54
               result.test_note("Skipping because ", e.what());
×
55
            }
×
56
         }
57

58
         return result;
1✔
59
      }
1✔
60
};
61

62
BOTAN_REGISTER_TEST("pubkey", "ecdh_unit", ECDH_Unit_Tests);
63

64
#endif
65

66
}  // namespace
67

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