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

randombit / botan / 5111374265

29 May 2023 11:19AM UTC coverage: 92.227% (+0.5%) from 91.723%
5111374265

push

github

randombit
Next release will be 3.1.0. Update release notes

75588 of 81959 relevant lines covered (92.23%)

11886470.91 hits per line

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

95.22
/src/cli/speed.cpp
1
/*
2
* (C) 2009,2010,2014,2015,2017,2018 Jack Lloyd
3
* (C) 2015 Simon Warta (Kullo GmbH)
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include "../tests/test_rng.h"  // FIXME
9
#include "cli.h"
10

11
#include <algorithm>
12
#include <chrono>
13
#include <functional>
14
#include <iomanip>
15
#include <map>
16
#include <set>
17
#include <sstream>
18

19
// Always available:
20
#include <botan/entropy_src.h>
21
#include <botan/version.h>
22
#include <botan/internal/cpuid.h>
23
#include <botan/internal/os_utils.h>
24
#include <botan/internal/timer.h>
25

26
#if defined(BOTAN_HAS_BIGINT)
27
   #include <botan/bigint.h>
28
   #include <botan/internal/divide.h>
29
#endif
30

31
#if defined(BOTAN_HAS_BLOCK_CIPHER)
32
   #include <botan/block_cipher.h>
33
#endif
34

35
#if defined(BOTAN_HAS_STREAM_CIPHER)
36
   #include <botan/stream_cipher.h>
37
#endif
38

39
#if defined(BOTAN_HAS_HASH)
40
   #include <botan/hash.h>
41
#endif
42

43
#if defined(BOTAN_HAS_CIPHER_MODES)
44
   #include <botan/cipher_mode.h>
45
#endif
46

47
#if defined(BOTAN_HAS_MAC)
48
   #include <botan/mac.h>
49
#endif
50

51
#if defined(BOTAN_HAS_AUTO_SEEDING_RNG)
52
   #include <botan/auto_rng.h>
53
#endif
54

55
#if defined(BOTAN_HAS_SYSTEM_RNG)
56
   #include <botan/system_rng.h>
57
#endif
58

59
#if defined(BOTAN_HAS_HMAC_DRBG)
60
   #include <botan/hmac_drbg.h>
61
#endif
62

63
#if defined(BOTAN_HAS_PROCESSOR_RNG)
64
   #include <botan/processor_rng.h>
65
#endif
66

67
#if defined(BOTAN_HAS_CHACHA_RNG)
68
   #include <botan/chacha_rng.h>
69
#endif
70

71
#if defined(BOTAN_HAS_FPE_FE1)
72
   #include <botan/fpe_fe1.h>
73
#endif
74

75
#if defined(BOTAN_HAS_RFC3394_KEYWRAP)
76
   #include <botan/rfc3394.h>
77
#endif
78

79
#if defined(BOTAN_HAS_COMPRESSION)
80
   #include <botan/compression.h>
81
#endif
82

83
#if defined(BOTAN_HAS_POLY_DBL)
84
   #include <botan/internal/poly_dbl.h>
85
#endif
86

87
#if defined(BOTAN_HAS_PUBLIC_KEY_CRYPTO)
88
   #include <botan/pk_algs.h>
89
   #include <botan/pkcs8.h>
90
   #include <botan/pubkey.h>
91
   #include <botan/x509_key.h>
92
   #include <botan/internal/workfactor.h>
93
#endif
94

95
#if defined(BOTAN_HAS_NUMBERTHEORY)
96
   #include <botan/numthry.h>
97
   #include <botan/reducer.h>
98
   #include <botan/internal/curve_nistp.h>
99
   #include <botan/internal/primality.h>
100
#endif
101

102
#if defined(BOTAN_HAS_ECC_GROUP)
103
   #include <botan/ec_group.h>
104
#endif
105

106
#if defined(BOTAN_HAS_DL_GROUP)
107
   #include <botan/dl_group.h>
108
#endif
109

110
#if defined(BOTAN_HAS_MCELIECE)
111
   #include <botan/mceliece.h>
112
#endif
113

114
#if defined(BOTAN_HAS_KYBER) || defined(BOTAN_HAS_KYBER_90S)
115
   #include <botan/kyber.h>
116
#endif
117

118
#if defined(BOTAN_HAS_DILITHIUM) || defined(BOTAN_HAS_DILITHIUM_AES)
119
   #include <botan/dilithium.h>
120
#endif
121

122
#if defined(BOTAN_HAS_ECDSA)
123
   #include <botan/ecdsa.h>
124
#endif
125

126
#if defined(BOTAN_HAS_BCRYPT)
127
   #include <botan/bcrypt.h>
128
#endif
129

130
#if defined(BOTAN_HAS_PASSHASH9)
131
   #include <botan/passhash9.h>
132
#endif
133

134
#if defined(BOTAN_HAS_PASSWORD_HASHING)
135
   #include <botan/pwdhash.h>
136
#endif
137

138
#if defined(BOTAN_HAS_ZFEC)
139
   #include <botan/zfec.h>
140
#endif
141

142
namespace Botan_CLI {
143

144
using Botan::Timer;
145

146
namespace {
147

148
class JSON_Output final {
2✔
149
   public:
150
      void add(const Timer& timer) { m_results.push_back(timer); }
2✔
151

152
      std::string print() const {
1✔
153
         std::ostringstream out;
1✔
154

155
         out << "[\n";
1✔
156

157
         for(size_t i = 0; i != m_results.size(); ++i) {
3✔
158
            const Timer& t = m_results[i];
2✔
159

160
            out << "{"
2✔
161
                << "\"algo\": \"" << t.get_name() << "\", "
2✔
162
                << "\"op\": \"" << t.doing() << "\", "
4✔
163
                << "\"events\": " << t.events() << ", ";
6✔
164

165
            if(t.cycles_consumed() > 0)
4✔
166
               out << "\"cycles\": " << t.cycles_consumed() << ", ";
4✔
167

168
            if(t.buf_size() > 0) {
2✔
169
               out << "\"bps\": " << static_cast<uint64_t>(t.events() / (t.value() / 1000000000.0)) << ", ";
2✔
170
               out << "\"buf_size\": " << t.buf_size() << ", ";
2✔
171
            }
172

173
            out << "\"nanos\": " << t.value() << "}";
2✔
174

175
            if(i != m_results.size() - 1)
2✔
176
               out << ",";
1✔
177

178
            out << "\n";
2✔
179
         }
180
         out << "]\n";
1✔
181

182
         return out.str();
2✔
183
      }
1✔
184

185
   private:
186
      std::vector<Timer> m_results;
187
};
188

189
class Summary final {
1✔
190
   public:
191
      Summary() = default;
1✔
192

193
      void add(const Timer& t) {
2✔
194
         if(t.buf_size() == 0) {
2✔
195
            m_ops_entries.push_back(t);
×
196
         } else {
197
            m_bps_entries[std::make_pair(t.doing(), t.get_name())].push_back(t);
4✔
198
         }
199
      }
2✔
200

201
      std::string print() {
1✔
202
         const size_t name_padding = 35;
1✔
203
         const size_t op_name_padding = 16;
1✔
204
         const size_t op_padding = 16;
1✔
205

206
         std::ostringstream result_ss;
1✔
207
         result_ss << std::fixed;
1✔
208

209
         if(!m_bps_entries.empty()) {
1✔
210
            result_ss << "\n";
1✔
211

212
            // add table header
213
            result_ss << std::setw(name_padding) << std::left << "algo" << std::setw(op_name_padding) << std::left
1✔
214
                      << "operation";
1✔
215

216
            for(const Timer& t : m_bps_entries.begin()->second) {
2✔
217
               result_ss << std::setw(op_padding) << std::right << (std::to_string(t.buf_size()) + " bytes");
2✔
218
            }
219
            result_ss << "\n";
1✔
220

221
            // add table entries
222
            for(const auto& entry : m_bps_entries) {
3✔
223
               if(entry.second.empty())
2✔
224
                  continue;
×
225

226
               result_ss << std::setw(name_padding) << std::left << (entry.first.second) << std::setw(op_name_padding)
2✔
227
                         << std::left << (entry.first.first);
2✔
228

229
               for(const Timer& t : entry.second) {
4✔
230
                  if(t.events() == 0) {
2✔
231
                     result_ss << std::setw(op_padding) << std::right << "N/A";
×
232
                  } else {
233
                     result_ss << std::setw(op_padding) << std::right << std::setprecision(2)
2✔
234
                               << (t.bytes_per_second() / 1000.0);
2✔
235
                  }
236
               }
237

238
               result_ss << "\n";
2✔
239
            }
240

241
            result_ss << "\n[results are the number of 1000s bytes processed per second]\n";
1✔
242
         }
243

244
         if(!m_ops_entries.empty()) {
1✔
245
            result_ss << std::setprecision(6) << "\n";
×
246

247
            // sort entries
248
            std::sort(m_ops_entries.begin(), m_ops_entries.end());
×
249

250
            // add table header
251
            result_ss << std::setw(name_padding) << std::left << "algo" << std::setw(op_name_padding) << std::left
×
252
                      << "operation" << std::setw(op_padding) << std::right << "sec/op" << std::setw(op_padding)
×
253
                      << std::right << "op/sec"
×
254
                      << "\n";
×
255

256
            // add table entries
257
            for(const Timer& entry : m_ops_entries) {
×
258
               result_ss << std::setw(name_padding) << std::left << entry.get_name() << std::setw(op_name_padding)
×
259
                         << std::left << entry.doing() << std::setw(op_padding) << std::right
×
260
                         << entry.seconds_per_event() << std::setw(op_padding) << std::right
×
261
                         << entry.events_per_second() << "\n";
×
262
            }
263
         }
264

265
         return result_ss.str();
2✔
266
      }
1✔
267

268
   private:
269
      std::map<std::pair<std::string, std::string>, std::vector<Timer>> m_bps_entries;
270
      std::vector<Timer> m_ops_entries;
271
};
272

273
std::vector<size_t> unique_buffer_sizes(const std::string& cmdline_arg) {
34✔
274
   const size_t MAX_BUF_SIZE = 64 * 1024 * 1024;
34✔
275

276
   std::set<size_t> buf;
34✔
277
   for(const std::string& size_str : Command::split_on(cmdline_arg, ',')) {
66✔
278
      size_t x = 0;
35✔
279
      try {
35✔
280
         size_t converted = 0;
35✔
281
         x = static_cast<size_t>(std::stoul(size_str, &converted, 0));
35✔
282

283
         if(converted != size_str.size())
34✔
284
            throw CLI_Usage_Error("Invalid integer");
×
285
      } catch(std::exception&) {
1✔
286
         throw CLI_Usage_Error("Invalid integer value '" + size_str + "' for option buf-size");
3✔
287
      }
1✔
288

289
      if(x == 0)
34✔
290
         throw CLI_Usage_Error("Cannot have a zero-sized buffer");
3✔
291

292
      if(x > MAX_BUF_SIZE)
33✔
293
         throw CLI_Usage_Error("Specified buffer size is too large");
3✔
294

295
      buf.insert(x);
32✔
296
   }
34✔
297

298
   return std::vector<size_t>(buf.begin(), buf.end());
34✔
299
}
31✔
300

301
}  // namespace
302

303
class Speed final : public Command {
×
304
   public:
305
      Speed() :
35✔
306
            Command(
307
               "speed --msec=500 --format=default --ecc-groups= --provider= --buf-size=1024 --clear-cpuid= --cpu-clock-speed=0 --cpu-clock-ratio=1.0 *algos") {
70✔
308
      }
35✔
309

310
      static std::vector<std::string> default_benchmark_list() {
×
311
         /*
312
         This is not intended to be exhaustive: it just hits the high
313
         points of the most interesting or widely used algorithms.
314
         */
315

