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