Botan 3.6.1
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*/
21 public:
22 Bcrypt_PBKDF(size_t iterations);
23
24 Bcrypt_PBKDF(const Bcrypt_PBKDF& other) = default;
26
27 /**
28 * Derive a new key under the current Bcrypt-PBKDF parameter set
29 */
30 void derive_key(uint8_t out[],
31 size_t out_len,
32 const char* password,
33 size_t password_len,
34 const uint8_t salt[],
35 size_t salt_len) const override;
36
37 std::string to_string() const override;
38
39 size_t iterations() const override { return m_iterations; }
40
41 size_t parallelism() const override { return 0; }
42
43 size_t memory_param() const override { return 0; }
44
45 size_t total_memory_usage() const override { return 4096; }
46
47 private:
48 size_t m_iterations;
49};
50
52 public:
54
55 std::string name() const override;
56
57 std::unique_ptr<PasswordHash> tune(size_t output_length,
58 std::chrono::milliseconds msec,
59 size_t max_memory,
60 std::chrono::milliseconds tune_msec) const override;
61
62 std::unique_ptr<PasswordHash> default_params() const override;
63
64 std::unique_ptr<PasswordHash> from_iterations(size_t iter) const override;
65
66 std::unique_ptr<PasswordHash> from_params(size_t i, size_t, size_t) const override;
67};
68
69/**
70* Bcrypt PBKDF compatible with OpenBSD bcrypt_pbkdf
71*/
72BOTAN_DEPRECATED("Use PasswordHashFamily+PasswordHash")
73
74inline void bcrypt_pbkdf(uint8_t output[],
75 size_t output_len,
76 const char* password,
77 size_t password_len,
78 const uint8_t salt[],
79 size_t salt_len,
80 size_t rounds) {
81 auto pwdhash_fam = PasswordHashFamily::create_or_throw("Bcrypt-PBKDF");
82 auto pwdhash = pwdhash_fam->from_params(rounds);
83 pwdhash->derive_key(output, output_len, password, password_len, salt, salt_len);
84}
85
86} // namespace Botan
87
88#endif
Bcrypt_PBKDF(const Bcrypt_PBKDF &other)=default
size_t iterations() const override
size_t total_memory_usage() const override
size_t parallelism() const override
size_t memory_param() const override
Bcrypt_PBKDF & operator=(const Bcrypt_PBKDF &)=default
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
std::string name
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
Definition compiler.h:150
#define BOTAN_DEPRECATED(msg)
Definition compiler.h:125
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)