316
         return {
×
317
            /* Block ciphers */
318
            "AES-128",
319
            "AES-192",
320
            "AES-256",
321
            "ARIA-128",
322
            "ARIA-192",
323
            "ARIA-256",
324
            "Blowfish",
325
            "CAST-128",
326
            "Camellia-128",
327
            "Camellia-192",
328
            "Camellia-256",
329
            "DES",
330
            "TripleDES",
331
            "GOST-28147-89",
332
            "IDEA",
333
            "Noekeon",
334
            "SHACAL2",
335
            "SM4",
336
            "Serpent",
337
            "Threefish-512",
338
            "Twofish",
339

340
            /* Cipher modes */
341
            "AES-128/CBC",
342
            "AES-128/CTR-BE",
343
            "AES-128/EAX",
344
            "AES-128/OCB",
345
            "AES-128/GCM",
346
            "AES-128/XTS",
347
            "AES-128/SIV",
348

349
            "Serpent/CBC",
350
            "Serpent/CTR-BE",
351
            "Serpent/EAX",
352
            "Serpent/OCB",
353
            "Serpent/GCM",
354
            "Serpent/XTS",
355
            "Serpent/SIV",
356

357
            "ChaCha20Poly1305",
358

359
            /* Stream ciphers */
360
            "RC4",
361
            "Salsa20",
362
            "ChaCha20",
363

364
            /* Hashes */
365
            "SHA-1",
366
            "SHA-256",
367
            "SHA-512",
368
            "SHA-3(256)",
369
            "SHA-3(512)",
370
            "RIPEMD-160",
371
            "Skein-512",
372
            "Blake2b",
373
            "Whirlpool",
374

375
            /* MACs */
376
            "CMAC(AES-128)",
377
            "HMAC(SHA-256)",
378

379
            /* pubkey */
380
            "RSA",
381
            "DH",
382
            "ECDH",
383
            "ECDSA",
384
            "Ed25519",
385
            "Curve25519",
386
            "McEliece",
387
            "Kyber",
388
         };
×
389
      }
390

391
      std::string group() const override { return "misc"; }
1✔
392

393
      std::string description() const override { return "Measures the speed of algorithms"; }
1✔
394

395
      void go() override {
34✔
396
         std::chrono::milliseconds msec(get_arg_sz("msec"));
34✔
397
         const std::string provider = get_arg("provider");
34✔
398
         std::vector<std::string> ecc_groups = Command::split_on(get_arg("ecc-groups"), ',');
71✔
399
         const std::string format = get_arg("format");
34✔
400
         const std::string clock_ratio = get_arg("cpu-clock-ratio");
37✔
401
         m_clock_speed = get_arg_sz("cpu-clock-speed");
34✔
402

403
         m_clock_cycle_ratio = std::strtod(clock_ratio.c_str(), nullptr);
34✔
404

405
         /*
406
         * This argument is intended to be the ratio between the cycle counter
407
         * and the actual machine cycles. It is extremely unlikely that there is
408
         * any machine where the cycle counter increments faster than the actual
409
         * clock.
410
         */
411
         if(m_clock_cycle_ratio < 0.0 || m_clock_cycle_ratio > 1.0)
34✔
412
            throw CLI_Usage_Error("Unlikely CPU clock ratio of " + clock_ratio);
×
413

414
         m_clock_cycle_ratio = 1.0 / m_clock_cycle_ratio;
34✔
415

416
         if(m_clock_speed != 0 && Botan::OS::get_cpu_cycle_counter() != 0) {
34✔
417
            error_output() << "The --cpu-clock-speed option is only intended to be used on "
×
418
                              "platforms without access to a cycle counter.\n"
419
                              "Expected incorrect results\n\n";
×
420
         }
421

422
         if(format == "table")
34✔
423
            m_summary = std::make_unique<Summary>();
1✔
424
         else if(format == "json")
33✔
425
            m_json = std::make_unique<JSON_Output>();
1✔
426
         else if(format != "default")
32✔
427
            throw CLI_Usage_Error("Unknown --format type '" + format + "'");
×
428

429
#if defined(BOTAN_HAS_ECC_GROUP)
430
         if(ecc_groups.empty()) {
34✔
431
            ecc_groups = {"secp256r1", "brainpool256r1", "secp384r1", "brainpool384r1", "secp521r1", "brainpool512r1"};
272✔
432
         } else if(ecc_groups.size() == 1 && ecc_groups[0] == "all") {
×
433
            auto all = Botan::EC_Group::known_named_groups();
×
434
            ecc_groups.assign(all.begin(), all.end());
×
435
         }
×
436
#endif
437

438
         std::vector<std::string> algos = get_arg_list("algos");
37✔
439

440
         const std::vector<size_t> buf_sizes = unique_buffer_sizes(get_arg("buf-size"));
68✔
441

442
         for(const std::string& cpuid_to_clear : Command::split_on(get_arg("clear-cpuid"), ',')) {
32✔
443
            auto bits = Botan::CPUID::bit_from_string(cpuid_to_clear);
1✔
444
            if(bits.empty()) {
1✔
445
               error_output() << "Warning don't know CPUID flag '" << cpuid_to_clear << "'\n";
1✔
446
            }
447

448
            for(auto bit : bits) {
1✔
449
               Botan::CPUID::clear_cpuid_bit(bit);
×
450
            }
451
         }
32✔
452

453
         if(verbose() || m_summary) {
31✔
454
            output() << Botan::version_string() << "\n"
2✔
455
                     << "CPUID: " << Botan::CPUID::to_string() << "\n\n";
3✔
456
         }
457

458
         const bool using_defaults = (algos.empty());
31✔
459
         if(using_defaults) {
31✔
460
            algos = default_benchmark_list();
×
461
         }
462

463
         for(const auto& algo : algos) {
81✔
464
            using namespace std::placeholders;
50✔
465

466
            if(false) {
50✔
467
               // Since everything might be disabled, need a block to else if from
468
            }
469
#if defined(BOTAN_HAS_HASH)
470
            else if(!Botan::HashFunction::providers(algo).empty()) {
50✔
471
               bench_providers_of<Botan::HashFunction>(
1✔
472
                  algo, provider, msec, buf_sizes, std::bind(&Speed::bench_hash, this, _1, _2, _3, _4));
2✔
473
            }
474
#endif
475
#if defined(BOTAN_HAS_BLOCK_CIPHER)
476
            else if(!Botan::BlockCipher::providers(algo).empty()) {
49✔
477
               bench_providers_of<Botan::BlockCipher>(
4✔
478
                  algo, provider, msec, buf_sizes, std::bind(&Speed::bench_block_cipher, this, _1, _2, _3, _4));
8✔
479
            }
480
#endif
481
#if defined(BOTAN_HAS_STREAM_CIPHER)
482
            else if(!Botan::StreamCipher::providers(algo).empty()) {
45✔
483
               bench_providers_of<Botan::StreamCipher>(
1✔
484
                  algo, provider, msec, buf_sizes, std::bind(&Speed::bench_stream_cipher, this, _1, _2, _3, _4));
2✔
485
            }
486
#endif
487
#if defined(BOTAN_HAS_CIPHER_MODES)
488
            else if(auto enc = Botan::Cipher_Mode::create(algo, Botan::Cipher_Dir::Encryption, provider)) {
44✔
489
               auto dec = Botan::Cipher_Mode::create_or_throw(algo, Botan::Cipher_Dir::Decryption, provider);
1✔
490
               bench_cipher_mode(*enc, *dec, msec, buf_sizes);
1✔
491
            }
1✔
492
#endif
493
#if defined(BOTAN_HAS_MAC)
494
            else if(!Botan::MessageAuthenticationCode::providers(algo).empty()) {
43✔
495
               bench_providers_of<Botan::MessageAuthenticationCode>(
1✔
496
                  algo, provider, msec, buf_sizes, std::bind(&Speed::bench_mac, this, _1, _2, _3, _4));
2✔
497
            }
498
#endif
499
#if defined(BOTAN_HAS_RSA)
500
            else if(algo == "RSA") {
42✔
501
               bench_rsa(provider, msec);
1✔
502
            } else if(algo == "RSA_keygen") {
41✔
503
               bench_rsa_keygen(provider, msec);
1✔
504
            }
505
#endif
506
#if defined(BOTAN_HAS_ECDSA)
507
            else if(algo == "ECDSA") {
40✔
508
               bench_ecdsa(ecc_groups, provider, msec);
1✔
509
            } else if(algo == "ecdsa_recovery") {
39✔
510
               bench_ecdsa_recovery(ecc_groups, provider, msec);
1✔
511
            }
512
#endif
513
#if defined(BOTAN_HAS_SM2)
514
            else if(algo == "SM2") {
38✔
515
               bench_sm2(ecc_groups, provider, msec);
1✔
516
            }
517
#endif
518
#if defined(BOTAN_HAS_ECKCDSA)
519
            else if(algo == "ECKCDSA") {
37✔
520
               bench_eckcdsa(ecc_groups, provider, msec);
1✔
521
            }
522
#endif
523
#if defined(BOTAN_HAS_GOST_34_10_2001)
524
            else if(algo == "GOST-34.10") {
36✔
525
               bench_gost_3410(provider, msec);
1✔
526
            }
527
#endif
528
#if defined(BOTAN_HAS_ECGDSA)
529
            else if(algo == "ECGDSA") {
35✔
530
               bench_ecgdsa(ecc_groups, provider, msec);
1✔
531
            }
532
#endif
533
#if defined(BOTAN_HAS_ED25519)
534
            else if(algo == "Ed25519") {
34✔
535
               bench_ed25519(provider, msec);
1✔
536
            }
537
#endif
538
#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
539
            else if(algo == "DH") {
33✔
540
               bench_dh(provider, msec);
1✔
541
            }
542
#endif
543
#if defined(BOTAN_HAS_DSA)
544
            else if(algo == "DSA") {
32✔
545
               bench_dsa(provider, msec);
1✔
546
            }
547
#endif
548
#if defined(BOTAN_HAS_ELGAMAL)
549
            else if(algo == "ElGamal") {
31✔
550
               bench_elgamal(provider, msec);
1✔
551
            }
552
#endif
553
#if defined(BOTAN_HAS_ECDH)
554
            else if(algo == "ECDH") {
30✔
555
               bench_ecdh(ecc_groups, provider, msec);
1✔
556
            }
557
#endif
558
#if defined(BOTAN_HAS_CURVE_25519)
559
            else if(algo == "Curve25519") {
29✔
560
               bench_curve25519(provider, msec);
1✔
561
            }
562
#endif
563
#if defined(BOTAN_HAS_MCELIECE)
564
            else if(algo == "McEliece") {
28✔
565
               bench_mceliece(provider, msec);
1✔
566
            }
567
#endif
568
#if defined(BOTAN_HAS_KYBER) || defined(BOTAN_HAS_KYBER_90S)
569
            else if(algo == "Kyber") {
27✔
570
               bench_kyber(provider, msec);
1✔
571
            }
572
#endif
573
#if defined(BOTAN_HAS_DILITHIUM) || defined(BOTAN_HAS_DILITHIUM_AES)
574
            else if(algo == "Dilithium") {
26✔
575
               bench_dilithium(provider, msec);
1✔
576
            }
577
#endif
578
#if defined(BOTAN_HAS_XMSS_RFC8391)
579
            else if(algo == "XMSS") {
25✔
580
               bench_xmss(provider, msec);
1✔
581
            }
582
#endif
583
#if defined(BOTAN_HAS_SCRYPT)
584
            else if(algo == "scrypt") {
24✔
585
               bench_scrypt(provider, msec);
1✔
586
            }
587
#endif
588
#if defined(BOTAN_HAS_ARGON2)
589
            else if(algo == "argon2") {
23✔
590
               bench_argon2(provider, msec);
1✔
591
            }
592
#endif
593
#if defined(BOTAN_HAS_BCRYPT)
594
            else if(algo == "bcrypt") {
22✔
595
               bench_bcrypt();
1✔
596
            }
597
#endif
598
#if defined(BOTAN_HAS_PASSHASH9)
599
            else if(algo == "passhash9") {
21✔
600
               bench_passhash9();
1✔
601
            }
602
#endif
603
#if defined(BOTAN_HAS_ZFEC)
604
            else if(algo == "zfec") {
20✔
605
               bench_zfec(msec);
1✔
606
            }
607
#endif
608
#if defined(BOTAN_HAS_POLY_DBL)
609
            else if(algo == "poly_dbl") {
19✔
610
               bench_poly_dbl(msec);
1✔
611
            }
612
#endif
613

614
#if defined(BOTAN_HAS_DL_GROUP)
615
            else if(algo == "modexp") {
18✔
616
               bench_modexp(msec);
1✔
617
            }
618
#endif
619

620
#if defined(BOTAN_HAS_BIGINT)
621
            else if(algo == "mp_mul") {
17✔
622
               bench_mp_mul(msec);
1✔
623
            } else if(algo == "mp_div") {
16✔
624
               bench_mp_div(msec);
1✔
625
            } else if(algo == "mp_div10") {
15✔
626
               bench_mp_div10(msec);
1✔
627
            }
628
#endif
629

630
#if defined(BOTAN_HAS_NUMBERTHEORY)
631
            else if(algo == "primality_test") {
14✔
632
               bench_primality_tests(msec);
1✔
633
            } else if(algo == "random_prime") {
13✔
634
               bench_random_prime(msec);
1✔
635
            } else if(algo == "inverse_mod") {
12✔
636
               bench_inverse_mod(msec);
1✔
637
            } else if(algo == "bn_redc") {
11✔
638
               bench_bn_redc(msec);
1✔
639
            } else if(algo == "nistp_redc") {
10✔
640
               bench_nistp_redc(msec);
1✔
641
            }
642
#endif
643

644
#if defined(BOTAN_HAS_FPE_FE1)
645
            else if(algo == "fpe_fe1") {
9✔
646
               bench_fpe_fe1(msec);
1✔
647
            }
648
#endif
649

650
#if defined(BOTAN_HAS_RFC3394_KEYWRAP)
651
            else if(algo == "rfc3394") {
8✔
652
               bench_rfc3394(msec);
1✔
653
            }
654
#endif
655

656
#if defined(BOTAN_HAS_ECC_GROUP)
657
            else if(algo == "ecc_mult") {
7✔
658
               bench_ecc_mult(ecc_groups, msec);
1✔
659
            } else if(algo == "ecc_ops") {
6✔
660
               bench_ecc_ops(ecc_groups, msec);
1✔
661
            } else if(algo == "ecc_init") {
5✔
662
               bench_ecc_init(ecc_groups, msec);
1✔
663
            } else if(algo == "os2ecp") {
4✔
664
               bench_os2ecp(ecc_groups, msec);
1✔
665
            }
666
#endif
667
#if defined(BOTAN_HAS_EC_HASH_TO_CURVE)
668
            else if(algo == "ec_h2c") {
3✔
669
               bench_ec_h2c(msec);
1✔
670
            }
671
#endif
672
            else if(algo == "RNG") {
2✔
673
#if defined(BOTAN_HAS_AUTO_SEEDING_RNG)
674
               Botan::AutoSeeded_RNG auto_rng;
1✔
675
               bench_rng(auto_rng, "AutoSeeded_RNG (with reseed)", msec, buf_sizes);
1✔
676
#endif
677

678
#if defined(BOTAN_HAS_SYSTEM_RNG)
679
               bench_rng(Botan::system_rng(), "System_RNG", msec, buf_sizes);
1✔
680
#endif
681

682
#if defined(BOTAN_HAS_PROCESSOR_RNG)
683
               if(Botan::Processor_RNG::available()) {
1✔
684
                  Botan::Processor_RNG hwrng;
1✔
685
                  bench_rng(hwrng, "Processor_RNG", msec, buf_sizes);
2✔
686
               }
1✔
687
#endif
688

689
#if defined(BOTAN_HAS_HMAC_DRBG)
690
               for(std::string hash : {"SHA-256", "SHA-384", "SHA-512"}) {
4✔
691
                  Botan::HMAC_DRBG hmac_drbg(hash);
3✔
692
                  bench_rng(hmac_drbg, hmac_drbg.name(), msec, buf_sizes);
3✔
693
               }
3✔
694
#endif
695

696
#if defined(BOTAN_HAS_CHACHA_RNG)
697
               // Provide a dummy seed
698
               Botan::ChaCha_RNG chacha_rng(Botan::secure_vector<uint8_t>(32));
1✔
699
               bench_rng(chacha_rng, "ChaCha_RNG", msec, buf_sizes);
1✔
700
#endif
701

702
            } else if(algo == "entropy") {
2✔
703
               bench_entropy_sources(msec);
1✔
704
            } else {
705
               if(verbose() || !using_defaults) {
×
706
                  error_output() << "Unknown algorithm '" << algo << "'\n";
×
707
               }
708
            }
44✔
709
         }
710

711
         if(m_json) {
31✔
712
            output() << m_json->print();
3✔
713
         }
714
         if(m_summary) {
31✔
715
            output() << m_summary->print() << "\n";
3✔
716
         }
717

718
         if(verbose() && m_clock_speed == 0 && m_cycles_consumed > 0 && m_ns_taken > 0) {
31✔
719
            const double seconds = static_cast<double>(m_ns_taken) / 1000000000;
×
720
            const double Hz = static_cast<double>(m_cycles_consumed) / seconds;
×
721
            const double MHz = Hz / 1000000;
×
722
            output() << "\nEstimated clock speed " << MHz << " MHz\n";
×
723
         }
724
      }
