/src/botan/build/include/public/botan/pbkdf2.h
Line | Count | Source (jump to first uncovered line) |
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 |
17 | | BOTAN_FUTURE_INTERNAL_HEADER(pbkdf2.h) |
18 | | |
19 | | namespace Botan { |
20 | | |
21 | | BOTAN_PUBLIC_API(2, 0) |
22 | | size_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 | | */ |
34 | | BOTAN_PUBLIC_API(2, 8) |
35 | | void 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 | | */ |
45 | | class BOTAN_PUBLIC_API(2, 8) PBKDF2 final : public PasswordHash { |
46 | | public: |
47 | 0 | 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 | 0 | 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 | | */ |
71 | | class BOTAN_PUBLIC_API(2, 8) PBKDF2_Family final : public PasswordHashFamily { |
72 | | public: |
73 | 0 | 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 | | */ |
100 | | class BOTAN_PUBLIC_API(2, 0) PKCS5_PBKDF2 final : public PBKDF { |
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 | 0 | explicit PKCS5_PBKDF2(MessageAuthenticationCode* mac_fn) : m_mac(mac_fn) {} |
120 | | |
121 | | /** |
122 | | * Create a PKCS #5 instance using the specified message auth code |
123 | | * @param mac_fn the MAC object to use as PRF |
124 | | */ |
125 | | BOTAN_DEPRECATED("Use PasswordHashFamily + PasswordHash") |
126 | 0 | 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 |