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

randombit / botan / 20579846577

29 Dec 2025 06:24PM UTC coverage: 90.415% (+0.2%) from 90.243%
20579846577

push

github

web-flow
Merge pull request #5167 from randombit/jack/src-size-reductions

Changes to reduce unnecessary inclusions

101523 of 112285 relevant lines covered (90.42%)

12817276.56 hits per line

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

98.46
/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 <cstring>
12
#endif
13

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

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

22
namespace Botan_CLI {
23

24
#if defined(BOTAN_HAS_BCRYPT)
25

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

31
         for(size_t work_factor = 4; work_factor <= 14; ++work_factor) {
12✔
32
            auto timer = config.make_timer(Botan::fmt("bcrypt wf={}", work_factor));
22✔
33

34
            timer->run([&] { Botan::generate_bcrypt(password, config.rng(), static_cast<uint16_t>(work_factor)); });
22✔
35

36
            config.record_result(*timer);
22✔
37
         }
11✔
38
      }
1✔
39
};
40

41
BOTAN_REGISTER_PERF_TEST("bcrypt", PerfTest_Bcrypt);
1✔
42

43
#endif
44

45
#if defined(BOTAN_HAS_PASSHASH9)
46

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

52
         for(uint8_t alg = 0; alg <= 4; ++alg) {
6✔
53
            if(!Botan::is_passhash9_alg_supported(alg)) {
5✔
54
               continue;
×
55
            }
56

57
            for(auto work_factor : {10, 15}) {
15✔
58
               auto timer = config.make_timer(Botan::fmt("passhash9 alg={} wf={}", alg, work_factor));
20✔
59

60
               timer->run(
10✔
61
                  [&] { Botan::generate_passhash9(password, config.rng(), static_cast<uint8_t>(work_factor), alg); });
10✔
62

63
               config.record_result(*timer);
20✔
64
            }
10✔
65
         }
66
      }
1✔
67
};
68

69
BOTAN_REGISTER_PERF_TEST("passhash9", PerfTest_Passhash9);
1✔
70

71
#endif
72

73
#if defined(BOTAN_HAS_SCRYPT)
74

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

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

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

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

92
                  auto runtime = config.runtime();
12✔
93

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

101
                  config.record_result(*scrypt_timer);
12✔
102

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

112
BOTAN_REGISTER_PERF_TEST("scrypt", PerfTest_Scrypt);
1✔
113

114
#endif
115

116
#if defined(BOTAN_HAS_ARGON2)
117

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

123
         const auto msec = config.runtime();
1✔
124

125
         for(const size_t M : {8 * 1024, 64 * 1024, 256 * 1024}) {
4✔
126
            for(const size_t t : {1, 4}) {
9✔
127
               for(const size_t p : {1, 4}) {
18✔
128
                  auto pwhash = pwhash_fam->from_params(M, t, p);
12✔
129
                  auto timer = config.make_timer(pwhash->to_string());
24✔
130

131
                  uint8_t out[64];
12✔
132
                  uint8_t salt[16];
12✔
133
                  config.rng().randomize(salt, sizeof(salt));
12✔
134

135
                  while(timer->under(msec)) {
24✔
136
                     timer->run([&] { pwhash->derive_key(out, sizeof(out), "password", 8, salt, sizeof(salt)); });
24✔
137
                  }
138

139
                  config.record_result(*timer);
24✔
140
               }
24✔
141
            }
142
         }
143
      }
1✔
144
};
145

146
BOTAN_REGISTER_PERF_TEST("argon2", PerfTest_Argon2);
1✔
147

148
#endif
149

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