40✔
725

726
   private:
727
      size_t m_clock_speed = 0;
728
      double m_clock_cycle_ratio = 0.0;
729
      uint64_t m_cycles_consumed = 0;
730
      uint64_t m_ns_taken = 0;
731
      std::unique_ptr<Summary> m_summary;
732
      std::unique_ptr<JSON_Output> m_json;
733

734
      void record_result(const std::unique_ptr<Timer>& t) {
467✔
735
         m_ns_taken += t->value();
467✔
736
         m_cycles_consumed += t->cycles_consumed();
467✔
737
         if(m_json) {
467✔
738
            m_json->add(*t);
2✔
739
         } else {
740
            output() << t->to_string() << std::flush;
465✔
741
            if(m_summary)
465✔
742
               m_summary->add(*t);
2✔
743
         }
744
      }
467✔
745

746
      template <typename T>
747
      using bench_fn = std::function<void(T&, std::string, std::chrono::milliseconds, const std::vector<size_t>&)>;
748

749
      template <typename T>
750
      void bench_providers_of(const std::string& algo,
7✔
751
                              const std::string& provider, /* user request, if any */
752
                              const std::chrono::milliseconds runtime,
753
                              const std::vector<size_t>& buf_sizes,
754
                              bench_fn<T> bench_one) {
755
         for(const auto& prov : T::providers(algo)) {
14✔
756
            if(provider.empty() || provider == prov) {
7✔
757
               auto p = T::create(algo, prov);
7✔
758

759
               if(p) {
7✔
760
                  bench_one(*p, prov, runtime, buf_sizes);
14✔
761
               }
762
            }
7✔
763
         }
764
      }
7✔
765

766
      std::unique_ptr<Timer> make_timer(const std::string& name,
471✔
767
                                        uint64_t event_mult = 1,
768
                                        const std::string& what = "",
769
                                        const std::string& provider = "",
770
                                        size_t buf_size = 0) {
771
         return std::make_unique<Timer>(name, provider, what, event_mult, buf_size, m_clock_cycle_ratio, m_clock_speed);
252✔
772
      }
773

774
      std::unique_ptr<Timer> make_timer(const std::string& algo, const std::string& provider, const std::string& what) {
212✔
775
         return make_timer(algo, 1, what, provider, 0);
212✔
776
      }
777

778
#if defined(BOTAN_HAS_BLOCK_CIPHER)
779
      void bench_block_cipher(Botan::BlockCipher& cipher,
4✔
780
                              const std::string& provider,
781
                              std::chrono::milliseconds runtime,
782
                              const std::vector<size_t>& buf_sizes) {
783
         auto ks_timer = make_timer(cipher.name(), provider, "key schedule");
8✔
784

785
         const Botan::SymmetricKey key(rng(), cipher.maximum_keylength());
4✔
786
         ks_timer->run([&]() { cipher.set_key(key); });
8✔
787

788
         const size_t bs = cipher.block_size();
4✔
789
         std::set<size_t> buf_sizes_in_blocks;
4✔
790
         for(size_t buf_size : buf_sizes) {
9✔
791
            if(buf_size % bs == 0)
5✔
792
               buf_sizes_in_blocks.insert(buf_size);
10✔
793
            else
794
               buf_sizes_in_blocks.insert(buf_size + bs - (buf_size % bs));
×
795
         }
796

797
         for(size_t buf_size : buf_sizes_in_blocks) {
9✔
798
            std::vector<uint8_t> buffer(buf_size);
5✔
799
            const size_t blocks = buf_size / bs;
5✔
800

801
            auto encrypt_timer = make_timer(cipher.name(), buffer.size(), "encrypt", provider, buf_size);
10✔
802
            auto decrypt_timer = make_timer(cipher.name(), buffer.size(), "decrypt", provider, buf_size);
10✔
803

804
            encrypt_timer->run_until_elapsed(runtime, [&]() { cipher.encrypt_n(&buffer[0], &buffer[0], blocks); });
2,549✔
805
            record_result(encrypt_timer);
5✔
806

807
            decrypt_timer->run_until_elapsed(runtime, [&]() { cipher.decrypt_n(&buffer[0], &buffer[0], blocks); });
2,520✔
808
            record_result(decrypt_timer);
5✔
809
         }
10✔
810
      }
8✔
811
#endif
812

813
#if defined(BOTAN_HAS_STREAM_CIPHER)
814
      void bench_stream_cipher(Botan::StreamCipher& cipher,
1✔
815
                               const std::string& provider,
816
                               const std::chrono::milliseconds runtime,
817
                               const std::vector<size_t>& buf_sizes) {
818
         for(auto buf_size : buf_sizes) {
2✔
819
            Botan::secure_vector<uint8_t> buffer = rng().random_vec(buf_size);
1✔
820

821
            auto encrypt_timer = make_timer(cipher.name(), buffer.size(), "encrypt", provider, buf_size);
2✔
822

823
            const Botan::SymmetricKey key(rng(), cipher.maximum_keylength());
1✔
824
            cipher.set_key(key);
1✔
825

826
            if(cipher.valid_iv_length(12)) {
1✔
827
               const Botan::InitializationVector iv(rng(), 12);
1✔
828
               cipher.set_iv(iv.begin(), iv.size());
1✔
829
            }
1✔
830

831
            while(encrypt_timer->under(runtime)) {
725✔
832
               encrypt_timer->run([&]() { cipher.encipher(buffer); });
1,448✔
833
            }
834

835
            record_result(encrypt_timer);
1✔
836

837
            if(verbose()) {
1✔
838
               auto ks_timer = make_timer(cipher.name(), buffer.size(), "write_keystream", provider, buf_size);
×
839

840
               while(ks_timer->under(runtime)) {
×
841
                  ks_timer->run([&]() { cipher.write_keystream(buffer.data(), buffer.size()); });
×
842
               }
843
               record_result(ks_timer);
×
844
            }
×
845
         }
2✔
846
      }
1✔
847
#endif
848

849
#if defined(BOTAN_HAS_HASH)
850
      void bench_hash(Botan::HashFunction& hash,
1✔
851
                      const std::string& provider,
852
                      const std::chrono::milliseconds runtime,
853
                      const std::vector<size_t>& buf_sizes) {
854
         std::vector<uint8_t> output(hash.output_length());
1✔
855

856
         for(auto buf_size : buf_sizes) {
2✔
857
            Botan::secure_vector<uint8_t> buffer = rng().random_vec(buf_size);
1✔
858

859
            auto timer = make_timer(hash.name(), buffer.size(), "hash", provider, buf_size);
2✔
860
            timer->run_until_elapsed(runtime, [&]() {
1✔
861
               hash.update(buffer);
128✔
862
               hash.final(output.data());
128✔
863
            });
128✔
864
            record_result(timer);
1✔
865
         }
2✔
866
      }
1✔
867
#endif
868

869
#if defined(BOTAN_HAS_MAC)
870
      void bench_mac(Botan::MessageAuthenticationCode& mac,
1✔
871
                     const std::string& provider,
872
                     const std::chrono::milliseconds runtime,
873
                     const std::vector<size_t>& buf_sizes) {
874
         std::vector<uint8_t> output(mac.output_length());
1✔
875

876
         for(auto buf_size : buf_sizes) {
2✔
877
            Botan::secure_vector<uint8_t> buffer = rng().random_vec(buf_size);
1✔
878

879
            const Botan::SymmetricKey key(rng(), mac.maximum_keylength());
1✔
880
            mac.set_key(key);
1✔
881
            mac.start(nullptr, 0);
1✔
882

883
            auto timer = make_timer(mac.name(), buffer.size(), "mac", provider, buf_size);
2✔
884
            timer->run_until_elapsed(runtime, [&]() { mac.update(buffer); });
141✔
885
            timer->run([&]() { mac.final(output.data()); });
2✔
886
            record_result(timer);
1✔
887
         }
3✔
888
      }
1✔
889
#endif
890

