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

randombit / botan / 21031897445

15 Jan 2026 12:50PM UTC coverage: 90.037% (-0.4%) from 90.395%
21031897445

Pull #5240

github

web-flow
Merge 13ffffdd5 into 32478179d
Pull Request #5240: Some changes to reduce time taken by the coverage build

102027 of 113317 relevant lines covered (90.04%)

11676540.94 hits per line

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

65.69
/src/cli/perf_pk_sig.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/pk_algs.h>
11
   #include <botan/pubkey.h>
12
#endif
13

14
namespace Botan_CLI {
15

16
#if defined(BOTAN_HAS_PUBLIC_KEY_CRYPTO)
17

18
class PerfTest_PKSig : public PerfTest {
9✔
19
   public:
20
      virtual std::string algo() const = 0;
21

22
      virtual std::string hash() const { return "SHA-256"; }
4✔
23

24
      virtual std::vector<std::string> keygen_params(const PerfConfig& /*config*/) const { return {""}; }
2✔
25

26
      void go(const PerfConfig& config) override {
9✔
27
         const std::string alg = this->algo();
9✔
28
         const std::string padding = this->hash();
9✔
29

30
         const auto params = this->keygen_params(config);
9✔
31

32
         for(const auto& param : params) {
37✔
33
            const std::string nm = this->format_name(alg, param);
28✔
34
            bench_pk_sig(config, nm, alg, param, padding);
56✔
35
         }
28✔
36
      }
9✔
37

38
      static void bench_pk_sig(const PerfConfig& config,
28✔
39
                               const std::string& nm,
40
                               const std::string& alg,
41
                               const std::string& param,
42
                               const std::string& padding,
43
                               const std::string& provider = "") {
44
         auto& rng = config.rng();
28✔
45
         const auto msec = config.runtime();
28✔
46

47
         auto keygen_timer = config.make_timer(nm, 1, "keygen");
56✔
48

49
         auto sk = keygen_timer->run([&] { return Botan::create_private_key(alg, rng, param); });
56✔
50

51
         if(sk != nullptr) {
28✔
52
            while(keygen_timer->under(msec)) {
74✔
53
               sk = keygen_timer->run([&] { return Botan::create_private_key(alg, rng, param); });
138✔
54
            }
55

56
            config.record_result(*keygen_timer);
28✔
57

58
            auto pk = sk->public_key();
28✔
59

60
            std::vector<uint8_t> message;
28✔
61
            std::vector<uint8_t> signature;
28✔
62
            std::vector<uint8_t> bad_signature;
28✔
63

64
            Botan::PK_Signer sig(*sk, rng, padding, Botan::Signature_Format::Standard, provider);
28✔
65
            Botan::PK_Verifier ver(*pk, padding, Botan::Signature_Format::Standard, provider);
28✔
66

67
            auto sig_timer = config.make_timer(nm, 1, "sign");
56✔
68
            auto ver_timer = config.make_timer(nm, 1, "verify");
56✔
69

70
            size_t invalid_sigs = 0;
28✔
71

72
            while(ver_timer->under(msec) || sig_timer->under(msec)) {
118✔
73
               if(signature.empty() || sig_timer->under(msec)) {
106✔
74
                  /*
75
                  Length here is kind of arbitrary, but 48 bytes fits into a single
76
                  hash block so minimizes hashing overhead versus the PK op itself.
77
                  */
78
                  rng.random_vec(message, 48);
101✔
79

80
                  signature = sig_timer->run([&]() { return sig.sign_message(message, rng); });
202✔
81

82
                  bad_signature = signature;
101✔
83
                  bad_signature[rng.next_byte() % bad_signature.size()] ^= rng.next_nonzero_byte();
101✔
84
               }
85

86
               if(ver_timer->under(msec)) {
240✔
87
                  const bool verified = ver_timer->run([&] { return ver.verify_message(message, signature); });
88✔
88

89
                  if(!verified) {
44✔
90
                     invalid_sigs += 1;
×
91
                  }
92

93
                  const bool verified_bad = ver_timer->run([&] { return ver.verify_message(message, bad_signature); });
88✔
94

95
                  if(verified_bad) {
44✔
96
                     config.error_output() << "Bad signature accepted in " << nm << " signature bench\n";
×
97
                  }
98
               }
99
            }
100

101
            if(invalid_sigs > 0) {
28✔
102
               config.error_output() << invalid_sigs << " generated signatures rejected in " << nm
×
103
                                     << " signature bench\n";
×
104
            }
105
            config.record_result(*sig_timer);
28✔
106
            config.record_result(*ver_timer);
56✔
107
         }
56✔
108
      }
28✔
109
};
110

111
#endif
112

113
#if defined(BOTAN_HAS_DSA)
114

115
class PerfTest_DSA final : public PerfTest_PKSig {
1✔
116
   public:
117
      std::string algo() const override { return "DSA"; }
1✔
118

119
      std::vector<std::string> keygen_params(const PerfConfig& /*config*/) const override {
1✔
120
         return {"dsa/jce/1024", "dsa/botan/2048", "dsa/botan/3072"};
1✔
121
      }
122

123
      std::string format_name(const std::string& alg, const std::string& param) const override {
3✔
124
         return Botan::fmt("{}-{}", alg, param.substr(param.find_last_of('/') + 1));
6✔
125
      }
126
};
127

128
BOTAN_REGISTER_PERF_TEST("DSA", PerfTest_DSA);
1✔
129

130
#endif
131

132
#if defined(BOTAN_HAS_RSA)
133

134
class PerfTest_RSA final : public PerfTest_PKSig {
×
135
   public:
136
      std::string algo() const override { return "RSA"; }
×
137

138
      std::string hash() const override { return "PKCS1v15(SHA-256)"; }
×
139

140
      std::vector<std::string> keygen_params(const PerfConfig& /*config*/) const override {
×
141
         return {"1024", "2048", "3072", "4096"};
×
142
      }
143
};
144

145
BOTAN_REGISTER_PERF_TEST("RSA", PerfTest_RSA);
×
146

147
#endif
148

149
#if defined(BOTAN_HAS_ECDSA)
150

151
class PerfTest_ECDSA final : public PerfTest_PKSig {
1✔
152
   public:
153
      std::string algo() const override { return "ECDSA"; }
1✔
154

155
      std::vector<std::string> keygen_params(const PerfConfig& config) const override { return config.ecc_groups(); }
1✔
156
};
157

158
BOTAN_REGISTER_PERF_TEST("ECDSA", PerfTest_ECDSA);
1✔
159

160
#endif
161

162
#if defined(BOTAN_HAS_ECKCDSA)
163

164
class PerfTest_ECKCDSA final : public PerfTest_PKSig {
1✔
165
   public:
166
      std::string algo() const override { return "ECKCDSA"; }
1✔
167

168
      std::vector<std::string> keygen_params(const PerfConfig& config) const override { return config.ecc_groups(); }
1✔
169
};
170

171
BOTAN_REGISTER_PERF_TEST("ECKCDSA", PerfTest_ECKCDSA);
1✔
172

173
#endif
174

175
#if defined(BOTAN_HAS_ECGDSA)
176

177
class PerfTest_ECGDSA final : public PerfTest_PKSig {
1✔
178
   public:
179
      std::string algo() const override { return "ECGDSA"; }
1✔
180

181
      std::vector<std::string> keygen_params(const PerfConfig& config) const override { return config.ecc_groups(); }
1✔
182
};
183

184
BOTAN_REGISTER_PERF_TEST("ECGDSA", PerfTest_ECGDSA);
1✔
185

186
#endif
187

188
#if defined(BOTAN_HAS_GOST_34_10_2001) && defined(BOTAN_HAS_GOST_34_11)
189

190
class PerfTest_Gost3410 final : public PerfTest_PKSig {
1✔
191
   public:
192
      std::string algo() const override { return "GOST-34.10"; }
1✔
193

194
      std::string hash() const override { return "GOST-34.11"; }
1✔
195

196
      std::vector<std::string> keygen_params(const PerfConfig& /*config*/) const override { return {"gost_256A"}; }
1✔
197
};
198

199
BOTAN_REGISTER_PERF_TEST("GOST-34.10", PerfTest_Gost3410);
1✔
200

201
#endif
202

203
#if defined(BOTAN_HAS_SM2) && defined(BOTAN_HAS_SM3)
204

205
class PerfTest_SM2 final : public PerfTest_PKSig {
1✔
206
   public:
207
      std::string algo() const override { return "SM2"; }
1✔
208

209
      std::string hash() const override { return "SM3"; }
1✔
210

211
      std::vector<std::string> keygen_params(const PerfConfig& /*config*/) const override { return {"sm2p256v1"}; }
1✔
212
};
213

214
BOTAN_REGISTER_PERF_TEST("SM2", PerfTest_SM2);
1✔
215

216
#endif
217

218
#if defined(BOTAN_HAS_ED25519)
219

220
class PerfTest_Ed25519 final : public PerfTest_PKSig {
1✔
221
   public:
222
      std::string algo() const override { return "Ed25519"; }
1✔
223

224
      std::string hash() const override { return "Pure"; }
1✔
225
};
226

227
BOTAN_REGISTER_PERF_TEST("Ed25519", PerfTest_Ed25519);
1✔
228

229
#endif
230

231
#if defined(BOTAN_HAS_ED448)
232

233
class PerfTest_Ed448 final : public PerfTest_PKSig {
1✔
234
   public:
235
      std::string algo() const override { return "Ed448"; }
1✔
236

237
      std::string hash() const override { return "Pure"; }
1✔
238
};
239

240
BOTAN_REGISTER_PERF_TEST("Ed448", PerfTest_Ed448);
1✔
241

242
#endif
243

244
#if defined(BOTAN_HAS_XMSS_RFC8391)
245

246
class PerfTest_XMSS final : public PerfTest_PKSig {
×
247
   public:
248
      std::string algo() const override { return "XMSS"; }
×
249

250
      std::string hash() const override { return ""; }
×
251

252
      std::vector<std::string> keygen_params(const PerfConfig& /*config*/) const override {
×
253
         /*
254
         We only test H10 signatures here since already they are quite slow (a
255
         few seconds per signature). On a fast machine, H16 signatures take 1-2
256
         minutes to generate and H20 signatures take 5-10 minutes to generate
257
         */
258
         return {
×
259
            "XMSS-SHA2_10_256",
260
            "XMSS-SHAKE_10_256",
261
            "XMSS-SHA2_10_512",
262
            "XMSS-SHAKE_10_512",
263
         };
×
264
      }
265
};
266

267
BOTAN_REGISTER_PERF_TEST("XMSS", PerfTest_XMSS);
×
268

269
#endif
270

271
#if defined(BOTAN_HAS_HSS_LMS)
272

273
class PerfTest_HSS_LMS final : public PerfTest_PKSig {
×
274
   public:
275
      std::string algo() const override { return "HSS-LMS"; }
×
276

277
      std::string hash() const override { return ""; }
×
278

279
      std::vector<std::string> keygen_params(const PerfConfig& /*config*/) const override {
×
280
         // At first we compare instances with multiple hash functions. LMS trees with
281
         // height 10 are suitable, since they can be used for enough signatures and are
282
         // fast enough for speed testing.
283
         // Afterward, setups with multiple HSS layers are tested
284
         return {"SHA-256,HW(10,1)",
×
285
                 "SHAKE-256(256),HW(10,1)",
286
                 "SHAKE-256(192),HW(10,1)",
287
                 "Truncated(SHA-256,192),HW(10,1)",
288
                 "SHA-256,HW(10,1),HW(10,1)",
289
                 "SHA-256,HW(10,1),HW(10,1),HW(10,1)"};
×
290
      }
291
};
292

293
BOTAN_REGISTER_PERF_TEST("HSS-LMS", PerfTest_HSS_LMS);
×
294

295
#endif
296

297
#if defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHA2) || defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHAKE)
298

299
class PerfTest_SPHINCSp final : public PerfTest_PKSig {
×
300
   public:
301
      std::string algo() const override { return "SPHINCS+"; }
×
302

303
      std::string hash() const override { return ""; }
×
304

305
      std::string format_name(const std::string& alg, const std::string& param) const override {
×
306
         return alg + param.substr(11);
×
307
      }
308

309
      std::vector<std::string> keygen_params(const PerfConfig& /*config*/) const override {
×
310
         return {"SphincsPlus-sha2-128s-r3.1",
×
311
                 "SphincsPlus-sha2-128f-r3.1",
312
                 "SphincsPlus-sha2-192s-r3.1",
313
                 "SphincsPlus-sha2-192f-r3.1",
314
                 "SphincsPlus-sha2-256s-r3.1",
315
                 "SphincsPlus-sha2-256f-r3.1",
316
                 "SphincsPlus-shake-128s-r3.1",
317
                 "SphincsPlus-shake-128f-r3.1",
318
                 "SphincsPlus-shake-192s-r3.1",
319
                 "SphincsPlus-shake-192f-r3.1",
320
                 "SphincsPlus-shake-256s-r3.1",
321
                 "SphincsPlus-shake-256f-r3.1"};
×
322
      }
323
};
324

325
BOTAN_REGISTER_PERF_TEST("SPHINCS+", PerfTest_SPHINCSp);
×
326

327
#endif
328

329
#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
330

331
class PerfTest_SLH_DSA final : public PerfTest_PKSig {
×
332
   public:
333
      std::string algo() const override { return "SLH-DSA"; }
×
334

335
      std::string hash() const override { return ""; }
×
336

337
      std::vector<std::string> keygen_params(const PerfConfig& /*config*/) const override {
×
338
         return {"SLH-DSA-SHA2-128s",
×
339
                 "SLH-DSA-SHA2-128f",
340
                 "SLH-DSA-SHA2-192s",
341
                 "SLH-DSA-SHA2-192f",
342
                 "SLH-DSA-SHA2-256s",
343
                 "SLH-DSA-SHA2-256f",
344
                 "SLH-DSA-SHAKE-128s",
345
                 "SLH-DSA-SHAKE-128f",
346
                 "SLH-DSA-SHAKE-192s",
347
                 "SLH-DSA-SHAKE-192f",
348
                 "SLH-DSA-SHAKE-256s",
349
                 "SLH-DSA-SHAKE-256f"};
×
350
      }
351
};
352

353
BOTAN_REGISTER_PERF_TEST("SLH-DSA", PerfTest_SLH_DSA);
×
354

355
#endif
356

357
#if defined(BOTAN_HAS_DILITHIUM) || defined(BOTAN_HAS_DILITHIUM_AES)
358

359
class PerfTest_Dilithium final : public PerfTest_PKSig {
×
360
   public:
361
      std::string algo() const override { return "Dilithium"; }
×
362

363
      std::string hash() const override { return ""; }
×
364

365
      std::vector<std::string> keygen_params(const PerfConfig& /*config*/) const override {
×
366
         return {
×
367
            "Dilithium-4x4-r3",
368
            "Dilithium-4x4-AES-r3",
369
            "Dilithium-6x5-r3",
370
            "Dilithium-6x5-AES-r3",
371
            "Dilithium-8x7-r3",
372
            "Dilithium-8x7-AES-r3",
373
         };
×
374
      }
375
};
376

377
BOTAN_REGISTER_PERF_TEST("Dilithium", PerfTest_Dilithium);
×
378

379
#endif
380

381
#if defined(BOTAN_HAS_ML_DSA)
382

383
class PerfTest_ML_DSA final : public PerfTest_PKSig {
1✔
384
   public:
385
      std::string algo() const override { return "ML-DSA"; }
1✔
386

387
      std::string hash() const override { return ""; }
1✔
388

389
      std::vector<std::string> keygen_params(const PerfConfig& /*config*/) const override {
1✔
390
         return {
1✔
391
            "ML-DSA-4x4",
392
            "ML-DSA-6x5",
393
            "ML-DSA-8x7",
394
         };
1✔
395
      }
396
};
397

398
BOTAN_REGISTER_PERF_TEST("ML-DSA", PerfTest_ML_DSA);
1✔
399

400
#endif
401

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