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

randombit / botan / 23225340130

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

push

github

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

Fix various warnings from clang-tidy 22

104438 of 116460 relevant lines covered (89.68%)

11819947.55 hits per line

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

97.87
/src/cli/perf_pk_enc.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
   #include <botan/rng.h>
13
   #include <botan/internal/fmt.h>
14
#endif
15

16
namespace Botan_CLI {
17

18
namespace {
19

20
#if defined(BOTAN_HAS_PUBLIC_KEY_CRYPTO)
21

22
class PerfTest_PKEnc : public PerfTest {
1✔
23
   public:
24
      virtual std::string algo() const = 0;
25

26
      virtual std::vector<std::string> keygen_params(const PerfConfig& /*config*/) const { return {""}; }
27

28
      void go(const PerfConfig& config) override {
1✔
29
         const std::string alg = this->algo();
2✔
30

31
         const auto params = this->keygen_params(config);
1✔
32

33
         for(const auto& param : params) {
5✔
34
            const std::string nm = this->format_name(alg, param);
4✔
35
            bench_pk_ka(config, nm, alg, param);
8✔
36
         }
4✔
37
      }
1✔
38

39
      static void bench_pk_ka(const PerfConfig& config,
4✔
40
                              const std::string& nm,
41
                              const std::string& algo,
42
                              const std::string& params,
43
                              const std::string& provider = "") {
44
         auto& rng = config.rng();
4✔
45
         const auto msec = config.runtime();
4✔
46

47
         std::vector<uint8_t> plaintext;
4✔
48
         std::vector<uint8_t> ciphertext;
4✔
49

50
         auto keygen_timer = config.make_timer(nm, 1, "keygen");
8✔
51

52
         auto sk = keygen_timer->run([&] { return Botan::create_private_key(algo, rng, params); });
8✔
53

54
         if(sk) {
4✔
55
            while(keygen_timer->under(msec)) {
8✔
56
               sk = keygen_timer->run([&] { return Botan::create_private_key(algo, rng, params); });
12✔
57
            }
58

59
            auto pk = sk->public_key();
4✔
60

61
            // TODO this would have to be generalized for anything but RSA/ElGamal
62
            const std::string padding = "PKCS1v15";
4✔
63

64
            Botan::PK_Encryptor_EME enc(*pk, rng, padding, provider);
4✔
65
            Botan::PK_Decryptor_EME dec(*sk, rng, padding, provider);
4✔
66

67
            auto enc_timer = config.make_timer(nm + " " + padding, 1, "encrypt");
8✔
68
            auto dec_timer = config.make_timer(nm + " " + padding, 1, "decrypt");
8✔
69

70
            while(enc_timer->under(msec) || dec_timer->under(msec)) {
12✔
71
               // Generate a new random ciphertext to decrypt
72
               if(ciphertext.empty() || enc_timer->under(msec)) {
4✔
73
                  rng.random_vec(plaintext, enc.maximum_input_size());
4✔
74
                  ciphertext = enc_timer->run([&]() { return enc.encrypt(plaintext, rng); });
16✔
75
               }
76

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

80
                  // sanity check
81
                  if(!(Botan::unlock(dec_pt) == plaintext)) {
8✔
82
                     config.error_output() << "Bad roundtrip in PK encrypt/decrypt bench\n";
×
83
                  }
84
               }
4✔
85
            }
86

87
            config.record_result(*keygen_timer);
4✔
88
            config.record_result(*enc_timer);
4✔
89
            config.record_result(*dec_timer);
8✔
90
         }
8✔
91
      }
12✔
92
};
93

94
#endif
95

96
#if defined(BOTAN_HAS_ELGAMAL)
97

98
class PerfTest_ElGamal final : public PerfTest_PKEnc {
1✔
99
   public:
100
      std::string algo() const override { return "ElGamal"; }
1✔
101

102
      std::vector<std::string> keygen_params(const PerfConfig& /*config*/) const override {
1✔
103
         return {
1✔
104
            "modp/ietf/1024",
105
            "modp/ietf/2048",
106
            "modp/ietf/3072",
107
            "modp/ietf/4096",
108
         };
1✔
109
      }
110

111
      std::string format_name(const std::string& alg, const std::string& param) const override {
4✔
112
         return Botan::fmt("{}-{}", alg, param.substr(param.find_last_of('/') + 1));
8✔
113
      }
114
};
115

116
BOTAN_REGISTER_PERF_TEST("ElGamal", PerfTest_ElGamal);
1✔
117

118
#endif
119

120
}  // namespace
121

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