891
#if defined(BOTAN_HAS_CIPHER_MODES)
892
      void bench_cipher_mode(Botan::Cipher_Mode& enc,
1✔
893
                             Botan::Cipher_Mode& dec,
894
                             const std::chrono::milliseconds runtime,
895
                             const std::vector<size_t>& buf_sizes) {
896
         auto ks_timer = make_timer(enc.name(), enc.provider(), "key schedule");
2✔
897

898
         const Botan::SymmetricKey key(rng(), enc.key_spec().maximum_keylength());
1✔
899

900
         ks_timer->run([&]() { enc.set_key(key); });
2✔
901
         ks_timer->run([&]() { dec.set_key(key); });
2✔
902

903
         record_result(ks_timer);
1✔
904

905
         for(auto buf_size : buf_sizes) {
2✔
906
            Botan::secure_vector<uint8_t> buffer = rng().random_vec(buf_size);
1✔
907

908
            auto encrypt_timer = make_timer(enc.name(), buffer.size(), "encrypt", enc.provider(), buf_size);
2✔
909
            auto decrypt_timer = make_timer(dec.name(), buffer.size(), "decrypt", dec.provider(), buf_size);
2✔
910

911
            Botan::secure_vector<uint8_t> iv = rng().random_vec(enc.default_nonce_length());
1✔
912

913
            if(buf_size >= enc.minimum_final_size()) {
1✔
914
               while(encrypt_timer->under(runtime) && decrypt_timer->under(runtime)) {
86✔
915
                  // Must run in this order, or AEADs will reject the ciphertext
916
                  encrypt_timer->run([&]() {
85✔
917
                     enc.start(iv);
85✔
918
                     enc.finish(buffer);
85✔
919
                  });
85✔
920

921
                  decrypt_timer->run([&]() {
85✔
922
                     dec.start(iv);
85✔
923
                     dec.finish(buffer);
85✔
924
                  });
85✔
925

926
                  if(!iv.empty()) {
85✔
927
                     iv[iv.size() - 1] += 1;
85✔
928
                  }
929
               }
930
            }
931

932
            record_result(encrypt_timer);
1✔
933
            record_result(decrypt_timer);
1✔
934
         }
2✔
935
      }
1✔
936
#endif
937

938
      void bench_rng(Botan::RandomNumberGenerator& rng,
7✔
939
                     const std::string& rng_name,
940
                     const std::chrono::milliseconds runtime,
941
                     const std::vector<size_t>& buf_sizes) {
942
         for(auto buf_size : buf_sizes) {
14✔
943
            Botan::secure_vector<uint8_t> buffer(buf_size);
7✔
944

945
#if defined(BOTAN_HAS_SYSTEM_RNG)
946
            rng.reseed_from_rng(Botan::system_rng(), 256);
7✔
947
#endif
948

949
            auto timer = make_timer(rng_name, buffer.size(), "generate", "", buf_size);
7✔
950
            timer->run_until_elapsed(runtime, [&]() { rng.randomize(buffer.data(), buffer.size()); });
914✔
951
            record_result(timer);
7✔
952
         }
14✔
953
      }
7✔
954

955
      void bench_entropy_sources(const std::chrono::milliseconds /*unused*/) {
1✔
956
         Botan::Entropy_Sources& srcs = Botan::Entropy_Sources::global_sources();
1✔
957

958
         for(auto src : srcs.enabled_sources()) {
5✔
959
            size_t entropy_bits = 0;
4✔
960
            Botan_Tests::SeedCapturing_RNG rng;
4✔
961

962
            auto timer = make_timer(src, "", "bytes");
8✔
963
            timer->run([&]() { entropy_bits = srcs.poll_just(rng, src); });
8✔
964

965
            size_t compressed_size = 0;
4✔
966

967
#if defined(BOTAN_HAS_ZLIB)
968
            auto comp = Botan::Compression_Algorithm::create("zlib");
4✔
969

970
            if(comp) {
4✔
971
               Botan::secure_vector<uint8_t> compressed;
4✔
972
               compressed.assign(rng.seed_material().begin(), rng.seed_material().end());
4✔
973
               comp->start(9);
4✔
974
               comp->finish(compressed);
4✔
975

976
               compressed_size = compressed.size();
4✔
977
            }
4✔
978
#endif
979

980
            std::ostringstream msg;
4✔
981

982
            msg << "Entropy source " << src << " output " << rng.seed_material().size() << " bytes"
4✔
983
                << " estimated entropy " << entropy_bits << " in " << timer->milliseconds() << " ms";
4✔
984

985
            if(compressed_size > 0) {
4✔
986
               msg << " output compressed to " << compressed_size << " bytes";
4✔
987
            }
988

989
            msg << " total samples " << rng.samples() << "\n";
4✔
990

991
            timer->set_custom_msg(msg.str());
8✔
992

993
            record_result(timer);
4✔
994
         }
13✔
995
      }
1✔
996

997
#if defined(BOTAN_HAS_ECC_GROUP)
998
      void bench_ecc_ops(const std::vector<std::string>& groups, const std::chrono::milliseconds runtime) {
1✔
999
         for(const std::string& group_name : groups) {
7✔
1000
            const Botan::EC_Group ec_group(group_name);
6✔
1001

1002
            auto add_timer = make_timer(group_name + " add");
15✔
1003
            auto addf_timer = make_timer(group_name + " addf");
15✔
1004
            auto dbl_timer = make_timer(group_name + " dbl");
15✔
1005

1006
            const Botan::EC_Point& base_point = ec_group.get_base_point();
6✔
1007

1008
            // create a non-affine point
1009
            const auto random_k = Botan::BigInt::from_u64(0x4E6F537465707E);
6✔
1010
            Botan::EC_Point non_affine_pt = ec_group.get_base_point() * random_k;
6✔
1011
            Botan::EC_Point pt = ec_group.get_base_point();
6✔
1012

1013
            std::vector<Botan::BigInt> ws(Botan::EC_Point::WORKSPACE_SIZE);
6✔
1014

1015
            while(add_timer->under(runtime) && addf_timer->under(runtime) && dbl_timer->under(runtime)) {
775✔
1016
               dbl_timer->run([&]() { pt.mult2(ws); });
1,538✔
1017
               add_timer->run([&]() { pt.add(non_affine_pt, ws); });
1,538✔
1018
               addf_timer->run([&]() { pt.add_affine(base_point, ws); });
1,538✔
1019
            }
1020

1021
            record_result(dbl_timer);
6✔
1022
            record_result(add_timer);
6✔
1023
            record_result(addf_timer);
6✔
1024
         }
12✔
1025
      }
1✔
1026

1027
      void bench_ecc_init(const std::vector<std::string>& groups, const std::chrono::milliseconds runtime) {
1✔
1028
         for(std::string group_name : groups) {
7✔
1029
            auto timer = make_timer(group_name + " initialization");
18✔
1030

1031
            while(timer->under(runtime)) {
12✔
1032
               Botan::EC_Group::clear_registered_curve_data();
6✔
1033
               timer->run([&]() { Botan::EC_Group group(group_name); });
12✔
1034
            }
1035

1036
            record_result(timer);
6✔
1037
         }
6✔
1038
      }
1✔
1039

1040
      void bench_ecc_mult(const std::vector<std::string>& groups, const std::chrono::milliseconds runtime) {
1✔
1041
         for(const std::string& group_name : groups) {
7✔
1042
            const Botan::EC_Group ec_group(group_name);
6✔
1043

1044
            auto mult_timer = make_timer(group_name + " Montgomery ladder");
18✔
1045
            auto blinded_mult_timer = make_timer(group_name + " blinded comb");
18✔
1046
            auto blinded_var_mult_timer = make_timer(group_name + " blinded window");
18✔
1047

1048
            const Botan::EC_Point& base_point = ec_group.get_base_point();
6✔
1049

1050
            std::vector<Botan::BigInt> ws;
6✔
1051

1052
            while(mult_timer->under(runtime) && blinded_mult_timer->under(runtime) &&
12✔
1053
                  blinded_var_mult_timer->under(runtime)) {
6✔
1054
               const Botan::BigInt scalar(rng(), ec_group.get_p_bits());
6✔
1055

1056
               const Botan::EC_Point r1 = mult_timer->run([&]() { return base_point * scalar; });
18✔
1057

1058
               const Botan::EC_Point r2 =
6✔
1059
                  blinded_mult_timer->run([&]() { return ec_group.blinded_base_point_multiply(scalar, rng(), ws); });
12✔
1060

1061
               const Botan::EC_Point r3 = blinded_var_mult_timer->run(
6✔
1062
                  [&]() { return ec_group.blinded_var_point_multiply(base_point, scalar, rng(), ws); });
12✔
1063

1064
               BOTAN_ASSERT_EQUAL(r1, r2, "Same point computed by Montgomery and comb");
6✔
1065
               BOTAN_ASSERT_EQUAL(r1, r3, "Same point computed by Montgomery and window");
6✔
1066
            }
12✔
1067

1068
            record_result(mult_timer);
6✔
1069
            record_result(blinded_mult_timer);
6✔
1070
            record_result(blinded_var_mult_timer);
6✔
1071
         }
6✔
1072
      }
1✔
1073

1074
      void bench_os2ecp(const std::vector<std::string>& groups, const std::chrono::milliseconds runtime) {
1✔
1075
         for(const std::string& group_name : groups) {
7✔
1076
            auto uncmp_timer = make_timer("OS2ECP uncompressed " + group_name);
18✔
1077
            auto cmp_timer = make_timer("OS2ECP compressed " + group_name);
18✔
1078

1079
            const Botan::EC_Group ec_group(group_name);
6✔
1080

1081
            while(uncmp_timer->under(runtime) && cmp_timer->under(runtime)) {
12✔
1082
               const Botan::BigInt k(rng(), 256);
6✔
1083
               const Botan::EC_Point p = ec_group.get_base_point() * k;
6✔
1084
               const std::vector<uint8_t> os_cmp = p.encode(Botan::EC_Point_Format::Compressed);
6✔
1085
               const std::vector<uint8_t> os_uncmp = p.encode(Botan::EC_Point_Format::Uncompressed);
6✔
1086

1087
               uncmp_timer->run([&]() { ec_group.OS2ECP(os_uncmp); });
12✔
1088
               cmp_timer->run([&]() { ec_group.OS2ECP(os_cmp); });
12✔
1089
            }
18✔
1090

1091
            record_result(uncmp_timer);
6✔
1092
            record_result(cmp_timer);
6✔
1093
         }
6✔
1094
      }
1✔
1095

1096
#endif
1097

1098
#if defined(BOTAN_HAS_EC_HASH_TO_CURVE)
1099
      void bench_ec_h2c(const std::chrono::milliseconds runtime) {
1✔
1100
         for(std::string group_name : {"secp256r1", "secp384r1", "secp521r1"}) {
4✔
1101
            auto h2c_ro_timer = make_timer(group_name + "-RO", "", "hash to curve");
6✔
1102
            auto h2c_nu_timer = make_timer(group_name + "-NU", "", "hash to curve");
6✔
1103

1104
            const Botan::EC_Group group(group_name);
3✔
1105

1106
            while(h2c_ro_timer->under(runtime)) {
6✔
1107
               std::vector<uint8_t> input(32);
3✔
1108

1109
               rng().randomize(input.data(), input.size());
3✔
1110

1111
               const Botan::EC_Point p1 = h2c_ro_timer->run(
3✔
1112
                  [&]() { return group.hash_to_curve("SHA-256", input.data(), input.size(), nullptr, 0, true); });
6✔
1113

1114
               BOTAN_ASSERT_NOMSG(p1.on_the_curve());
3✔
1115

1116
               const Botan::EC_Point p2 = h2c_nu_timer->run(
3✔
1117
                  [&]() { return group.hash_to_curve("SHA-256", input.data(), input.size(), nullptr, 0, false); });
6✔
1118

1119
               BOTAN_ASSERT_NOMSG(p2.on_the_curve());
3✔
1120
            }
6✔
1121

1122
            record_result(h2c_ro_timer);
3✔
1123
            record_result(h2c_nu_timer);
3✔
1124
         }
3✔
1125
      }
1✔
1126
#endif
1127

1128
#if defined(BOTAN_HAS_FPE_FE1)
1129

1130
      void bench_fpe_fe1(const std::chrono::milliseconds runtime) {
1✔
1131
         const auto n = Botan::BigInt::from_u64(1000000000000000);
1✔
1132

1133
         auto enc_timer = make_timer("FPE_FE1 encrypt");
2✔
1134
         auto dec_timer = make_timer("FPE_FE1 decrypt");
2✔
1135

1136
         const Botan::SymmetricKey key(rng(), 32);
1✔
1137
         const std::vector<uint8_t> tweak(8);  // 8 zeros
1✔
1138

1139
         auto x = Botan::BigInt::one();
1✔
1140

1141
         Botan::FPE_FE1 fpe_fe1(n);
1✔
1142
         fpe_fe1.set_key(key);
1✔
1143

1144
         while(enc_timer->under(runtime)) {
3✔
1145
            enc_timer->start();
2✔
1146
            x = fpe_fe1.encrypt(x, tweak.data(), tweak.size());
2✔
1147
            enc_timer->stop();
2✔
1148
         }
1149

1150
         for(size_t i = 0; i != enc_timer->events(); ++i) {
3✔
1151
            dec_timer->start();
2✔
1152
            x = fpe_fe1.decrypt(x, tweak.data(), tweak.size());
2✔
1153
            dec_timer->stop();
2✔
1154
         }
1155

1156
         BOTAN_ASSERT(x == 1, "FPE works");
1✔
1157

1158
         record_result(enc_timer);
1✔
1159
         record_result(dec_timer);
1✔
1160
      }
