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

randombit / botan / 21885850724

10 Feb 2026 11:05PM UTC coverage: 91.638% (+1.6%) from 90.068%
21885850724

push

github

web-flow
Merge pull request #5310 from randombit/jack/fix-build-deps

Fix some build dependency issues

104006 of 113497 relevant lines covered (91.64%)

11190952.72 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
#include <botan/internal/fmt.h>
10

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

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

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

25
namespace Botan_CLI {
26

27
#if defined(BOTAN_HAS_BCRYPT)
28

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

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

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

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

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

46
#endif
47

48
#if defined(BOTAN_HAS_PASSHASH9)
49

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

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

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

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

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

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

74
#endif
75

76
#if defined(BOTAN_HAS_SCRYPT)
77

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

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

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

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

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

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

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

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

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

117
#endif
118

119
#if defined(BOTAN_HAS_ARGON2)
120

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

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

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

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

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

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

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

151
#endif
152

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