aboutsummaryrefslogtreecommitdiffstats
path: root/src/pbkdf/pbkdf.cpp
blob: 8f29295f32b73429a777d654c3155a8e0a4d3e09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* PBKDF
* (C) 2012 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/

#include <botan/pbkdf.h>
#include <botan/internal/assert.h>

namespace Botan {

OctetString PBKDF::derive_key(size_t output_len,
                              const std::string& passphrase,
                              const byte salt[], size_t salt_len,
                              size_t iterations) const
   {
   if(iterations == 0)
      throw std::invalid_argument(name() + ": Invalid iteration count");

   auto derived = key_derivation(output_len, passphrase,
                                 salt, salt_len, iterations,
                                 std::chrono::milliseconds(0));

   BOTAN_ASSERT(derived.first == iterations,
                "PBKDF used the correct number of iterations");

   return derived.second;
   }

OctetString PBKDF::derive_key(size_t output_len,
                              const std::string& passphrase,
                              const byte salt[], size_t salt_len,
                              std::chrono::milliseconds ms,
                              size_t& iterations) const
   {
   auto derived = key_derivation(output_len, passphrase, salt, salt_len, 0, ms);

   iterations = derived.first;

   return derived.second;
   }

}