5✔
1161
#endif
1162

1163
#if defined(BOTAN_HAS_RFC3394_KEYWRAP)
1164

1165
      void bench_rfc3394(const std::chrono::milliseconds runtime) {
1✔
1166
         auto wrap_timer = make_timer("RFC3394 AES-256 key wrap");
3✔
1167
         auto unwrap_timer = make_timer("RFC3394 AES-256 key unwrap");
3✔
1168

1169
         const Botan::SymmetricKey kek(rng(), 32);
1✔
1170
         Botan::secure_vector<uint8_t> key(64, 0);
1✔
1171

1172
         while(wrap_timer->under(runtime)) {
42✔
1173
            wrap_timer->start();
41✔
1174
            key = Botan::rfc3394_keywrap(key, kek);
82✔
1175
            wrap_timer->stop();
41✔
1176

1177
            unwrap_timer->start();
41✔
1178
            key = Botan::rfc3394_keyunwrap(key, kek);
82✔
1179
            unwrap_timer->stop();
41✔
1180

1181
            key[0] += 1;
41✔
1182
         }
1183

1184
         record_result(wrap_timer);
1✔
1185
         record_result(unwrap_timer);
1✔
1186
      }
2✔
1187
#endif
1188

1189
#if defined(BOTAN_HAS_BIGINT)
1190

1191
      void bench_mp_mul(const std::chrono::milliseconds runtime) {
1✔
1192
         std::chrono::milliseconds runtime_per_size = runtime;
1✔
1193
         for(size_t bits : {256, 384, 512, 768, 1024, 1536, 2048, 3072, 4096}) {
10✔
1194
            auto mul_timer = make_timer("BigInt mul " + std::to_string(bits));
18✔
1195
            auto sqr_timer = make_timer("BigInt sqr " + std::to_string(bits));
18✔
1196

1197
            const Botan::BigInt y(rng(), bits);
9✔
1198
            Botan::secure_vector<Botan::word> ws;
9✔
1199

1200
            while(mul_timer->under(runtime_per_size)) {
4,520✔
1201
               Botan::BigInt x(rng(), bits);
4,511✔
1202

1203
               sqr_timer->start();
4,511✔
1204
               x.square(ws);
4,511✔
1205
               sqr_timer->stop();
4,511✔
1206

1207
               x.mask_bits(bits);
4,511✔
1208

1209
               mul_timer->start();
4,511✔
1210
               x.mul(y, ws);
4,511✔
1211
               mul_timer->stop();
4,511✔
1212
            }
4,511✔
1213

1214
            record_result(mul_timer);
9✔
1215
            record_result(sqr_timer);
9✔
1216
         }
18✔
1217
      }
1✔
1218

1219
      void bench_mp_div(const std::chrono::milliseconds runtime) {
1✔
1220
         std::chrono::milliseconds runtime_per_size = runtime;
1✔
1221

1222
         for(size_t n_bits : {256, 384, 512, 768, 1024, 1536, 2048, 3072, 4096}) {
10✔
1223
            const size_t q_bits = n_bits / 2;
9✔
1224
            const std::string bit_descr = std::to_string(n_bits) + "/" + std::to_string(q_bits);
18✔
1225

1226
            auto div_timer = make_timer("BigInt div " + bit_descr);
27✔
1227
            auto ct_div_timer = make_timer("BigInt ct_div " + bit_descr);
27✔
1228

1229
            Botan::BigInt y;
9✔
1230
            Botan::BigInt x;
9✔
1231
            Botan::secure_vector<Botan::word> ws;
9✔
1232

1233
            Botan::BigInt q1, r1, q2, r2;
9✔
1234

1235
            while(ct_div_timer->under(runtime_per_size)) {
45✔
1236
               x.randomize(rng(), n_bits);
36✔
1237
               y.randomize(rng(), q_bits);
36✔
1238

1239
               div_timer->start();
36✔
1240
               Botan::vartime_divide(x, y, q1, r1);
36✔
1241
               div_timer->stop();
36✔
1242

1243
               ct_div_timer->start();
36✔
1244
               Botan::ct_divide(x, y, q2, r2);
36✔
1245
               ct_div_timer->stop();
36✔
1246

1247
               BOTAN_ASSERT_EQUAL(q1, q2, "Quotient ok");
36✔
1248
               BOTAN_ASSERT_EQUAL(r1, r2, "Remainder ok");
81✔
1249
            }
1250

1251
            record_result(div_timer);
9✔
1252
            record_result(ct_div_timer);
9✔
1253
         }
54✔
1254
      }
1✔
1255

1256
      void bench_mp_div10(const std::chrono::milliseconds runtime) {
1✔
1257
         std::chrono::milliseconds runtime_per_size = runtime;
1✔
1258

1259
         for(size_t n_bits : {256, 384, 512, 768, 1024, 1536, 2048, 3072, 4096}) {
10✔
1260
            const std::string bit_descr = std::to_string(n_bits) + "/10";
9✔
1261

1262
            auto div_timer = make_timer("BigInt div " + bit_descr);
27✔
1263
            auto ct_div_timer = make_timer("BigInt ct_div " + bit_descr);
27✔
1264

1265
            Botan::BigInt x;
9✔
1266
            Botan::secure_vector<Botan::word> ws;
9✔
1267

1268
            const auto ten = Botan::BigInt::from_word(10);
9✔
1269
            Botan::BigInt q1, r1, q2;
9✔
1270
            Botan::word r2;
1271

1272
            while(ct_div_timer->under(runtime_per_size)) {
264✔
1273
               x.randomize(rng(), n_bits);
255✔
1274

1275
               div_timer->start();
255✔
1276
               Botan::vartime_divide(x, ten, q1, r1);
255✔
1277
               div_timer->stop();
255✔
1278

1279
               ct_div_timer->start();
255✔
1280
               Botan::ct_divide_word(x, 10, q2, r2);
255✔
1281
               ct_div_timer->stop();
255✔
1282

1283
               BOTAN_ASSERT_EQUAL(q1, q2, "Quotient ok");
255✔
1284
               BOTAN_ASSERT_EQUAL(r1, r2, "Remainder ok");
519✔
1285
            }
1286

1287
            record_result(div_timer);
9✔
1288
            record_result(ct_div_timer);
9✔
1289
         }
45✔
1290
      }
1✔
1291

1292
#endif
1293

1294
#if defined(BOTAN_HAS_DL_GROUP)
1295

1296
      void bench_modexp(const std::chrono::milliseconds runtime) {
1✔
1297
         for(size_t group_bits : {1024, 1536, 2048, 3072, 4096}) {
6✔
1298
            const std::string group_bits_str = std::to_string(group_bits);
5✔
1299
            const Botan::DL_Group group("modp/srp/" + group_bits_str);
5✔
1300

1301
            const size_t e_bits = Botan::dl_exponent_size(group_bits);
5✔
1302
            const size_t f_bits = group_bits - 1;
5✔
1303

1304
            const Botan::BigInt random_e(rng(), e_bits);
5✔
1305
            const Botan::BigInt random_f(rng(), f_bits);
5✔
1306

1307
            auto e_timer = make_timer(group_bits_str + " short exponent");
15✔
1308
            auto f_timer = make_timer(group_bits_str + "  full exponent");
15✔
1309

1310
            while(f_timer->under(runtime)) {
10✔
1311
               e_timer->run([&]() { group.power_g_p(random_e); });
10✔
1312
               f_timer->run([&]() { group.power_g_p(random_f); });
10✔
1313
            }
1314

1315
            record_result(e_timer);
5✔
1316
            record_result(f_timer);
5✔
1317
         }
20✔
1318
      }
1✔
1319
#endif
1320

1321
#if defined(BOTAN_HAS_NUMBERTHEORY)
1322
      void bench_nistp_redc(const std::chrono::milliseconds runtime) {
1✔
1323
         Botan::secure_vector<Botan::word> ws;
1✔
1324

1325
         auto p192_timer = make_timer("P-192 redc");
2✔
1326
         Botan::BigInt r192(rng(), 192 * 2 - 1);
1✔
1327
         while(p192_timer->under(runtime)) {
2,841✔
1328
            Botan::BigInt r = r192;
2,840✔
1329
            p192_timer->run([&]() { Botan::redc_p192(r, ws); });
5,680✔
1330
            r192 += 1;
2,840✔
1331
         }
2,840✔
1332
         record_result(p192_timer);
1✔
1333

1334
         auto p224_timer = make_timer("P-224 redc");
2✔
1335
         Botan::BigInt r224(rng(), 224 * 2 - 1);
1✔
1336
         while(p224_timer->under(runtime)) {
2,641✔
1337
            Botan::BigInt r = r224;
2,640✔
1338
            p224_timer->run([&]() { Botan::redc_p224(r, ws); });
5,280✔
1339
            r224 += 1;
2,640✔
1340
         }
2,640✔
1341
         record_result(p224_timer);
1✔
1342

1343
         auto p256_timer = make_timer("P-256 redc");
2✔
1344
         Botan::BigInt r256(rng(), 256 * 2 - 1);
1✔
1345
         while(p256_timer->under(runtime)) {
2,629✔
1346
            Botan::BigInt r = r256;
2,628✔
1347
            p256_timer->run([&]() { Botan::redc_p256(r, ws); });
5,256✔
1348
            r256 += 1;
2,628✔
1349
         }
2,628✔
1350
         record_result(p256_timer);
1✔
1351

1352
         auto p384_timer = make_timer("P-384 redc");
2✔
1353
         Botan::BigInt r384(rng(), 384 * 2 - 1);
1✔
1354
         while(p384_timer->under(runtime)) {
2,377✔
1355
            Botan::BigInt r = r384;
2,376✔
1356
            p384_timer->run([&]() { Botan::redc_p384(r384, ws); });
4,752✔
1357
            r384 += 1;
2,376✔
1358
         }
2,376✔
1359
         record_result(p384_timer);
1✔
1360

1361
         auto p521_timer = make_timer("P-521 redc");
2✔
1362
         Botan::BigInt r521(rng(), 521 * 2 - 1);
1✔
1363
         while(p521_timer->under(runtime)) {
1,619✔
1364
            Botan::BigInt r = r521;
1,618✔
1365
            p521_timer->run([&]() { Botan::redc_p521(r521, ws); });
3,236✔
1366
            r521 += 1;
1,618✔
1367
         }
1,618✔
1368
         record_result(p521_timer);
1✔
1369
      }
6✔
1370

1371
      void bench_bn_redc(const std::chrono::milliseconds runtime) {
1✔
1372
         for(size_t bitsize : {512, 1024, 2048, 4096}) {
5✔
1373
            Botan::BigInt p(rng(), bitsize);
4✔
1374

1375
            std::string bit_str = std::to_string(bitsize);
4✔
1376
            auto barrett_timer = make_timer("Barrett-" + bit_str);
8✔
1377
            auto schoolbook_timer = make_timer("Schoolbook-" + bit_str);
8✔
1378

1379
            Botan::Modular_Reducer mod_p(p);
4✔
1380

1381
            while(schoolbook_timer->under(runtime)) {
50✔
1382
               const Botan::BigInt x(rng(), p.bits() * 2 - 2);
46✔
1383

1384
               const Botan::BigInt r1 = barrett_timer->run([&] { return mod_p.reduce(x); });
92✔
1385
               const Botan::BigInt r2 = schoolbook_timer->run([&] { return x % p; });
92✔
1386

1387
               BOTAN_ASSERT(r1 == r2, "Computed different results");
46✔
1388
            }
138✔
1389

1390
            record_result(barrett_timer);
4✔
1391
            record_result(schoolbook_timer);
4✔
1392
         }
8✔
1393
      }
1✔
1394

