Botan  1.11.4
kdf.h
Go to the documentation of this file.
1 /*
2 * KDF/MGF
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7 
8 #ifndef BOTAN_KDF_BASE_H__
9 #define BOTAN_KDF_BASE_H__
10 
11 #include <botan/algo_base.h>
12 #include <botan/secmem.h>
13 #include <botan/types.h>
14 
15 namespace Botan {
16 
17 /**
18 * Key Derivation Function
19 */
20 class BOTAN_DLL KDF : public Algorithm
21  {
22  public:
23  /**
24  * Derive a key
25  * @param key_len the desired output length in bytes
26  * @param secret the secret input
27  * @param salt a diversifier
28  */
29  secure_vector<byte> derive_key(size_t key_len,
30  const secure_vector<byte>& secret,
31  const std::string& salt = "") const;
32 
33  /**
34  * Derive a key
35  * @param key_len the desired output length in bytes
36  * @param secret the secret input
37  * @param salt a diversifier
38  */
39  template<typename Alloc, typename Alloc2>
41  const std::vector<byte, Alloc>& secret,
42  const std::vector<byte, Alloc2>& salt) const
43  {
44  return derive_key(key_len, &secret[0], secret.size(),
45  &salt[0], salt.size());
46  }
47 
48  /**
49  * Derive a key
50  * @param key_len the desired output length in bytes
51  * @param secret the secret input
52  * @param salt a diversifier
53  * @param salt_len size of salt in bytes
54  */
55  secure_vector<byte> derive_key(size_t key_len,
56  const secure_vector<byte>& secret,
57  const byte salt[],
58  size_t salt_len) const;
59 
60  /**
61  * Derive a key
62  * @param key_len the desired output length in bytes
63  * @param secret the secret input
64  * @param secret_len size of secret in bytes
65  * @param salt a diversifier
66  */
67  secure_vector<byte> derive_key(size_t key_len,
68  const byte secret[],
69  size_t secret_len,
70  const std::string& salt = "") const;
71 
72  /**
73  * Derive a key
74  * @param key_len the desired output length in bytes
75  * @param secret the secret input
76  * @param secret_len size of secret in bytes
77  * @param salt a diversifier
78  * @param salt_len size of salt in bytes
79  */
80  secure_vector<byte> derive_key(size_t key_len,
81  const byte secret[],
82  size_t secret_len,
83  const byte salt[],
84  size_t salt_len) const;
85 
86  void clear() {}
87 
88  virtual KDF* clone() const = 0;
89  private:
90  virtual secure_vector<byte>
91  derive(size_t key_len,
92  const byte secret[], size_t secret_len,
93  const byte salt[], size_t salt_len) const = 0;
94  };
95 
96 /**
97 * Mask Generation Function
98 */
99 class BOTAN_DLL MGF
100  {
101  public:
102  virtual void mask(const byte in[], size_t in_len,
103  byte out[], size_t out_len) const = 0;
104 
105  virtual ~MGF() {}
106  };
107 
108 }
109 
110 #endif