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

randombit / botan / 21780928802

07 Feb 2026 01:36PM UTC coverage: 90.068% (+0.003%) from 90.065%
21780928802

Pull #5295

github

web-flow
Merge cbabeb61a into ebf8f0044
Pull Request #5295: Reduce header dependencies in tests and cli

102234 of 113508 relevant lines covered (90.07%)

11464546.51 hits per line

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

35.38
/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
#if defined(BOTAN_HAS_PASSWORD_HASHING)
10
   #include <botan/pwdhash.h>
11
   #include <botan/rng.h>
12
   #include <botan/internal/fmt.h>
13
   #include <cstring>
14
#endif
15

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

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

24
namespace Botan_CLI {
25

26
#if defined(BOTAN_HAS_BCRYPT)
27

28
class PerfTest_Bcrypt final : public PerfTest {
×
29
   public:
30
      void go(const PerfConfig& config) override {
×
31
         const std::string password = "not a very good password";
×
32

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

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

38
            config.record_result(*timer);
×
39
         }
×
40
      }
×
41
};
42

43
BOTAN_REGISTER_PERF_TEST("bcrypt", PerfTest_Bcrypt);
×
44

45
#endif
46

47
#if defined(BOTAN_HAS_PASSHASH9)
48

49
class PerfTest_Passhash9 final : public PerfTest {
×
50
   public:
51
      void go(const PerfConfig& config) override {
×
52
         const std::string password = "not a very good password";
×
53

54
         for(uint8_t alg = 0; alg <= 4; ++alg) {
×
55
            if(!Botan::is_passhash9_alg_supported(alg)) {
×
56
               continue;
×
57
            }
58

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

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

65
               config.record_result(*timer);
×
66
            }
×
67
         }
68
      }
×
69
};
70

71
BOTAN_REGISTER_PERF_TEST("passhash9", PerfTest_Passhash9);
×
72

73
#endif
74

75
#if defined(BOTAN_HAS_SCRYPT)
76

77
class PerfTest_Scrypt final : public PerfTest {
1✔
78
   public:
79
      void go(const PerfConfig& config) override {
1✔
80
         auto pwdhash_fam = Botan::PasswordHashFamily::create_or_throw("Scrypt");
1✔
81

82
         for(const size_t N : {8192, 16384, 32768, 65536}) {
5✔
83
            for(const size_t r : {1, 8, 16}) {
16✔
84
               for(const size_t p : {1}) {
12✔
85
                  auto pwdhash = pwdhash_fam->from_params(N, r, p);
12✔
86

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

90
                  uint8_t out[64];
12✔
91
                  uint8_t salt[8];
12✔
92
                  config.rng().randomize(salt, sizeof(salt));
12✔
93

94
                  auto runtime = config.runtime();
12✔
95

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

103
                  config.record_result(*scrypt_timer);
12✔
104

105
                  if(scrypt_timer->events() == 1) {
12✔
106
                     break;
107
                  }
108
               }
24✔
109
            }
110
         }
111
      }
1✔
112
};
113

114
BOTAN_REGISTER_PERF_TEST("scrypt", PerfTest_Scrypt);
1✔
115

116
#endif
117

118
#if defined(BOTAN_HAS_ARGON2)
119

120
class PerfTest_Argon2 final : public PerfTest {
×
121
   public:
122
      void go(const PerfConfig& config) override {
×
123
         auto pwhash_fam = Botan::PasswordHashFamily::create_or_throw("Argon2id");
×
124

125
         const auto msec = config.runtime();
×
126

127
         for(const size_t M : {8 * 1024, 64 * 1024, 256 * 1024}) {
×
128
            for(const size_t t : {1, 4}) {
×
129
               for(const size_t p : {1, 4}) {
×
130
                  auto pwhash = pwhash_fam->from_params(M, t, p);
×
131
                  auto timer = config.make_timer(pwhash->to_string());
×
132

133
                  uint8_t out[64];
×
134
                  uint8_t salt[16];
×
135
                  config.rng().randomize(salt, sizeof(salt));
×
136

137
                  while(timer->under(msec)) {
×
138
                     timer->run([&] { pwhash->derive_key(out, sizeof(out), "password", 8, salt, sizeof(salt)); });
×
139
                  }
140

141
                  config.record_result(*timer);
×
142
               }
×
143
            }
144
         }
145
      }
×
146
};
147

148
BOTAN_REGISTER_PERF_TEST("argon2", PerfTest_Argon2);
×
149

150
#endif
151

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