Botan 2.19.5 Crypto and TLS for C&

Public Member Functions | Static Public Member Functions | List of all members
Botan::Bcrypt_PBKDF_Family Class Referencefinal

`#include <bcrypt_pbkdf.h>`

Inheritance diagram for Botan::Bcrypt_PBKDF_Family:

## Public Member Functions
| Bcrypt_PBKDF_Family ()
std::unique_ptr< PasswordHash > | default_params () const override
std::unique_ptr< PasswordHash > | from_iterations (size_t iter) const override
std::unique_ptr< PasswordHash > | from_params (size_t i, size_t, size_t) const override
std::string | name () const override
std::unique_ptr< PasswordHash > | tune (size_t output_length, std::chrono::milliseconds msec, size_t max_memory) const override

## Static Public Member Functions
static std::unique_ptr< PasswordHashFamily > | create (const std::string &algo_spec, const std::string &provider="")
static std::unique_ptr< PasswordHashFamily > | create_or_throw (const std::string &algo_spec, const std::string &provider="")
static std::vector< std::string > | providers (const std::string &algo_spec)

## Detailed Description

Definition at line 48 of file bcrypt_pbkdf.h.

## Constructor & Destructor Documentation

## ◆ Bcrypt_PBKDF_Family()

Botan::Bcrypt_PBKDF_Family::Bcrypt_PBKDF_Family | ( |  | ) |
| inline

Definition at line 51 of file bcrypt_pbkdf.h.

51{}

## Member Function Documentation

## ◆ create()

std::unique_ptr< PasswordHashFamily > Botan::PasswordHashFamily::create | ( | const std::string & | algo_spec,
|  | const std::string & | provider = `""`
| ) |  |
| static inherited

Create an instance based on a name If provider is empty then best available is chosen.

Parameters

  algo_spec | algorithm name
  provider | provider implementation to choose

Returns
  a null pointer if the algo/provider combination cannot be found

Definition at line 33 of file pwdhash.cpp.

35 {
36 const SCAN_Name req(algo_spec);
37
38#if defined(BOTAN_HAS_PBKDF2)
39 if(req.algo_name() == "PBKDF2")
40 {
41 if(provider.empty() || provider == "base")
42 {
43 if(auto mac = MessageAuthenticationCode::create(req.arg(0)))
44 return std::unique_ptr<PasswordHashFamily>(new PBKDF2_Family(mac.release()));
45
46 if(auto mac = MessageAuthenticationCode::create("HMAC(" + req.arg(0) + ")"))
47 return std::unique_ptr<PasswordHashFamily>(new PBKDF2_Family(mac.release()));
48 }
49
50 return nullptr;
51 }
52#endif
53
54#if defined(BOTAN_HAS_SCRYPT)
55 if(req.algo_name() == "Scrypt")
56 {
57 return std::unique_ptr<PasswordHashFamily>(new Scrypt_Family);
58 }
59#endif
60
61#if defined(BOTAN_HAS_ARGON2)
62 if(req.algo_name() == "Argon2d")
63 {
64 return std::unique_ptr<PasswordHashFamily>(new Argon2_Family(0));
65 }
66 else if(req.algo_name() == "Argon2i")
67 {
68 return std::unique_ptr<PasswordHashFamily>(new Argon2_Family(1));
69 }
70 else if(req.algo_name() == "Argon2id")
71 {
72 return std::unique_ptr<PasswordHashFamily>(new Argon2_Family(2));
73 }
74#endif
75
76#if defined(BOTAN_HAS_PBKDF_BCRYPT)
77 if(req.algo_name() == "Bcrypt-PBKDF")
78 {
79 return std::unique_ptr<PasswordHashFamily>(new Bcrypt_PBKDF_Family);
80 }
81#endif
82
83#if defined(BOTAN_HAS_PGP_S2K)
84 if(req.algo_name() == "OpenPGP-S2K" && req.arg_count() == 1)
85 {
86 if(auto hash = HashFunction::create(req.arg(0)))
87 {
88 return std::unique_ptr<PasswordHashFamily>(new RFC4880_S2K_Family(hash.release()));
89 }
90 }
91#endif
92
93 BOTAN_UNUSED(req);
94 BOTAN_UNUSED(provider);
95
96 return nullptr;
97 }
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan::HashFunction::create
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:102
Botan::MessageAuthenticationCode::create
static std::unique_ptr< MessageAuthenticationCode > create(const std::string &algo_spec, const std::string &provider="")
Definition: mac.cpp:46
hash
MechanismType hash
Definition: p11_mechanism.cpp:64

References Botan::SCAN_Name::algo_name(), Botan::SCAN_Name::arg(), Botan::SCAN_Name::arg_count(), BOTAN_UNUSED, Botan::HashFunction::create(), Botan::MessageAuthenticationCode::create(), and hash.

Referenced by botan_pwdhash(), botan_pwdhash_timed(), and Botan::PasswordHashFamily::create_or_throw().

## ◆ create_or_throw()

std::unique_ptr< PasswordHashFamily > Botan::PasswordHashFamily::create_or_throw | ( | const std::string & | algo_spec,
|  | const std::string & | provider = `""`
| ) |  |
| static inherited

Create an instance based on a name, or throw if the algo/provider combination cannot be found. If provider is empty then best available is chosen.

Definition at line 101 of file pwdhash.cpp.

103 {
104 if(auto pbkdf = PasswordHashFamily::create(algo, provider))
105 {
106 return pbkdf;
107 }
108 throw Lookup_Error("PasswordHashFamily", algo, provider);
109 }
Botan::PasswordHashFamily::create
static std::unique_ptr< PasswordHashFamily > create(const std::string &algo_spec, const std::string &provider="")
Definition: pwdhash.cpp:33

