Botan 3.9.0
Crypto and TLS for C&
bcrypt_pbkdf.h
Go to the documentation of this file.
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
14
15namespace Botan {
16
17/**
18* Bcrypt-PBKDF key derivation function
19*/
20class BOTAN_PUBLIC_API(2, 11) Bcrypt_PBKDF final : public PasswordHash {
21 public:
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 size_t iterations() const override { return m_iterations; }
37
38 size_t parallelism() const override { return 0; }
39
40 size_t memory_param() const override { return 0; }
41
42 size_t total_memory_usage() const override { return 4096; }
43
44 private:
45 size_t m_iterations;
46};
47
49 public:
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*/
69BOTAN_DEPRECATED("Use PasswordHashFamily+PasswordHash")
70
71inline 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 size_t rounds) {
78 auto pwdhash_fam = PasswordHashFamily::create_or_throw("Bcrypt-PBKDF");
79 auto pwdhash = pwdhash_fam->from_params(rounds);
80 pwdhash->derive_key(output, output_len, password, password_len, salt, salt_len);
81}
82
83} // namespace Botan
84
85#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
Definition api.h:98
#define BOTAN_DEPRECATED(msg)
Definition api.h:73
#define BOTAN_FUTURE_EXPLICIT
Definition api.h:52
std::unique_ptr< PasswordHash > from_iterations(size_t iterations) const override
std::unique_ptr< PasswordHash > from_params(size_t iterations, size_t, size_t) const override
std::unique_ptr< PasswordHash > default_params() const override
std::unique_ptr< PasswordHash > tune(size_t output_length, std::chrono::milliseconds msec, size_t max_memory, std::chrono::milliseconds tune_msec) const override
std::string name() const override
size_t iterations() const override
size_t total_memory_usage() const override
size_t parallelism() const override
size_t memory_param() const override
BOTAN_FUTURE_EXPLICIT Bcrypt_PBKDF(size_t iterations)
static std::unique_ptr< PasswordHashFamily > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition pwdhash.cpp:110
virtual void derive_key(uint8_t out[], size_t out_len, const char *password, size_t password_len, const uint8_t salt[], size_t salt_len) const =0
virtual std::string to_string() const =0
void bcrypt_pbkdf(uint8_t output[], size_t output_len, const char *password, size_t password_len, const uint8_t salt[], size_t salt_len, size_t rounds)