Coverage Report

Created: 2026-02-07 06:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/botan/build/include/public/botan/bcrypt_pbkdf.h
Line
Count
Source
1
/*
2
* (C) 2018,2019 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6
7
#ifndef BOTAN_PBKDF_BCRYPT_H_
8
#define BOTAN_PBKDF_BCRYPT_H_
9
10
#include <botan/pwdhash.h>
11
12
// Use pwdhash.h
13
BOTAN_FUTURE_INTERNAL_HEADER(bcrypt_pbkdf.h)
14
15
namespace Botan {
16
17
/**
18
* Bcrypt-PBKDF key derivation function
19
*/
20
class BOTAN_PUBLIC_API(2, 11) Bcrypt_PBKDF final : public PasswordHash {
21
   public:
22
      BOTAN_FUTURE_EXPLICIT Bcrypt_PBKDF(size_t iterations);
23
24
      /**
25
      * Derive a new key under the current Bcrypt-PBKDF parameter set
26
      */
27
      void derive_key(uint8_t out[],
28
                      size_t out_len,
29
                      const char* password,
30
                      size_t password_len,
31
                      const uint8_t salt[],
32
                      size_t salt_len) const override;
33
34
      std::string to_string() const override;
35
36
0
      size_t iterations() const override { return m_iterations; }
37
38
0
      size_t parallelism() const override { return 0; }
39
40
0
      size_t memory_param() const override { return 0; }
41
42
0
      size_t total_memory_usage() const override { return 4096; }
43
44
   private:
45
      size_t m_iterations;
46
};
47
48
class BOTAN_PUBLIC_API(2, 11) Bcrypt_PBKDF_Family final : public PasswordHashFamily {
49
   public:
50
0
      Bcrypt_PBKDF_Family() = default;
51
52
      std::string name() const override;
53
54
      std::unique_ptr<PasswordHash> tune(size_t output_length,
55
                                         std::chrono::milliseconds msec,
56
                                         size_t max_memory,
57
                                         std::chrono::milliseconds tune_msec) const override;
58
59
      std::unique_ptr<PasswordHash> default_params() const override;
60
61
      std::unique_ptr<PasswordHash> from_iterations(size_t iterations) const override;
62
63
      std::unique_ptr<PasswordHash> from_params(size_t iterations, size_t /*unused*/, size_t /*unused*/) const override;
64
};
65
66
/**
67
* Bcrypt PBKDF compatible with OpenBSD bcrypt_pbkdf
68
*/
69
BOTAN_DEPRECATED("Use PasswordHashFamily+PasswordHash")
70
71
inline void bcrypt_pbkdf(uint8_t output[],
72
                         size_t output_len,
73
                         const char* password,
74
                         size_t password_len,
75
                         const uint8_t salt[],
76
                         size_t salt_len,
77
0
                         size_t rounds) {
78
0
   auto pwdhash_fam = PasswordHashFamily::create_or_throw("Bcrypt-PBKDF");
79
0
   auto pwdhash = pwdhash_fam->from_params(rounds);
80
0
   pwdhash->derive_key(output, output_len, password, password_len, salt, salt_len);
81
0
}
82
83
}  // namespace Botan
84
85
#endif