• 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

89.74
/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
#endif
12

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

17
namespace Botan_CLI {
18

19
namespace {
20

21
#if defined(BOTAN_HAS_PASSWORD_HASHING)
22

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

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

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

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

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

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

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

47
            if(time == "default") {
12✔
48
               pwhash = pwdhash_fam->default_params();
3✔
49
            } else {
50
               size_t desired_runtime_msec = 0;
9✔
51
               try {
9✔
52
                  desired_runtime_msec = std::stoul(time);
9✔
53
               } catch(std::exception&) {
×
54
                  throw CLI_Usage_Error("Unknown time value '" + time + "' for pbkdf_tune");
×
55
               }
×
56

57
               pwhash = pwdhash_fam->tune_params(output_len, desired_runtime_msec, max_mem, tune_msec);
9✔
58
            }
59

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

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

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

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

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

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

87
BOTAN_REGISTER_COMMAND("pbkdf_tune", PBKDF_Tune);
4✔
88

89
#endif
90

91
}  // namespace
92

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