Botan
1.11.15
|
00001 /* 00002 * PBKDF 00003 * (C) 2012 Jack Lloyd 00004 * 00005 * Botan is released under the Simplified BSD License (see license.txt) 00006 */ 00007 00008 #include <botan/pbkdf.h> 00009 #include <stdexcept> 00010 00011 namespace Botan { 00012 00013 void PBKDF::pbkdf_timed(byte out[], size_t out_len, 00014 const std::string& passphrase, 00015 const byte salt[], size_t salt_len, 00016 std::chrono::milliseconds msec, 00017 size_t& iterations) const 00018 { 00019 iterations = pbkdf(out, out_len, passphrase, salt, salt_len, 0, msec); 00020 } 00021 00022 void PBKDF::pbkdf_iterations(byte out[], size_t out_len, 00023 const std::string& passphrase, 00024 const byte salt[], size_t salt_len, 00025 size_t iterations) const 00026 { 00027 if(iterations == 0) 00028 throw std::invalid_argument(name() + ": Invalid iteration count"); 00029 00030 const size_t iterations_run = pbkdf(out, out_len, passphrase, 00031 salt, salt_len, iterations, 00032 std::chrono::milliseconds(0)); 00033 BOTAN_ASSERT_EQUAL(iterations, iterations_run, "Expected PBKDF iterations"); 00034 } 00035 00036 secure_vector<byte> PBKDF::pbkdf_iterations(size_t out_len, 00037 const std::string& passphrase, 00038 const byte salt[], size_t salt_len, 00039 size_t iterations) const 00040 { 00041 secure_vector<byte> out(out_len); 00042 pbkdf_iterations(&out[0], out_len, passphrase, salt, salt_len, iterations); 00043 return out; 00044 } 00045 00046 secure_vector<byte> PBKDF::pbkdf_timed(size_t out_len, 00047 const std::string& passphrase, 00048 const byte salt[], size_t salt_len, 00049 std::chrono::milliseconds msec, 00050 size_t& iterations) const 00051 { 00052 secure_vector<byte> out(out_len); 00053 pbkdf_timed(&out[0], out_len, passphrase, salt, salt_len, msec, iterations); 00054 return out; 00055 } 00056 00057 }