Botan 2.19.2
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/pbkdf.h>
13#include <botan/pwdhash.h>
14#include <botan/mac.h>
15
17
18namespace Botan {
19
20BOTAN_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*/
31BOTAN_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*/
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*/
65 {
66 public:
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*/
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
PBKDF2_Family(MessageAuthenticationCode *prf)
Definition: pbkdf2.h:67
PBKDF2(const MessageAuthenticationCode &prf, size_t iter)
Definition: pbkdf2.h:42
size_t iterations() const override
Definition: pbkdf2.h:49
PKCS5_PBKDF2(MessageAuthenticationCode *mac_fn)
Definition: pbkdf2.h:110
virtual std::string name() const =0
virtual std::unique_ptr< PasswordHash > tune(size_t output_length, std::chrono::milliseconds msec, size_t max_memory_usage_mb=0) 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
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
Definition: compiler.h:136
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:213
Definition: alg_id.cpp:13
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
Definition: bigint.h:1143
size_t salt_len
Definition: x509_obj.cpp:25