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

randombit / botan / 26995937053

04 Jun 2026 09:38PM UTC coverage: 89.394% (-2.3%) from 91.672%
26995937053

push

github

web-flow
Merge pull request #5642 from randombit/jack/prefetch-in-ks

Improve prefetching for table based implementations

110588 of 123708 relevant lines covered (89.39%)

11056434.37 hits per line

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

94.29
/src/cli/pbkdf.cpp
1
/*
2
* (C) 2018 Ribose Inc
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "cli.h"
8

9
#if defined(BOTAN_HAS_PASSWORD_HASHING)
10
   #include <botan/pwdhash.h>
11
   #include <botan/internal/parsing.h>
12
#endif
13

14
#if defined(BOTAN_HAS_OS_UTILS)
15
   #include <botan/internal/os_utils.h>
16
#endif
17

18
namespace Botan_CLI {
19

20
namespace {
21

22
#if defined(BOTAN_HAS_PASSWORD_HASHING)
23

24
class PBKDF_Tune final : public Command {
25
   public:
26
      PBKDF_Tune() : Command("pbkdf_tune --algo=Scrypt --max-mem=256 --tune-msec=10 --output-len=32 --check *times") {}
8✔
27

28
      std::string group() const override { return "passhash"; }
1✔
29

30
      std::string description() const override { return "Tune a PBKDF algo"; }
1✔
31

32
      void go() override {
3✔
33
         const size_t output_len = get_arg_sz("output-len");
3✔
34
         const size_t max_mem = get_arg_sz("max-mem");
3✔
35
         const size_t tune_msec = get_arg_sz("tune-msec");
3✔
36
         const std::string algo = get_arg("algo");
3✔
37
         const bool check_time = flag_set("check");
3✔
38

39
         auto pwdhash_fam = Botan::PasswordHashFamily::create(algo);
3✔
40

41
         if(!pwdhash_fam) {
3✔
42
            throw CLI_Error_Unsupported("Password hashing", algo);
×
43
         }
44

45
         for(const std::string& time : get_arg_list("times")) {
15✔
46
            std::unique_ptr<Botan::PasswordHash> pwhash;
12✔
47

48
            if(time == "default") {
12✔
49
               pwhash = pwdhash_fam->default_params();
3✔
50
            } else {
51
               if(const auto desired_runtime_msec = Botan::parse_sz(time)) {
9✔
52
                  pwhash = pwdhash_fam->tune_params(output_len, *desired_runtime_msec, max_mem, tune_msec);
9✔
53
               } else {
54
                  throw CLI_Usage_Error("Unknown time value '" + time + "' for pbkdf_tune");
×
55
               }
56
            }
57

58
            output() << "For " << time << " ms selected " << pwhash->to_string();
24✔
59

60
            if(pwhash->total_memory_usage() > 0) {
12✔
61
               output() << " using " << pwhash->total_memory_usage() / (1024 * 1024) << " MiB";
8✔
62
            }
63

64
            if(check_time) {
12✔
65
   #if defined(BOTAN_HAS_OS_UTILS)
66
               std::vector<uint8_t> outbuf(output_len);
12✔
67
               const uint8_t salt[8] = {0};
12✔
68

69
               const uint64_t start_ns = Botan::OS::get_system_timestamp_ns();
12✔
70
               pwhash->derive_key(outbuf.data(), outbuf.size(), "test", 4, salt, sizeof(salt));
12✔
71
               const uint64_t end_ns = Botan::OS::get_system_timestamp_ns();
12✔
72
               const uint64_t dur_ns = end_ns - start_ns;
12✔
73

74
               output() << " took " << (static_cast<double>(dur_ns) / 1000000.0) << " msec to compute";
12✔
75
   #else
76
               output() << "No system clock";
77
   #endif
78
            }
12✔
79

80
            output() << "\n";
12✔
81
         }
15✔
82
      }
3✔
83
};
84

85
BOTAN_REGISTER_COMMAND("pbkdf_tune", PBKDF_Tune);
4✔
86

87
#endif
88

89
}  // namespace
90

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