Botan  2.8.0
Crypto and TLS for C++11
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/pbkdf.h>
13 #include <botan/pwdhash.h>
14 #include <botan/mac.h>
15 
16 namespace Botan {
17 
18 BOTAN_PUBLIC_API(2,0) size_t pbkdf2(MessageAuthenticationCode& prf,
19  uint8_t out[],
20  size_t out_len,
21  const std::string& passphrase,
22  const uint8_t salt[], size_t salt_len,
23  size_t iterations,
24  std::chrono::milliseconds msec);
25 
26 /**
27 * Perform PBKDF2. The prf is assumed to be keyed already.
28 */
29 BOTAN_PUBLIC_API(2,8) void pbkdf2(MessageAuthenticationCode& prf,
30  uint8_t out[], size_t out_len,
31  const uint8_t salt[], size_t salt_len,
32  size_t iterations);
33 
34 /**
35 * PBKDF2
36 */
38  {
39  public:
40  PBKDF2(const MessageAuthenticationCode& prf, size_t iter) :
41  m_prf(prf.clone()),
42  m_iterations(iter)
43  {}
44 
45  PBKDF2(const MessageAuthenticationCode& prf, size_t olen, std::chrono::milliseconds msec);
46 
47  size_t iterations() const override { return m_iterations; }
48 
49  std::string to_string() const override;
50 
51  void derive_key(uint8_t out[], size_t out_len,
52  const char* password, size_t password_len,
53  const uint8_t salt[], size_t salt_len) const override;
54  private:
55  std::unique_ptr<MessageAuthenticationCode> m_prf;
56  size_t m_iterations;
57  };
58 
59 /**
60 * Family of PKCS #5 PBKDF2 operations
61 */
63  {
64  public:
66 
67  std::string name() const override;
68 
69  std::unique_ptr<PasswordHash> tune(size_t output_len,
70  std::chrono::milliseconds msec,
71  size_t max_memory) const override;
72 
73  /**
74  * Return some default parameter set for this PBKDF that should be good
75  * enough for most users. The value returned may change over time as
76  * processing power and attacks improve.
77  */
78  std::unique_ptr<PasswordHash> default_params() const override;
79 
80  std::unique_ptr<PasswordHash> from_iterations(size_t iter) const override;
81 
82  std::unique_ptr<PasswordHash> from_params(
83  size_t iter, size_t, size_t) const override;
84  private:
85  std::unique_ptr<MessageAuthenticationCode> m_prf;
86  };
87 
88 /**
89 * PKCS #5 PBKDF2 (old interface)
90 */
92  {
93  public:
94  std::string name() const override;
95 
96  PBKDF* clone() const override;
97 
98  size_t pbkdf(uint8_t output_buf[], size_t output_len,
99  const std::string& passphrase,
100  const uint8_t salt[], size_t salt_len,
101  size_t iterations,
102  std::chrono::milliseconds msec) const override;
103 
104  /**
105  * Create a PKCS #5 instance using the specified message auth code
106  * @param mac_fn the MAC object to use as PRF
107  */
108  explicit PKCS5_PBKDF2(MessageAuthenticationCode* mac_fn) : m_mac(mac_fn) {}
109  private:
110  std::unique_ptr<MessageAuthenticationCode> m_mac;
111  };
112 
113 }
114 
115 #endif
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
Definition: bigint.h:891
PBKDF2_Family(MessageAuthenticationCode *prf)
Definition: pbkdf2.h:65
PBKDF2(const MessageAuthenticationCode &prf, size_t iter)
Definition: pbkdf2.h:40
PKCS5_PBKDF2(MessageAuthenticationCode *mac_fn)
Definition: pbkdf2.h:108
std::string name
size_t iterations() const override
Definition: pbkdf2.h:47
size_t salt_len
Definition: x509_obj.cpp:26
Definition: alg_id.cpp:13
std::string to_string(const secure_vector< uint8_t > &bytes)
Definition: stl_util.h:25
size_t pbkdf2(MessageAuthenticationCode &prf, uint8_t out[], size_t out_len, const std::string &password, const uint8_t salt[], size_t salt_len, size_t iterations, std::chrono::milliseconds msec)
Definition: pbkdf2.cpp:35