• 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

26.44
/src/cli/perf_pwdhash.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
#include <botan/internal/fmt.h>
10
#include <array>
11

12
#if defined(BOTAN_HAS_PASSWORD_HASHING)
13
   #include <botan/pwdhash.h>
14
   #include <botan/rng.h>
15
   #include <cstring>
16
#endif
17

18
#if defined(BOTAN_HAS_BCRYPT)
19
   #include <botan/bcrypt.h>
20
#endif
21

22
#if defined(BOTAN_HAS_PASSHASH9)
23
   #include <botan/passhash9.h>
24
#endif
25

26
namespace Botan_CLI {
27

28
namespace {
29

30
#if defined(BOTAN_HAS_BCRYPT)
31

32
class PerfTest_Bcrypt final : public PerfTest {
×
33
   public:
34
      void go(const PerfConfig& config) override {
×
35
         const std::string password = "not a very good password";
×
36

37
         for(size_t work_factor = 4; work_factor <= 14; ++work_factor) {
×
38
            auto timer = config.make_timer(Botan::fmt("bcrypt wf={}", work_factor));
×
39

40
            timer->run([&] { Botan::generate_bcrypt(password, config.rng(), static_cast<uint16_t>(work_factor)); });
×
41

42
            config.record_result(*timer);
×
43
         }
×
44
      }
×
45
};
46

47
BOTAN_REGISTER_PERF_TEST("bcrypt", PerfTest_Bcrypt);
×
48

49
#endif
50

51
#if defined(BOTAN_HAS_PASSHASH9)
52

53
class PerfTest_Passhash9 final : public PerfTest {
×
54
   public:
55
      void go(const PerfConfig& config) override {
×
56
         const std::string password = "not a very good password";
×
57

58
         for(uint8_t alg = 0; alg <= 4; ++alg) {
×
59
            if(!Botan::is_passhash9_alg_supported(alg)) {
×
60
               continue;
×
61
            }
62

63
            for(auto work_factor : {10, 15}) {
×
64
               auto timer = config.make_timer(Botan::fmt("passhash9 alg={} wf={}", alg, work_factor));
×
65

66
               timer->run(
×
67
                  [&] { Botan::generate_passhash9(password, config.rng(), static_cast<uint8_t>(work_factor), alg); });
×
68

69
               config.record_result(*timer);
×
70
            }
×
71
         }
72
      }
×
73
};
74

75
BOTAN_REGISTER_PERF_TEST("passhash9", PerfTest_Passhash9);
×
76

77
#endif
78

79
#if defined(BOTAN_HAS_SCRYPT)
80

81
class PerfTest_Scrypt final : public PerfTest {
1✔
82
   public:
83
      void go(const PerfConfig& config) override {
1✔
84
         auto pwdhash_fam = Botan::PasswordHashFamily::create_or_throw("Scrypt");
1✔
85

86
         for(const size_t N : {8192, 16384, 32768, 65536}) {
5✔
87
            for(const size_t r : {1, 8, 16}) {
16✔
88
               for(const size_t p : {1}) {
12✔
89
                  auto pwdhash = pwdhash_fam->from_params(N, r, p);
12✔
90

91
                  const size_t mem_usage = pwdhash->total_memory_usage() / (1024 * 1024);
12✔
92
                  auto scrypt_timer = config.make_timer(Botan::fmt("scrypt-{}-{}-{} ({} MiB)", N, r, p, mem_usage));
24✔
93

94
                  uint8_t out[64];
12✔
95
                  uint8_t salt[8];
12✔
96
                  config.rng().randomize(salt, sizeof(salt));
12✔
97

98
                  auto runtime = config.runtime();
12✔
99

100
                  while(scrypt_timer->under(runtime)) {
24✔
101
                     scrypt_timer->run([&] {
12✔
102
                        pwdhash->derive_key(out, sizeof(out), "password", 8, salt, sizeof(salt));
12✔
103
                        std::memcpy(salt, out, 8);
12✔
104
                     });
12✔
105
                  }
106

107
                  config.record_result(*scrypt_timer);
12✔
108

109
                  if(scrypt_timer->events() == 1) {
12✔
110
                     break;
111
                  }
112
               }
24✔
113
            }
114
         }
115
      }
1✔
116
};
117

118
BOTAN_REGISTER_PERF_TEST("scrypt", PerfTest_Scrypt);
1✔
119

120
#endif
121

122
#if defined(BOTAN_HAS_PBKDF2) && defined(BOTAN_HAS_PASSWORD_HASHING)
123

124
class PerfTest_PBKDF2 final : public PerfTest {
×
125
   public:
126
      void go(const PerfConfig& config) override {
×
127
         const std::string hash = "SHA-256";
×
128
         auto pwdhash_fam = Botan::PasswordHashFamily::create(Botan::fmt("PBKDF2({})", hash));
×
129

130
         if(pwdhash_fam != nullptr) {
×
131
            for(const size_t iter : {10000, 100000}) {
×
132
               auto pwdhash = pwdhash_fam->from_params(iter);
×
133

134
               auto pbkdf2_timer = config.make_timer(Botan::fmt("PBKDF2({},{})", hash, iter));
×
135

136
               std::array<uint8_t, 16> salt{};
×
137
               config.rng().randomize(salt);
×
138

139
               const std::string password = "password";
×
140
               auto runtime = config.runtime();
×
141

142
               std::array<uint8_t, 32> out{};
×
143

144
               while(pbkdf2_timer->under(runtime)) {
×
145
                  pbkdf2_timer->run([&] {
×
146
                     pwdhash->hash(out, password, salt);
×
147
                     std::memcpy(salt.data(), out.data(), 8);
×
148
                  });
×
149
               }
150

151
               config.record_result(*pbkdf2_timer);
×
152
            }
×
153
         }
154
      }
×
155
};
156

157
BOTAN_REGISTER_PERF_TEST("pbkdf2", PerfTest_PBKDF2);
×
158

159
#endif
160

161
#if defined(BOTAN_HAS_ARGON2)
162

163
class PerfTest_Argon2 final : public PerfTest {
×
164
   public:
165
      void go(const PerfConfig& config) override {
×
166
         auto pwhash_fam = Botan::PasswordHashFamily::create_or_throw("Argon2id");
×
167

168
         const auto msec = config.runtime();
×
169

170
         for(const size_t M : {8 * 1024, 64 * 1024, 256 * 1024}) {
×
171
            for(const size_t t : {1, 4}) {
×
172
               for(const size_t p : {1, 4}) {
×
173
                  auto pwhash = pwhash_fam->from_params(M, t, p);
×
174
                  auto timer = config.make_timer(pwhash->to_string());
×
175

176
                  uint8_t out[64];
×
177
                  uint8_t salt[16];
×
178
                  config.rng().randomize(salt, sizeof(salt));
×
179

180
                  while(timer->under(msec)) {
×
181
                     timer->run([&] { pwhash->derive_key(out, sizeof(out), "password", 8, salt, sizeof(salt)); });
×
182
                  }
183

184
                  config.record_result(*timer);
×
185
               }
×
186
            }
187
         }
188
      }
×
189
};
190

191
BOTAN_REGISTER_PERF_TEST("argon2", PerfTest_Argon2);
×
192

193
#endif
194

195
}  // namespace
196

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