Botan  2.15.0
Crypto and TLS for C++11
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 
13 
14 namespace Botan {
15 
16 /**
17 * Bcrypt-PBKDF key derivation function
18 */
20  {
21  public:
22  Bcrypt_PBKDF(size_t iterations) : m_iterations(iterations) {}
23 
24  Bcrypt_PBKDF(const Bcrypt_PBKDF& other) = default;
25  Bcrypt_PBKDF& operator=(const Bcrypt_PBKDF&) = default;
26 
27  /**
28  * Derive a new key under the current Bcrypt-PBKDF parameter set
29  */
30  void derive_key(uint8_t out[], size_t out_len,
31  const char* password, size_t password_len,
32  const uint8_t salt[], 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  {
50  public:
52 
53  std::string name() const override;
54 
55  std::unique_ptr<PasswordHash> tune(size_t output_length,
56  std::chrono::milliseconds msec,
57  size_t max_memory) const override;
58 
59  std::unique_ptr<PasswordHash> default_params() const override;
60 
61  std::unique_ptr<PasswordHash> from_iterations(size_t iter) const override;
62 
63  std::unique_ptr<PasswordHash> from_params(
64  size_t i, size_t, size_t) const override;
65  };
66 
67 /**
68 * Bcrypt PBKDF compatible with OpenBSD bcrypt_pbkdf
69 */
70 void BOTAN_UNSTABLE_API bcrypt_pbkdf(uint8_t output[], size_t output_len,
71  const char* pass, size_t pass_len,
72  const uint8_t salt[], size_t salt_len,
73  size_t rounds);
74 
75 }
76 
77 #endif
#define BOTAN_UNSTABLE_API
Definition: compiler.h:44
virtual std::unique_ptr< PasswordHash > tune(size_t output_length, std::chrono::milliseconds msec, size_t max_memory_usage_mb=0) const =0
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)
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
size_t parallelism() const override
Definition: bcrypt_pbkdf.h:38
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
size_t total_memory_usage() const override
Definition: bcrypt_pbkdf.h:42
size_t iterations() const override
Definition: bcrypt_pbkdf.h:36
virtual std::unique_ptr< PasswordHash > from_iterations(size_t iterations) const =0
Bcrypt_PBKDF(size_t iterations)
Definition: bcrypt_pbkdf.h:22
virtual std::string to_string() const =0
size_t salt_len
Definition: x509_obj.cpp:25
Definition: alg_id.cpp:13
size_t memory_param() const override
Definition: bcrypt_pbkdf.h:40
virtual std::unique_ptr< PasswordHash > default_params() const =0
virtual std::string name() const =0
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
Definition: compiler.h:145
virtual std::unique_ptr< PasswordHash > from_params(size_t i1, size_t i2=0, size_t i3=0) const =0