1395
      void bench_inverse_mod(const std::chrono::milliseconds runtime) {
1✔
1396
         for(size_t bits : {256, 384, 512, 1024, 2048}) {
6✔
1397
            const std::string bit_str = std::to_string(bits);
5✔
1398

1399
            auto timer = make_timer("inverse_mod-" + bit_str);
12✔
1400
            auto gcd_timer = make_timer("gcd-" + bit_str);
10✔
1401

1402
            while(timer->under(runtime) && gcd_timer->under(runtime)) {
11✔
1403
               const Botan::BigInt x(rng(), bits - 1);
6✔
1404
               Botan::BigInt mod(rng(), bits);
6✔
1405

1406
               const Botan::BigInt x_inv = timer->run([&] { return Botan::inverse_mod(x, mod); });
12✔
1407

1408
               const Botan::BigInt g = gcd_timer->run([&] { return gcd(x, mod); });
12✔
1409

1410
               if(x_inv == 0) {
6✔
1411
                  BOTAN_ASSERT(g != 1, "Inversion only fails if gcd(x, mod) > 1");
2✔
1412
               } else {
1413
                  BOTAN_ASSERT(g == 1, "Inversion succeeds only if gcd != 1");
4✔
1414
                  const Botan::BigInt check = (x_inv * x) % mod;
4✔
1415
                  BOTAN_ASSERT_EQUAL(check, 1, "Const time inversion correct");
4✔
1416
               }
4✔
1417
            }
23✔
1418

1419
            record_result(timer);
5✔
1420
            record_result(gcd_timer);
5✔
1421
         }
5✔
1422
      }
1✔
1423

1424
      void bench_primality_tests(const std::chrono::milliseconds runtime) {
1✔
1425
         for(size_t bits : {256, 512, 1024}) {
4✔
1426
            auto mr_timer = make_timer("Miller-Rabin-" + std::to_string(bits));
9✔
1427
            auto bpsw_timer = make_timer("Bailie-PSW-" + std::to_string(bits));
6✔
1428
            auto lucas_timer = make_timer("Lucas-" + std::to_string(bits));
6✔
1429

1430
            Botan::BigInt n = Botan::random_prime(rng(), bits);
3✔
1431

1432
            while(lucas_timer->under(runtime)) {
6✔
1433
               Botan::Modular_Reducer mod_n(n);
3✔
1434

1435
               mr_timer->run([&]() { return Botan::is_miller_rabin_probable_prime(n, mod_n, rng(), 2); });
6✔
1436

1437
               bpsw_timer->run([&]() { return Botan::is_bailie_psw_probable_prime(n, mod_n); });
6✔
1438

1439
               lucas_timer->run([&]() { return Botan::is_lucas_probable_prime(n, mod_n); });
6✔
1440

1441
               n += 2;
3✔
1442
            }
3✔
1443

1444
            record_result(mr_timer);
3✔
1445
            record_result(bpsw_timer);
3✔
1446
            record_result(lucas_timer);
3✔
1447
         }
3✔
1448
      }
1✔
1449

1450
      void bench_random_prime(const std::chrono::milliseconds runtime) {
1✔
1451
         const auto coprime = Botan::BigInt::from_word(0x10001);
1✔
1452

1453
         for(size_t bits : {256, 384, 512, 768, 1024, 1536}) {
7✔
1454
            auto genprime_timer = make_timer("random_prime " + std::to_string(bits));
18✔
1455
            auto gensafe_timer = make_timer("random_safe_prime " + std::to_string(bits));
18✔
1456
            auto is_prime_timer = make_timer("is_prime " + std::to_string(bits));
12✔
1457

1458
            while(gensafe_timer->under(runtime)) {
12✔
1459
               const Botan::BigInt p = genprime_timer->run([&] { return Botan::random_prime(rng(), bits, coprime); });
12✔
1460

1461
               if(!is_prime_timer->run([&] { return Botan::is_prime(p, rng(), 64, true); })) {
12✔
1462
                  error_output() << "Generated prime " << p << " which failed a primality test";
×
1463
               }
1464

1465
               const Botan::BigInt sg = gensafe_timer->run([&] { return Botan::random_safe_prime(rng(), bits); });
12✔
1466

1467
               if(!is_prime_timer->run([&] { return Botan::is_prime(sg, rng(), 64, true); })) {
12✔
1468
                  error_output() << "Generated safe prime " << sg << " which failed a primality test";
×
1469
               }
1470

1471
               if(!is_prime_timer->run([&] { return Botan::is_prime(sg / 2, rng(), 64, true); })) {
18✔
1472
                  error_output() << "Generated prime " << sg / 2 << " which failed a primality test";
×
1473
               }
1474

1475
               // Now test p+2, p+4, ... which may or may not be prime
1476
               for(size_t i = 2; i <= 64; i += 2) {
198✔
1477
                  is_prime_timer->run([&]() { Botan::is_prime(p + i, rng(), 64, true); });
576✔
1478
               }
1479
            }
12✔
1480

1481
            record_result(genprime_timer);
6✔
1482
            record_result(gensafe_timer);
6✔
1483
            record_result(is_prime_timer);
6✔
1484
         }
6✔
1485
      }
1✔
1486
#endif
1487

1488
#if defined(BOTAN_HAS_PUBLIC_KEY_CRYPTO)
1489
      void bench_pk_enc(const Botan::Private_Key& key,
4✔
1490
                        const std::string& nm,
1491
                        const std::string& provider,
1492
                        const std::string& padding,
1493
                        std::chrono::milliseconds msec) {
1494
         std::vector<uint8_t> plaintext, ciphertext;
4✔
1495

1496
         Botan::PK_Encryptor_EME enc(key, rng(), padding, provider);
4✔
1497
         Botan::PK_Decryptor_EME dec(key, rng(), padding, provider);
4✔
1498

1499
         auto enc_timer = make_timer(nm + " " + padding, provider, "encrypt");
12✔
1500
         auto dec_timer = make_timer(nm + " " + padding, provider, "decrypt");
12✔
1501

1502
         while(enc_timer->under(msec) || dec_timer->under(msec)) {
12✔
1503
            // Generate a new random ciphertext to decrypt
1504
            if(ciphertext.empty() || enc_timer->under(msec)) {
4✔
1505
               rng().random_vec(plaintext, enc.maximum_input_size());
4✔
1506
               ciphertext = enc_timer->run([&]() { return enc.encrypt(plaintext, rng()); });
12✔
1507
            }
1508

1509
            if(dec_timer->under(msec)) {
4✔
1510
               const auto dec_pt = dec_timer->run([&]() { return dec.decrypt(ciphertext); });
12✔
1511

1512
               if(!(Botan::unlock(dec_pt) == plaintext))  // sanity check
8✔
1513
               {
1514
                  error_output() << "Bad roundtrip in PK encrypt/decrypt bench\n";
×
1515
               }
1516
            }
4✔
1517
         }
1518

1519
         record_result(enc_timer);
4✔
1520
         record_result(dec_timer);
4✔
1521
      }
12✔
1522

1523
      void bench_pk_ka(const std::string& algo,
14✔
1524
                       const std::string& nm,
1525
                       const std::string& params,
1526
                       const std::string& provider,
1527
                       std::chrono::milliseconds msec) {
1528
         const std::string kdf = "KDF2(SHA-256)";  // arbitrary choice
14✔
1529

1530
         auto keygen_timer = make_timer(nm, provider, "keygen");
28✔
1531

1532
         std::unique_ptr<Botan::Private_Key> key1(
14✔
1533
            keygen_timer->run([&] { return Botan::create_private_key(algo, rng(), params); }));
28✔
1534
         std::unique_ptr<Botan::Private_Key> key2(
14✔
1535
            keygen_timer->run([&] { return Botan::create_private_key(algo, rng(), params); }));
28✔
1536

1537
         record_result(keygen_timer);
14✔
1538

1539
         const Botan::PK_Key_Agreement_Key& ka_key1 = dynamic_cast<const Botan::PK_Key_Agreement_Key&>(*key1);
14✔
1540
         const Botan::PK_Key_Agreement_Key& ka_key2 = dynamic_cast<const Botan::PK_Key_Agreement_Key&>(*key2);
14✔
1541

1542
         Botan::PK_Key_Agreement ka1(ka_key1, rng(), kdf, provider);
14✔
1543
         Botan::PK_Key_Agreement ka2(ka_key2, rng(), kdf, provider);
14✔
1544

1545
         const std::vector<uint8_t> ka1_pub = ka_key1.public_value();
14✔
1546
         const std::vector<uint8_t> ka2_pub = ka_key2.public_value();
14✔
1547

1548
         auto ka_timer = make_timer(nm, provider, "key agreements");
28✔
1549

1550
         while(ka_timer->under(msec)) {
32✔
1551
            Botan::SymmetricKey symkey1 = ka_timer->run([&]() { return ka1.derive_key(32, ka2_pub); });
36✔
1552
            Botan::SymmetricKey symkey2 = ka_timer->run([&]() { return ka2.derive_key(32, ka1_pub); });
36✔
1553

1554
            if(symkey1 != symkey2) {
18✔
1555
               error_output() << "Key agreement mismatch in PK bench\n";
×
1556
            }
1557
         }
36✔
1558

1559
         record_result(ka_timer);
14✔
1560
      }
70✔
1561

1562
      void bench_pk_kem(const Botan::Private_Key& key,
11✔
1563
                        const std::string& nm,
1564
                        const std::string& provider,
1565
                        const std::string& kdf,
1566
                        std::chrono::milliseconds msec) {
1567
         Botan::PK_KEM_Decryptor dec(key, rng(), kdf, provider);
11✔
1568
         Botan::PK_KEM_Encryptor enc(key, kdf, provider);
11✔
1569

1570
         auto kem_enc_timer = make_timer(nm, provider, "KEM encrypt");
22✔
1571
         auto kem_dec_timer = make_timer(nm, provider, "KEM decrypt");
22✔
1572

1573
         while(kem_enc_timer->under(msec) && kem_dec_timer->under(msec)) {
35✔
1574
            Botan::secure_vector<uint8_t> encap_key, enc_shared_key;
24✔
1575
            Botan::secure_vector<uint8_t> salt = rng().random_vec(16);
24✔
1576

1577
            kem_enc_timer->start();
24✔
1578
            enc.encrypt(encap_key, enc_shared_key, 64, rng(), salt);
24✔
1579
            kem_enc_timer->stop();
24✔
1580

1581
            kem_dec_timer->start();
24✔
1582
            Botan::secure_vector<uint8_t> dec_shared_key = dec.decrypt(encap_key, 64, salt);
24✔
1583
            kem_dec_timer->stop();
24✔
1584

1585
            if(enc_shared_key != dec_shared_key) {
24✔
1586
               error_output() << "KEM mismatch in PK bench\n";
×
1587
            }
1588
         }
96✔
1589

1590
         record_result(kem_enc_timer);
11✔
1591
         record_result(kem_dec_timer);
11✔
1592
      }
11✔
1593

1594
      void bench_pk_sig_ecc(const std::string& algo,
6✔
1595
                            const std::string& emsa,
1596
                            const std::string& provider,
1597
                            const std::vector<std::string>& params,
1598
                            std::chrono::milliseconds msec) {
1599
         for(std::string grp : params) {
32✔
1600
            const std::string nm = grp.empty() ? algo : (algo + "-" + grp);
26✔
1601

1602
            auto keygen_timer = make_timer(nm, provider, "keygen");
52✔
1603

1604
            std::unique_ptr<Botan::Private_Key> key(
26✔
1605
               keygen_timer->run([&] { return Botan::create_private_key(algo, rng(), grp); }));
52✔
1606

1607
            record_result(keygen_timer);
26✔
1608
            bench_pk_sig(*key, nm, provider, emsa, msec);
26✔
1609
         }
48✔
1610
      }
6✔
1611

1612
      size_t bench_pk_sig(const Botan::Private_Key& key,
40✔
1613
                          const std::string& nm,
1614
                          const std::string& provider,
1615
                          const std::string& padding,
1616
                          std::chrono::milliseconds msec) {
1617
         std::vector<uint8_t> message, signature, bad_signature;
40✔
1618

1619
         Botan::PK_Signer sig(key, rng(), padding, Botan::Signature_Format::Standard, provider);
40✔
1620
         Botan::PK_Verifier ver(key, padding, Botan::Signature_Format::Standard, provider);
40✔
1621

1622
         auto sig_timer = make_timer(nm + " " + padding, provider, "sign");
119✔
1623
         auto ver_timer = make_timer(nm + " " + padding, provider, "verify");
119✔
1624

1625
         size_t invalid_sigs = 0;
40✔
1626

1627
         while(ver_timer->under(msec) || sig_timer->under(msec)) {
167✔
1628
            if(signature.empty() || sig_timer->under(msec)) {
87✔
1629
               /*
1630
               Length here is kind of arbitrary, but 48 bytes fits into a single
1631
               hash block so minimizes hashing overhead versus the PK op itself.
1632
               */
1633
               rng().random_vec(message, 48);
55✔
1634

1635
               signature = sig_timer->run([&]() { return sig.sign_message(message, rng()); });
165✔
1636

1637
               bad_signature = signature;
55✔
1638
               bad_signature[rng().next_byte() % bad_signature.size()] ^= rng().next_nonzero_byte();
55✔
1639
            }
1640

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

1644
               if(!verified) {
74✔
1645
                  invalid_sigs += 1;
×
1646
               }
1647

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

1650
               if(verified_bad) {
74✔
1651
                  error_output() << "Bad signature accepted in " << nm << " signature bench\n";
×
1652
               }
1653
            }
1654
         }
