Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 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 {}
46
47 PBKDF2(const MessageAuthenticationCode& prf, size_t olen, std::chrono::milliseconds msec);
48
49 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 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 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
Botan::PasswordHashFamily::tune
virtual std::unique_ptr< PasswordHash > tune(size_t output_length, std::chrono::milliseconds msec, size_t max_memory_usage_mb=0) const =0
Botan::PKCS5_PBKDF2
Definition: pbkdf2.h:93
final
int(* final)(unsigned char *, CTX *)
Definition: commoncrypto_hash.cpp:28
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
std
Definition: bigint.h:1135
Botan::MessageAuthenticationCode
Definition: mac.h:21
Botan::ASN1::to_string
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:213
Botan::PBKDF2_Family::PBKDF2_Family
PBKDF2_Family(MessageAuthenticationCode *prf)
Definition: pbkdf2.h:67
Botan::PBKDF::name
virtual std::string name() const =0
Botan::PBKDF2::PBKDF2
PBKDF2(const MessageAuthenticationCode &prf, size_t iter)
Definition: pbkdf2.h:42
Botan::PBKDF2_Family
Definition: pbkdf2.h:64
Botan::PKCS5_PBKDF2::PKCS5_PBKDF2
PKCS5_PBKDF2(MessageAuthenticationCode *mac_fn)
Definition: pbkdf2.h:110
Botan::PasswordHashFamily::from_iterations
virtual std::unique_ptr< PasswordHash > from_iterations(size_t iterations) const =0
Botan::PasswordHash
Definition: pwdhash.h:24
Botan::PBKDF2::iterations
size_t iterations() const override
Definition: pbkdf2.h:49
Botan::PBKDF::pbkdf
virtual size_t pbkdf(uint8_t out[], size_t out_len, const std::string &passphrase, const uint8_t salt[], size_t salt_len, size_t iterations, std::chrono::milliseconds msec) const =0
Botan::PasswordHashFamily
Definition: pwdhash.h:79
salt_len
size_t salt_len
Definition: x509_obj.cpp:25
Botan
Definition: alg_id.cpp:13
Botan::PBKDF2
Definition: pbkdf2.h:39
Botan::PBKDF::clone
virtual PBKDF * clone() const =0
Botan::PasswordHashFamily::default_params
virtual std::unique_ptr< PasswordHash > default_params() const =0
Botan::pbkdf2
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
Botan::PasswordHashFamily::name
virtual std::string name() const =0
BOTAN_FUTURE_INTERNAL_HEADER
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
Definition: compiler.h:139
Botan::PasswordHashFamily::from_params
virtual std::unique_ptr< PasswordHash > from_params(size_t i1, size_t i2=0, size_t i3=0) const =0
Botan::PBKDF
Definition: pbkdf.h:24