Botan 3.3.0
Crypto and TLS for C&
pbkdf2.h
Go to the documentation of this file.
1/*
2* PBKDF2
3* (C) 1999-2007,2012 Jack Lloyd
4* (C) 2018 Ribose Inc
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#ifndef BOTAN_PBKDF2_H_
10#define BOTAN_PBKDF2_H_
11
12#include <botan/mac.h>
13#include <botan/pbkdf.h>
14#include <botan/pwdhash.h>
15
16// Use pwdhash.h
18
19namespace Botan {
20
22size_t pbkdf2(MessageAuthenticationCode& prf,
23 uint8_t out[],
24 size_t out_len,
25 std::string_view passphrase,
26 const uint8_t salt[],
27 size_t salt_len,
28 size_t iterations,
29 std::chrono::milliseconds msec);
30
31/**
32* Perform PBKDF2. The prf is assumed to be keyed already.
33*/
35void pbkdf2(MessageAuthenticationCode& prf,
36 uint8_t out[],
37 size_t out_len,
38 const uint8_t salt[],
39 size_t salt_len,
40 size_t iterations);
41
42/**
43* PBKDF2
44*/
46 public:
47 PBKDF2(const MessageAuthenticationCode& prf, size_t iter) : m_prf(prf.new_object()), m_iterations(iter) {}
48
49 BOTAN_DEPRECATED("For runtime tuning use PBKDF2_Family::tune")
50 PBKDF2(const MessageAuthenticationCode& prf, size_t olen, std::chrono::milliseconds msec);
51
52 size_t iterations() const override { return m_iterations; }
53
54 std::string to_string() const override;
55
56 void derive_key(uint8_t out[],
57 size_t out_len,
58 const char* password,
59 size_t password_len,
60 const uint8_t salt[],
61 size_t salt_len) const override;
62
63 private:
64 std::unique_ptr<MessageAuthenticationCode> m_prf;
65 size_t m_iterations;
66};
67
68/**
69* Family of PKCS #5 PBKDF2 operations
70*/
72 public:
73 PBKDF2_Family(std::unique_ptr<MessageAuthenticationCode> prf) : m_prf(std::move(prf)) {}
74
75 std::string name() const override;
76
77 std::unique_ptr<PasswordHash> tune(size_t output_len,
78 std::chrono::milliseconds msec,
79 size_t max_memory,
80 std::chrono::milliseconds tune_msec) const override;
81
82 /**
83 * Return some default parameter set for this PBKDF that should be good
84 * enough for most users. The value returned may change over time as
85 * processing power and attacks improve.
86 */
87 std::unique_ptr<PasswordHash> default_params() const override;
88
89 std::unique_ptr<PasswordHash> from_iterations(size_t iter) const override;
90
91 std::unique_ptr<PasswordHash> from_params(size_t iter, size_t, size_t) const override;
92
93 private:
94 std::unique_ptr<MessageAuthenticationCode> m_prf;
95};
96
97/**
98* PKCS #5 PBKDF2 (old interface)
99*/
101 public:
102 std::string name() const override;
103
104 std::unique_ptr<PBKDF> new_object() const override;
105
106 size_t pbkdf(uint8_t output_buf[],
107 size_t output_len,
108 std::string_view passphrase,
109 const uint8_t salt[],
110 size_t salt_len,
111 size_t iterations,
112 std::chrono::milliseconds msec) const override;
113
114 /**
115 * Create a PKCS #5 instance using the specified message auth code
116 * @param mac_fn the MAC object to use as PRF
117 */
118 BOTAN_DEPRECATED("Use version taking unique_ptr")
119
120 explicit PKCS5_PBKDF2(MessageAuthenticationCode* mac_fn) : m_mac(mac_fn) {}
121
122 /**
123 * Create a PKCS #5 instance using the specified message auth code
124 * @param mac_fn the MAC object to use as PRF
125 */
126 explicit PKCS5_PBKDF2(std::unique_ptr<MessageAuthenticationCode> mac_fn) : m_mac(std::move(mac_fn)) {}
127
128 private:
129 std::unique_ptr<MessageAuthenticationCode> m_mac;
130};
131
132} // namespace Botan
133
134#endif
PBKDF2_Family(std::unique_ptr< MessageAuthenticationCode > prf)
Definition pbkdf2.h:73
PBKDF2(const MessageAuthenticationCode &prf, size_t iter)
Definition pbkdf2.h:47
PKCS5_PBKDF2(std::unique_ptr< MessageAuthenticationCode > mac_fn)
Definition pbkdf2.h:126
virtual std::string name() const =0
virtual std::unique_ptr< PasswordHash > from_iterations(size_t iterations) const =0
virtual std::unique_ptr< PasswordHash > default_params() const =0
virtual std::unique_ptr< PasswordHash > from_params(size_t i1, size_t i2=0, size_t i3=0) const =0
virtual std::unique_ptr< PasswordHash > tune(size_t output_length, std::chrono::milliseconds msec, size_t max_memory_usage_mb=0, std::chrono::milliseconds tuning_msec=std::chrono::milliseconds(10)) const =0
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
size_t pbkdf2(MessageAuthenticationCode &prf, uint8_t out[], size_t out_len, std::string_view password, const uint8_t salt[], size_t salt_len, size_t iterations, std::chrono::milliseconds msec)
Definition pbkdf2.cpp:78