1655

1656
         if(invalid_sigs > 0)
40✔
1657
            error_output() << invalid_sigs << " generated signatures rejected in " << nm << " signature bench\n";
×
1658

1659
         const size_t events = static_cast<size_t>(std::min(sig_timer->events(), ver_timer->events()));
40✔
1660

1661
         record_result(sig_timer);
40✔
1662
         record_result(ver_timer);
40✔
1663

1664
         return events;
80✔
1665
      }
160✔
1666
#endif
1667

1668
#if defined(BOTAN_HAS_RSA)
1669
      void bench_rsa_keygen(const std::string& provider, std::chrono::milliseconds msec) {
1✔
1670
         for(size_t keylen : {1024, 2048, 3072, 4096}) {
5✔
1671
            const std::string nm = "RSA-" + std::to_string(keylen);
4✔
1672
            auto keygen_timer = make_timer(nm, provider, "keygen");
8✔
1673

1674
            while(keygen_timer->under(msec)) {
8✔
1675
               std::unique_ptr<Botan::Private_Key> key(
4✔
1676
                  keygen_timer->run([&] { return Botan::create_private_key("RSA", rng(), std::to_string(keylen)); }));
8✔
1677

1678
               BOTAN_ASSERT(key->check_key(rng(), true), "Key is ok");
4✔
1679
            }
4✔
1680

1681
            record_result(keygen_timer);
4✔
1682
         }
4✔
1683
      }
1✔
1684

1685
      void bench_rsa(const std::string& provider, std::chrono::milliseconds msec) {
1✔
1686
         for(size_t keylen : {1024, 2048, 3072, 4096}) {
5✔
1687
            const std::string nm = "RSA-" + std::to_string(keylen);
4✔
1688

1689
            auto keygen_timer = make_timer(nm, provider, "keygen");
8✔
1690

1691
            std::unique_ptr<Botan::Private_Key> key(
4✔
1692
               keygen_timer->run([&] { return Botan::create_private_key("RSA", rng(), std::to_string(keylen)); }));
8✔
1693

1694
            record_result(keygen_timer);
4✔
1695

1696
            // Using PKCS #1 padding so OpenSSL provider can play along
1697
            bench_pk_sig(*key, nm, provider, "EMSA-PKCS1-v1_5(SHA-256)", msec);
8✔
1698

1699
            //bench_pk_sig(*key, nm, provider, "PSSR(SHA-256)", msec);
1700
            //bench_pk_enc(*key, nm, provider, "EME-PKCS1-v1_5", msec);
1701
            //bench_pk_enc(*key, nm, provider, "OAEP(SHA-1)", msec);
1702
         }
4✔
1703
      }
1✔
1704
#endif
1705

1706
#if defined(BOTAN_HAS_ECDSA)
1707
      void bench_ecdsa(const std::vector<std::string>& groups,
1✔
1708
                       const std::string& provider,
1709
                       std::chrono::milliseconds msec) {
1710
         return bench_pk_sig_ecc("ECDSA", "SHA-256", provider, groups, msec);
2✔
1711
      }
1712

1713
      void bench_ecdsa_recovery(const std::vector<std::string>& groups,
1✔
1714
                                const std::string& /*unused*/,
1715
                                std::chrono::milliseconds msec) {
1716
         for(const std::string& group_name : groups) {
7✔
1717
            Botan::EC_Group group(group_name);
6✔
1718
            auto recovery_timer = make_timer("ECDSA recovery " + group_name);
18✔
1719

1720
            while(recovery_timer->under(msec)) {
12✔
1721
               Botan::ECDSA_PrivateKey key(rng(), group);
6✔
1722

1723
               std::vector<uint8_t> message(group.get_order_bits() / 8);
6✔
1724
               rng().randomize(message.data(), message.size());
6✔
1725

1726
               Botan::PK_Signer signer(key, rng(), "Raw");
6✔
1727
               signer.update(message);
6✔
1728
               std::vector<uint8_t> signature = signer.signature(rng());
6✔
1729

1730
               Botan::PK_Verifier verifier(key, "Raw", Botan::Signature_Format::Standard, "base");
6✔
1731
               verifier.update(message);
6✔
1732
               BOTAN_ASSERT(verifier.check_signature(signature), "Valid signature");
6✔
1733

1734
               Botan::BigInt r(signature.data(), signature.size() / 2);
6✔
1735
               Botan::BigInt s(signature.data() + signature.size() / 2, signature.size() / 2);
6✔
1736

1737
               const uint8_t v = key.recovery_param(message, r, s);
6✔
1738

1739
               recovery_timer->run([&]() {
6✔
1740
                  Botan::ECDSA_PublicKey pubkey(group, message, r, s, v);
6✔
1741
                  BOTAN_ASSERT(pubkey.public_point() == key.public_point(), "Recovered public key");
6✔
1742
               });
6✔
1743
            }
24✔
1744

1745
            record_result(recovery_timer);
6✔
1746
         }
6✔
1747
      }
1✔
1748

1749
#endif
1750

1751
#if defined(BOTAN_HAS_ECKCDSA)
1752
      void bench_eckcdsa(const std::vector<std::string>& groups,
1✔
1753
                         const std::string& provider,
1754
                         std::chrono::milliseconds msec) {
1755
         return bench_pk_sig_ecc("ECKCDSA", "SHA-256", provider, groups, msec);
2✔
1756
      }
1757
#endif
1758

1759
#if defined(BOTAN_HAS_GOST_34_10_2001)
1760
      void bench_gost_3410(const std::string& provider, std::chrono::milliseconds msec) {
1✔
1761
         return bench_pk_sig_ecc("GOST-34.10", "GOST-34.11", provider, {"gost_256A"}, msec);
3✔
1762
      }
1763
#endif
1764

1765
#if defined(BOTAN_HAS_SM2)
1766
      void bench_sm2(const std::vector<std::string>& groups,
1✔
1767
                     const std::string& provider,
1768
                     std::chrono::milliseconds msec) {
1769
         return bench_pk_sig_ecc("SM2_Sig", "SM3", provider, groups, msec);
2✔
1770
      }
1771
#endif
1772

1773
#if defined(BOTAN_HAS_ECGDSA)
1774
      void bench_ecgdsa(const std::vector<std::string>& groups,
1✔
1775
                        const std::string& provider,
1776
                        std::chrono::milliseconds msec) {
1777
         return bench_pk_sig_ecc("ECGDSA", "SHA-256", provider, groups, msec);
2✔
1778
      }
1779
#endif
1780

1781
#if defined(BOTAN_HAS_ED25519)
1782
      void bench_ed25519(const std::string& provider, std::chrono::milliseconds msec) {
1✔
1783
         return bench_pk_sig_ecc("Ed25519", "Pure", provider, std::vector<std::string>{""}, msec);
3✔
1784
      }
1785
#endif
1786

1787
#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
1788
      void bench_dh(const std::string& provider, std::chrono::milliseconds msec) {
1✔
1789
         for(size_t bits : {1024, 1536, 2048, 3072, 4096, 6144, 8192}) {
8✔
1790
            bench_pk_ka("DH", "DH-" + std::to_string(bits), "modp/ietf/" + std::to_string(bits), provider, msec);
14✔
1791
         }
1792
      }
1✔
1793
#endif
1794

1795
#if defined(BOTAN_HAS_DSA)
1796
      void bench_dsa(const std::string& provider, std::chrono::milliseconds msec) {
1✔
1797
         for(size_t bits : {1024, 2048, 3072}) {
4✔
1798
            const std::string nm = "DSA-" + std::to_string(bits);
3✔
1799

1800
            const std::string params = (bits == 1024) ? "dsa/jce/1024" : ("dsa/botan/" + std::to_string(bits));
3✔
1801

1802
            auto keygen_timer = make_timer(nm, provider, "keygen");
6✔
1803

1804
            std::unique_ptr<Botan::Private_Key> key(
3✔
1805
               keygen_timer->run([&] { return Botan::create_private_key("DSA", rng(), params); }));
6✔
1806

1807
            record_result(keygen_timer);
3✔
1808

1809
            bench_pk_sig(*key, nm, provider, "SHA-256", msec);
6✔
1810
         }
3✔
1811
      }
1✔
1812
#endif
1813

1814
#if defined(BOTAN_HAS_ELGAMAL)
1815
      void bench_elgamal(const std::string& provider, std::chrono::milliseconds msec) {
1✔
1816
         for(size_t keylen : {1024, 2048, 3072, 4096}) {
5✔
1817
            const std::string nm = "ElGamal-" + std::to_string(keylen);
4✔
1818

1819
            const std::string params = "modp/ietf/" + std::to_string(keylen);
4✔
1820

1821
            auto keygen_timer = make_timer(nm, provider, "keygen");
8✔
1822

1823
            std::unique_ptr<Botan::Private_Key> key(
4✔
1824
               keygen_timer->run([&] { return Botan::create_private_key("ElGamal", rng(), params); }));
8✔
1825

1826
            record_result(keygen_timer);
4✔
1827

1828
            bench_pk_enc(*key, nm, provider, "EME-PKCS1-v1_5", msec);
8✔
1829
         }
4✔
1830
      }
1✔
1831
#endif
1832

1833
#if defined(BOTAN_HAS_ECDH)
1834
      void bench_ecdh(const std::vector<std::string>& groups,
1✔
1835
                      const std::string& provider,
1836
                      std::chrono::milliseconds msec) {
1837
         for(const std::string& grp : groups) {
7✔
1838
            bench_pk_ka("ECDH", "ECDH-" + grp, grp, provider, msec);
15✔
1839
         }
1840
      }
1✔
1841
#endif
1842

1843
#if defined(BOTAN_HAS_CURVE_25519)
1844
      void bench_curve25519(const std::string& provider, std::chrono::milliseconds msec) {
1✔
1845
         bench_pk_ka("Curve25519", "Curve25519", "", provider, msec);
2✔
1846
      }
1✔
1847
#endif
1848

1849
#if defined(BOTAN_HAS_MCELIECE)
1850
      void bench_mceliece(const std::string& provider, std::chrono::milliseconds msec) {
1✔
1851
         /*
1852
         SL=80 n=1632 t=33 - 59 KB pubkey 140 KB privkey
1853
         SL=107 n=2480 t=45 - 128 KB pubkey 300 KB privkey
1854
         SL=128 n=2960 t=57 - 195 KB pubkey 459 KB privkey
1855
         SL=147 n=3408 t=67 - 265 KB pubkey 622 KB privkey
1856
         SL=191 n=4624 t=95 - 516 KB pubkey 1234 KB privkey
1857
         SL=256 n=6624 t=115 - 942 KB pubkey 2184 KB privkey
1858
         */
1859

1860
         const std::vector<std::pair<size_t, size_t>> mce_params = {
1✔
1861
            {2480, 45}, {2960, 57}, {3408, 67}, {4624, 95}, {6624, 115}};
1✔
1862

1863
         for(auto params : mce_params) {
6✔
1864
            size_t n = params.first;
5✔
1865
            size_t t = params.second;
5✔
1866

1867
            const std::string nm = "McEliece-" + std::to_string(n) + "," + std::to_string(t) +
10✔
1868
                                   " (WF=" + std::to_string(Botan::mceliece_work_factor(n, t)) + ")";
15✔
1869

1870
            auto keygen_timer = make_timer(nm, provider, "keygen");
10✔
1871

1872
            std::unique_ptr<Botan::Private_Key> key =
5✔
1873
               keygen_timer->run([&] { return std::make_unique<Botan::McEliece_PrivateKey>(rng(), n, t); });
10✔
1874

1875
            record_result(keygen_timer);
5✔
1876
            bench_pk_kem(*key, nm, provider, "KDF2(SHA-256)", msec);
10✔
1877
         }
10✔
1878
      }
