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

randombit / botan / 21794448852

08 Feb 2026 12:09AM UTC coverage: 90.065% (-0.008%) from 90.073%
21794448852

push

github

web-flow
Merge pull request #5295 from randombit/jack/header-patrol-3

Reduce header dependencies in tests and cli

102230 of 113507 relevant lines covered (90.06%)

11492365.41 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/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
#if defined(BOTAN_HAS_PUBLIC_KEY_CRYPTO)
27

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

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

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

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

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

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

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

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

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

71
#endif
72

73
#if defined(BOTAN_HAS_RSA)
74

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

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

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

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

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

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

99
#endif
100

101
#if defined(BOTAN_HAS_ECDSA)
102

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

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

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

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

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

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

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

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

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

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

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

146
#endif
147

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