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

randombit / botan / 23225340130

18 Mar 2026 01:53AM UTC coverage: 89.677% (-0.001%) from 89.678%
23225340130

push

github

web-flow
Merge pull request #5456 from randombit/jack/clang-tidy-22

Fix various warnings from clang-tidy 22

104438 of 116460 relevant lines covered (89.68%)

11819947.55 hits per line

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

42.65
/src/cli/perf_pk_misc.cpp
1
/*
2
* (C) 2024 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "perf.h"
8

9
#if defined(BOTAN_HAS_PUBLIC_KEY_CRYPTO)
10
   #include <botan/assert.h>
11
   #include <botan/pk_algs.h>
12
   #include <botan/pkcs8.h>
13
   #include <botan/rng.h>
14
   #include <botan/x509_key.h>
15
   #include <botan/internal/fmt.h>
16
#endif
17

18
#if defined(BOTAN_HAS_ECDSA)
19
   #include <botan/ec_group.h>
20
   #include <botan/ecdsa.h>
21
   #include <botan/pubkey.h>
22
#endif
23

24
namespace Botan_CLI {
25

26
namespace {
27

28
#if defined(BOTAN_HAS_PUBLIC_KEY_CRYPTO)
29

30
class PerfTest_PKKeyParsing final : public PerfTest {
×
31
   public:
32
      void go(const PerfConfig& config) override {
×
33
         const auto runtime = config.runtime();
×
34
         auto& rng = config.rng();
×
35

36
         const std::pair<std::string, std::string> keygen_algos[] = {
×
37
            {"RSA", "2048"},
38
            {"ECDSA", "secp256r1"},
39
            {"ECDSA", "brainpool512r1"},
40
            {"DH", "modp/ietf/2048"},
41
            {"X25519", ""},
42
            {"Ed25519", ""},
43
            {"ML-DSA", "ML-DSA-6x5"},
44
            {"ML-KEM", "ML-KEM-768"},
45
         };
×
46

47
         for(const auto& [algo, params] : keygen_algos) {
×
48
            auto sk = Botan::create_private_key(algo, rng, params);
×
49

50
            if(!sk) {
×
51
               continue;
×
52
            }
53

54
            const auto pk = sk->public_key();
×
55

56
            const std::string nm = params.empty() ? algo : Botan::fmt("{} {}", algo, params);
×
57

58
            auto pk_parse = config.make_timer(nm, 1, "public key parse");
×
59
            const auto pk_bytes = pk->subject_public_key();
×
60
            pk_parse->run_until_elapsed(runtime, [&]() { Botan::X509::load_key(pk_bytes); });
×
61
            config.record_result(*pk_parse);
×
62

63
            auto sk_parse = config.make_timer(nm, 1, "private key parse");
×
64
            const auto sk_bytes = sk->private_key_info();
×
65
            sk_parse->run_until_elapsed(runtime, [&]() { Botan::PKCS8::load_key(sk_bytes); });
×
66
            config.record_result(*sk_parse);
×
67
         }
×
68
      }
×
69
};
70

71
BOTAN_REGISTER_PERF_TEST("key_parsing", PerfTest_PKKeyParsing);
×
72

73
#endif
74

75
#if defined(BOTAN_HAS_RSA)
76

77
class PerfTest_RSAKeyGen final : public PerfTest {
×
78
   public:
79
      void go(const PerfConfig& config) override {
×
80
         const auto runtime = config.runtime();
×
81
         auto& rng = config.rng();
×
82

83
         for(size_t keylen : {1024, 2048, 3072, 4096}) {
×
84
            const std::string nm = Botan::fmt("RSA-{}", keylen);
×
85
            auto keygen_timer = config.make_timer(nm, 1, "keygen");
×
86

87
            while(keygen_timer->under(runtime)) {
×
88
               auto key =
×
89
                  keygen_timer->run([&] { return Botan::create_private_key("RSA", rng, std::to_string(keylen)); });
×
90

91
               BOTAN_ASSERT(key->check_key(rng, true), "Key is ok");
×
92
            }
×
93

94
            config.record_result(*keygen_timer);
×
95
         }
×
96
      }
×
97
};
98

99
BOTAN_REGISTER_PERF_TEST("RSA_keygen", PerfTest_RSAKeyGen);
×
100

101
#endif
102

103
#if defined(BOTAN_HAS_ECDSA)
104

105
class PerfTest_ECDSAKeyRec final : public PerfTest {
1✔
106
   public:
107
      void go(const PerfConfig& config) override {
1✔
108
         const auto runtime = config.runtime();
1✔
109
         auto& rng = config.rng();
1✔
110

111
         for(const std::string& group_name : config.ecc_groups()) {
7✔
112
            const auto group = Botan::EC_Group::from_name(group_name);
6✔
113
            auto recovery_timer = config.make_timer("ECDSA recovery " + group_name);
12✔
114

115
            while(recovery_timer->under(runtime)) {
15✔
116
               Botan::ECDSA_PrivateKey key(rng, group);
9✔
117

118
               std::vector<uint8_t> message(group.get_order_bits() / 8);
9✔
119
               rng.randomize(message.data(), message.size());
9✔
120

121
               Botan::PK_Signer signer(key, rng, "Raw");
9✔
122
               signer.update(message);
9✔
123
               std::vector<uint8_t> signature = signer.signature(rng);
9✔
124

125
               Botan::PK_Verifier verifier(key, "Raw", Botan::Signature_Format::Standard, "base");
9✔
126
               verifier.update(message);
9✔
127
               BOTAN_ASSERT(verifier.check_signature(signature), "Valid signature");
9✔
128

129
               Botan::BigInt r(signature.data(), signature.size() / 2);
9✔
130
               Botan::BigInt s(signature.data() + signature.size() / 2, signature.size() / 2);
9✔
131

132
               const uint8_t v = key.recovery_param(message, r, s);
9✔
133

134
               recovery_timer->run([&]() {
9✔
135
                  const Botan::ECDSA_PublicKey recovered_key(group, message, r, s, v);
9✔
136
                  BOTAN_ASSERT(recovered_key.public_key_bits() == key.public_key_bits(),
27✔
137
                               "Recovered public key correctly");
138
               });
9✔
139
            }
27✔
140

141
            config.record_result(*recovery_timer);
12✔
142
         }
6✔
143
      }
1✔
144
};
145

146
BOTAN_REGISTER_PERF_TEST("ecdsa_recovery", PerfTest_ECDSAKeyRec);
1✔
147

148
#endif
149

150
}  // namespace
151

152
}  // namespace Botan_CLI
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