1✔
1879
#endif
1880

1881
#if defined(BOTAN_HAS_KYBER) || defined(BOTAN_HAS_KYBER_90S)
1882
      void bench_kyber(const std::string& provider, std::chrono::milliseconds msec) {
1✔
1883
         const Botan::KyberMode::Mode all_modes[] = {
1✔
1884
            Botan::KyberMode::Kyber512,
1885
            Botan::KyberMode::Kyber512_90s,
1886
            Botan::KyberMode::Kyber768,
1887
            Botan::KyberMode::Kyber768_90s,
1888
            Botan::KyberMode::Kyber1024,
1889
            Botan::KyberMode::Kyber1024_90s,
1890
         };
1891

1892
         for(auto modet : all_modes) {
7✔
1893
            Botan::KyberMode mode(modet);
6✔
1894

1895
   #if !defined(BOTAN_HAS_KYBER)
1896
            if(mode.is_modern())
1897
               continue;
1898
   #endif
1899

1900
   #if !defined(BOTAN_HAS_KYBER_90S)
1901
            if(mode.is_90s())
1902
               continue;
1903
   #endif
1904

1905
            auto keygen_timer = make_timer(mode.to_string(), provider, "keygen");
15✔
1906

1907
            auto key = keygen_timer->run([&] { return Botan::Kyber_PrivateKey(rng(), mode); });
12✔
1908

1909
            record_result(keygen_timer);
6✔
1910

1911
            bench_pk_kem(key, mode.to_string(), provider, "KDF2(SHA-256)", msec);
12✔
1912
         }
6✔
1913
      }
1✔
1914
#endif
1915

1916
#if defined(BOTAN_HAS_DILITHIUM) || defined(BOTAN_HAS_DILITHIUM_AES)
1917
      void bench_dilithium(const std::string& provider, std::chrono::milliseconds msec) {
1✔
1918
         const Botan::DilithiumMode::Mode all_modes[] = {Botan::DilithiumMode::Dilithium4x4,
1✔
1919
                                                         Botan::DilithiumMode::Dilithium4x4_AES,
1920
                                                         Botan::DilithiumMode::Dilithium6x5,
1921
                                                         Botan::DilithiumMode::Dilithium6x5_AES,
1922
                                                         Botan::DilithiumMode::Dilithium8x7,
1923
                                                         Botan::DilithiumMode::Dilithium8x7_AES};
1924

1925
         for(auto modet : all_modes) {
7✔
1926
            Botan::DilithiumMode mode(modet);
6✔
1927

1928
   #if !defined(BOTAN_HAS_DILITHIUM)
1929
            if(mode.is_modern())
1930
               continue;
1931
   #endif
1932

1933
   #if !defined(BOTAN_HAS_DILITHIUM_AES)
1934
            if(mode.is_aes())
1935
               continue;
1936
   #endif
1937

1938
            auto keygen_timer = make_timer(mode.to_string(), provider, "keygen");
18✔
1939

1940
            auto key = keygen_timer->run([&] { return Botan::Dilithium_PrivateKey(rng(), mode); });
12✔
1941

1942
            record_result(keygen_timer);
6✔
1943

1944
            bench_pk_sig(key, mode.to_string(), provider, "", msec);
12✔
1945
         }
6✔
1946
      }
1✔
1947
#endif
1948

1949
#if defined(BOTAN_HAS_XMSS_RFC8391)
1950
      void bench_xmss(const std::string& provider, std::chrono::milliseconds msec) {
1✔
1951
         /*
1952
         We only test H10 signatures here since already they are quite slow (a
1953
         few seconds per signature). On a fast machine, H16 signatures take 1-2
1954
         minutes to generate and H20 signatures take 5-10 minutes to generate
1955
         */
1956
         std::vector<std::string> xmss_params{
1✔
1957
            "XMSS-SHA2_10_256",
1958
            "XMSS-SHAKE_10_256",
1959
            "XMSS-SHA2_10_512",
1960
            "XMSS-SHAKE_10_512",
1961
         };
5✔
1962

1963
         for(std::string params : xmss_params) {
1✔
1964
            auto keygen_timer = make_timer(params, provider, "keygen");
2✔
1965

1966
            std::unique_ptr<Botan::Private_Key> key(
1✔
1967
               keygen_timer->run([&] { return Botan::create_private_key("XMSS", rng(), params); }));
2✔
1968

1969
            record_result(keygen_timer);
1✔
1970
            if(bench_pk_sig(*key, params, provider, "", msec) == 1)
1✔
1971
               break;
1972
         }
2✔
1973
      }
1✔
1974
#endif
1975

1976
#if defined(BOTAN_HAS_ZFEC)
1977
      void bench_zfec(std::chrono::milliseconds msec) {
1✔
1978
         const size_t k = 4;
1✔
1979
         const size_t n = 16;
1✔
1980

1981
         Botan::ZFEC zfec(k, n);
1✔
1982

1983
         const size_t share_size = 256 * 1024;
1✔
1984

1985
         std::vector<uint8_t> input(share_size * k);
1✔
1986
         rng().randomize(input.data(), input.size());
1✔
1987

1988
         std::vector<uint8_t> output(share_size * n);
1✔
1989

1990
         auto enc_fn = [&](size_t share, const uint8_t buf[], size_t len) {
17✔
1991
            std::memcpy(&output[share * share_size], buf, len);
16✔
1992
         };
1✔
1993

1994
         auto enc_timer =
1✔
1995
            make_timer("zfec " + std::to_string(k) + "/" + std::to_string(n), input.size(), "encode", "", input.size());
2✔
1996

1997
         enc_timer->run_until_elapsed(msec, [&]() { zfec.encode(input.data(), input.size(), enc_fn); });
3✔
1998

1999
         record_result(enc_timer);
1✔
2000

2001
         auto dec_timer =
1✔
2002
            make_timer("zfec " + std::to_string(k) + "/" + std::to_string(n), input.size(), "decode", "", input.size());
2✔
2003

2004
         std::map<size_t, const uint8_t*> shares;
1✔
2005
         for(size_t i = 0; i != n; ++i) {
17✔
2006
            shares[i] = &output[share_size * i];
16✔
2007
         }
2008

2009
         // remove data shares to make decoding maximally expensive:
2010
         while(shares.size() != k) {
13✔
2011
            shares.erase(shares.begin());
12✔
2012
         }
2013

2014
         std::vector<uint8_t> recovered(share_size * k);
1✔
2015

2016
         auto dec_fn = [&](size_t share, const uint8_t buf[], size_t len) {
5✔
2017
            std::memcpy(&recovered[share * share_size], buf, len);
4✔
2018
         };
1✔
2019

2020
         dec_timer->run_until_elapsed(msec, [&]() { zfec.decode_shares(shares, share_size, dec_fn); });
3✔
2021

2022
         record_result(dec_timer);
1✔
2023

2024
         if(recovered != input) {
1✔
2025
            error_output() << "ZFEC recovery failed\n";
×
2026
         }
2027
      }
4✔
2028

2029
#endif
2030

2031
#if defined(BOTAN_HAS_POLY_DBL)
2032
      void bench_poly_dbl(std::chrono::milliseconds msec) {
1✔
2033
         for(size_t sz : {8, 16, 24, 32, 64, 128}) {
7✔
2034
            auto be_timer = make_timer("poly_dbl_be_" + std::to_string(sz));
12✔
2035
            auto le_timer = make_timer("poly_dbl_le_" + std::to_string(sz));
12✔
2036

2037
            std::vector<uint8_t> buf(sz);
6✔
2038
            rng().randomize(buf.data(), sz);
6✔
2039

2040
            be_timer->run_until_elapsed(msec, [&]() { Botan::poly_double_n(buf.data(), buf.data(), sz); });
18,056✔
2041
            le_timer->run_until_elapsed(msec, [&]() { Botan::poly_double_n_le(buf.data(), buf.data(), sz); });
20,694✔
2042

2043
            record_result(be_timer);
6✔
2044
            record_result(le_timer);
6✔
2045
         }
6✔
2046
      }
1✔
2047
#endif
2048

2049
#if defined(BOTAN_HAS_BCRYPT)
2050

2051
      void bench_bcrypt() {
1✔
2052
         const std::string password = "not a very good password";
1✔
2053

2054
         for(uint8_t work_factor = 4; work_factor <= 14; ++work_factor) {
12✔
2055
            auto timer = make_timer("bcrypt wf=" + std::to_string(work_factor));
22✔
2056

2057
            timer->run([&] { Botan::generate_bcrypt(password, rng(), work_factor); });
22✔
2058

2059
            record_result(timer);
11✔
2060
         }
11✔
2061
      }
1✔
2062
#endif
2063

2064
#if defined(BOTAN_HAS_PASSHASH9)
2065

2066
      void bench_passhash9() {
1✔
2067
         const std::string password = "not a very good password";
1✔
2068

2069
         for(uint8_t alg = 0; alg <= 4; ++alg) {
6✔
2070
            if(Botan::is_passhash9_alg_supported(alg) == false)
5✔
2071
               continue;
×
2072

2073
            for(auto work_factor : {10, 15}) {
15✔
2074
               auto timer = make_timer("passhash9 alg=" + std::to_string(alg) + " wf=" + std::to_string(work_factor));
30✔
2075

2076
               timer->run([&] { Botan::generate_passhash9(password, rng(), static_cast<uint8_t>(work_factor), alg); });
20✔
2077

2078
               record_result(timer);
10✔
2079
            }
10✔
2080
         }
2081
      }
1✔
2082
#endif
2083

2084
#if defined(BOTAN_HAS_SCRYPT)
2085

2086
      void bench_scrypt(const std::string& /*provider*/, std::chrono::milliseconds msec) {
1✔
2087
         auto pwdhash_fam = Botan::PasswordHashFamily::create_or_throw("Scrypt");
1✔
2088

2089
         for(size_t N : {8192, 16384, 32768, 65536}) {
5✔
2090
            for(size_t r : {1, 8, 16}) {
16✔
2091
               for(size_t p : {1}) {
12✔
2092
                  auto pwdhash = pwdhash_fam->from_params(N, r, p);
12✔
2093

2094
                  auto scrypt_timer =
12✔
2095
                     make_timer("scrypt-" + std::to_string(N) + "-" + std::to_string(r) + "-" + std::to_string(p) +
24✔
2096
                                " (" + std::to_string(pwdhash->total_memory_usage() / (1024 * 1024)) + " MiB)");
60✔
2097

2098
                  uint8_t out[64];
12✔
2099
                  uint8_t salt[8];
12✔
2100
                  rng().randomize(salt, sizeof(salt));
12✔
2101

2102
                  while(scrypt_timer->under(msec)) {
24✔
2103
                     scrypt_timer->run([&] {
12✔
2104
                        pwdhash->derive_key(out, sizeof(out), "password", 8, salt, sizeof(salt));
12✔
2105

2106
                        Botan::copy_mem(salt, out, 8);
12✔
2107
                     });
12✔
2108
                  }
2109

2110
                  record_result(scrypt_timer);
12✔
2111

2112
                  if(scrypt_timer->events() == 1)
12✔
2113
                     break;
2114
               }
24✔
2115
            }
2116
         }
2117
      }
1✔
2118

2119
#endif
2120

2121
#if defined(BOTAN_HAS_ARGON2)
2122

2123
      void bench_argon2(const std::string& /*provider*/, std::chrono::milliseconds msec) {
1✔
2124
         auto pwhash_fam = Botan::PasswordHashFamily::create_or_throw("Argon2id");
1✔
2125

2126
         for(size_t M : {8 * 1024, 64 * 1024, 256 * 1024}) {
4✔
2127
            for(size_t t : {1, 4}) {
9✔
2128
               for(size_t p : {1, 4}) {
18✔
2129
                  auto pwhash = pwhash_fam->from_params(M, t, p);
12✔
2130
                  auto timer = make_timer(pwhash->to_string());
36✔
2131

2132
                  uint8_t out[64];
12✔
2133
                  uint8_t salt[16];
12✔
2134
                  rng().randomize(salt, sizeof(salt));
12✔
2135

2136
                  while(timer->under(msec)) {
24✔
2137
                     timer->run([&] { pwhash->derive_key(out, sizeof(out), "password", 8, salt, sizeof(salt)); });
24✔
2138
                  }
2139

2140
                  record_result(timer);
12✔
2141
               }
24✔
2142
            }
2143
         }
2144
      }
1✔
2145

2146
#endif
2147
};
2148

2149
BOTAN_REGISTER_COMMAND("speed", Speed);
35✔
2150

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

© 2025 Coveralls, Inc