diff options
author | lloyd <[email protected]> | 2014-01-10 03:41:59 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-01-10 03:41:59 +0000 |
commit | 6894dca64c04936d07048c0e8cbf7e25858548c3 (patch) | |
tree | 5d572bfde9fe667dab14e3f04b5285a85d8acd95 /src/lib/pbkdf/pbkdf.cpp | |
parent | 9efa3be92442afb3d0b69890a36c7f122df18eda (diff) |
Move lib into src
Diffstat (limited to 'src/lib/pbkdf/pbkdf.cpp')
-rw-r--r-- | src/lib/pbkdf/pbkdf.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/lib/pbkdf/pbkdf.cpp b/src/lib/pbkdf/pbkdf.cpp new file mode 100644 index 000000000..ccd203dbd --- /dev/null +++ b/src/lib/pbkdf/pbkdf.cpp @@ -0,0 +1,44 @@ +/* +* PBKDF +* (C) 2012 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#include <botan/pbkdf.h> +#include <stdexcept> + +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; + } + +} |