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

randombit / botan / 5134090420

31 May 2023 03:12PM UTC coverage: 91.721% (-0.3%) from 91.995%
5134090420

push

github

randombit
Merge GH #3565 Disable noisy/pointless pylint warnings

76048 of 82912 relevant lines covered (91.72%)

11755290.1 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
   #include <botan/internal/os_utils.h>
12
#endif
13

14
namespace Botan_CLI {
15

16
#if defined(BOTAN_HAS_PASSWORD_HASHING)
17

18
class PBKDF_Tune final : public Command {
19
   public:
20
      PBKDF_Tune() : Command("pbkdf_tune --algo=Scrypt --max-mem=256 --tune-msec=10 --output-len=32 --check *times") {}
8✔
21

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

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

26
      void go() override {
3✔
27
         const size_t output_len = get_arg_sz("output-len");
3✔
28
         const size_t max_mem = get_arg_sz("max-mem");
3✔
29
         const auto tune_msec = std::chrono::milliseconds(get_arg_sz("tune-msec"));
3✔
30
         const std::string algo = get_arg("algo");
3✔
31
         const bool check_time = flag_set("check");
3✔
32

33
         auto pwdhash_fam = Botan::PasswordHashFamily::create(algo);
3✔
34

35
         if(!pwdhash_fam) {
3✔
36
            throw CLI_Error_Unsupported("Password hashing", algo);
×
37
         }
38

39
         for(const std::string& time : get_arg_list("times")) {
15✔
40
            std::unique_ptr<Botan::PasswordHash> pwhash;
12✔
41

42
            if(time == "default") {
12✔
43
               pwhash = pwdhash_fam->default_params();
3✔
44
            } else {
45
               size_t msec = 0;
9✔
46
               try {
9✔
47
                  msec = std::stoul(time);
9✔
48
               } catch(std::exception&) {
×
49
                  throw CLI_Usage_Error("Unknown time value '" + time + "' for pbkdf_tune");
×
50
               }
×
51

52
               pwhash = pwdhash_fam->tune(output_len, std::chrono::milliseconds(msec), max_mem, tune_msec);
9✔
53
            }
54

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

57
            if(pwhash->total_memory_usage() > 0) {
12✔
58
               output() << " using " << pwhash->total_memory_usage() / (1024 * 1024) << " MiB";
8✔
59
            }
60

61
            if(check_time) {
12✔
62
               std::vector<uint8_t> outbuf(output_len);
12✔
63
               const uint8_t salt[8] = {0};
12✔
64

65
               const uint64_t start_ns = Botan::OS::get_system_timestamp_ns();
12✔
66
               pwhash->derive_key(outbuf.data(), outbuf.size(), "test", 4, salt, sizeof(salt));
12✔
67
               const uint64_t end_ns = Botan::OS::get_system_timestamp_ns();
12✔
68
               const uint64_t dur_ns = end_ns - start_ns;
12✔
69

70
               output() << " took " << (dur_ns / 1000000.0) << " msec to compute";
12✔
71
            }
12✔
72

73
            output() << "\n";
12✔
74
         }
15✔
75
      }
3✔
76
};
77

78
BOTAN_REGISTER_COMMAND("pbkdf_tune", PBKDF_Tune);
4✔
79

80
#endif
81

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

© 2025 Coveralls, Inc