References Botan::PasswordHashFamily::create().

## ◆ default_params()

std::unique_ptr< PasswordHash > Botan::Bcrypt_PBKDF_Family::default_params | ( |  | ) | const
| override virtual

Return some default parameter set for this PBKDF that should be good enough for most users. The value returned may change over time as processing power and attacks improve.

Implements Botan::PasswordHashFamily.

Definition at line 69 of file bcrypt_pbkdf.cpp.

70 {
71 return this->from_iterations(32); // About 100 ms on fast machine
72 }
Botan::Bcrypt_PBKDF_Family::from_iterations
std::unique_ptr< PasswordHash > from_iterations(size_t iter) const override
Definition: bcrypt_pbkdf.cpp:74

References from_iterations().

Referenced by tune().

## ◆ from_iterations()

std::unique_ptr< PasswordHash > Botan::Bcrypt_PBKDF_Family::from_iterations | ( | size_t | iterations | ) | const
| override virtual

Return a parameter chosen based on a rough approximation with the specified iteration count. The exact value this returns for a particular algorithm may change from over time. Think of it as an alternative to tune, where time is expressed in terms of PBKDF2 iterations rather than milliseconds.

Implements Botan::PasswordHashFamily.

Definition at line 74 of file bcrypt_pbkdf.cpp.

75 {
76 return std::unique_ptr<PasswordHash>(new Bcrypt_PBKDF(iter));
77 }

Referenced by default_params(), from_params(), and tune().

## ◆ from_params()

std::unique_ptr< PasswordHash > Botan::Bcrypt_PBKDF_Family::from_params | ( | size_t | i1,
|  | size_t | i2,
|  | size_t | i3
| ) |  | const
| override virtual

Create a password hash using some scheme specific format. Eg PBKDF2 and PGP-S2K set iterations in i1 Scrypt uses N,r,p in i{1-3} Bcrypt-PBKDF just has iterations Argon2{i,d,id} would use iterations, memory, parallelism for i{1-3}, and Argon2 type is part of the family.

Values not needed should be set to 0

Implements Botan::PasswordHashFamily.

Definition at line 79 of file bcrypt_pbkdf.cpp.

80 {
81 return this->from_iterations(iter);
82 }

References from_iterations().

## ◆ name()

std::string Botan::Bcrypt_PBKDF_Family::name | ( |  | ) | const
| override virtual

Returns
  name of this PasswordHash

Implements Botan::PasswordHashFamily.

Definition at line 30 of file bcrypt_pbkdf.cpp.

31 {
32 return "Bcrypt-PBKDF";
33 }

## ◆ providers()

std::vector< std::string > Botan::PasswordHashFamily::providers | ( | const std::string & | algo_spec | ) |
| static inherited

Returns
  list of available providers for this algorithm, empty if not available

Definition at line 111 of file pwdhash.cpp.

112 {
113 return probe_providers_of<PasswordHashFamily>(algo_spec, { "base", "openssl" });
114 }

## ◆ tune()

std::unique_ptr< PasswordHash > Botan::Bcrypt_PBKDF_Family::tune | ( | size_t | output_length,
|  | std::chrono::milliseconds | msec,
|  | size_t | max_memory_usage_mb
| ) |  | const
| override virtual

Return a new parameter set tuned for this machine

Parameters

  output_length | how long the output length will be
  msec | the desired execution time in milliseconds
  max_memory_usage_mb | some password hash functions can use a tunable amount of memory, in this case max_memory_usage limits the amount of RAM the returned parameters will require, in mebibytes (2**20 bytes). It may require some small amount above the request. Set to zero to place no limit at all.

Implements Botan::PasswordHashFamily.

Definition at line 35 of file bcrypt_pbkdf.cpp.

38 {
39 Timer timer("Bcrypt_PBKDF");
40 const auto tune_time = BOTAN_PBKDF_TUNING_TIME;
41
42 const size_t blocks = (output_length + 32 - 1) / 32;
43
44 if(blocks == 0)
45 return default_params();
46
47 const size_t starting_iter = 2;
48
49 timer.run_until_elapsed(tune_time, [&]() {
50 uint8_t output[32] = { 0 };
51 bcrypt_pbkdf(output, sizeof(output), "test", 4, nullptr, 0, starting_iter);
52 });
53
54 if(timer.events() < blocks || timer.value() == 0)
55 return default_params();
56
57 const uint64_t measured_time = timer.value() / (timer.events() / blocks);
58
59 const uint64_t target_nsec = msec.count() * static_cast<uint64_t>(1000000);
60
61 const uint64_t desired_increase = target_nsec / measured_time;
62
63 if(desired_increase == 0)
64 return this->from_iterations(starting_iter);
65
66 return this->from_iterations(static_cast<size_t>(desired_increase * starting_iter));
67 }
Botan::Bcrypt_PBKDF_Family::default_params
std::unique_ptr< PasswordHash > default_params() const override
Definition: bcrypt_pbkdf.cpp:69
Botan::bcrypt_pbkdf
void bcrypt_pbkdf(uint8_t output[], size_t output_len, const char *pass, size_t pass_len, const uint8_t salt[], size_t salt_len, size_t rounds)
Definition: bcrypt_pbkdf.cpp:130

References Botan::bcrypt_pbkdf(), default_params(), Botan::Timer::events(), from_iterations(), Botan::Timer::run_until_elapsed(), and Botan::Timer::value().

The documentation for this class was generated from the following files:

- src/lib/pbkdf/bcrypt_pbkdf/bcrypt_pbkdf.h
- src/lib/pbkdf/bcrypt_pbkdf/bcrypt_pbkdf.cpp