summaryrefslogtreecommitdiff
path: root/pwdbased.h
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2018-03-30 00:10:26 -0400
committerJeffrey Walton <noloader@gmail.com>2018-03-30 00:10:26 -0400
commit616741d4ea7ccdb575dfc6be872d496d6c635fa1 (patch)
treedd9ed41bb735f621cdffe9cf8b36c7537668a645 /pwdbased.h
parent57a35a6896c85df0d0466f3a99c8c54d12c4c2ba (diff)
downloadcryptopp-git-616741d4ea7ccdb575dfc6be872d496d6c635fa1.tar.gz
Add missing function body for PKCS5_PBKDF1<T>::DeriveKey (GH #610)
Not sure how I missed that entire body... Also added a default timeInSeconds to all PBKDFs
Diffstat (limited to 'pwdbased.h')
-rw-r--r--pwdbased.h36
1 files changed, 27 insertions, 9 deletions
diff --git a/pwdbased.h b/pwdbased.h
index c4307257..11944a2c 100644
--- a/pwdbased.h
+++ b/pwdbased.h
@@ -68,8 +68,8 @@ public:
/// a seed and other parameters. Each class that derives from KeyDerivationFunction
/// provides an overload that accepts most parameters used by the derivation function.
/// \details If <tt>timeInSeconds</tt> is <tt>&gt; 0.0</tt> then DeriveKey will run for
- /// that amount of time. If <tt>timeInSeconds</tt> is <tt>0.0</tt> then DeriveKey will
- /// run for the specified number of iterations.
+ /// the specified amount of time. If <tt>timeInSeconds</tt> is <tt>0.0</tt> then DeriveKey
+ /// will run for the specified number of iterations.
/// \details PKCS #5 says PBKDF1 should only take 8-byte salts. This implementation
/// allows salts of any length.
size_t DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *secret, size_t secretLen, const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds=0) const;
@@ -93,7 +93,19 @@ template <class T>
size_t PKCS5_PBKDF1<T>::DeriveKey(byte *derived, size_t derivedLen,
const byte *secret, size_t secretLen, const NameValuePairs& params) const
{
- return derivedLen;
+ CRYPTOPP_ASSERT(derived && derivedLen);
+ CRYPTOPP_ASSERT(secret && secretLen);
+
+ byte purpose = (byte)params.GetIntValueWithDefault("Purpose", 0);
+ unsigned int iterations = (unsigned int)params.GetIntValueWithDefault("Iterations", 1);
+
+ double timeInSeconds = 0.0f;
+ (void)params.GetValue("TimeInSeconds", timeInSeconds);
+
+ ConstByteArrayParameter salt;
+ (void)params.GetValue(Name::Salt(), salt);
+
+ return DeriveKey(derived, derivedLen, purpose, secret, secretLen, salt.begin(), salt.size(), iterations, timeInSeconds);
}
template <class T>
@@ -180,8 +192,8 @@ public:
/// a seed and other parameters. Each class that derives from KeyDerivationFunction
/// provides an overload that accepts most parameters used by the derivation function.
/// \details If <tt>timeInSeconds</tt> is <tt>&gt; 0.0</tt> then DeriveKey will run for
- /// that amount of time. If <tt>timeInSeconds</tt> is <tt>0.0</tt> then DeriveKey will
- /// run for the specified number of iterations.
+ /// the specified amount of time. If <tt>timeInSeconds</tt> is <tt>0.0</tt> then DeriveKey
+ /// will run for the specified number of iterations.
size_t DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *secret, size_t secretLen,
const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds=0) const;
@@ -210,10 +222,13 @@ size_t PKCS5_PBKDF2_HMAC<T>::DeriveKey(byte *derived, size_t derivedLen,
byte purpose = (byte)params.GetIntValueWithDefault("Purpose", 0);
unsigned int iterations = (unsigned int)params.GetIntValueWithDefault("Iterations", 1);
+ double timeInSeconds = 0.0f;
+ (void)params.GetValue("TimeInSeconds", timeInSeconds);
+
ConstByteArrayParameter salt;
(void)params.GetValue(Name::Salt(), salt);
- return DeriveKey(derived, derivedLen, purpose, secret, secretLen, salt.begin(), salt.size(), iterations, 0.0f);
+ return DeriveKey(derived, derivedLen, purpose, secret, secretLen, salt.begin(), salt.size(), iterations, timeInSeconds);
}
template <class T>
@@ -329,8 +344,8 @@ public:
/// a seed and other parameters. Each class that derives from KeyDerivationFunction
/// provides an overload that accepts most parameters used by the derivation function.
/// \details If <tt>timeInSeconds</tt> is <tt>&gt; 0.0</tt> then DeriveKey will run for
- /// that amount of time. If <tt>timeInSeconds</tt> is <tt>0.0</tt> then DeriveKey will
- /// run for the specified number of iterations.
+ /// the specified amount of time. If <tt>timeInSeconds</tt> is <tt>0.0</tt> then DeriveKey
+ /// will run for the specified number of iterations.
size_t DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *secret, size_t secretLen,
const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds) const;
@@ -360,11 +375,14 @@ size_t PKCS12_PBKDF<T>::DeriveKey(byte *derived, size_t derivedLen,
byte purpose = (byte)params.GetIntValueWithDefault("Purpose", 0);
unsigned int iterations = (unsigned int)params.GetIntValueWithDefault("Iterations", 1);
+ double timeInSeconds = 0.0f;
+ (void)params.GetValue("TimeInSeconds", timeInSeconds);
+
// NULL or 0 length salt OK
ConstByteArrayParameter salt;
(void)params.GetValue(Name::Salt(), salt);
- return DeriveKey(derived, derivedLen, purpose, secret, secretLen, salt.begin(), salt.size(), iterations, 0.0f);
+ return DeriveKey(derived, derivedLen, purpose, secret, secretLen, salt.begin(), salt.size(), iterations, timeInSeconds);
}
template <class T>