|
Botan
1.11.15
|
#include <pbkdf1.h>
Public Types | |
| typedef SCAN_Name | Spec |
Public Member Functions | |
| PBKDF * | clone () const |
| OctetString | derive_key (size_t out_len, const std::string &passphrase, const byte salt[], size_t salt_len, size_t iterations) const |
| template<typename Alloc > | |
| OctetString | derive_key (size_t out_len, const std::string &passphrase, const std::vector< byte, Alloc > &salt, size_t iterations) const |
| OctetString | derive_key (size_t out_len, const std::string &passphrase, const byte salt[], size_t salt_len, std::chrono::milliseconds msec, size_t &iterations) const |
| template<typename Alloc > | |
| OctetString | derive_key (size_t out_len, const std::string &passphrase, const std::vector< byte, Alloc > &salt, std::chrono::milliseconds msec, size_t &iterations) const |
| std::string | name () const |
| size_t | pbkdf (byte output_buf[], size_t output_len, const std::string &passphrase, const byte salt[], size_t salt_len, size_t iterations, std::chrono::milliseconds msec) const override |
| void | pbkdf_iterations (byte out[], size_t out_len, const std::string &passphrase, const byte salt[], size_t salt_len, size_t iterations) const |
| secure_vector< byte > | pbkdf_iterations (size_t out_len, const std::string &passphrase, const byte salt[], size_t salt_len, size_t iterations) const |
| void | pbkdf_timed (byte out[], size_t out_len, const std::string &passphrase, const byte salt[], size_t salt_len, std::chrono::milliseconds msec, size_t &iterations) const |
| secure_vector< byte > | pbkdf_timed (size_t out_len, const std::string &passphrase, const byte salt[], size_t salt_len, std::chrono::milliseconds msec, size_t &iterations) const |
| PKCS5_PBKDF1 (HashFunction *hash) | |
PKCS #5 v1 PBKDF, aka PBKDF1 Can only generate a key up to the size of the hash output. Unless needed for backwards compatability, use PKCS5_PBKDF2
typedef SCAN_Name Botan::PBKDF::Spec [inherited] |
| Botan::PKCS5_PBKDF1::PKCS5_PBKDF1 | ( | HashFunction * | hash | ) | [inline] |
| PBKDF* Botan::PKCS5_PBKDF1::clone | ( | ) | const [inline, virtual] |
Implements Botan::PBKDF.
Definition at line 35 of file pbkdf1.h.
References m_hash.
{
return new PKCS5_PBKDF1(m_hash->clone());
}
| OctetString Botan::PBKDF::derive_key | ( | size_t | out_len, |
| const std::string & | passphrase, | ||
| const byte | salt[], | ||
| size_t | salt_len, | ||
| size_t | iterations | ||
| ) | const [inline, inherited] |
Derive a key from a passphrase
| out_len | the desired length of the key to produce |
| passphrase | the password to derive the key from |
| salt | a randomly chosen salt |
| salt_len | length of salt in bytes |
| iterations | the number of iterations to use (use 10K or more) |
Definition at line 89 of file pbkdf.h.
Referenced by Botan::check_passhash9(), Botan::CryptoBox::decrypt(), Botan::CryptoBox::encrypt(), Botan::generate_passhash9(), Botan::pbes2_decrypt(), and Botan::pbes2_encrypt().
{
return pbkdf_iterations(out_len, passphrase, salt, salt_len, iterations);
}
| OctetString Botan::PBKDF::derive_key | ( | size_t | out_len, |
| const std::string & | passphrase, | ||
| const std::vector< byte, Alloc > & | salt, | ||
| size_t | iterations | ||
| ) | const [inline, inherited] |
Derive a key from a passphrase
| out_len | the desired length of the key to produce |
| passphrase | the password to derive the key from |
| salt | a randomly chosen salt |
| iterations | the number of iterations to use (use 10K or more) |
Definition at line 105 of file pbkdf.h.
{
return pbkdf_iterations(out_len, passphrase, &salt[0], salt.size(), iterations);
}
| OctetString Botan::PBKDF::derive_key | ( | size_t | out_len, |
| const std::string & | passphrase, | ||
| const byte | salt[], | ||
| size_t | salt_len, | ||
| std::chrono::milliseconds | msec, | ||
| size_t & | iterations | ||
| ) | const [inline, inherited] |
Derive a key from a passphrase
| out_len | the desired length of the key to produce |
| passphrase | the password to derive the key from |
| salt | a randomly chosen salt |
| salt_len | length of salt in bytes |
| msec | is how long to run the PBKDF |
| iterations | is set to the number of iterations used |
Definition at line 122 of file pbkdf.h.
{
return pbkdf_timed(out_len, passphrase, salt, salt_len, msec, iterations);
}
| OctetString Botan::PBKDF::derive_key | ( | size_t | out_len, |
| const std::string & | passphrase, | ||
| const std::vector< byte, Alloc > & | salt, | ||
| std::chrono::milliseconds | msec, | ||
| size_t & | iterations | ||
| ) | const [inline, inherited] |
Derive a key from a passphrase using a certain amount of time
| out_len | the desired length of the key to produce |
| passphrase | the password to derive the key from |
| salt | a randomly chosen salt |
| msec | is how long to run the PBKDF |
| iterations | is set to the number of iterations used |
Definition at line 140 of file pbkdf.h.
{
return pbkdf_timed(out_len, passphrase, &salt[0], salt.size(), msec, iterations);
}
| std::string Botan::PKCS5_PBKDF1::name | ( | ) | const [inline, virtual] |
Implements Botan::PBKDF.
Definition at line 30 of file pbkdf1.h.
References m_hash.
{
return "PBKDF1(" + m_hash->name() + ")";
}
| size_t Botan::PKCS5_PBKDF1::pbkdf | ( | byte | out[], |
| size_t | out_len, | ||
| const std::string & | passphrase, | ||
| const byte | salt[], | ||
| size_t | salt_len, | ||
| size_t | iterations, | ||
| std::chrono::milliseconds | msec | ||
| ) | const [override, virtual] |
Derive a key from a passphrase for a number of iterations specified by either iterations or if iterations == 0 then running until seconds time has elapsed.
| out_len | the desired length of the key to produce |
| passphrase | the password to derive the key from |
| salt | a randomly chosen salt |
| salt_len | length of salt in bytes |
| iterations | the number of iterations to use (use 10K or more) |
| msec | if iterations is zero, then instead the PBKDF is run until msec milliseconds has passed. |
Implements Botan::PBKDF.
Definition at line 16 of file pbkdf1.cpp.
References Botan::copy_mem(), and m_hash.
{
if(output_len > m_hash->output_length())
throw Invalid_Argument("PKCS5_PBKDF1: Requested output length too long");
m_hash->update(passphrase);
m_hash->update(salt, salt_len);
secure_vector<byte> key = m_hash->final();
const auto start = std::chrono::high_resolution_clock::now();
size_t iterations_performed = 1;
while(true)
{
if(iterations == 0)
{
if(iterations_performed % 10000 == 0)
{
auto time_taken = std::chrono::high_resolution_clock::now() - start;
auto msec_taken = std::chrono::duration_cast<std::chrono::milliseconds>(time_taken);
if(msec_taken > msec)
break;
}
}
else if(iterations_performed == iterations)
break;
m_hash->update(key);
m_hash->final(&key[0]);
++iterations_performed;
}
copy_mem(output_buf, &key[0], output_len);
return iterations_performed;
}
| void Botan::PBKDF::pbkdf_iterations | ( | byte | out[], |
| size_t | out_len, | ||
| const std::string & | passphrase, | ||
| const byte | salt[], | ||
| size_t | salt_len, | ||
| size_t | iterations | ||
| ) | const [inherited] |
Definition at line 22 of file pbkdf.cpp.
References BOTAN_ASSERT_EQUAL, Botan::PBKDF::name(), and Botan::PBKDF::pbkdf().
Referenced by Botan::PBKDF::pbkdf_iterations().
{
if(iterations == 0)
throw std::invalid_argument(name() + ": Invalid iteration count");
const size_t iterations_run = pbkdf(out, out_len, passphrase,
salt, salt_len, iterations,
std::chrono::milliseconds(0));
BOTAN_ASSERT_EQUAL(iterations, iterations_run, "Expected PBKDF iterations");
}
| secure_vector< byte > Botan::PBKDF::pbkdf_iterations | ( | size_t | out_len, |
| const std::string & | passphrase, | ||
| const byte | salt[], | ||
| size_t | salt_len, | ||
| size_t | iterations | ||
| ) | const [inherited] |
Definition at line 36 of file pbkdf.cpp.
References Botan::PBKDF::pbkdf_iterations().
{
secure_vector<byte> out(out_len);
pbkdf_iterations(&out[0], out_len, passphrase, salt, salt_len, iterations);
return out;
}
| void Botan::PBKDF::pbkdf_timed | ( | byte | out[], |
| size_t | out_len, | ||
| const std::string & | passphrase, | ||
| const byte | salt[], | ||
| size_t | salt_len, | ||
| std::chrono::milliseconds | msec, | ||
| size_t & | iterations | ||
| ) | const [inherited] |
Definition at line 13 of file pbkdf.cpp.
References Botan::PBKDF::pbkdf().
Referenced by Botan::PBKDF::pbkdf_timed().
{
iterations = pbkdf(out, out_len, passphrase, salt, salt_len, 0, msec);
}
| secure_vector< byte > Botan::PBKDF::pbkdf_timed | ( | size_t | out_len, |
| const std::string & | passphrase, | ||
| const byte | salt[], | ||
| size_t | salt_len, | ||
| std::chrono::milliseconds | msec, | ||
| size_t & | iterations | ||
| ) | const [inherited] |
Definition at line 46 of file pbkdf.cpp.
References Botan::PBKDF::pbkdf_timed().
{
secure_vector<byte> out(out_len);
pbkdf_timed(&out[0], out_len, passphrase, salt, salt_len, msec, iterations);
return out;
}
1.7.6.1