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

randombit / botan / 21753596263

06 Feb 2026 02:13PM UTC coverage: 90.063% (-0.01%) from 90.073%
21753596263

Pull #5289

github

web-flow
Merge 587099284 into 8ea0ca252
Pull Request #5289: Further misc header reductions, forward declarations, etc

102237 of 113517 relevant lines covered (90.06%)

11402137.11 hits per line

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

0.0
/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/x509_key.h>
14
   #include <botan/internal/fmt.h>
15
#endif
16

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

23
namespace Botan_CLI {
24

25
#if defined(BOTAN_HAS_PUBLIC_KEY_CRYPTO)
26

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

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

44
         for(const auto& [algo, params] : keygen_algos) {
×
45
            auto sk = Botan::create_private_key(algo, rng, params);
×
46

47
            if(!sk) {
×
48
               continue;
×
49
            }
50

51
            const auto pk = sk->public_key();
×
52

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

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

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

68
BOTAN_REGISTER_PERF_TEST("key_parsing", PerfTest_PKKeyParsing);
×
69

70
#endif
71

72
#if defined(BOTAN_HAS_RSA)
73

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

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

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

88
               BOTAN_ASSERT(key->check_key(rng, true), "Key is ok");
×
89
            }
×
90

91
            config.record_result(*keygen_timer);
×
92
         }
×
93
      }
×
94
};
95

96
BOTAN_REGISTER_PERF_TEST("RSA_keygen", PerfTest_RSAKeyGen);
×
97

98
#endif
99

100
#if defined(BOTAN_HAS_ECDSA)
101

102
class PerfTest_ECDSAKeyRec final : public PerfTest {
×
103
   public:
104
      void go(const PerfConfig& config) override {
×
105
         const auto runtime = config.runtime();
×
106
         auto& rng = config.rng();
×
107

108
         for(const std::string& group_name : config.ecc_groups()) {
×
109
            const auto group = Botan::EC_Group::from_name(group_name);
×
110
            auto recovery_timer = config.make_timer("ECDSA recovery " + group_name);
×
111

112
            while(recovery_timer->under(runtime)) {
×
113
               Botan::ECDSA_PrivateKey key(rng, group);
×
114

115
               std::vector<uint8_t> message(group.get_order_bits() / 8);
×
116
               rng.randomize(message.data(), message.size());
×
117

118
               Botan::PK_Signer signer(key, rng, "Raw");
×
119
               signer.update(message);
×
120
               std::vector<uint8_t> signature = signer.signature(rng);
×
121

122
               Botan::PK_Verifier verifier(key, "Raw", Botan::Signature_Format::Standard, "base");
×
123
               verifier.update(message);
×
124
               BOTAN_ASSERT(verifier.check_signature(signature), "Valid signature");
×
125

126
               Botan::BigInt r(signature.data(), signature.size() / 2);
×
127
               Botan::BigInt s(signature.data() + signature.size() / 2, signature.size() / 2);
×
128

129
               const uint8_t v = key.recovery_param(message, r, s);
×
130

131
               recovery_timer->run([&]() {
×
132
                  const Botan::ECDSA_PublicKey recovered_key(group, message, r, s, v);
×
133
                  BOTAN_ASSERT(recovered_key.public_key_bits() == key.public_key_bits(),
×
134
                               "Recovered public key correctly");
135
               });
×
136
            }
×
137

138
            config.record_result(*recovery_timer);
×
139
         }
×
140
      }
×
141
};
142

143
BOTAN_REGISTER_PERF_TEST("ecdsa_recovery", PerfTest_ECDSAKeyRec);
×
144

145
#endif
146

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