Line | Count | Source (jump to first uncovered line) |
1 | | // pwdbased.h - originally written and placed in the public domain by Wei Dai |
2 | | // Cutover to KeyDerivationFunction interface by Uri Blumenthal |
3 | | // Marcel Raad and Jeffrey Walton in March 2018. |
4 | | |
5 | | /// \file pwdbased.h |
6 | | /// \brief Password based key derivation functions |
7 | | |
8 | | #ifndef CRYPTOPP_PWDBASED_H |
9 | | #define CRYPTOPP_PWDBASED_H |
10 | | |
11 | | #include "cryptlib.h" |
12 | | #include "hrtimer.h" |
13 | | #include "integer.h" |
14 | | #include "argnames.h" |
15 | | #include "algparam.h" |
16 | | #include "hmac.h" |
17 | | |
18 | | NAMESPACE_BEGIN(CryptoPP) |
19 | | |
20 | | // ******************** PBKDF1 ******************** |
21 | | |
22 | | /// \brief PBKDF1 from PKCS #5 |
23 | | /// \tparam T a HashTransformation class |
24 | | /// \sa PasswordBasedKeyDerivationFunction, <A |
25 | | /// HREF="https://www.cryptopp.com/wiki/PKCS5_PBKDF1">PKCS5_PBKDF1</A> |
26 | | /// on the Crypto++ wiki |
27 | | /// \since Crypto++ 2.0 |
28 | | template <class T> |
29 | | class PKCS5_PBKDF1 : public PasswordBasedKeyDerivationFunction |
30 | | { |
31 | | public: |
32 | | virtual ~PKCS5_PBKDF1() {} |
33 | | |
34 | 0 | static std::string StaticAlgorithmName () { |
35 | 0 | const std::string name(std::string("PBKDF1(") + |
36 | 0 | std::string(T::StaticAlgorithmName()) + std::string(")")); |
37 | 0 | return name; |
38 | 0 | } Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA1>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA224>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA384>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA512>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SHAKE128>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SHAKE256>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD128>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD160>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD256>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD320>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Whirlpool>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Weak1::MD2>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Weak1::MD4>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Weak1::MD5>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SM3>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::BLAKE2b>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::BLAKE2s>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Tiger>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<28u> >::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<32u> >::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<48u> >::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<64u> >::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH224>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH256>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH384>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH512>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH512_256>::StaticAlgorithmName() |
39 | | |
40 | | // KeyDerivationFunction interface |
41 | 0 | std::string AlgorithmName() const { |
42 | 0 | return StaticAlgorithmName(); |
43 | 0 | } Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA1>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA224>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA384>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA512>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SHAKE128>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SHAKE256>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD128>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD160>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD256>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD320>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Whirlpool>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Weak1::MD2>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Weak1::MD4>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Weak1::MD5>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SM3>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::BLAKE2b>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::BLAKE2s>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Tiger>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<28u> >::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<32u> >::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<48u> >::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<64u> >::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH224>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH256>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH384>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH512>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH512_256>::AlgorithmName() const |
44 | | |
45 | | // KeyDerivationFunction interface |
46 | 162 | size_t MaxDerivedKeyLength() const { |
47 | 162 | return static_cast<size_t>(T::DIGESTSIZE); |
48 | 162 | } CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA1>::MaxDerivedKeyLength() const Line | Count | Source | 46 | 4 | size_t MaxDerivedKeyLength() const { | 47 | 4 | return static_cast<size_t>(T::DIGESTSIZE); | 48 | 4 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA224>::MaxDerivedKeyLength() const Line | Count | Source | 46 | 3 | size_t MaxDerivedKeyLength() const { | 47 | 3 | return static_cast<size_t>(T::DIGESTSIZE); | 48 | 3 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA384>::MaxDerivedKeyLength() const Line | Count | Source | 46 | 4 | size_t MaxDerivedKeyLength() const { | 47 | 4 | return static_cast<size_t>(T::DIGESTSIZE); | 48 | 4 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA512>::MaxDerivedKeyLength() const Line | Count | Source | 46 | 7 | size_t MaxDerivedKeyLength() const { | 47 | 7 | return static_cast<size_t>(T::DIGESTSIZE); | 48 | 7 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::SHAKE128>::MaxDerivedKeyLength() const Line | Count | Source | 46 | 4 | size_t MaxDerivedKeyLength() const { | 47 | 4 | return static_cast<size_t>(T::DIGESTSIZE); | 48 | 4 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::SHAKE256>::MaxDerivedKeyLength() const Line | Count | Source | 46 | 26 | size_t MaxDerivedKeyLength() const { | 47 | 26 | return static_cast<size_t>(T::DIGESTSIZE); | 48 | 26 | } |
Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD128>::MaxDerivedKeyLength() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD160>::MaxDerivedKeyLength() const CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD256>::MaxDerivedKeyLength() const Line | Count | Source | 46 | 3 | size_t MaxDerivedKeyLength() const { | 47 | 3 | return static_cast<size_t>(T::DIGESTSIZE); | 48 | 3 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD320>::MaxDerivedKeyLength() const Line | Count | Source | 46 | 5 | size_t MaxDerivedKeyLength() const { | 47 | 5 | return static_cast<size_t>(T::DIGESTSIZE); | 48 | 5 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::Whirlpool>::MaxDerivedKeyLength() const Line | Count | Source | 46 | 8 | size_t MaxDerivedKeyLength() const { | 47 | 8 | return static_cast<size_t>(T::DIGESTSIZE); | 48 | 8 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::Weak1::MD2>::MaxDerivedKeyLength() const Line | Count | Source | 46 | 5 | size_t MaxDerivedKeyLength() const { | 47 | 5 | return static_cast<size_t>(T::DIGESTSIZE); | 48 | 5 | } |
Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Weak1::MD4>::MaxDerivedKeyLength() const CryptoPP::PKCS5_PBKDF1<CryptoPP::Weak1::MD5>::MaxDerivedKeyLength() const Line | Count | Source | 46 | 4 | size_t MaxDerivedKeyLength() const { | 47 | 4 | return static_cast<size_t>(T::DIGESTSIZE); | 48 | 4 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::SM3>::MaxDerivedKeyLength() const Line | Count | Source | 46 | 3 | size_t MaxDerivedKeyLength() const { | 47 | 3 | return static_cast<size_t>(T::DIGESTSIZE); | 48 | 3 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::BLAKE2b>::MaxDerivedKeyLength() const Line | Count | Source | 46 | 9 | size_t MaxDerivedKeyLength() const { | 47 | 9 | return static_cast<size_t>(T::DIGESTSIZE); | 48 | 9 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::BLAKE2s>::MaxDerivedKeyLength() const Line | Count | Source | 46 | 3 | size_t MaxDerivedKeyLength() const { | 47 | 3 | return static_cast<size_t>(T::DIGESTSIZE); | 48 | 3 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::Tiger>::MaxDerivedKeyLength() const Line | Count | Source | 46 | 6 | size_t MaxDerivedKeyLength() const { | 47 | 6 | return static_cast<size_t>(T::DIGESTSIZE); | 48 | 6 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<28u> >::MaxDerivedKeyLength() const Line | Count | Source | 46 | 3 | size_t MaxDerivedKeyLength() const { | 47 | 3 | return static_cast<size_t>(T::DIGESTSIZE); | 48 | 3 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<32u> >::MaxDerivedKeyLength() const Line | Count | Source | 46 | 3 | size_t MaxDerivedKeyLength() const { | 47 | 3 | return static_cast<size_t>(T::DIGESTSIZE); | 48 | 3 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<48u> >::MaxDerivedKeyLength() const Line | Count | Source | 46 | 8 | size_t MaxDerivedKeyLength() const { | 47 | 8 | return static_cast<size_t>(T::DIGESTSIZE); | 48 | 8 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<64u> >::MaxDerivedKeyLength() const Line | Count | Source | 46 | 39 | size_t MaxDerivedKeyLength() const { | 47 | 39 | return static_cast<size_t>(T::DIGESTSIZE); | 48 | 39 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH224>::MaxDerivedKeyLength() const Line | Count | Source | 46 | 1 | size_t MaxDerivedKeyLength() const { | 47 | 1 | return static_cast<size_t>(T::DIGESTSIZE); | 48 | 1 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH256>::MaxDerivedKeyLength() const Line | Count | Source | 46 | 2 | size_t MaxDerivedKeyLength() const { | 47 | 2 | return static_cast<size_t>(T::DIGESTSIZE); | 48 | 2 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH384>::MaxDerivedKeyLength() const Line | Count | Source | 46 | 6 | size_t MaxDerivedKeyLength() const { | 47 | 6 | return static_cast<size_t>(T::DIGESTSIZE); | 48 | 6 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH512>::MaxDerivedKeyLength() const Line | Count | Source | 46 | 5 | size_t MaxDerivedKeyLength() const { | 47 | 5 | return static_cast<size_t>(T::DIGESTSIZE); | 48 | 5 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH512_256>::MaxDerivedKeyLength() const Line | Count | Source | 46 | 1 | size_t MaxDerivedKeyLength() const { | 47 | 1 | return static_cast<size_t>(T::DIGESTSIZE); | 48 | 1 | } |
|
49 | | |
50 | | // KeyDerivationFunction interface |
51 | | size_t GetValidDerivedLength(size_t keylength) const; |
52 | | |
53 | | // KeyDerivationFunction interface |
54 | | virtual size_t DeriveKey(byte *derived, size_t derivedLen, const byte *secret, size_t secretLen, |
55 | | const NameValuePairs& params = g_nullNameValuePairs) const; |
56 | | |
57 | | /// \brief Derive a key from a secret seed |
58 | | /// \param derived the derived output buffer |
59 | | /// \param derivedLen the size of the derived buffer, in bytes |
60 | | /// \param purpose a purpose byte |
61 | | /// \param secret the seed input buffer |
62 | | /// \param secretLen the size of the secret buffer, in bytes |
63 | | /// \param salt the salt input buffer |
64 | | /// \param saltLen the size of the salt buffer, in bytes |
65 | | /// \param iterations the number of iterations |
66 | | /// \param timeInSeconds the in seconds |
67 | | /// \return the number of iterations performed |
68 | | /// \throw InvalidDerivedKeyLength if <tt>derivedLen</tt> is invalid for the scheme |
69 | | /// \details DeriveKey() provides a standard interface to derive a key from |
70 | | /// a seed and other parameters. Each class that derives from KeyDerivationFunction |
71 | | /// provides an overload that accepts most parameters used by the derivation function. |
72 | | /// \details If <tt>timeInSeconds</tt> is <tt>> 0.0</tt> then DeriveKey will run for |
73 | | /// the specified amount of time. If <tt>timeInSeconds</tt> is <tt>0.0</tt> then DeriveKey |
74 | | /// will run for the specified number of iterations. |
75 | | /// \details PKCS #5 says PBKDF1 should only take 8-byte salts. This implementation |
76 | | /// allows salts of any length. |
77 | | 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; |
78 | | |
79 | | protected: |
80 | | // KeyDerivationFunction interface |
81 | 0 | const Algorithm & GetAlgorithm() const { |
82 | 0 | return *this; |
83 | 0 | } Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA1>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA224>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA384>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA512>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SHAKE128>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SHAKE256>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD128>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD160>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD256>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD320>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Whirlpool>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Weak1::MD2>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Weak1::MD4>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Weak1::MD5>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SM3>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::BLAKE2b>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::BLAKE2s>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Tiger>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<28u> >::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<32u> >::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<48u> >::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<64u> >::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH224>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH256>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH384>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH512>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH512_256>::GetAlgorithm() const |
84 | | }; |
85 | | |
86 | | template <class T> |
87 | | size_t PKCS5_PBKDF1<T>::GetValidDerivedLength(size_t keylength) const |
88 | 162 | { |
89 | 162 | if (keylength > MaxDerivedKeyLength()) |
90 | 0 | return MaxDerivedKeyLength(); |
91 | 162 | return keylength; |
92 | 162 | } CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA1>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 88 | 4 | { | 89 | 4 | if (keylength > MaxDerivedKeyLength()) | 90 | 0 | return MaxDerivedKeyLength(); | 91 | 4 | return keylength; | 92 | 4 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA224>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 88 | 3 | { | 89 | 3 | if (keylength > MaxDerivedKeyLength()) | 90 | 0 | return MaxDerivedKeyLength(); | 91 | 3 | return keylength; | 92 | 3 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA384>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 88 | 4 | { | 89 | 4 | if (keylength > MaxDerivedKeyLength()) | 90 | 0 | return MaxDerivedKeyLength(); | 91 | 4 | return keylength; | 92 | 4 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA512>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 88 | 7 | { | 89 | 7 | if (keylength > MaxDerivedKeyLength()) | 90 | 0 | return MaxDerivedKeyLength(); | 91 | 7 | return keylength; | 92 | 7 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::SHAKE128>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 88 | 4 | { | 89 | 4 | if (keylength > MaxDerivedKeyLength()) | 90 | 0 | return MaxDerivedKeyLength(); | 91 | 4 | return keylength; | 92 | 4 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::SHAKE256>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 88 | 26 | { | 89 | 26 | if (keylength > MaxDerivedKeyLength()) | 90 | 0 | return MaxDerivedKeyLength(); | 91 | 26 | return keylength; | 92 | 26 | } |
Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD128>::GetValidDerivedLength(unsigned long) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD160>::GetValidDerivedLength(unsigned long) const CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD256>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 88 | 3 | { | 89 | 3 | if (keylength > MaxDerivedKeyLength()) | 90 | 0 | return MaxDerivedKeyLength(); | 91 | 3 | return keylength; | 92 | 3 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD320>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 88 | 5 | { | 89 | 5 | if (keylength > MaxDerivedKeyLength()) | 90 | 0 | return MaxDerivedKeyLength(); | 91 | 5 | return keylength; | 92 | 5 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::Whirlpool>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 88 | 8 | { | 89 | 8 | if (keylength > MaxDerivedKeyLength()) | 90 | 0 | return MaxDerivedKeyLength(); | 91 | 8 | return keylength; | 92 | 8 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::Weak1::MD2>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 88 | 5 | { | 89 | 5 | if (keylength > MaxDerivedKeyLength()) | 90 | 0 | return MaxDerivedKeyLength(); | 91 | 5 | return keylength; | 92 | 5 | } |
Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Weak1::MD4>::GetValidDerivedLength(unsigned long) const CryptoPP::PKCS5_PBKDF1<CryptoPP::Weak1::MD5>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 88 | 4 | { | 89 | 4 | if (keylength > MaxDerivedKeyLength()) | 90 | 0 | return MaxDerivedKeyLength(); | 91 | 4 | return keylength; | 92 | 4 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::SM3>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 88 | 3 | { | 89 | 3 | if (keylength > MaxDerivedKeyLength()) | 90 | 0 | return MaxDerivedKeyLength(); | 91 | 3 | return keylength; | 92 | 3 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::BLAKE2b>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 88 | 9 | { | 89 | 9 | if (keylength > MaxDerivedKeyLength()) | 90 | 0 | return MaxDerivedKeyLength(); | 91 | 9 | return keylength; | 92 | 9 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::BLAKE2s>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 88 | 3 | { | 89 | 3 | if (keylength > MaxDerivedKeyLength()) | 90 | 0 | return MaxDerivedKeyLength(); | 91 | 3 | return keylength; | 92 | 3 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::Tiger>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 88 | 6 | { | 89 | 6 | if (keylength > MaxDerivedKeyLength()) | 90 | 0 | return MaxDerivedKeyLength(); | 91 | 6 | return keylength; | 92 | 6 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<28u> >::GetValidDerivedLength(unsigned long) const Line | Count | Source | 88 | 3 | { | 89 | 3 | if (keylength > MaxDerivedKeyLength()) | 90 | 0 | return MaxDerivedKeyLength(); | 91 | 3 | return keylength; | 92 | 3 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<32u> >::GetValidDerivedLength(unsigned long) const Line | Count | Source | 88 | 3 | { | 89 | 3 | if (keylength > MaxDerivedKeyLength()) | 90 | 0 | return MaxDerivedKeyLength(); | 91 | 3 | return keylength; | 92 | 3 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<48u> >::GetValidDerivedLength(unsigned long) const Line | Count | Source | 88 | 8 | { | 89 | 8 | if (keylength > MaxDerivedKeyLength()) | 90 | 0 | return MaxDerivedKeyLength(); | 91 | 8 | return keylength; | 92 | 8 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<64u> >::GetValidDerivedLength(unsigned long) const Line | Count | Source | 88 | 39 | { | 89 | 39 | if (keylength > MaxDerivedKeyLength()) | 90 | 0 | return MaxDerivedKeyLength(); | 91 | 39 | return keylength; | 92 | 39 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH224>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 88 | 1 | { | 89 | 1 | if (keylength > MaxDerivedKeyLength()) | 90 | 0 | return MaxDerivedKeyLength(); | 91 | 1 | return keylength; | 92 | 1 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH256>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 88 | 2 | { | 89 | 2 | if (keylength > MaxDerivedKeyLength()) | 90 | 0 | return MaxDerivedKeyLength(); | 91 | 2 | return keylength; | 92 | 2 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH384>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 88 | 6 | { | 89 | 6 | if (keylength > MaxDerivedKeyLength()) | 90 | 0 | return MaxDerivedKeyLength(); | 91 | 6 | return keylength; | 92 | 6 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH512>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 88 | 5 | { | 89 | 5 | if (keylength > MaxDerivedKeyLength()) | 90 | 0 | return MaxDerivedKeyLength(); | 91 | 5 | return keylength; | 92 | 5 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH512_256>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 88 | 1 | { | 89 | 1 | if (keylength > MaxDerivedKeyLength()) | 90 | 0 | return MaxDerivedKeyLength(); | 91 | 1 | return keylength; | 92 | 1 | } |
|
93 | | |
94 | | template <class T> |
95 | | size_t PKCS5_PBKDF1<T>::DeriveKey(byte *derived, size_t derivedLen, |
96 | | const byte *secret, size_t secretLen, const NameValuePairs& params) const |
97 | 0 | { |
98 | 0 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); |
99 | 0 | CRYPTOPP_ASSERT(derived && derivedLen); |
100 | 0 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); |
101 | |
|
102 | 0 | byte purpose = (byte)params.GetIntValueWithDefault("Purpose", 0); |
103 | 0 | unsigned int iterations = (unsigned int)params.GetIntValueWithDefault("Iterations", 1); |
104 | |
|
105 | 0 | double timeInSeconds = 0.0f; |
106 | 0 | (void)params.GetValue("TimeInSeconds", timeInSeconds); |
107 | |
|
108 | 0 | ConstByteArrayParameter salt; |
109 | 0 | (void)params.GetValue(Name::Salt(), salt); |
110 | |
|
111 | 0 | return DeriveKey(derived, derivedLen, purpose, secret, secretLen, salt.begin(), salt.size(), iterations, timeInSeconds); |
112 | 0 | } Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA1>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA224>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA384>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA512>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SHAKE128>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SHAKE256>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD128>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD160>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD256>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD320>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Whirlpool>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Weak1::MD2>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Weak1::MD4>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Weak1::MD5>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::SM3>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::BLAKE2b>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::BLAKE2s>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Tiger>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<28u> >::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<32u> >::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<48u> >::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<64u> >::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH224>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH256>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH384>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH512>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH512_256>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const |
113 | | |
114 | | template <class T> |
115 | | size_t PKCS5_PBKDF1<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 |
116 | 162 | { |
117 | 162 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); |
118 | 162 | CRYPTOPP_ASSERT(derived && derivedLen); |
119 | 162 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); |
120 | 162 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); |
121 | 162 | CRYPTOPP_UNUSED(purpose); |
122 | | |
123 | 162 | ThrowIfInvalidDerivedKeyLength(derivedLen); |
124 | | |
125 | | // Business logic |
126 | 162 | if (!iterations) { iterations = 1; } |
127 | | |
128 | 162 | T hash; |
129 | 162 | hash.Update(secret, secretLen); |
130 | 162 | hash.Update(salt, saltLen); |
131 | | |
132 | 162 | SecByteBlock buffer(hash.DigestSize()); |
133 | 162 | hash.Final(buffer); |
134 | | |
135 | 162 | unsigned int i; |
136 | 162 | ThreadUserTimer timer; |
137 | | |
138 | 162 | if (timeInSeconds) |
139 | 0 | timer.StartTimer(); |
140 | | |
141 | 379 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) |
142 | 217 | hash.CalculateDigest(buffer, buffer, buffer.size()); |
143 | | |
144 | 162 | if (derived) |
145 | 162 | std::memcpy(derived, buffer, derivedLen); |
146 | 162 | return i; |
147 | 162 | } CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA1>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 116 | 4 | { | 117 | 4 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 118 | 4 | CRYPTOPP_ASSERT(derived && derivedLen); | 119 | 4 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 120 | 4 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 121 | 4 | CRYPTOPP_UNUSED(purpose); | 122 | | | 123 | 4 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 124 | | | 125 | | // Business logic | 126 | 4 | if (!iterations) { iterations = 1; } | 127 | | | 128 | 4 | T hash; | 129 | 4 | hash.Update(secret, secretLen); | 130 | 4 | hash.Update(salt, saltLen); | 131 | | | 132 | 4 | SecByteBlock buffer(hash.DigestSize()); | 133 | 4 | hash.Final(buffer); | 134 | | | 135 | 4 | unsigned int i; | 136 | 4 | ThreadUserTimer timer; | 137 | | | 138 | 4 | if (timeInSeconds) | 139 | 0 | timer.StartTimer(); | 140 | | | 141 | 9 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 142 | 5 | hash.CalculateDigest(buffer, buffer, buffer.size()); | 143 | | | 144 | 4 | if (derived) | 145 | 4 | std::memcpy(derived, buffer, derivedLen); | 146 | 4 | return i; | 147 | 4 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA224>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 116 | 3 | { | 117 | 3 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 118 | 3 | CRYPTOPP_ASSERT(derived && derivedLen); | 119 | 3 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 120 | 3 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 121 | 3 | CRYPTOPP_UNUSED(purpose); | 122 | | | 123 | 3 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 124 | | | 125 | | // Business logic | 126 | 3 | if (!iterations) { iterations = 1; } | 127 | | | 128 | 3 | T hash; | 129 | 3 | hash.Update(secret, secretLen); | 130 | 3 | hash.Update(salt, saltLen); | 131 | | | 132 | 3 | SecByteBlock buffer(hash.DigestSize()); | 133 | 3 | hash.Final(buffer); | 134 | | | 135 | 3 | unsigned int i; | 136 | 3 | ThreadUserTimer timer; | 137 | | | 138 | 3 | if (timeInSeconds) | 139 | 0 | timer.StartTimer(); | 140 | | | 141 | 11 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 142 | 8 | hash.CalculateDigest(buffer, buffer, buffer.size()); | 143 | | | 144 | 3 | if (derived) | 145 | 3 | std::memcpy(derived, buffer, derivedLen); | 146 | 3 | return i; | 147 | 3 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA384>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 116 | 4 | { | 117 | 4 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 118 | 4 | CRYPTOPP_ASSERT(derived && derivedLen); | 119 | 4 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 120 | 4 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 121 | 4 | CRYPTOPP_UNUSED(purpose); | 122 | | | 123 | 4 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 124 | | | 125 | | // Business logic | 126 | 4 | if (!iterations) { iterations = 1; } | 127 | | | 128 | 4 | T hash; | 129 | 4 | hash.Update(secret, secretLen); | 130 | 4 | hash.Update(salt, saltLen); | 131 | | | 132 | 4 | SecByteBlock buffer(hash.DigestSize()); | 133 | 4 | hash.Final(buffer); | 134 | | | 135 | 4 | unsigned int i; | 136 | 4 | ThreadUserTimer timer; | 137 | | | 138 | 4 | if (timeInSeconds) | 139 | 0 | timer.StartTimer(); | 140 | | | 141 | 8 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 142 | 4 | hash.CalculateDigest(buffer, buffer, buffer.size()); | 143 | | | 144 | 4 | if (derived) | 145 | 4 | std::memcpy(derived, buffer, derivedLen); | 146 | 4 | return i; | 147 | 4 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::SHA512>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 116 | 7 | { | 117 | 7 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 118 | 7 | CRYPTOPP_ASSERT(derived && derivedLen); | 119 | 7 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 120 | 7 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 121 | 7 | CRYPTOPP_UNUSED(purpose); | 122 | | | 123 | 7 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 124 | | | 125 | | // Business logic | 126 | 7 | if (!iterations) { iterations = 1; } | 127 | | | 128 | 7 | T hash; | 129 | 7 | hash.Update(secret, secretLen); | 130 | 7 | hash.Update(salt, saltLen); | 131 | | | 132 | 7 | SecByteBlock buffer(hash.DigestSize()); | 133 | 7 | hash.Final(buffer); | 134 | | | 135 | 7 | unsigned int i; | 136 | 7 | ThreadUserTimer timer; | 137 | | | 138 | 7 | if (timeInSeconds) | 139 | 0 | timer.StartTimer(); | 140 | | | 141 | 14 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 142 | 7 | hash.CalculateDigest(buffer, buffer, buffer.size()); | 143 | | | 144 | 7 | if (derived) | 145 | 7 | std::memcpy(derived, buffer, derivedLen); | 146 | 7 | return i; | 147 | 7 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::SHAKE128>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 116 | 4 | { | 117 | 4 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 118 | 4 | CRYPTOPP_ASSERT(derived && derivedLen); | 119 | 4 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 120 | 4 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 121 | 4 | CRYPTOPP_UNUSED(purpose); | 122 | | | 123 | 4 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 124 | | | 125 | | // Business logic | 126 | 4 | if (!iterations) { iterations = 1; } | 127 | | | 128 | 4 | T hash; | 129 | 4 | hash.Update(secret, secretLen); | 130 | 4 | hash.Update(salt, saltLen); | 131 | | | 132 | 4 | SecByteBlock buffer(hash.DigestSize()); | 133 | 4 | hash.Final(buffer); | 134 | | | 135 | 4 | unsigned int i; | 136 | 4 | ThreadUserTimer timer; | 137 | | | 138 | 4 | if (timeInSeconds) | 139 | 0 | timer.StartTimer(); | 140 | | | 141 | 9 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 142 | 5 | hash.CalculateDigest(buffer, buffer, buffer.size()); | 143 | | | 144 | 4 | if (derived) | 145 | 4 | std::memcpy(derived, buffer, derivedLen); | 146 | 4 | return i; | 147 | 4 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::SHAKE256>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 116 | 26 | { | 117 | 26 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 118 | 26 | CRYPTOPP_ASSERT(derived && derivedLen); | 119 | 26 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 120 | 26 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 121 | 26 | CRYPTOPP_UNUSED(purpose); | 122 | | | 123 | 26 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 124 | | | 125 | | // Business logic | 126 | 26 | if (!iterations) { iterations = 1; } | 127 | | | 128 | 26 | T hash; | 129 | 26 | hash.Update(secret, secretLen); | 130 | 26 | hash.Update(salt, saltLen); | 131 | | | 132 | 26 | SecByteBlock buffer(hash.DigestSize()); | 133 | 26 | hash.Final(buffer); | 134 | | | 135 | 26 | unsigned int i; | 136 | 26 | ThreadUserTimer timer; | 137 | | | 138 | 26 | if (timeInSeconds) | 139 | 0 | timer.StartTimer(); | 140 | | | 141 | 87 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 142 | 61 | hash.CalculateDigest(buffer, buffer, buffer.size()); | 143 | | | 144 | 26 | if (derived) | 145 | 26 | std::memcpy(derived, buffer, derivedLen); | 146 | 26 | return i; | 147 | 26 | } |
Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD128>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD160>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD256>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 116 | 3 | { | 117 | 3 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 118 | 3 | CRYPTOPP_ASSERT(derived && derivedLen); | 119 | 3 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 120 | 3 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 121 | 3 | CRYPTOPP_UNUSED(purpose); | 122 | | | 123 | 3 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 124 | | | 125 | | // Business logic | 126 | 3 | if (!iterations) { iterations = 1; } | 127 | | | 128 | 3 | T hash; | 129 | 3 | hash.Update(secret, secretLen); | 130 | 3 | hash.Update(salt, saltLen); | 131 | | | 132 | 3 | SecByteBlock buffer(hash.DigestSize()); | 133 | 3 | hash.Final(buffer); | 134 | | | 135 | 3 | unsigned int i; | 136 | 3 | ThreadUserTimer timer; | 137 | | | 138 | 3 | if (timeInSeconds) | 139 | 0 | timer.StartTimer(); | 140 | | | 141 | 9 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 142 | 6 | hash.CalculateDigest(buffer, buffer, buffer.size()); | 143 | | | 144 | 3 | if (derived) | 145 | 3 | std::memcpy(derived, buffer, derivedLen); | 146 | 3 | return i; | 147 | 3 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::RIPEMD320>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 116 | 5 | { | 117 | 5 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 118 | 5 | CRYPTOPP_ASSERT(derived && derivedLen); | 119 | 5 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 120 | 5 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 121 | 5 | CRYPTOPP_UNUSED(purpose); | 122 | | | 123 | 5 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 124 | | | 125 | | // Business logic | 126 | 5 | if (!iterations) { iterations = 1; } | 127 | | | 128 | 5 | T hash; | 129 | 5 | hash.Update(secret, secretLen); | 130 | 5 | hash.Update(salt, saltLen); | 131 | | | 132 | 5 | SecByteBlock buffer(hash.DigestSize()); | 133 | 5 | hash.Final(buffer); | 134 | | | 135 | 5 | unsigned int i; | 136 | 5 | ThreadUserTimer timer; | 137 | | | 138 | 5 | if (timeInSeconds) | 139 | 0 | timer.StartTimer(); | 140 | | | 141 | 13 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 142 | 8 | hash.CalculateDigest(buffer, buffer, buffer.size()); | 143 | | | 144 | 5 | if (derived) | 145 | 5 | std::memcpy(derived, buffer, derivedLen); | 146 | 5 | return i; | 147 | 5 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::Whirlpool>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 116 | 8 | { | 117 | 8 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 118 | 8 | CRYPTOPP_ASSERT(derived && derivedLen); | 119 | 8 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 120 | 8 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 121 | 8 | CRYPTOPP_UNUSED(purpose); | 122 | | | 123 | 8 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 124 | | | 125 | | // Business logic | 126 | 8 | if (!iterations) { iterations = 1; } | 127 | | | 128 | 8 | T hash; | 129 | 8 | hash.Update(secret, secretLen); | 130 | 8 | hash.Update(salt, saltLen); | 131 | | | 132 | 8 | SecByteBlock buffer(hash.DigestSize()); | 133 | 8 | hash.Final(buffer); | 134 | | | 135 | 8 | unsigned int i; | 136 | 8 | ThreadUserTimer timer; | 137 | | | 138 | 8 | if (timeInSeconds) | 139 | 0 | timer.StartTimer(); | 140 | | | 141 | 14 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 142 | 6 | hash.CalculateDigest(buffer, buffer, buffer.size()); | 143 | | | 144 | 8 | if (derived) | 145 | 8 | std::memcpy(derived, buffer, derivedLen); | 146 | 8 | return i; | 147 | 8 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::Weak1::MD2>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 116 | 5 | { | 117 | 5 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 118 | 5 | CRYPTOPP_ASSERT(derived && derivedLen); | 119 | 5 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 120 | 5 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 121 | 5 | CRYPTOPP_UNUSED(purpose); | 122 | | | 123 | 5 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 124 | | | 125 | | // Business logic | 126 | 5 | if (!iterations) { iterations = 1; } | 127 | | | 128 | 5 | T hash; | 129 | 5 | hash.Update(secret, secretLen); | 130 | 5 | hash.Update(salt, saltLen); | 131 | | | 132 | 5 | SecByteBlock buffer(hash.DigestSize()); | 133 | 5 | hash.Final(buffer); | 134 | | | 135 | 5 | unsigned int i; | 136 | 5 | ThreadUserTimer timer; | 137 | | | 138 | 5 | if (timeInSeconds) | 139 | 0 | timer.StartTimer(); | 140 | | | 141 | 16 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 142 | 11 | hash.CalculateDigest(buffer, buffer, buffer.size()); | 143 | | | 144 | 5 | if (derived) | 145 | 5 | std::memcpy(derived, buffer, derivedLen); | 146 | 5 | return i; | 147 | 5 | } |
Unexecuted instantiation: CryptoPP::PKCS5_PBKDF1<CryptoPP::Weak1::MD4>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const CryptoPP::PKCS5_PBKDF1<CryptoPP::Weak1::MD5>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 116 | 4 | { | 117 | 4 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 118 | 4 | CRYPTOPP_ASSERT(derived && derivedLen); | 119 | 4 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 120 | 4 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 121 | 4 | CRYPTOPP_UNUSED(purpose); | 122 | | | 123 | 4 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 124 | | | 125 | | // Business logic | 126 | 4 | if (!iterations) { iterations = 1; } | 127 | | | 128 | 4 | T hash; | 129 | 4 | hash.Update(secret, secretLen); | 130 | 4 | hash.Update(salt, saltLen); | 131 | | | 132 | 4 | SecByteBlock buffer(hash.DigestSize()); | 133 | 4 | hash.Final(buffer); | 134 | | | 135 | 4 | unsigned int i; | 136 | 4 | ThreadUserTimer timer; | 137 | | | 138 | 4 | if (timeInSeconds) | 139 | 0 | timer.StartTimer(); | 140 | | | 141 | 10 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 142 | 6 | hash.CalculateDigest(buffer, buffer, buffer.size()); | 143 | | | 144 | 4 | if (derived) | 145 | 4 | std::memcpy(derived, buffer, derivedLen); | 146 | 4 | return i; | 147 | 4 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::SM3>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 116 | 3 | { | 117 | 3 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 118 | 3 | CRYPTOPP_ASSERT(derived && derivedLen); | 119 | 3 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 120 | 3 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 121 | 3 | CRYPTOPP_UNUSED(purpose); | 122 | | | 123 | 3 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 124 | | | 125 | | // Business logic | 126 | 3 | if (!iterations) { iterations = 1; } | 127 | | | 128 | 3 | T hash; | 129 | 3 | hash.Update(secret, secretLen); | 130 | 3 | hash.Update(salt, saltLen); | 131 | | | 132 | 3 | SecByteBlock buffer(hash.DigestSize()); | 133 | 3 | hash.Final(buffer); | 134 | | | 135 | 3 | unsigned int i; | 136 | 3 | ThreadUserTimer timer; | 137 | | | 138 | 3 | if (timeInSeconds) | 139 | 0 | timer.StartTimer(); | 140 | | | 141 | 5 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 142 | 2 | hash.CalculateDigest(buffer, buffer, buffer.size()); | 143 | | | 144 | 3 | if (derived) | 145 | 3 | std::memcpy(derived, buffer, derivedLen); | 146 | 3 | return i; | 147 | 3 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::BLAKE2b>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 116 | 9 | { | 117 | 9 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 118 | 9 | CRYPTOPP_ASSERT(derived && derivedLen); | 119 | 9 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 120 | 9 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 121 | 9 | CRYPTOPP_UNUSED(purpose); | 122 | | | 123 | 9 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 124 | | | 125 | | // Business logic | 126 | 9 | if (!iterations) { iterations = 1; } | 127 | | | 128 | 9 | T hash; | 129 | 9 | hash.Update(secret, secretLen); | 130 | 9 | hash.Update(salt, saltLen); | 131 | | | 132 | 9 | SecByteBlock buffer(hash.DigestSize()); | 133 | 9 | hash.Final(buffer); | 134 | | | 135 | 9 | unsigned int i; | 136 | 9 | ThreadUserTimer timer; | 137 | | | 138 | 9 | if (timeInSeconds) | 139 | 0 | timer.StartTimer(); | 140 | | | 141 | 20 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 142 | 11 | hash.CalculateDigest(buffer, buffer, buffer.size()); | 143 | | | 144 | 9 | if (derived) | 145 | 9 | std::memcpy(derived, buffer, derivedLen); | 146 | 9 | return i; | 147 | 9 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::BLAKE2s>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 116 | 3 | { | 117 | 3 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 118 | 3 | CRYPTOPP_ASSERT(derived && derivedLen); | 119 | 3 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 120 | 3 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 121 | 3 | CRYPTOPP_UNUSED(purpose); | 122 | | | 123 | 3 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 124 | | | 125 | | // Business logic | 126 | 3 | if (!iterations) { iterations = 1; } | 127 | | | 128 | 3 | T hash; | 129 | 3 | hash.Update(secret, secretLen); | 130 | 3 | hash.Update(salt, saltLen); | 131 | | | 132 | 3 | SecByteBlock buffer(hash.DigestSize()); | 133 | 3 | hash.Final(buffer); | 134 | | | 135 | 3 | unsigned int i; | 136 | 3 | ThreadUserTimer timer; | 137 | | | 138 | 3 | if (timeInSeconds) | 139 | 0 | timer.StartTimer(); | 140 | | | 141 | 6 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 142 | 3 | hash.CalculateDigest(buffer, buffer, buffer.size()); | 143 | | | 144 | 3 | if (derived) | 145 | 3 | std::memcpy(derived, buffer, derivedLen); | 146 | 3 | return i; | 147 | 3 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::Tiger>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 116 | 6 | { | 117 | 6 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 118 | 6 | CRYPTOPP_ASSERT(derived && derivedLen); | 119 | 6 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 120 | 6 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 121 | 6 | CRYPTOPP_UNUSED(purpose); | 122 | | | 123 | 6 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 124 | | | 125 | | // Business logic | 126 | 6 | if (!iterations) { iterations = 1; } | 127 | | | 128 | 6 | T hash; | 129 | 6 | hash.Update(secret, secretLen); | 130 | 6 | hash.Update(salt, saltLen); | 131 | | | 132 | 6 | SecByteBlock buffer(hash.DigestSize()); | 133 | 6 | hash.Final(buffer); | 134 | | | 135 | 6 | unsigned int i; | 136 | 6 | ThreadUserTimer timer; | 137 | | | 138 | 6 | if (timeInSeconds) | 139 | 0 | timer.StartTimer(); | 140 | | | 141 | 17 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 142 | 11 | hash.CalculateDigest(buffer, buffer, buffer.size()); | 143 | | | 144 | 6 | if (derived) | 145 | 6 | std::memcpy(derived, buffer, derivedLen); | 146 | 6 | return i; | 147 | 6 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<28u> >::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 116 | 3 | { | 117 | 3 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 118 | 3 | CRYPTOPP_ASSERT(derived && derivedLen); | 119 | 3 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 120 | 3 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 121 | 3 | CRYPTOPP_UNUSED(purpose); | 122 | | | 123 | 3 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 124 | | | 125 | | // Business logic | 126 | 3 | if (!iterations) { iterations = 1; } | 127 | | | 128 | 3 | T hash; | 129 | 3 | hash.Update(secret, secretLen); | 130 | 3 | hash.Update(salt, saltLen); | 131 | | | 132 | 3 | SecByteBlock buffer(hash.DigestSize()); | 133 | 3 | hash.Final(buffer); | 134 | | | 135 | 3 | unsigned int i; | 136 | 3 | ThreadUserTimer timer; | 137 | | | 138 | 3 | if (timeInSeconds) | 139 | 0 | timer.StartTimer(); | 140 | | | 141 | 4 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 142 | 1 | hash.CalculateDigest(buffer, buffer, buffer.size()); | 143 | | | 144 | 3 | if (derived) | 145 | 3 | std::memcpy(derived, buffer, derivedLen); | 146 | 3 | return i; | 147 | 3 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<32u> >::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 116 | 3 | { | 117 | 3 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 118 | 3 | CRYPTOPP_ASSERT(derived && derivedLen); | 119 | 3 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 120 | 3 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 121 | 3 | CRYPTOPP_UNUSED(purpose); | 122 | | | 123 | 3 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 124 | | | 125 | | // Business logic | 126 | 3 | if (!iterations) { iterations = 1; } | 127 | | | 128 | 3 | T hash; | 129 | 3 | hash.Update(secret, secretLen); | 130 | 3 | hash.Update(salt, saltLen); | 131 | | | 132 | 3 | SecByteBlock buffer(hash.DigestSize()); | 133 | 3 | hash.Final(buffer); | 134 | | | 135 | 3 | unsigned int i; | 136 | 3 | ThreadUserTimer timer; | 137 | | | 138 | 3 | if (timeInSeconds) | 139 | 0 | timer.StartTimer(); | 140 | | | 141 | 8 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 142 | 5 | hash.CalculateDigest(buffer, buffer, buffer.size()); | 143 | | | 144 | 3 | if (derived) | 145 | 3 | std::memcpy(derived, buffer, derivedLen); | 146 | 3 | return i; | 147 | 3 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<48u> >::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 116 | 8 | { | 117 | 8 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 118 | 8 | CRYPTOPP_ASSERT(derived && derivedLen); | 119 | 8 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 120 | 8 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 121 | 8 | CRYPTOPP_UNUSED(purpose); | 122 | | | 123 | 8 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 124 | | | 125 | | // Business logic | 126 | 8 | if (!iterations) { iterations = 1; } | 127 | | | 128 | 8 | T hash; | 129 | 8 | hash.Update(secret, secretLen); | 130 | 8 | hash.Update(salt, saltLen); | 131 | | | 132 | 8 | SecByteBlock buffer(hash.DigestSize()); | 133 | 8 | hash.Final(buffer); | 134 | | | 135 | 8 | unsigned int i; | 136 | 8 | ThreadUserTimer timer; | 137 | | | 138 | 8 | if (timeInSeconds) | 139 | 0 | timer.StartTimer(); | 140 | | | 141 | 19 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 142 | 11 | hash.CalculateDigest(buffer, buffer, buffer.size()); | 143 | | | 144 | 8 | if (derived) | 145 | 8 | std::memcpy(derived, buffer, derivedLen); | 146 | 8 | return i; | 147 | 8 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::Keccak_Final<64u> >::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 116 | 39 | { | 117 | 39 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 118 | 39 | CRYPTOPP_ASSERT(derived && derivedLen); | 119 | 39 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 120 | 39 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 121 | 39 | CRYPTOPP_UNUSED(purpose); | 122 | | | 123 | 39 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 124 | | | 125 | | // Business logic | 126 | 39 | if (!iterations) { iterations = 1; } | 127 | | | 128 | 39 | T hash; | 129 | 39 | hash.Update(secret, secretLen); | 130 | 39 | hash.Update(salt, saltLen); | 131 | | | 132 | 39 | SecByteBlock buffer(hash.DigestSize()); | 133 | 39 | hash.Final(buffer); | 134 | | | 135 | 39 | unsigned int i; | 136 | 39 | ThreadUserTimer timer; | 137 | | | 138 | 39 | if (timeInSeconds) | 139 | 0 | timer.StartTimer(); | 140 | | | 141 | 67 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 142 | 28 | hash.CalculateDigest(buffer, buffer, buffer.size()); | 143 | | | 144 | 39 | if (derived) | 145 | 39 | std::memcpy(derived, buffer, derivedLen); | 146 | 39 | return i; | 147 | 39 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH224>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 116 | 1 | { | 117 | 1 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 118 | 1 | CRYPTOPP_ASSERT(derived && derivedLen); | 119 | 1 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 120 | 1 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 121 | 1 | CRYPTOPP_UNUSED(purpose); | 122 | | | 123 | 1 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 124 | | | 125 | | // Business logic | 126 | 1 | if (!iterations) { iterations = 1; } | 127 | | | 128 | 1 | T hash; | 129 | 1 | hash.Update(secret, secretLen); | 130 | 1 | hash.Update(salt, saltLen); | 131 | | | 132 | 1 | SecByteBlock buffer(hash.DigestSize()); | 133 | 1 | hash.Final(buffer); | 134 | | | 135 | 1 | unsigned int i; | 136 | 1 | ThreadUserTimer timer; | 137 | | | 138 | 1 | if (timeInSeconds) | 139 | 0 | timer.StartTimer(); | 140 | | | 141 | 4 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 142 | 3 | hash.CalculateDigest(buffer, buffer, buffer.size()); | 143 | | | 144 | 1 | if (derived) | 145 | 1 | std::memcpy(derived, buffer, derivedLen); | 146 | 1 | return i; | 147 | 1 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH256>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 116 | 2 | { | 117 | 2 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 118 | 2 | CRYPTOPP_ASSERT(derived && derivedLen); | 119 | 2 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 120 | 2 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 121 | 2 | CRYPTOPP_UNUSED(purpose); | 122 | | | 123 | 2 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 124 | | | 125 | | // Business logic | 126 | 2 | if (!iterations) { iterations = 1; } | 127 | | | 128 | 2 | T hash; | 129 | 2 | hash.Update(secret, secretLen); | 130 | 2 | hash.Update(salt, saltLen); | 131 | | | 132 | 2 | SecByteBlock buffer(hash.DigestSize()); | 133 | 2 | hash.Final(buffer); | 134 | | | 135 | 2 | unsigned int i; | 136 | 2 | ThreadUserTimer timer; | 137 | | | 138 | 2 | if (timeInSeconds) | 139 | 0 | timer.StartTimer(); | 140 | | | 141 | 4 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 142 | 2 | hash.CalculateDigest(buffer, buffer, buffer.size()); | 143 | | | 144 | 2 | if (derived) | 145 | 2 | std::memcpy(derived, buffer, derivedLen); | 146 | 2 | return i; | 147 | 2 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH384>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 116 | 6 | { | 117 | 6 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 118 | 6 | CRYPTOPP_ASSERT(derived && derivedLen); | 119 | 6 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 120 | 6 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 121 | 6 | CRYPTOPP_UNUSED(purpose); | 122 | | | 123 | 6 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 124 | | | 125 | | // Business logic | 126 | 6 | if (!iterations) { iterations = 1; } | 127 | | | 128 | 6 | T hash; | 129 | 6 | hash.Update(secret, secretLen); | 130 | 6 | hash.Update(salt, saltLen); | 131 | | | 132 | 6 | SecByteBlock buffer(hash.DigestSize()); | 133 | 6 | hash.Final(buffer); | 134 | | | 135 | 6 | unsigned int i; | 136 | 6 | ThreadUserTimer timer; | 137 | | | 138 | 6 | if (timeInSeconds) | 139 | 0 | timer.StartTimer(); | 140 | | | 141 | 13 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 142 | 7 | hash.CalculateDigest(buffer, buffer, buffer.size()); | 143 | | | 144 | 6 | if (derived) | 145 | 6 | std::memcpy(derived, buffer, derivedLen); | 146 | 6 | return i; | 147 | 6 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH512>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 116 | 5 | { | 117 | 5 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 118 | 5 | CRYPTOPP_ASSERT(derived && derivedLen); | 119 | 5 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 120 | 5 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 121 | 5 | CRYPTOPP_UNUSED(purpose); | 122 | | | 123 | 5 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 124 | | | 125 | | // Business logic | 126 | 5 | if (!iterations) { iterations = 1; } | 127 | | | 128 | 5 | T hash; | 129 | 5 | hash.Update(secret, secretLen); | 130 | 5 | hash.Update(salt, saltLen); | 131 | | | 132 | 5 | SecByteBlock buffer(hash.DigestSize()); | 133 | 5 | hash.Final(buffer); | 134 | | | 135 | 5 | unsigned int i; | 136 | 5 | ThreadUserTimer timer; | 137 | | | 138 | 5 | if (timeInSeconds) | 139 | 0 | timer.StartTimer(); | 140 | | | 141 | 11 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 142 | 6 | hash.CalculateDigest(buffer, buffer, buffer.size()); | 143 | | | 144 | 5 | if (derived) | 145 | 5 | std::memcpy(derived, buffer, derivedLen); | 146 | 5 | return i; | 147 | 5 | } |
CryptoPP::PKCS5_PBKDF1<CryptoPP::LSH512_256>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 116 | 1 | { | 117 | 1 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 118 | 1 | CRYPTOPP_ASSERT(derived && derivedLen); | 119 | 1 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 120 | 1 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 121 | 1 | CRYPTOPP_UNUSED(purpose); | 122 | | | 123 | 1 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 124 | | | 125 | | // Business logic | 126 | 1 | if (!iterations) { iterations = 1; } | 127 | | | 128 | 1 | T hash; | 129 | 1 | hash.Update(secret, secretLen); | 130 | 1 | hash.Update(salt, saltLen); | 131 | | | 132 | 1 | SecByteBlock buffer(hash.DigestSize()); | 133 | 1 | hash.Final(buffer); | 134 | | | 135 | 1 | unsigned int i; | 136 | 1 | ThreadUserTimer timer; | 137 | | | 138 | 1 | if (timeInSeconds) | 139 | 0 | timer.StartTimer(); | 140 | | | 141 | 1 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 142 | 0 | hash.CalculateDigest(buffer, buffer, buffer.size()); | 143 | | | 144 | 1 | if (derived) | 145 | 1 | std::memcpy(derived, buffer, derivedLen); | 146 | 1 | return i; | 147 | 1 | } |
|
148 | | |
149 | | // ******************** PKCS5_PBKDF2_HMAC ******************** |
150 | | |
151 | | /// \brief PBKDF2 from PKCS #5 |
152 | | /// \tparam T a HashTransformation class |
153 | | /// \sa PasswordBasedKeyDerivationFunction, <A |
154 | | /// HREF="https://www.cryptopp.com/wiki/PKCS5_PBKDF2_HMAC">PKCS5_PBKDF2_HMAC</A> |
155 | | /// on the Crypto++ wiki |
156 | | /// \since Crypto++ 2.0 |
157 | | template <class T> |
158 | | class PKCS5_PBKDF2_HMAC : public PasswordBasedKeyDerivationFunction |
159 | | { |
160 | | public: |
161 | | virtual ~PKCS5_PBKDF2_HMAC() {} |
162 | | |
163 | 0 | static std::string StaticAlgorithmName () { |
164 | 0 | const std::string name(std::string("PBKDF2_HMAC(") + |
165 | 0 | std::string(T::StaticAlgorithmName()) + std::string(")")); |
166 | 0 | return name; |
167 | 0 | } Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA1>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA224>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA384>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA512>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHAKE128>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHAKE256>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD128>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD160>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD256>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD320>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Whirlpool>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Weak1::MD2>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Weak1::MD4>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Weak1::MD5>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SM3>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::BLAKE2b>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::BLAKE2s>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Tiger>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<28u> >::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<32u> >::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<48u> >::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<64u> >::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH224>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH256>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH384>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH512>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH512_256>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA256>::StaticAlgorithmName() |
168 | | |
169 | | // KeyDerivationFunction interface |
170 | 0 | std::string AlgorithmName() const { |
171 | 0 | return StaticAlgorithmName(); |
172 | 0 | } Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA1>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA224>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA384>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA512>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHAKE128>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHAKE256>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD128>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD160>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD256>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD320>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Whirlpool>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Weak1::MD2>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Weak1::MD4>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Weak1::MD5>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SM3>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::BLAKE2b>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::BLAKE2s>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Tiger>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<28u> >::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<32u> >::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<48u> >::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<64u> >::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH224>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH256>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH384>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH512>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH512_256>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA256>::AlgorithmName() const |
173 | | |
174 | | // KeyDerivationFunction interface |
175 | | // should multiply by T::DIGESTSIZE, but gets overflow that way |
176 | 2.27k | size_t MaxDerivedKeyLength() const { |
177 | 2.27k | return 0xffffffffU; |
178 | 2.27k | } CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA1>::MaxDerivedKeyLength() const Line | Count | Source | 176 | 83 | size_t MaxDerivedKeyLength() const { | 177 | 83 | return 0xffffffffU; | 178 | 83 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA224>::MaxDerivedKeyLength() const Line | Count | Source | 176 | 55 | size_t MaxDerivedKeyLength() const { | 177 | 55 | return 0xffffffffU; | 178 | 55 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA384>::MaxDerivedKeyLength() const Line | Count | Source | 176 | 105 | size_t MaxDerivedKeyLength() const { | 177 | 105 | return 0xffffffffU; | 178 | 105 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA512>::MaxDerivedKeyLength() const Line | Count | Source | 176 | 83 | size_t MaxDerivedKeyLength() const { | 177 | 83 | return 0xffffffffU; | 178 | 83 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHAKE128>::MaxDerivedKeyLength() const Line | Count | Source | 176 | 38 | size_t MaxDerivedKeyLength() const { | 177 | 38 | return 0xffffffffU; | 178 | 38 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHAKE256>::MaxDerivedKeyLength() const Line | Count | Source | 176 | 39 | size_t MaxDerivedKeyLength() const { | 177 | 39 | return 0xffffffffU; | 178 | 39 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD128>::MaxDerivedKeyLength() const Line | Count | Source | 176 | 75 | size_t MaxDerivedKeyLength() const { | 177 | 75 | return 0xffffffffU; | 178 | 75 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD160>::MaxDerivedKeyLength() const Line | Count | Source | 176 | 52 | size_t MaxDerivedKeyLength() const { | 177 | 52 | return 0xffffffffU; | 178 | 52 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD256>::MaxDerivedKeyLength() const Line | Count | Source | 176 | 42 | size_t MaxDerivedKeyLength() const { | 177 | 42 | return 0xffffffffU; | 178 | 42 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD320>::MaxDerivedKeyLength() const Line | Count | Source | 176 | 52 | size_t MaxDerivedKeyLength() const { | 177 | 52 | return 0xffffffffU; | 178 | 52 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Whirlpool>::MaxDerivedKeyLength() const Line | Count | Source | 176 | 55 | size_t MaxDerivedKeyLength() const { | 177 | 55 | return 0xffffffffU; | 178 | 55 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Weak1::MD2>::MaxDerivedKeyLength() const Line | Count | Source | 176 | 41 | size_t MaxDerivedKeyLength() const { | 177 | 41 | return 0xffffffffU; | 178 | 41 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Weak1::MD4>::MaxDerivedKeyLength() const Line | Count | Source | 176 | 98 | size_t MaxDerivedKeyLength() const { | 177 | 98 | return 0xffffffffU; | 178 | 98 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Weak1::MD5>::MaxDerivedKeyLength() const Line | Count | Source | 176 | 51 | size_t MaxDerivedKeyLength() const { | 177 | 51 | return 0xffffffffU; | 178 | 51 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SM3>::MaxDerivedKeyLength() const Line | Count | Source | 176 | 41 | size_t MaxDerivedKeyLength() const { | 177 | 41 | return 0xffffffffU; | 178 | 41 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::BLAKE2b>::MaxDerivedKeyLength() const Line | Count | Source | 176 | 44 | size_t MaxDerivedKeyLength() const { | 177 | 44 | return 0xffffffffU; | 178 | 44 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::BLAKE2s>::MaxDerivedKeyLength() const Line | Count | Source | 176 | 34 | size_t MaxDerivedKeyLength() const { | 177 | 34 | return 0xffffffffU; | 178 | 34 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Tiger>::MaxDerivedKeyLength() const Line | Count | Source | 176 | 51 | size_t MaxDerivedKeyLength() const { | 177 | 51 | return 0xffffffffU; | 178 | 51 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<28u> >::MaxDerivedKeyLength() const Line | Count | Source | 176 | 41 | size_t MaxDerivedKeyLength() const { | 177 | 41 | return 0xffffffffU; | 178 | 41 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<32u> >::MaxDerivedKeyLength() const Line | Count | Source | 176 | 39 | size_t MaxDerivedKeyLength() const { | 177 | 39 | return 0xffffffffU; | 178 | 39 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<48u> >::MaxDerivedKeyLength() const Line | Count | Source | 176 | 48 | size_t MaxDerivedKeyLength() const { | 177 | 48 | return 0xffffffffU; | 178 | 48 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<64u> >::MaxDerivedKeyLength() const Line | Count | Source | 176 | 68 | size_t MaxDerivedKeyLength() const { | 177 | 68 | return 0xffffffffU; | 178 | 68 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH224>::MaxDerivedKeyLength() const Line | Count | Source | 176 | 40 | size_t MaxDerivedKeyLength() const { | 177 | 40 | return 0xffffffffU; | 178 | 40 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH256>::MaxDerivedKeyLength() const Line | Count | Source | 176 | 33 | size_t MaxDerivedKeyLength() const { | 177 | 33 | return 0xffffffffU; | 178 | 33 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH384>::MaxDerivedKeyLength() const Line | Count | Source | 176 | 36 | size_t MaxDerivedKeyLength() const { | 177 | 36 | return 0xffffffffU; | 178 | 36 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH512>::MaxDerivedKeyLength() const Line | Count | Source | 176 | 37 | size_t MaxDerivedKeyLength() const { | 177 | 37 | return 0xffffffffU; | 178 | 37 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH512_256>::MaxDerivedKeyLength() const Line | Count | Source | 176 | 37 | size_t MaxDerivedKeyLength() const { | 177 | 37 | return 0xffffffffU; | 178 | 37 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA256>::MaxDerivedKeyLength() const Line | Count | Source | 176 | 858 | size_t MaxDerivedKeyLength() const { | 177 | 858 | return 0xffffffffU; | 178 | 858 | } |
|
179 | | |
180 | | // KeyDerivationFunction interface |
181 | | size_t GetValidDerivedLength(size_t keylength) const; |
182 | | |
183 | | // KeyDerivationFunction interface |
184 | | size_t DeriveKey(byte *derived, size_t derivedLen, const byte *secret, size_t secretLen, |
185 | | const NameValuePairs& params = g_nullNameValuePairs) const; |
186 | | |
187 | | /// \brief Derive a key from a secret seed |
188 | | /// \param derived the derived output buffer |
189 | | /// \param derivedLen the size of the derived buffer, in bytes |
190 | | /// \param purpose a purpose byte |
191 | | /// \param secret the seed input buffer |
192 | | /// \param secretLen the size of the secret buffer, in bytes |
193 | | /// \param salt the salt input buffer |
194 | | /// \param saltLen the size of the salt buffer, in bytes |
195 | | /// \param iterations the number of iterations |
196 | | /// \param timeInSeconds the in seconds |
197 | | /// \return the number of iterations performed |
198 | | /// \throw InvalidDerivedKeyLength if <tt>derivedLen</tt> is invalid for the scheme |
199 | | /// \details DeriveKey() provides a standard interface to derive a key from |
200 | | /// a seed and other parameters. Each class that derives from KeyDerivationFunction |
201 | | /// provides an overload that accepts most parameters used by the derivation function. |
202 | | /// \details If <tt>timeInSeconds</tt> is <tt>> 0.0</tt> then DeriveKey will run for |
203 | | /// the specified amount of time. If <tt>timeInSeconds</tt> is <tt>0.0</tt> then DeriveKey |
204 | | /// will run for the specified number of iterations. |
205 | | size_t DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *secret, size_t secretLen, |
206 | | const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds=0) const; |
207 | | |
208 | | protected: |
209 | | // KeyDerivationFunction interface |
210 | 0 | const Algorithm & GetAlgorithm() const { |
211 | 0 | return *this; |
212 | 0 | } Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA1>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA224>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA384>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA512>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHAKE128>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHAKE256>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD128>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD160>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD256>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD320>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Whirlpool>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Weak1::MD2>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Weak1::MD4>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Weak1::MD5>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SM3>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::BLAKE2b>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::BLAKE2s>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Tiger>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<28u> >::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<32u> >::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<48u> >::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<64u> >::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH224>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH256>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH384>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH512>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH512_256>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA256>::GetAlgorithm() const |
213 | | }; |
214 | | |
215 | | template <class T> |
216 | | size_t PKCS5_PBKDF2_HMAC<T>::GetValidDerivedLength(size_t keylength) const |
217 | 2.27k | { |
218 | 2.27k | if (keylength > MaxDerivedKeyLength()) |
219 | 0 | return MaxDerivedKeyLength(); |
220 | 2.27k | return keylength; |
221 | 2.27k | } CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA1>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 83 | { | 218 | 83 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 83 | return keylength; | 221 | 83 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA224>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 55 | { | 218 | 55 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 55 | return keylength; | 221 | 55 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA384>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 105 | { | 218 | 105 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 105 | return keylength; | 221 | 105 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA512>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 83 | { | 218 | 83 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 83 | return keylength; | 221 | 83 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHAKE128>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 38 | { | 218 | 38 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 38 | return keylength; | 221 | 38 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHAKE256>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 39 | { | 218 | 39 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 39 | return keylength; | 221 | 39 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD128>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 75 | { | 218 | 75 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 75 | return keylength; | 221 | 75 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD160>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 52 | { | 218 | 52 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 52 | return keylength; | 221 | 52 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD256>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 42 | { | 218 | 42 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 42 | return keylength; | 221 | 42 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD320>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 52 | { | 218 | 52 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 52 | return keylength; | 221 | 52 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Whirlpool>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 55 | { | 218 | 55 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 55 | return keylength; | 221 | 55 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Weak1::MD2>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 41 | { | 218 | 41 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 41 | return keylength; | 221 | 41 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Weak1::MD4>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 98 | { | 218 | 98 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 98 | return keylength; | 221 | 98 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Weak1::MD5>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 51 | { | 218 | 51 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 51 | return keylength; | 221 | 51 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SM3>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 41 | { | 218 | 41 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 41 | return keylength; | 221 | 41 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::BLAKE2b>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 44 | { | 218 | 44 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 44 | return keylength; | 221 | 44 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::BLAKE2s>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 34 | { | 218 | 34 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 34 | return keylength; | 221 | 34 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Tiger>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 51 | { | 218 | 51 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 51 | return keylength; | 221 | 51 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<28u> >::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 41 | { | 218 | 41 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 41 | return keylength; | 221 | 41 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<32u> >::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 39 | { | 218 | 39 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 39 | return keylength; | 221 | 39 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<48u> >::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 48 | { | 218 | 48 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 48 | return keylength; | 221 | 48 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<64u> >::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 68 | { | 218 | 68 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 68 | return keylength; | 221 | 68 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH224>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 40 | { | 218 | 40 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 40 | return keylength; | 221 | 40 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH256>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 33 | { | 218 | 33 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 33 | return keylength; | 221 | 33 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH384>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 36 | { | 218 | 36 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 36 | return keylength; | 221 | 36 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH512>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 37 | { | 218 | 37 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 37 | return keylength; | 221 | 37 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH512_256>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 37 | { | 218 | 37 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 37 | return keylength; | 221 | 37 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA256>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 217 | 858 | { | 218 | 858 | if (keylength > MaxDerivedKeyLength()) | 219 | 0 | return MaxDerivedKeyLength(); | 220 | 858 | return keylength; | 221 | 858 | } |
|
222 | | |
223 | | template <class T> |
224 | | size_t PKCS5_PBKDF2_HMAC<T>::DeriveKey(byte *derived, size_t derivedLen, |
225 | | const byte *secret, size_t secretLen, const NameValuePairs& params) const |
226 | 0 | { |
227 | 0 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); |
228 | 0 | CRYPTOPP_ASSERT(derived && derivedLen); |
229 | 0 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); |
230 | |
|
231 | 0 | byte purpose = (byte)params.GetIntValueWithDefault("Purpose", 0); |
232 | 0 | unsigned int iterations = (unsigned int)params.GetIntValueWithDefault("Iterations", 1); |
233 | |
|
234 | 0 | double timeInSeconds = 0.0f; |
235 | 0 | (void)params.GetValue("TimeInSeconds", timeInSeconds); |
236 | |
|
237 | 0 | ConstByteArrayParameter salt; |
238 | 0 | (void)params.GetValue(Name::Salt(), salt); |
239 | |
|
240 | 0 | return DeriveKey(derived, derivedLen, purpose, secret, secretLen, salt.begin(), salt.size(), iterations, timeInSeconds); |
241 | 0 | } Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA1>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA224>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA384>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA512>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHAKE128>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHAKE256>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD128>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD160>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD256>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD320>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Whirlpool>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Weak1::MD2>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Weak1::MD4>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Weak1::MD5>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SM3>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::BLAKE2b>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::BLAKE2s>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Tiger>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<28u> >::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<32u> >::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<48u> >::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<64u> >::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH224>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH256>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH384>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH512>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH512_256>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA256>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const |
242 | | |
243 | | template <class T> |
244 | | size_t PKCS5_PBKDF2_HMAC<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 |
245 | 2.27k | { |
246 | 2.27k | CRYPTOPP_ASSERT(secret /*&& secretLen*/); |
247 | 2.27k | CRYPTOPP_ASSERT(derived && derivedLen); |
248 | 2.27k | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); |
249 | 2.27k | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); |
250 | 2.27k | CRYPTOPP_UNUSED(purpose); |
251 | | |
252 | 2.27k | ThrowIfInvalidDerivedKeyLength(derivedLen); |
253 | | |
254 | | // Business logic |
255 | 2.27k | if (!iterations) { iterations = 1; } |
256 | | |
257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 |
258 | 2.27k | HMAC<T> hmac(secret, secretLen); |
259 | 2.27k | if (hmac.DigestSize() == 0) |
260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); |
261 | | |
262 | 2.27k | SecByteBlock buffer(hmac.DigestSize()); |
263 | 2.27k | ThreadUserTimer timer; |
264 | | |
265 | 2.27k | unsigned int i=1; |
266 | 57.8k | while (derivedLen > 0) |
267 | 55.5k | { |
268 | 55.5k | hmac.Update(salt, saltLen); |
269 | 55.5k | unsigned int j; |
270 | 277k | for (j=0; j<4; j++) |
271 | 222k | { |
272 | 222k | byte b = byte(i >> ((3-j)*8)); |
273 | 222k | hmac.Update(&b, 1); |
274 | 222k | } |
275 | 55.5k | hmac.Final(buffer); |
276 | | |
277 | | #if CRYPTOPP_MSC_VERSION |
278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); |
279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); |
280 | | #else |
281 | 55.5k | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); |
282 | 55.5k | std::memcpy(derived, buffer, segmentLen); |
283 | 55.5k | #endif |
284 | | |
285 | 55.5k | if (timeInSeconds) |
286 | 0 | { |
287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); |
288 | 0 | timer.StartTimer(); |
289 | 0 | } |
290 | | |
291 | 83.1k | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) |
292 | 27.5k | { |
293 | 27.5k | hmac.CalculateDigest(buffer, buffer, buffer.size()); |
294 | 27.5k | xorbuf(derived, buffer, segmentLen); |
295 | 27.5k | } |
296 | | |
297 | 55.5k | if (timeInSeconds) |
298 | 0 | { |
299 | 0 | iterations = j; |
300 | 0 | timeInSeconds = 0; |
301 | 0 | } |
302 | | |
303 | 55.5k | derived += segmentLen; |
304 | 55.5k | derivedLen -= segmentLen; |
305 | 55.5k | i++; |
306 | 55.5k | } |
307 | | |
308 | 2.27k | return iterations; |
309 | 2.27k | } CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA1>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 83 | { | 246 | 83 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 83 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 83 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 83 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 83 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 83 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 83 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 83 | HMAC<T> hmac(secret, secretLen); | 259 | 83 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 83 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 83 | ThreadUserTimer timer; | 264 | | | 265 | 83 | unsigned int i=1; | 266 | 2.14k | while (derivedLen > 0) | 267 | 2.05k | { | 268 | 2.05k | hmac.Update(salt, saltLen); | 269 | 2.05k | unsigned int j; | 270 | 10.2k | for (j=0; j<4; j++) | 271 | 8.23k | { | 272 | 8.23k | byte b = byte(i >> ((3-j)*8)); | 273 | 8.23k | hmac.Update(&b, 1); | 274 | 8.23k | } | 275 | 2.05k | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 2.05k | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 2.05k | std::memcpy(derived, buffer, segmentLen); | 283 | 2.05k | #endif | 284 | | | 285 | 2.05k | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 5.09k | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 3.03k | { | 293 | 3.03k | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 3.03k | xorbuf(derived, buffer, segmentLen); | 295 | 3.03k | } | 296 | | | 297 | 2.05k | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 2.05k | derived += segmentLen; | 304 | 2.05k | derivedLen -= segmentLen; | 305 | 2.05k | i++; | 306 | 2.05k | } | 307 | | | 308 | 83 | return iterations; | 309 | 83 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA224>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 55 | { | 246 | 55 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 55 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 55 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 55 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 55 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 55 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 55 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 55 | HMAC<T> hmac(secret, secretLen); | 259 | 55 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 55 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 55 | ThreadUserTimer timer; | 264 | | | 265 | 55 | unsigned int i=1; | 266 | 851 | while (derivedLen > 0) | 267 | 796 | { | 268 | 796 | hmac.Update(salt, saltLen); | 269 | 796 | unsigned int j; | 270 | 3.98k | for (j=0; j<4; j++) | 271 | 3.18k | { | 272 | 3.18k | byte b = byte(i >> ((3-j)*8)); | 273 | 3.18k | hmac.Update(&b, 1); | 274 | 3.18k | } | 275 | 796 | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 796 | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 796 | std::memcpy(derived, buffer, segmentLen); | 283 | 796 | #endif | 284 | | | 285 | 796 | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 1.84k | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 1.05k | { | 293 | 1.05k | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 1.05k | xorbuf(derived, buffer, segmentLen); | 295 | 1.05k | } | 296 | | | 297 | 796 | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 796 | derived += segmentLen; | 304 | 796 | derivedLen -= segmentLen; | 305 | 796 | i++; | 306 | 796 | } | 307 | | | 308 | 55 | return iterations; | 309 | 55 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA384>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 105 | { | 246 | 105 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 105 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 105 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 105 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 105 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 105 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 105 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 105 | HMAC<T> hmac(secret, secretLen); | 259 | 105 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 105 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 105 | ThreadUserTimer timer; | 264 | | | 265 | 105 | unsigned int i=1; | 266 | 745 | while (derivedLen > 0) | 267 | 640 | { | 268 | 640 | hmac.Update(salt, saltLen); | 269 | 640 | unsigned int j; | 270 | 3.20k | for (j=0; j<4; j++) | 271 | 2.56k | { | 272 | 2.56k | byte b = byte(i >> ((3-j)*8)); | 273 | 2.56k | hmac.Update(&b, 1); | 274 | 2.56k | } | 275 | 640 | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 640 | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 640 | std::memcpy(derived, buffer, segmentLen); | 283 | 640 | #endif | 284 | | | 285 | 640 | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 1.55k | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 912 | { | 293 | 912 | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 912 | xorbuf(derived, buffer, segmentLen); | 295 | 912 | } | 296 | | | 297 | 640 | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 640 | derived += segmentLen; | 304 | 640 | derivedLen -= segmentLen; | 305 | 640 | i++; | 306 | 640 | } | 307 | | | 308 | 105 | return iterations; | 309 | 105 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA512>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 83 | { | 246 | 83 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 83 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 83 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 83 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 83 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 83 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 83 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 83 | HMAC<T> hmac(secret, secretLen); | 259 | 83 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 83 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 83 | ThreadUserTimer timer; | 264 | | | 265 | 83 | unsigned int i=1; | 266 | 648 | while (derivedLen > 0) | 267 | 565 | { | 268 | 565 | hmac.Update(salt, saltLen); | 269 | 565 | unsigned int j; | 270 | 2.82k | for (j=0; j<4; j++) | 271 | 2.26k | { | 272 | 2.26k | byte b = byte(i >> ((3-j)*8)); | 273 | 2.26k | hmac.Update(&b, 1); | 274 | 2.26k | } | 275 | 565 | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 565 | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 565 | std::memcpy(derived, buffer, segmentLen); | 283 | 565 | #endif | 284 | | | 285 | 565 | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 1.32k | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 755 | { | 293 | 755 | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 755 | xorbuf(derived, buffer, segmentLen); | 295 | 755 | } | 296 | | | 297 | 565 | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 565 | derived += segmentLen; | 304 | 565 | derivedLen -= segmentLen; | 305 | 565 | i++; | 306 | 565 | } | 307 | | | 308 | 83 | return iterations; | 309 | 83 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHAKE128>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 38 | { | 246 | 38 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 38 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 38 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 38 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 38 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 38 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 38 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 38 | HMAC<T> hmac(secret, secretLen); | 259 | 38 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 38 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 38 | ThreadUserTimer timer; | 264 | | | 265 | 38 | unsigned int i=1; | 266 | 456 | while (derivedLen > 0) | 267 | 418 | { | 268 | 418 | hmac.Update(salt, saltLen); | 269 | 418 | unsigned int j; | 270 | 2.09k | for (j=0; j<4; j++) | 271 | 1.67k | { | 272 | 1.67k | byte b = byte(i >> ((3-j)*8)); | 273 | 1.67k | hmac.Update(&b, 1); | 274 | 1.67k | } | 275 | 418 | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 418 | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 418 | std::memcpy(derived, buffer, segmentLen); | 283 | 418 | #endif | 284 | | | 285 | 418 | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 1.04k | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 623 | { | 293 | 623 | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 623 | xorbuf(derived, buffer, segmentLen); | 295 | 623 | } | 296 | | | 297 | 418 | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 418 | derived += segmentLen; | 304 | 418 | derivedLen -= segmentLen; | 305 | 418 | i++; | 306 | 418 | } | 307 | | | 308 | 38 | return iterations; | 309 | 38 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHAKE256>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 39 | { | 246 | 39 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 39 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 39 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 39 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 39 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 39 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 39 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 39 | HMAC<T> hmac(secret, secretLen); | 259 | 39 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 39 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 39 | ThreadUserTimer timer; | 264 | | | 265 | 39 | unsigned int i=1; | 266 | 323 | while (derivedLen > 0) | 267 | 284 | { | 268 | 284 | hmac.Update(salt, saltLen); | 269 | 284 | unsigned int j; | 270 | 1.42k | for (j=0; j<4; j++) | 271 | 1.13k | { | 272 | 1.13k | byte b = byte(i >> ((3-j)*8)); | 273 | 1.13k | hmac.Update(&b, 1); | 274 | 1.13k | } | 275 | 284 | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 284 | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 284 | std::memcpy(derived, buffer, segmentLen); | 283 | 284 | #endif | 284 | | | 285 | 284 | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 651 | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 367 | { | 293 | 367 | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 367 | xorbuf(derived, buffer, segmentLen); | 295 | 367 | } | 296 | | | 297 | 284 | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 284 | derived += segmentLen; | 304 | 284 | derivedLen -= segmentLen; | 305 | 284 | i++; | 306 | 284 | } | 307 | | | 308 | 39 | return iterations; | 309 | 39 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD128>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 75 | { | 246 | 75 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 75 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 75 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 75 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 75 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 75 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 75 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 75 | HMAC<T> hmac(secret, secretLen); | 259 | 75 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 75 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 75 | ThreadUserTimer timer; | 264 | | | 265 | 75 | unsigned int i=1; | 266 | 3.40k | while (derivedLen > 0) | 267 | 3.33k | { | 268 | 3.33k | hmac.Update(salt, saltLen); | 269 | 3.33k | unsigned int j; | 270 | 16.6k | for (j=0; j<4; j++) | 271 | 13.3k | { | 272 | 13.3k | byte b = byte(i >> ((3-j)*8)); | 273 | 13.3k | hmac.Update(&b, 1); | 274 | 13.3k | } | 275 | 3.33k | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 3.33k | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 3.33k | std::memcpy(derived, buffer, segmentLen); | 283 | 3.33k | #endif | 284 | | | 285 | 3.33k | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 6.22k | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 2.89k | { | 293 | 2.89k | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 2.89k | xorbuf(derived, buffer, segmentLen); | 295 | 2.89k | } | 296 | | | 297 | 3.33k | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 3.33k | derived += segmentLen; | 304 | 3.33k | derivedLen -= segmentLen; | 305 | 3.33k | i++; | 306 | 3.33k | } | 307 | | | 308 | 75 | return iterations; | 309 | 75 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD160>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 52 | { | 246 | 52 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 52 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 52 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 52 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 52 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 52 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 52 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 52 | HMAC<T> hmac(secret, secretLen); | 259 | 52 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 52 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 52 | ThreadUserTimer timer; | 264 | | | 265 | 52 | unsigned int i=1; | 266 | 1.26k | while (derivedLen > 0) | 267 | 1.21k | { | 268 | 1.21k | hmac.Update(salt, saltLen); | 269 | 1.21k | unsigned int j; | 270 | 6.08k | for (j=0; j<4; j++) | 271 | 4.86k | { | 272 | 4.86k | byte b = byte(i >> ((3-j)*8)); | 273 | 4.86k | hmac.Update(&b, 1); | 274 | 4.86k | } | 275 | 1.21k | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 1.21k | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 1.21k | std::memcpy(derived, buffer, segmentLen); | 283 | 1.21k | #endif | 284 | | | 285 | 1.21k | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 2.95k | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 1.73k | { | 293 | 1.73k | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 1.73k | xorbuf(derived, buffer, segmentLen); | 295 | 1.73k | } | 296 | | | 297 | 1.21k | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 1.21k | derived += segmentLen; | 304 | 1.21k | derivedLen -= segmentLen; | 305 | 1.21k | i++; | 306 | 1.21k | } | 307 | | | 308 | 52 | return iterations; | 309 | 52 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD256>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 42 | { | 246 | 42 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 42 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 42 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 42 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 42 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 42 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 42 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 42 | HMAC<T> hmac(secret, secretLen); | 259 | 42 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 42 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 42 | ThreadUserTimer timer; | 264 | | | 265 | 42 | unsigned int i=1; | 266 | 491 | while (derivedLen > 0) | 267 | 449 | { | 268 | 449 | hmac.Update(salt, saltLen); | 269 | 449 | unsigned int j; | 270 | 2.24k | for (j=0; j<4; j++) | 271 | 1.79k | { | 272 | 1.79k | byte b = byte(i >> ((3-j)*8)); | 273 | 1.79k | hmac.Update(&b, 1); | 274 | 1.79k | } | 275 | 449 | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 449 | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 449 | std::memcpy(derived, buffer, segmentLen); | 283 | 449 | #endif | 284 | | | 285 | 449 | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 903 | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 454 | { | 293 | 454 | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 454 | xorbuf(derived, buffer, segmentLen); | 295 | 454 | } | 296 | | | 297 | 449 | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 449 | derived += segmentLen; | 304 | 449 | derivedLen -= segmentLen; | 305 | 449 | i++; | 306 | 449 | } | 307 | | | 308 | 42 | return iterations; | 309 | 42 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::RIPEMD320>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 52 | { | 246 | 52 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 52 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 52 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 52 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 52 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 52 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 52 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 52 | HMAC<T> hmac(secret, secretLen); | 259 | 52 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 52 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 52 | ThreadUserTimer timer; | 264 | | | 265 | 52 | unsigned int i=1; | 266 | 465 | while (derivedLen > 0) | 267 | 413 | { | 268 | 413 | hmac.Update(salt, saltLen); | 269 | 413 | unsigned int j; | 270 | 2.06k | for (j=0; j<4; j++) | 271 | 1.65k | { | 272 | 1.65k | byte b = byte(i >> ((3-j)*8)); | 273 | 1.65k | hmac.Update(&b, 1); | 274 | 1.65k | } | 275 | 413 | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 413 | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 413 | std::memcpy(derived, buffer, segmentLen); | 283 | 413 | #endif | 284 | | | 285 | 413 | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 984 | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 571 | { | 293 | 571 | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 571 | xorbuf(derived, buffer, segmentLen); | 295 | 571 | } | 296 | | | 297 | 413 | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 413 | derived += segmentLen; | 304 | 413 | derivedLen -= segmentLen; | 305 | 413 | i++; | 306 | 413 | } | 307 | | | 308 | 52 | return iterations; | 309 | 52 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Whirlpool>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 55 | { | 246 | 55 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 55 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 55 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 55 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 55 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 55 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 55 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 55 | HMAC<T> hmac(secret, secretLen); | 259 | 55 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 55 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 55 | ThreadUserTimer timer; | 264 | | | 265 | 55 | unsigned int i=1; | 266 | 526 | while (derivedLen > 0) | 267 | 471 | { | 268 | 471 | hmac.Update(salt, saltLen); | 269 | 471 | unsigned int j; | 270 | 2.35k | for (j=0; j<4; j++) | 271 | 1.88k | { | 272 | 1.88k | byte b = byte(i >> ((3-j)*8)); | 273 | 1.88k | hmac.Update(&b, 1); | 274 | 1.88k | } | 275 | 471 | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 471 | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 471 | std::memcpy(derived, buffer, segmentLen); | 283 | 471 | #endif | 284 | | | 285 | 471 | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 1.04k | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 573 | { | 293 | 573 | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 573 | xorbuf(derived, buffer, segmentLen); | 295 | 573 | } | 296 | | | 297 | 471 | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 471 | derived += segmentLen; | 304 | 471 | derivedLen -= segmentLen; | 305 | 471 | i++; | 306 | 471 | } | 307 | | | 308 | 55 | return iterations; | 309 | 55 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Weak1::MD2>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 41 | { | 246 | 41 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 41 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 41 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 41 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 41 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 41 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 41 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 41 | HMAC<T> hmac(secret, secretLen); | 259 | 41 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 41 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 41 | ThreadUserTimer timer; | 264 | | | 265 | 41 | unsigned int i=1; | 266 | 1.15k | while (derivedLen > 0) | 267 | 1.11k | { | 268 | 1.11k | hmac.Update(salt, saltLen); | 269 | 1.11k | unsigned int j; | 270 | 5.57k | for (j=0; j<4; j++) | 271 | 4.45k | { | 272 | 4.45k | byte b = byte(i >> ((3-j)*8)); | 273 | 4.45k | hmac.Update(&b, 1); | 274 | 4.45k | } | 275 | 1.11k | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 1.11k | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 1.11k | std::memcpy(derived, buffer, segmentLen); | 283 | 1.11k | #endif | 284 | | | 285 | 1.11k | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 2.73k | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 1.62k | { | 293 | 1.62k | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 1.62k | xorbuf(derived, buffer, segmentLen); | 295 | 1.62k | } | 296 | | | 297 | 1.11k | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 1.11k | derived += segmentLen; | 304 | 1.11k | derivedLen -= segmentLen; | 305 | 1.11k | i++; | 306 | 1.11k | } | 307 | | | 308 | 41 | return iterations; | 309 | 41 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Weak1::MD4>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 98 | { | 246 | 98 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 98 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 98 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 98 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 98 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 98 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 98 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 98 | HMAC<T> hmac(secret, secretLen); | 259 | 98 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 98 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 98 | ThreadUserTimer timer; | 264 | | | 265 | 98 | unsigned int i=1; | 266 | 4.06k | while (derivedLen > 0) | 267 | 3.96k | { | 268 | 3.96k | hmac.Update(salt, saltLen); | 269 | 3.96k | unsigned int j; | 270 | 19.8k | for (j=0; j<4; j++) | 271 | 15.8k | { | 272 | 15.8k | byte b = byte(i >> ((3-j)*8)); | 273 | 15.8k | hmac.Update(&b, 1); | 274 | 15.8k | } | 275 | 3.96k | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 3.96k | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 3.96k | std::memcpy(derived, buffer, segmentLen); | 283 | 3.96k | #endif | 284 | | | 285 | 3.96k | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 6.14k | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 2.17k | { | 293 | 2.17k | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 2.17k | xorbuf(derived, buffer, segmentLen); | 295 | 2.17k | } | 296 | | | 297 | 3.96k | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 3.96k | derived += segmentLen; | 304 | 3.96k | derivedLen -= segmentLen; | 305 | 3.96k | i++; | 306 | 3.96k | } | 307 | | | 308 | 98 | return iterations; | 309 | 98 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Weak1::MD5>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 51 | { | 246 | 51 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 51 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 51 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 51 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 51 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 51 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 51 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 51 | HMAC<T> hmac(secret, secretLen); | 259 | 51 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 51 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 51 | ThreadUserTimer timer; | 264 | | | 265 | 51 | unsigned int i=1; | 266 | 1.51k | while (derivedLen > 0) | 267 | 1.46k | { | 268 | 1.46k | hmac.Update(salt, saltLen); | 269 | 1.46k | unsigned int j; | 270 | 7.33k | for (j=0; j<4; j++) | 271 | 5.86k | { | 272 | 5.86k | byte b = byte(i >> ((3-j)*8)); | 273 | 5.86k | hmac.Update(&b, 1); | 274 | 5.86k | } | 275 | 1.46k | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 1.46k | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 1.46k | std::memcpy(derived, buffer, segmentLen); | 283 | 1.46k | #endif | 284 | | | 285 | 1.46k | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 3.58k | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 2.11k | { | 293 | 2.11k | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 2.11k | xorbuf(derived, buffer, segmentLen); | 295 | 2.11k | } | 296 | | | 297 | 1.46k | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 1.46k | derived += segmentLen; | 304 | 1.46k | derivedLen -= segmentLen; | 305 | 1.46k | i++; | 306 | 1.46k | } | 307 | | | 308 | 51 | return iterations; | 309 | 51 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SM3>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 41 | { | 246 | 41 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 41 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 41 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 41 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 41 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 41 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 41 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 41 | HMAC<T> hmac(secret, secretLen); | 259 | 41 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 41 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 41 | ThreadUserTimer timer; | 264 | | | 265 | 41 | unsigned int i=1; | 266 | 650 | while (derivedLen > 0) | 267 | 609 | { | 268 | 609 | hmac.Update(salt, saltLen); | 269 | 609 | unsigned int j; | 270 | 3.04k | for (j=0; j<4; j++) | 271 | 2.43k | { | 272 | 2.43k | byte b = byte(i >> ((3-j)*8)); | 273 | 2.43k | hmac.Update(&b, 1); | 274 | 2.43k | } | 275 | 609 | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 609 | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 609 | std::memcpy(derived, buffer, segmentLen); | 283 | 609 | #endif | 284 | | | 285 | 609 | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 1.33k | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 721 | { | 293 | 721 | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 721 | xorbuf(derived, buffer, segmentLen); | 295 | 721 | } | 296 | | | 297 | 609 | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 609 | derived += segmentLen; | 304 | 609 | derivedLen -= segmentLen; | 305 | 609 | i++; | 306 | 609 | } | 307 | | | 308 | 41 | return iterations; | 309 | 41 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::BLAKE2b>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 44 | { | 246 | 44 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 44 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 44 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 44 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 44 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 44 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 44 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 44 | HMAC<T> hmac(secret, secretLen); | 259 | 44 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 44 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 44 | ThreadUserTimer timer; | 264 | | | 265 | 44 | unsigned int i=1; | 266 | 382 | while (derivedLen > 0) | 267 | 338 | { | 268 | 338 | hmac.Update(salt, saltLen); | 269 | 338 | unsigned int j; | 270 | 1.69k | for (j=0; j<4; j++) | 271 | 1.35k | { | 272 | 1.35k | byte b = byte(i >> ((3-j)*8)); | 273 | 1.35k | hmac.Update(&b, 1); | 274 | 1.35k | } | 275 | 338 | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 338 | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 338 | std::memcpy(derived, buffer, segmentLen); | 283 | 338 | #endif | 284 | | | 285 | 338 | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 888 | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 550 | { | 293 | 550 | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 550 | xorbuf(derived, buffer, segmentLen); | 295 | 550 | } | 296 | | | 297 | 338 | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 338 | derived += segmentLen; | 304 | 338 | derivedLen -= segmentLen; | 305 | 338 | i++; | 306 | 338 | } | 307 | | | 308 | 44 | return iterations; | 309 | 44 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::BLAKE2s>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 34 | { | 246 | 34 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 34 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 34 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 34 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 34 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 34 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 34 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 34 | HMAC<T> hmac(secret, secretLen); | 259 | 34 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 34 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 34 | ThreadUserTimer timer; | 264 | | | 265 | 34 | unsigned int i=1; | 266 | 458 | while (derivedLen > 0) | 267 | 424 | { | 268 | 424 | hmac.Update(salt, saltLen); | 269 | 424 | unsigned int j; | 270 | 2.12k | for (j=0; j<4; j++) | 271 | 1.69k | { | 272 | 1.69k | byte b = byte(i >> ((3-j)*8)); | 273 | 1.69k | hmac.Update(&b, 1); | 274 | 1.69k | } | 275 | 424 | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 424 | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 424 | std::memcpy(derived, buffer, segmentLen); | 283 | 424 | #endif | 284 | | | 285 | 424 | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 928 | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 504 | { | 293 | 504 | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 504 | xorbuf(derived, buffer, segmentLen); | 295 | 504 | } | 296 | | | 297 | 424 | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 424 | derived += segmentLen; | 304 | 424 | derivedLen -= segmentLen; | 305 | 424 | i++; | 306 | 424 | } | 307 | | | 308 | 34 | return iterations; | 309 | 34 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Tiger>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 51 | { | 246 | 51 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 51 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 51 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 51 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 51 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 51 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 51 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 51 | HMAC<T> hmac(secret, secretLen); | 259 | 51 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 51 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 51 | ThreadUserTimer timer; | 264 | | | 265 | 51 | unsigned int i=1; | 266 | 980 | while (derivedLen > 0) | 267 | 929 | { | 268 | 929 | hmac.Update(salt, saltLen); | 269 | 929 | unsigned int j; | 270 | 4.64k | for (j=0; j<4; j++) | 271 | 3.71k | { | 272 | 3.71k | byte b = byte(i >> ((3-j)*8)); | 273 | 3.71k | hmac.Update(&b, 1); | 274 | 3.71k | } | 275 | 929 | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 929 | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 929 | std::memcpy(derived, buffer, segmentLen); | 283 | 929 | #endif | 284 | | | 285 | 929 | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 2.18k | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 1.25k | { | 293 | 1.25k | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 1.25k | xorbuf(derived, buffer, segmentLen); | 295 | 1.25k | } | 296 | | | 297 | 929 | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 929 | derived += segmentLen; | 304 | 929 | derivedLen -= segmentLen; | 305 | 929 | i++; | 306 | 929 | } | 307 | | | 308 | 51 | return iterations; | 309 | 51 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<28u> >::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 41 | { | 246 | 41 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 41 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 41 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 41 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 41 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 41 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 41 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 41 | HMAC<T> hmac(secret, secretLen); | 259 | 41 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 41 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 41 | ThreadUserTimer timer; | 264 | | | 265 | 41 | unsigned int i=1; | 266 | 611 | while (derivedLen > 0) | 267 | 570 | { | 268 | 570 | hmac.Update(salt, saltLen); | 269 | 570 | unsigned int j; | 270 | 2.85k | for (j=0; j<4; j++) | 271 | 2.28k | { | 272 | 2.28k | byte b = byte(i >> ((3-j)*8)); | 273 | 2.28k | hmac.Update(&b, 1); | 274 | 2.28k | } | 275 | 570 | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 570 | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 570 | std::memcpy(derived, buffer, segmentLen); | 283 | 570 | #endif | 284 | | | 285 | 570 | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 1.43k | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 865 | { | 293 | 865 | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 865 | xorbuf(derived, buffer, segmentLen); | 295 | 865 | } | 296 | | | 297 | 570 | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 570 | derived += segmentLen; | 304 | 570 | derivedLen -= segmentLen; | 305 | 570 | i++; | 306 | 570 | } | 307 | | | 308 | 41 | return iterations; | 309 | 41 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<32u> >::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 39 | { | 246 | 39 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 39 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 39 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 39 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 39 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 39 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 39 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 39 | HMAC<T> hmac(secret, secretLen); | 259 | 39 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 39 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 39 | ThreadUserTimer timer; | 264 | | | 265 | 39 | unsigned int i=1; | 266 | 529 | while (derivedLen > 0) | 267 | 490 | { | 268 | 490 | hmac.Update(salt, saltLen); | 269 | 490 | unsigned int j; | 270 | 2.45k | for (j=0; j<4; j++) | 271 | 1.96k | { | 272 | 1.96k | byte b = byte(i >> ((3-j)*8)); | 273 | 1.96k | hmac.Update(&b, 1); | 274 | 1.96k | } | 275 | 490 | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 490 | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 490 | std::memcpy(derived, buffer, segmentLen); | 283 | 490 | #endif | 284 | | | 285 | 490 | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 1.13k | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 642 | { | 293 | 642 | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 642 | xorbuf(derived, buffer, segmentLen); | 295 | 642 | } | 296 | | | 297 | 490 | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 490 | derived += segmentLen; | 304 | 490 | derivedLen -= segmentLen; | 305 | 490 | i++; | 306 | 490 | } | 307 | | | 308 | 39 | return iterations; | 309 | 39 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<48u> >::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 48 | { | 246 | 48 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 48 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 48 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 48 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 48 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 48 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 48 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 48 | HMAC<T> hmac(secret, secretLen); | 259 | 48 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 48 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 48 | ThreadUserTimer timer; | 264 | | | 265 | 48 | unsigned int i=1; | 266 | 566 | while (derivedLen > 0) | 267 | 518 | { | 268 | 518 | hmac.Update(salt, saltLen); | 269 | 518 | unsigned int j; | 270 | 2.59k | for (j=0; j<4; j++) | 271 | 2.07k | { | 272 | 2.07k | byte b = byte(i >> ((3-j)*8)); | 273 | 2.07k | hmac.Update(&b, 1); | 274 | 2.07k | } | 275 | 518 | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 518 | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 518 | std::memcpy(derived, buffer, segmentLen); | 283 | 518 | #endif | 284 | | | 285 | 518 | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 1.24k | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 731 | { | 293 | 731 | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 731 | xorbuf(derived, buffer, segmentLen); | 295 | 731 | } | 296 | | | 297 | 518 | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 518 | derived += segmentLen; | 304 | 518 | derivedLen -= segmentLen; | 305 | 518 | i++; | 306 | 518 | } | 307 | | | 308 | 48 | return iterations; | 309 | 48 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::Keccak_Final<64u> >::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 68 | { | 246 | 68 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 68 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 68 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 68 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 68 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 68 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 68 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 68 | HMAC<T> hmac(secret, secretLen); | 259 | 68 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 68 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 68 | ThreadUserTimer timer; | 264 | | | 265 | 68 | unsigned int i=1; | 266 | 592 | while (derivedLen > 0) | 267 | 524 | { | 268 | 524 | hmac.Update(salt, saltLen); | 269 | 524 | unsigned int j; | 270 | 2.62k | for (j=0; j<4; j++) | 271 | 2.09k | { | 272 | 2.09k | byte b = byte(i >> ((3-j)*8)); | 273 | 2.09k | hmac.Update(&b, 1); | 274 | 2.09k | } | 275 | 524 | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 524 | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 524 | std::memcpy(derived, buffer, segmentLen); | 283 | 524 | #endif | 284 | | | 285 | 524 | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 987 | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 463 | { | 293 | 463 | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 463 | xorbuf(derived, buffer, segmentLen); | 295 | 463 | } | 296 | | | 297 | 524 | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 524 | derived += segmentLen; | 304 | 524 | derivedLen -= segmentLen; | 305 | 524 | i++; | 306 | 524 | } | 307 | | | 308 | 68 | return iterations; | 309 | 68 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH224>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 40 | { | 246 | 40 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 40 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 40 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 40 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 40 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 40 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 40 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 40 | HMAC<T> hmac(secret, secretLen); | 259 | 40 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 40 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 40 | ThreadUserTimer timer; | 264 | | | 265 | 40 | unsigned int i=1; | 266 | 568 | while (derivedLen > 0) | 267 | 528 | { | 268 | 528 | hmac.Update(salt, saltLen); | 269 | 528 | unsigned int j; | 270 | 2.64k | for (j=0; j<4; j++) | 271 | 2.11k | { | 272 | 2.11k | byte b = byte(i >> ((3-j)*8)); | 273 | 2.11k | hmac.Update(&b, 1); | 274 | 2.11k | } | 275 | 528 | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 528 | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 528 | std::memcpy(derived, buffer, segmentLen); | 283 | 528 | #endif | 284 | | | 285 | 528 | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 1.42k | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 896 | { | 293 | 896 | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 896 | xorbuf(derived, buffer, segmentLen); | 295 | 896 | } | 296 | | | 297 | 528 | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 528 | derived += segmentLen; | 304 | 528 | derivedLen -= segmentLen; | 305 | 528 | i++; | 306 | 528 | } | 307 | | | 308 | 40 | return iterations; | 309 | 40 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH256>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 33 | { | 246 | 33 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 33 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 33 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 33 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 33 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 33 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 33 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 33 | HMAC<T> hmac(secret, secretLen); | 259 | 33 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 33 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 33 | ThreadUserTimer timer; | 264 | | | 265 | 33 | unsigned int i=1; | 266 | 425 | while (derivedLen > 0) | 267 | 392 | { | 268 | 392 | hmac.Update(salt, saltLen); | 269 | 392 | unsigned int j; | 270 | 1.96k | for (j=0; j<4; j++) | 271 | 1.56k | { | 272 | 1.56k | byte b = byte(i >> ((3-j)*8)); | 273 | 1.56k | hmac.Update(&b, 1); | 274 | 1.56k | } | 275 | 392 | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 392 | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 392 | std::memcpy(derived, buffer, segmentLen); | 283 | 392 | #endif | 284 | | | 285 | 392 | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 902 | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 510 | { | 293 | 510 | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 510 | xorbuf(derived, buffer, segmentLen); | 295 | 510 | } | 296 | | | 297 | 392 | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 392 | derived += segmentLen; | 304 | 392 | derivedLen -= segmentLen; | 305 | 392 | i++; | 306 | 392 | } | 307 | | | 308 | 33 | return iterations; | 309 | 33 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH384>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 36 | { | 246 | 36 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 36 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 36 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 36 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 36 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 36 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 36 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 36 | HMAC<T> hmac(secret, secretLen); | 259 | 36 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 36 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 36 | ThreadUserTimer timer; | 264 | | | 265 | 36 | unsigned int i=1; | 266 | 350 | while (derivedLen > 0) | 267 | 314 | { | 268 | 314 | hmac.Update(salt, saltLen); | 269 | 314 | unsigned int j; | 270 | 1.57k | for (j=0; j<4; j++) | 271 | 1.25k | { | 272 | 1.25k | byte b = byte(i >> ((3-j)*8)); | 273 | 1.25k | hmac.Update(&b, 1); | 274 | 1.25k | } | 275 | 314 | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 314 | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 314 | std::memcpy(derived, buffer, segmentLen); | 283 | 314 | #endif | 284 | | | 285 | 314 | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 766 | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 452 | { | 293 | 452 | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 452 | xorbuf(derived, buffer, segmentLen); | 295 | 452 | } | 296 | | | 297 | 314 | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 314 | derived += segmentLen; | 304 | 314 | derivedLen -= segmentLen; | 305 | 314 | i++; | 306 | 314 | } | 307 | | | 308 | 36 | return iterations; | 309 | 36 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH512>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 37 | { | 246 | 37 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 37 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 37 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 37 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 37 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 37 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 37 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 37 | HMAC<T> hmac(secret, secretLen); | 259 | 37 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 37 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 37 | ThreadUserTimer timer; | 264 | | | 265 | 37 | unsigned int i=1; | 266 | 336 | while (derivedLen > 0) | 267 | 299 | { | 268 | 299 | hmac.Update(salt, saltLen); | 269 | 299 | unsigned int j; | 270 | 1.49k | for (j=0; j<4; j++) | 271 | 1.19k | { | 272 | 1.19k | byte b = byte(i >> ((3-j)*8)); | 273 | 1.19k | hmac.Update(&b, 1); | 274 | 1.19k | } | 275 | 299 | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 299 | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 299 | std::memcpy(derived, buffer, segmentLen); | 283 | 299 | #endif | 284 | | | 285 | 299 | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 779 | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 480 | { | 293 | 480 | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 480 | xorbuf(derived, buffer, segmentLen); | 295 | 480 | } | 296 | | | 297 | 299 | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 299 | derived += segmentLen; | 304 | 299 | derivedLen -= segmentLen; | 305 | 299 | i++; | 306 | 299 | } | 307 | | | 308 | 37 | return iterations; | 309 | 37 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::LSH512_256>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 37 | { | 246 | 37 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 37 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 37 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 37 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 37 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 37 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 37 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 37 | HMAC<T> hmac(secret, secretLen); | 259 | 37 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 37 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 37 | ThreadUserTimer timer; | 264 | | | 265 | 37 | unsigned int i=1; | 266 | 434 | while (derivedLen > 0) | 267 | 397 | { | 268 | 397 | hmac.Update(salt, saltLen); | 269 | 397 | unsigned int j; | 270 | 1.98k | for (j=0; j<4; j++) | 271 | 1.58k | { | 272 | 1.58k | byte b = byte(i >> ((3-j)*8)); | 273 | 1.58k | hmac.Update(&b, 1); | 274 | 1.58k | } | 275 | 397 | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 397 | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 397 | std::memcpy(derived, buffer, segmentLen); | 283 | 397 | #endif | 284 | | | 285 | 397 | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 1.01k | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 618 | { | 293 | 618 | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 618 | xorbuf(derived, buffer, segmentLen); | 295 | 618 | } | 296 | | | 297 | 397 | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 397 | derived += segmentLen; | 304 | 397 | derivedLen -= segmentLen; | 305 | 397 | i++; | 306 | 397 | } | 307 | | | 308 | 37 | return iterations; | 309 | 37 | } |
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA256>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 245 | 858 | { | 246 | 858 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 247 | 858 | CRYPTOPP_ASSERT(derived && derivedLen); | 248 | 858 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 249 | 858 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 250 | 858 | CRYPTOPP_UNUSED(purpose); | 251 | | | 252 | 858 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 253 | | | 254 | | // Business logic | 255 | 858 | if (!iterations) { iterations = 1; } | 256 | | | 257 | | // DigestSize check due to https://github.com/weidai11/cryptopp/issues/855 | 258 | 858 | HMAC<T> hmac(secret, secretLen); | 259 | 858 | if (hmac.DigestSize() == 0) | 260 | 0 | throw InvalidArgument("PKCS5_PBKDF2_HMAC: DigestSize cannot be 0"); | 261 | | | 262 | 858 | SecByteBlock buffer(hmac.DigestSize()); | 263 | 858 | ThreadUserTimer timer; | 264 | | | 265 | 858 | unsigned int i=1; | 266 | 32.9k | while (derivedLen > 0) | 267 | 32.0k | { | 268 | 32.0k | hmac.Update(salt, saltLen); | 269 | 32.0k | unsigned int j; | 270 | 160k | for (j=0; j<4; j++) | 271 | 128k | { | 272 | 128k | byte b = byte(i >> ((3-j)*8)); | 273 | 128k | hmac.Update(&b, 1); | 274 | 128k | } | 275 | 32.0k | hmac.Final(buffer); | 276 | | | 277 | | #if CRYPTOPP_MSC_VERSION | 278 | | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 279 | | memcpy_s(derived, segmentLen, buffer, segmentLen); | 280 | | #else | 281 | 32.0k | const size_t segmentLen = STDMIN(derivedLen, buffer.size()); | 282 | 32.0k | std::memcpy(derived, buffer, segmentLen); | 283 | 32.0k | #endif | 284 | | | 285 | 32.0k | if (timeInSeconds) | 286 | 0 | { | 287 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size()); | 288 | 0 | timer.StartTimer(); | 289 | 0 | } | 290 | | | 291 | 32.0k | for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++) | 292 | 0 | { | 293 | 0 | hmac.CalculateDigest(buffer, buffer, buffer.size()); | 294 | 0 | xorbuf(derived, buffer, segmentLen); | 295 | 0 | } | 296 | | | 297 | 32.0k | if (timeInSeconds) | 298 | 0 | { | 299 | 0 | iterations = j; | 300 | 0 | timeInSeconds = 0; | 301 | 0 | } | 302 | | | 303 | 32.0k | derived += segmentLen; | 304 | 32.0k | derivedLen -= segmentLen; | 305 | 32.0k | i++; | 306 | 32.0k | } | 307 | | | 308 | 858 | return iterations; | 309 | 858 | } |
|
310 | | |
311 | | // ******************** PKCS12_PBKDF ******************** |
312 | | |
313 | | /// \brief PBKDF from PKCS #12, appendix B |
314 | | /// \tparam T a HashTransformation class |
315 | | /// \sa PasswordBasedKeyDerivationFunction, <A |
316 | | /// HREF="https://www.cryptopp.com/wiki/PKCS12_PBKDF">PKCS12_PBKDF</A> |
317 | | /// on the Crypto++ wiki |
318 | | /// \since Crypto++ 2.0 |
319 | | template <class T> |
320 | | class PKCS12_PBKDF : public PasswordBasedKeyDerivationFunction |
321 | | { |
322 | | public: |
323 | | virtual ~PKCS12_PBKDF() {} |
324 | | |
325 | 0 | static std::string StaticAlgorithmName () { |
326 | 0 | const std::string name(std::string("PBKDF_PKCS12(") + |
327 | 0 | std::string(T::StaticAlgorithmName()) + std::string(")")); |
328 | 0 | return name; |
329 | 0 | } Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHA1>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHA224>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHA384>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHA512>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHAKE128>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHAKE256>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD128>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD160>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD256>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD320>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Whirlpool>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Weak1::MD2>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Weak1::MD4>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Weak1::MD5>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SM3>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::BLAKE2b>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::BLAKE2s>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Tiger>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<28u> >::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<32u> >::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<48u> >::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<64u> >::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::LSH224>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::LSH256>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::LSH384>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::LSH512>::StaticAlgorithmName() Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::LSH512_256>::StaticAlgorithmName() |
330 | | |
331 | | // KeyDerivationFunction interface |
332 | 0 | std::string AlgorithmName() const { |
333 | 0 | return StaticAlgorithmName(); |
334 | 0 | } Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHA1>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHA224>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHA384>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHA512>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHAKE128>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHAKE256>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD128>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD160>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD256>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD320>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Whirlpool>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Weak1::MD2>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Weak1::MD4>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Weak1::MD5>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SM3>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::BLAKE2b>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::BLAKE2s>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Tiger>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<28u> >::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<32u> >::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<48u> >::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<64u> >::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::LSH224>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::LSH256>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::LSH384>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::LSH512>::AlgorithmName() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::LSH512_256>::AlgorithmName() const |
335 | | |
336 | | // TODO - check this |
337 | 1.56k | size_t MaxDerivedKeyLength() const { |
338 | 1.56k | return static_cast<size_t>(-1); |
339 | 1.56k | } CryptoPP::PKCS12_PBKDF<CryptoPP::SHA1>::MaxDerivedKeyLength() const Line | Count | Source | 337 | 52 | size_t MaxDerivedKeyLength() const { | 338 | 52 | return static_cast<size_t>(-1); | 339 | 52 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::SHA224>::MaxDerivedKeyLength() const Line | Count | Source | 337 | 64 | size_t MaxDerivedKeyLength() const { | 338 | 64 | return static_cast<size_t>(-1); | 339 | 64 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::SHA384>::MaxDerivedKeyLength() const Line | Count | Source | 337 | 60 | size_t MaxDerivedKeyLength() const { | 338 | 60 | return static_cast<size_t>(-1); | 339 | 60 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::SHA512>::MaxDerivedKeyLength() const Line | Count | Source | 337 | 83 | size_t MaxDerivedKeyLength() const { | 338 | 83 | return static_cast<size_t>(-1); | 339 | 83 | } |
Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHAKE128>::MaxDerivedKeyLength() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHAKE256>::MaxDerivedKeyLength() const CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD128>::MaxDerivedKeyLength() const Line | Count | Source | 337 | 50 | size_t MaxDerivedKeyLength() const { | 338 | 50 | return static_cast<size_t>(-1); | 339 | 50 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD160>::MaxDerivedKeyLength() const Line | Count | Source | 337 | 66 | size_t MaxDerivedKeyLength() const { | 338 | 66 | return static_cast<size_t>(-1); | 339 | 66 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD256>::MaxDerivedKeyLength() const Line | Count | Source | 337 | 51 | size_t MaxDerivedKeyLength() const { | 338 | 51 | return static_cast<size_t>(-1); | 339 | 51 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD320>::MaxDerivedKeyLength() const Line | Count | Source | 337 | 53 | size_t MaxDerivedKeyLength() const { | 338 | 53 | return static_cast<size_t>(-1); | 339 | 53 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Whirlpool>::MaxDerivedKeyLength() const Line | Count | Source | 337 | 68 | size_t MaxDerivedKeyLength() const { | 338 | 68 | return static_cast<size_t>(-1); | 339 | 68 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Weak1::MD2>::MaxDerivedKeyLength() const Line | Count | Source | 337 | 61 | size_t MaxDerivedKeyLength() const { | 338 | 61 | return static_cast<size_t>(-1); | 339 | 61 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Weak1::MD4>::MaxDerivedKeyLength() const Line | Count | Source | 337 | 134 | size_t MaxDerivedKeyLength() const { | 338 | 134 | return static_cast<size_t>(-1); | 339 | 134 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Weak1::MD5>::MaxDerivedKeyLength() const Line | Count | Source | 337 | 48 | size_t MaxDerivedKeyLength() const { | 338 | 48 | return static_cast<size_t>(-1); | 339 | 48 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::SM3>::MaxDerivedKeyLength() const Line | Count | Source | 337 | 53 | size_t MaxDerivedKeyLength() const { | 338 | 53 | return static_cast<size_t>(-1); | 339 | 53 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::BLAKE2b>::MaxDerivedKeyLength() const Line | Count | Source | 337 | 122 | size_t MaxDerivedKeyLength() const { | 338 | 122 | return static_cast<size_t>(-1); | 339 | 122 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::BLAKE2s>::MaxDerivedKeyLength() const Line | Count | Source | 337 | 94 | size_t MaxDerivedKeyLength() const { | 338 | 94 | return static_cast<size_t>(-1); | 339 | 94 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Tiger>::MaxDerivedKeyLength() const Line | Count | Source | 337 | 56 | size_t MaxDerivedKeyLength() const { | 338 | 56 | return static_cast<size_t>(-1); | 339 | 56 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<28u> >::MaxDerivedKeyLength() const Line | Count | Source | 337 | 55 | size_t MaxDerivedKeyLength() const { | 338 | 55 | return static_cast<size_t>(-1); | 339 | 55 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<32u> >::MaxDerivedKeyLength() const Line | Count | Source | 337 | 57 | size_t MaxDerivedKeyLength() const { | 338 | 57 | return static_cast<size_t>(-1); | 339 | 57 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<48u> >::MaxDerivedKeyLength() const Line | Count | Source | 337 | 51 | size_t MaxDerivedKeyLength() const { | 338 | 51 | return static_cast<size_t>(-1); | 339 | 51 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<64u> >::MaxDerivedKeyLength() const Line | Count | Source | 337 | 55 | size_t MaxDerivedKeyLength() const { | 338 | 55 | return static_cast<size_t>(-1); | 339 | 55 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::LSH224>::MaxDerivedKeyLength() const Line | Count | Source | 337 | 50 | size_t MaxDerivedKeyLength() const { | 338 | 50 | return static_cast<size_t>(-1); | 339 | 50 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::LSH256>::MaxDerivedKeyLength() const Line | Count | Source | 337 | 45 | size_t MaxDerivedKeyLength() const { | 338 | 45 | return static_cast<size_t>(-1); | 339 | 45 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::LSH384>::MaxDerivedKeyLength() const Line | Count | Source | 337 | 40 | size_t MaxDerivedKeyLength() const { | 338 | 40 | return static_cast<size_t>(-1); | 339 | 40 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::LSH512>::MaxDerivedKeyLength() const Line | Count | Source | 337 | 50 | size_t MaxDerivedKeyLength() const { | 338 | 50 | return static_cast<size_t>(-1); | 339 | 50 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::LSH512_256>::MaxDerivedKeyLength() const Line | Count | Source | 337 | 43 | size_t MaxDerivedKeyLength() const { | 338 | 43 | return static_cast<size_t>(-1); | 339 | 43 | } |
|
340 | | |
341 | | // KeyDerivationFunction interface |
342 | | size_t GetValidDerivedLength(size_t keylength) const; |
343 | | |
344 | | // KeyDerivationFunction interface |
345 | | size_t DeriveKey(byte *derived, size_t derivedLen, const byte *secret, size_t secretLen, |
346 | | const NameValuePairs& params = g_nullNameValuePairs) const; |
347 | | |
348 | | /// \brief Derive a key from a secret seed |
349 | | /// \param derived the derived output buffer |
350 | | /// \param derivedLen the size of the derived buffer, in bytes |
351 | | /// \param purpose a purpose byte |
352 | | /// \param secret the seed input buffer |
353 | | /// \param secretLen the size of the secret buffer, in bytes |
354 | | /// \param salt the salt input buffer |
355 | | /// \param saltLen the size of the salt buffer, in bytes |
356 | | /// \param iterations the number of iterations |
357 | | /// \param timeInSeconds the in seconds |
358 | | /// \return the number of iterations performed |
359 | | /// \throw InvalidDerivedKeyLength if <tt>derivedLen</tt> is invalid for the scheme |
360 | | /// \details DeriveKey() provides a standard interface to derive a key from |
361 | | /// a seed and other parameters. Each class that derives from KeyDerivationFunction |
362 | | /// provides an overload that accepts most parameters used by the derivation function. |
363 | | /// \details If <tt>timeInSeconds</tt> is <tt>> 0.0</tt> then DeriveKey will run for |
364 | | /// the specified amount of time. If <tt>timeInSeconds</tt> is <tt>0.0</tt> then DeriveKey |
365 | | /// will run for the specified number of iterations. |
366 | | size_t DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *secret, size_t secretLen, |
367 | | const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds) const; |
368 | | |
369 | | protected: |
370 | | // KeyDerivationFunction interface |
371 | 0 | const Algorithm & GetAlgorithm() const { |
372 | 0 | return *this; |
373 | 0 | } Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHA1>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHA224>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHA384>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHA512>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHAKE128>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHAKE256>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD128>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD160>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD256>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD320>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Whirlpool>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Weak1::MD2>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Weak1::MD4>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Weak1::MD5>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SM3>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::BLAKE2b>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::BLAKE2s>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Tiger>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<28u> >::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<32u> >::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<48u> >::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<64u> >::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::LSH224>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::LSH256>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::LSH384>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::LSH512>::GetAlgorithm() const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::LSH512_256>::GetAlgorithm() const |
374 | | }; |
375 | | |
376 | | template <class T> |
377 | | size_t PKCS12_PBKDF<T>::GetValidDerivedLength(size_t keylength) const |
378 | 1.56k | { |
379 | 1.56k | if (keylength > MaxDerivedKeyLength()) |
380 | 0 | return MaxDerivedKeyLength(); |
381 | 1.56k | return keylength; |
382 | 1.56k | } CryptoPP::PKCS12_PBKDF<CryptoPP::SHA1>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 52 | { | 379 | 52 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 52 | return keylength; | 382 | 52 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::SHA224>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 64 | { | 379 | 64 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 64 | return keylength; | 382 | 64 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::SHA384>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 60 | { | 379 | 60 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 60 | return keylength; | 382 | 60 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::SHA512>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 83 | { | 379 | 83 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 83 | return keylength; | 382 | 83 | } |
Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHAKE128>::GetValidDerivedLength(unsigned long) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHAKE256>::GetValidDerivedLength(unsigned long) const CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD128>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 50 | { | 379 | 50 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 50 | return keylength; | 382 | 50 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD160>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 66 | { | 379 | 66 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 66 | return keylength; | 382 | 66 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD256>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 51 | { | 379 | 51 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 51 | return keylength; | 382 | 51 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD320>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 53 | { | 379 | 53 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 53 | return keylength; | 382 | 53 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Whirlpool>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 68 | { | 379 | 68 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 68 | return keylength; | 382 | 68 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Weak1::MD2>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 61 | { | 379 | 61 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 61 | return keylength; | 382 | 61 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Weak1::MD4>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 134 | { | 379 | 134 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 134 | return keylength; | 382 | 134 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Weak1::MD5>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 48 | { | 379 | 48 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 48 | return keylength; | 382 | 48 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::SM3>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 53 | { | 379 | 53 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 53 | return keylength; | 382 | 53 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::BLAKE2b>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 122 | { | 379 | 122 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 122 | return keylength; | 382 | 122 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::BLAKE2s>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 94 | { | 379 | 94 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 94 | return keylength; | 382 | 94 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Tiger>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 56 | { | 379 | 56 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 56 | return keylength; | 382 | 56 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<28u> >::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 55 | { | 379 | 55 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 55 | return keylength; | 382 | 55 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<32u> >::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 57 | { | 379 | 57 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 57 | return keylength; | 382 | 57 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<48u> >::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 51 | { | 379 | 51 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 51 | return keylength; | 382 | 51 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<64u> >::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 55 | { | 379 | 55 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 55 | return keylength; | 382 | 55 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::LSH224>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 50 | { | 379 | 50 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 50 | return keylength; | 382 | 50 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::LSH256>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 45 | { | 379 | 45 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 45 | return keylength; | 382 | 45 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::LSH384>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 40 | { | 379 | 40 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 40 | return keylength; | 382 | 40 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::LSH512>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 50 | { | 379 | 50 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 50 | return keylength; | 382 | 50 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::LSH512_256>::GetValidDerivedLength(unsigned long) const Line | Count | Source | 378 | 43 | { | 379 | 43 | if (keylength > MaxDerivedKeyLength()) | 380 | 0 | return MaxDerivedKeyLength(); | 381 | 43 | return keylength; | 382 | 43 | } |
|
383 | | |
384 | | template <class T> |
385 | | size_t PKCS12_PBKDF<T>::DeriveKey(byte *derived, size_t derivedLen, |
386 | | const byte *secret, size_t secretLen, const NameValuePairs& params) const |
387 | 0 | { |
388 | 0 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); |
389 | 0 | CRYPTOPP_ASSERT(derived && derivedLen); |
390 | 0 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); |
391 | |
|
392 | 0 | byte purpose = (byte)params.GetIntValueWithDefault("Purpose", 0); |
393 | 0 | unsigned int iterations = (unsigned int)params.GetIntValueWithDefault("Iterations", 1); |
394 | |
|
395 | 0 | double timeInSeconds = 0.0f; |
396 | 0 | (void)params.GetValue("TimeInSeconds", timeInSeconds); |
397 | | |
398 | | // NULL or 0 length salt OK |
399 | 0 | ConstByteArrayParameter salt; |
400 | 0 | (void)params.GetValue(Name::Salt(), salt); |
401 | |
|
402 | 0 | return DeriveKey(derived, derivedLen, purpose, secret, secretLen, salt.begin(), salt.size(), iterations, timeInSeconds); |
403 | 0 | } Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHA1>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHA224>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHA384>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHA512>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHAKE128>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHAKE256>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD128>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD160>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD256>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD320>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Whirlpool>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Weak1::MD2>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Weak1::MD4>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Weak1::MD5>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SM3>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::BLAKE2b>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::BLAKE2s>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Tiger>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<28u> >::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<32u> >::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<48u> >::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<64u> >::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::LSH224>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::LSH256>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::LSH384>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::LSH512>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::LSH512_256>::DeriveKey(unsigned char*, unsigned long, unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&) const |
404 | | |
405 | | template <class T> |
406 | | size_t PKCS12_PBKDF<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 |
407 | 1.56k | { |
408 | 1.56k | CRYPTOPP_ASSERT(secret /*&& secretLen*/); |
409 | 1.56k | CRYPTOPP_ASSERT(derived && derivedLen); |
410 | 1.56k | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); |
411 | 1.56k | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); |
412 | | |
413 | 1.56k | ThrowIfInvalidDerivedKeyLength(derivedLen); |
414 | | |
415 | | // Business logic |
416 | 1.56k | if (!iterations) { iterations = 1; } |
417 | | |
418 | 1.56k | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 |
419 | 1.56k | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); |
420 | 1.56k | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; |
421 | 1.56k | SecByteBlock buffer(DLen + SLen + PLen); |
422 | 1.56k | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; |
423 | | |
424 | 1.56k | if (D) // GCC analyzer |
425 | 1.56k | std::memset(D, purpose, DLen); |
426 | | |
427 | 1.56k | size_t i; |
428 | 9.28M | for (i=0; i<SLen; i++) |
429 | 9.28M | S[i] = salt[i % saltLen]; |
430 | 8.93M | for (i=0; i<PLen; i++) |
431 | 8.93M | P[i] = secret[i % secretLen]; |
432 | | |
433 | 1.56k | T hash; |
434 | 1.56k | SecByteBlock Ai(T::DIGESTSIZE), B(v); |
435 | 1.56k | ThreadUserTimer timer; |
436 | | |
437 | 26.4k | while (derivedLen > 0) |
438 | 24.9k | { |
439 | 24.9k | hash.CalculateDigest(Ai, buffer, buffer.size()); |
440 | | |
441 | 24.9k | if (timeInSeconds) |
442 | 0 | { |
443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); |
444 | 0 | timer.StartTimer(); |
445 | 0 | } |
446 | | |
447 | 53.7k | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) |
448 | 28.8k | hash.CalculateDigest(Ai, Ai, Ai.size()); |
449 | | |
450 | 24.9k | if (timeInSeconds) |
451 | 0 | { |
452 | 0 | iterations = (unsigned int)i; |
453 | 0 | timeInSeconds = 0; |
454 | 0 | } |
455 | | |
456 | 2.21M | for (i=0; i<B.size(); i++) |
457 | 2.19M | B[i] = Ai[i % Ai.size()]; |
458 | | |
459 | 24.9k | Integer B1(B, B.size()); |
460 | 24.9k | ++B1; |
461 | 4.82M | for (i=0; i<ILen; i+=v) |
462 | 4.79M | (Integer(I+i, v) + B1).Encode(I+i, v); |
463 | | |
464 | | #if CRYPTOPP_MSC_VERSION |
465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); |
466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); |
467 | | #else |
468 | 24.9k | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); |
469 | 24.9k | std::memcpy(derived, Ai, segmentLen); |
470 | 24.9k | #endif |
471 | | |
472 | 24.9k | derived += segmentLen; |
473 | 24.9k | derivedLen -= segmentLen; |
474 | 24.9k | } |
475 | | |
476 | 1.56k | return iterations; |
477 | 1.56k | } CryptoPP::PKCS12_PBKDF<CryptoPP::SHA1>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 52 | { | 408 | 52 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 52 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 52 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 52 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 52 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 52 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 52 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 52 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 52 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 52 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 52 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 52 | if (D) // GCC analyzer | 425 | 52 | std::memset(D, purpose, DLen); | 426 | | | 427 | 52 | size_t i; | 428 | 308k | for (i=0; i<SLen; i++) | 429 | 308k | S[i] = salt[i % saltLen]; | 430 | 342k | for (i=0; i<PLen; i++) | 431 | 342k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 52 | T hash; | 434 | 52 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 52 | ThreadUserTimer timer; | 436 | | | 437 | 1.24k | while (derivedLen > 0) | 438 | 1.19k | { | 439 | 1.19k | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 1.19k | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 2.38k | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 1.19k | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 1.19k | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 77.4k | for (i=0; i<B.size(); i++) | 457 | 76.2k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 1.19k | Integer B1(B, B.size()); | 460 | 1.19k | ++B1; | 461 | 185k | for (i=0; i<ILen; i+=v) | 462 | 184k | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 1.19k | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 1.19k | std::memcpy(derived, Ai, segmentLen); | 470 | 1.19k | #endif | 471 | | | 472 | 1.19k | derived += segmentLen; | 473 | 1.19k | derivedLen -= segmentLen; | 474 | 1.19k | } | 475 | | | 476 | 52 | return iterations; | 477 | 52 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::SHA224>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 64 | { | 408 | 64 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 64 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 64 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 64 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 64 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 64 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 64 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 64 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 64 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 64 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 64 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 64 | if (D) // GCC analyzer | 425 | 64 | std::memset(D, purpose, DLen); | 426 | | | 427 | 64 | size_t i; | 428 | 301k | for (i=0; i<SLen; i++) | 429 | 301k | S[i] = salt[i % saltLen]; | 430 | 306k | for (i=0; i<PLen; i++) | 431 | 306k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 64 | T hash; | 434 | 64 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 64 | ThreadUserTimer timer; | 436 | | | 437 | 1.07k | while (derivedLen > 0) | 438 | 1.01k | { | 439 | 1.01k | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 1.01k | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 2.49k | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 1.48k | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 1.01k | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 65.7k | for (i=0; i<B.size(); i++) | 457 | 64.7k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 1.01k | Integer B1(B, B.size()); | 460 | 1.01k | ++B1; | 461 | 144k | for (i=0; i<ILen; i+=v) | 462 | 143k | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 1.01k | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 1.01k | std::memcpy(derived, Ai, segmentLen); | 470 | 1.01k | #endif | 471 | | | 472 | 1.01k | derived += segmentLen; | 473 | 1.01k | derivedLen -= segmentLen; | 474 | 1.01k | } | 475 | | | 476 | 64 | return iterations; | 477 | 64 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::SHA384>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 60 | { | 408 | 60 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 60 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 60 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 60 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 60 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 60 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 60 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 60 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 60 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 60 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 60 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 60 | if (D) // GCC analyzer | 425 | 60 | std::memset(D, purpose, DLen); | 426 | | | 427 | 60 | size_t i; | 428 | 309k | for (i=0; i<SLen; i++) | 429 | 309k | S[i] = salt[i % saltLen]; | 430 | 386k | for (i=0; i<PLen; i++) | 431 | 386k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 60 | T hash; | 434 | 60 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 60 | ThreadUserTimer timer; | 436 | | | 437 | 574 | while (derivedLen > 0) | 438 | 514 | { | 439 | 514 | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 514 | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 1.07k | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 561 | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 514 | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 66.3k | for (i=0; i<B.size(); i++) | 457 | 65.7k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 514 | Integer B1(B, B.size()); | 460 | 514 | ++B1; | 461 | 51.0k | for (i=0; i<ILen; i+=v) | 462 | 50.5k | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 514 | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 514 | std::memcpy(derived, Ai, segmentLen); | 470 | 514 | #endif | 471 | | | 472 | 514 | derived += segmentLen; | 473 | 514 | derivedLen -= segmentLen; | 474 | 514 | } | 475 | | | 476 | 60 | return iterations; | 477 | 60 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::SHA512>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 83 | { | 408 | 83 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 83 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 83 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 83 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 83 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 83 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 83 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 83 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 83 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 83 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 83 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 83 | if (D) // GCC analyzer | 425 | 83 | std::memset(D, purpose, DLen); | 426 | | | 427 | 83 | size_t i; | 428 | 425k | for (i=0; i<SLen; i++) | 429 | 425k | S[i] = salt[i % saltLen]; | 430 | 437k | for (i=0; i<PLen; i++) | 431 | 437k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 83 | T hash; | 434 | 83 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 83 | ThreadUserTimer timer; | 436 | | | 437 | 883 | while (derivedLen > 0) | 438 | 800 | { | 439 | 800 | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 800 | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 2.30k | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 1.50k | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 800 | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 103k | for (i=0; i<B.size(); i++) | 457 | 102k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 800 | Integer B1(B, B.size()); | 460 | 800 | ++B1; | 461 | 48.3k | for (i=0; i<ILen; i+=v) | 462 | 47.5k | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 800 | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 800 | std::memcpy(derived, Ai, segmentLen); | 470 | 800 | #endif | 471 | | | 472 | 800 | derived += segmentLen; | 473 | 800 | derivedLen -= segmentLen; | 474 | 800 | } | 475 | | | 476 | 83 | return iterations; | 477 | 83 | } |
Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHAKE128>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Unexecuted instantiation: CryptoPP::PKCS12_PBKDF<CryptoPP::SHAKE256>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD128>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 50 | { | 408 | 50 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 50 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 50 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 50 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 50 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 50 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 50 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 50 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 50 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 50 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 50 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 50 | if (D) // GCC analyzer | 425 | 50 | std::memset(D, purpose, DLen); | 426 | | | 427 | 50 | size_t i; | 428 | 390k | for (i=0; i<SLen; i++) | 429 | 389k | S[i] = salt[i % saltLen]; | 430 | 290k | for (i=0; i<PLen; i++) | 431 | 290k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 50 | T hash; | 434 | 50 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 50 | ThreadUserTimer timer; | 436 | | | 437 | 1.39k | while (derivedLen > 0) | 438 | 1.34k | { | 439 | 1.34k | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 1.34k | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 3.08k | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 1.73k | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 1.34k | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 87.6k | for (i=0; i<B.size(); i++) | 457 | 86.3k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 1.34k | Integer B1(B, B.size()); | 460 | 1.34k | ++B1; | 461 | 341k | for (i=0; i<ILen; i+=v) | 462 | 340k | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 1.34k | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 1.34k | std::memcpy(derived, Ai, segmentLen); | 470 | 1.34k | #endif | 471 | | | 472 | 1.34k | derived += segmentLen; | 473 | 1.34k | derivedLen -= segmentLen; | 474 | 1.34k | } | 475 | | | 476 | 50 | return iterations; | 477 | 50 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD160>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 66 | { | 408 | 66 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 66 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 66 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 66 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 66 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 66 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 66 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 66 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 66 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 66 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 66 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 66 | if (D) // GCC analyzer | 425 | 66 | std::memset(D, purpose, DLen); | 426 | | | 427 | 66 | size_t i; | 428 | 272k | for (i=0; i<SLen; i++) | 429 | 272k | S[i] = salt[i % saltLen]; | 430 | 310k | for (i=0; i<PLen; i++) | 431 | 309k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 66 | T hash; | 434 | 66 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 66 | ThreadUserTimer timer; | 436 | | | 437 | 1.71k | while (derivedLen > 0) | 438 | 1.64k | { | 439 | 1.64k | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 1.64k | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 4.04k | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 2.39k | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 1.64k | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 107k | for (i=0; i<B.size(); i++) | 457 | 105k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 1.64k | Integer B1(B, B.size()); | 460 | 1.64k | ++B1; | 461 | 211k | for (i=0; i<ILen; i+=v) | 462 | 210k | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 1.64k | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 1.64k | std::memcpy(derived, Ai, segmentLen); | 470 | 1.64k | #endif | 471 | | | 472 | 1.64k | derived += segmentLen; | 473 | 1.64k | derivedLen -= segmentLen; | 474 | 1.64k | } | 475 | | | 476 | 66 | return iterations; | 477 | 66 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD256>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 51 | { | 408 | 51 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 51 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 51 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 51 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 51 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 51 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 51 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 51 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 51 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 51 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 51 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 51 | if (D) // GCC analyzer | 425 | 51 | std::memset(D, purpose, DLen); | 426 | | | 427 | 51 | size_t i; | 428 | 262k | for (i=0; i<SLen; i++) | 429 | 261k | S[i] = salt[i % saltLen]; | 430 | 281k | for (i=0; i<PLen; i++) | 431 | 281k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 51 | T hash; | 434 | 51 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 51 | ThreadUserTimer timer; | 436 | | | 437 | 736 | while (derivedLen > 0) | 438 | 685 | { | 439 | 685 | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 685 | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 1.58k | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 902 | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 685 | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 44.5k | for (i=0; i<B.size(); i++) | 457 | 43.8k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 685 | Integer B1(B, B.size()); | 460 | 685 | ++B1; | 461 | 83.6k | for (i=0; i<ILen; i+=v) | 462 | 82.9k | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 685 | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 685 | std::memcpy(derived, Ai, segmentLen); | 470 | 685 | #endif | 471 | | | 472 | 685 | derived += segmentLen; | 473 | 685 | derivedLen -= segmentLen; | 474 | 685 | } | 475 | | | 476 | 51 | return iterations; | 477 | 51 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::RIPEMD320>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 53 | { | 408 | 53 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 53 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 53 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 53 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 53 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 53 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 53 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 53 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 53 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 53 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 53 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 53 | if (D) // GCC analyzer | 425 | 53 | std::memset(D, purpose, DLen); | 426 | | | 427 | 53 | size_t i; | 428 | 297k | for (i=0; i<SLen; i++) | 429 | 297k | S[i] = salt[i % saltLen]; | 430 | 270k | for (i=0; i<PLen; i++) | 431 | 270k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 53 | T hash; | 434 | 53 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 53 | ThreadUserTimer timer; | 436 | | | 437 | 705 | while (derivedLen > 0) | 438 | 652 | { | 439 | 652 | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 652 | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 1.37k | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 724 | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 652 | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 42.3k | for (i=0; i<B.size(); i++) | 457 | 41.7k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 652 | Integer B1(B, B.size()); | 460 | 652 | ++B1; | 461 | 93.5k | for (i=0; i<ILen; i+=v) | 462 | 92.8k | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 652 | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 652 | std::memcpy(derived, Ai, segmentLen); | 470 | 652 | #endif | 471 | | | 472 | 652 | derived += segmentLen; | 473 | 652 | derivedLen -= segmentLen; | 474 | 652 | } | 475 | | | 476 | 53 | return iterations; | 477 | 53 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Whirlpool>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 68 | { | 408 | 68 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 68 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 68 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 68 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 68 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 68 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 68 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 68 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 68 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 68 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 68 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 68 | if (D) // GCC analyzer | 425 | 68 | std::memset(D, purpose, DLen); | 426 | | | 427 | 68 | size_t i; | 428 | 226k | for (i=0; i<SLen; i++) | 429 | 226k | S[i] = salt[i % saltLen]; | 430 | 182k | for (i=0; i<PLen; i++) | 431 | 181k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 68 | T hash; | 434 | 68 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 68 | ThreadUserTimer timer; | 436 | | | 437 | 518 | while (derivedLen > 0) | 438 | 450 | { | 439 | 450 | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 450 | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 1.06k | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 614 | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 450 | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 29.2k | for (i=0; i<B.size(); i++) | 457 | 28.8k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 450 | Integer B1(B, B.size()); | 460 | 450 | ++B1; | 461 | 46.3k | for (i=0; i<ILen; i+=v) | 462 | 45.9k | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 450 | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 450 | std::memcpy(derived, Ai, segmentLen); | 470 | 450 | #endif | 471 | | | 472 | 450 | derived += segmentLen; | 473 | 450 | derivedLen -= segmentLen; | 474 | 450 | } | 475 | | | 476 | 68 | return iterations; | 477 | 68 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Weak1::MD2>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 61 | { | 408 | 61 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 61 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 61 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 61 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 61 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 61 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 61 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 61 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 61 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 61 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 61 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 61 | if (D) // GCC analyzer | 425 | 61 | std::memset(D, purpose, DLen); | 426 | | | 427 | 61 | size_t i; | 428 | 477k | for (i=0; i<SLen; i++) | 429 | 477k | S[i] = salt[i % saltLen]; | 430 | 533k | for (i=0; i<PLen; i++) | 431 | 533k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 61 | T hash; | 434 | 61 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 61 | ThreadUserTimer timer; | 436 | | | 437 | 1.76k | while (derivedLen > 0) | 438 | 1.70k | { | 439 | 1.70k | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 1.70k | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 3.85k | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 2.15k | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 1.70k | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 28.9k | for (i=0; i<B.size(); i++) | 457 | 27.2k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 1.70k | Integer B1(B, B.size()); | 460 | 1.70k | ++B1; | 461 | 1.59M | for (i=0; i<ILen; i+=v) | 462 | 1.59M | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 1.70k | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 1.70k | std::memcpy(derived, Ai, segmentLen); | 470 | 1.70k | #endif | 471 | | | 472 | 1.70k | derived += segmentLen; | 473 | 1.70k | derivedLen -= segmentLen; | 474 | 1.70k | } | 475 | | | 476 | 61 | return iterations; | 477 | 61 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Weak1::MD4>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 134 | { | 408 | 134 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 134 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 134 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 134 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 134 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 134 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 134 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 134 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 134 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 134 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 134 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 134 | if (D) // GCC analyzer | 425 | 134 | std::memset(D, purpose, DLen); | 426 | | | 427 | 134 | size_t i; | 428 | 348k | for (i=0; i<SLen; i++) | 429 | 347k | S[i] = salt[i % saltLen]; | 430 | 377k | for (i=0; i<PLen; i++) | 431 | 377k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 134 | T hash; | 434 | 134 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 134 | ThreadUserTimer timer; | 436 | | | 437 | 3.45k | while (derivedLen > 0) | 438 | 3.32k | { | 439 | 3.32k | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 3.32k | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 4.88k | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 1.55k | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 3.32k | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 215k | for (i=0; i<B.size(); i++) | 457 | 212k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 3.32k | Integer B1(B, B.size()); | 460 | 3.32k | ++B1; | 461 | 397k | for (i=0; i<ILen; i+=v) | 462 | 394k | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 3.32k | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 3.32k | std::memcpy(derived, Ai, segmentLen); | 470 | 3.32k | #endif | 471 | | | 472 | 3.32k | derived += segmentLen; | 473 | 3.32k | derivedLen -= segmentLen; | 474 | 3.32k | } | 475 | | | 476 | 134 | return iterations; | 477 | 134 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Weak1::MD5>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 48 | { | 408 | 48 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 48 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 48 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 48 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 48 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 48 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 48 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 48 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 48 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 48 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 48 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 48 | if (D) // GCC analyzer | 425 | 48 | std::memset(D, purpose, DLen); | 426 | | | 427 | 48 | size_t i; | 428 | 396k | for (i=0; i<SLen; i++) | 429 | 396k | S[i] = salt[i % saltLen]; | 430 | 333k | for (i=0; i<PLen; i++) | 431 | 333k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 48 | T hash; | 434 | 48 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 48 | ThreadUserTimer timer; | 436 | | | 437 | 1.50k | while (derivedLen > 0) | 438 | 1.46k | { | 439 | 1.46k | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 1.46k | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 3.13k | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 1.67k | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 1.46k | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 94.9k | for (i=0; i<B.size(); i++) | 457 | 93.4k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 1.46k | Integer B1(B, B.size()); | 460 | 1.46k | ++B1; | 461 | 325k | for (i=0; i<ILen; i+=v) | 462 | 323k | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 1.46k | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 1.46k | std::memcpy(derived, Ai, segmentLen); | 470 | 1.46k | #endif | 471 | | | 472 | 1.46k | derived += segmentLen; | 473 | 1.46k | derivedLen -= segmentLen; | 474 | 1.46k | } | 475 | | | 476 | 48 | return iterations; | 477 | 48 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::SM3>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 53 | { | 408 | 53 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 53 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 53 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 53 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 53 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 53 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 53 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 53 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 53 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 53 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 53 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 53 | if (D) // GCC analyzer | 425 | 53 | std::memset(D, purpose, DLen); | 426 | | | 427 | 53 | size_t i; | 428 | 379k | for (i=0; i<SLen; i++) | 429 | 379k | S[i] = salt[i % saltLen]; | 430 | 333k | for (i=0; i<PLen; i++) | 431 | 333k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 53 | T hash; | 434 | 53 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 53 | ThreadUserTimer timer; | 436 | | | 437 | 984 | while (derivedLen > 0) | 438 | 931 | { | 439 | 931 | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 931 | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 2.24k | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 1.31k | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 931 | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 60.5k | for (i=0; i<B.size(); i++) | 457 | 59.5k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 931 | Integer B1(B, B.size()); | 460 | 931 | ++B1; | 461 | 168k | for (i=0; i<ILen; i+=v) | 462 | 167k | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 931 | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 931 | std::memcpy(derived, Ai, segmentLen); | 470 | 931 | #endif | 471 | | | 472 | 931 | derived += segmentLen; | 473 | 931 | derivedLen -= segmentLen; | 474 | 931 | } | 475 | | | 476 | 53 | return iterations; | 477 | 53 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::BLAKE2b>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 122 | { | 408 | 122 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 122 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 122 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 122 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 122 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 122 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 122 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 122 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 122 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 122 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 122 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 122 | if (D) // GCC analyzer | 425 | 122 | std::memset(D, purpose, DLen); | 426 | | | 427 | 122 | size_t i; | 428 | 424k | for (i=0; i<SLen; i++) | 429 | 424k | S[i] = salt[i % saltLen]; | 430 | 375k | for (i=0; i<PLen; i++) | 431 | 375k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 122 | T hash; | 434 | 122 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 122 | ThreadUserTimer timer; | 436 | | | 437 | 1.21k | while (derivedLen > 0) | 438 | 1.08k | { | 439 | 1.08k | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 1.08k | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 2.43k | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 1.34k | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 1.08k | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 140k | for (i=0; i<B.size(); i++) | 457 | 139k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 1.08k | Integer B1(B, B.size()); | 460 | 1.08k | ++B1; | 461 | 43.9k | for (i=0; i<ILen; i+=v) | 462 | 42.8k | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 1.08k | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 1.08k | std::memcpy(derived, Ai, segmentLen); | 470 | 1.08k | #endif | 471 | | | 472 | 1.08k | derived += segmentLen; | 473 | 1.08k | derivedLen -= segmentLen; | 474 | 1.08k | } | 475 | | | 476 | 122 | return iterations; | 477 | 122 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::BLAKE2s>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 94 | { | 408 | 94 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 94 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 94 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 94 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 94 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 94 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 94 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 94 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 94 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 94 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 94 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 94 | if (D) // GCC analyzer | 425 | 94 | std::memset(D, purpose, DLen); | 426 | | | 427 | 94 | size_t i; | 428 | 440k | for (i=0; i<SLen; i++) | 429 | 440k | S[i] = salt[i % saltLen]; | 430 | 351k | for (i=0; i<PLen; i++) | 431 | 351k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 94 | T hash; | 434 | 94 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 94 | ThreadUserTimer timer; | 436 | | | 437 | 1.58k | while (derivedLen > 0) | 438 | 1.49k | { | 439 | 1.49k | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 1.49k | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 2.73k | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 1.24k | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 1.49k | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 96.8k | for (i=0; i<B.size(); i++) | 457 | 95.3k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 1.49k | Integer B1(B, B.size()); | 460 | 1.49k | ++B1; | 461 | 182k | for (i=0; i<ILen; i+=v) | 462 | 180k | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 1.49k | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 1.49k | std::memcpy(derived, Ai, segmentLen); | 470 | 1.49k | #endif | 471 | | | 472 | 1.49k | derived += segmentLen; | 473 | 1.49k | derivedLen -= segmentLen; | 474 | 1.49k | } | 475 | | | 476 | 94 | return iterations; | 477 | 94 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Tiger>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 56 | { | 408 | 56 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 56 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 56 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 56 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 56 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 56 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 56 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 56 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 56 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 56 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 56 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 56 | if (D) // GCC analyzer | 425 | 56 | std::memset(D, purpose, DLen); | 426 | | | 427 | 56 | size_t i; | 428 | 439k | for (i=0; i<SLen; i++) | 429 | 439k | S[i] = salt[i % saltLen]; | 430 | 518k | for (i=0; i<PLen; i++) | 431 | 518k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 56 | T hash; | 434 | 56 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 56 | ThreadUserTimer timer; | 436 | | | 437 | 1.12k | while (derivedLen > 0) | 438 | 1.06k | { | 439 | 1.06k | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 1.06k | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 2.49k | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 1.43k | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 1.06k | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 69.4k | for (i=0; i<B.size(); i++) | 457 | 68.3k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 1.06k | Integer B1(B, B.size()); | 460 | 1.06k | ++B1; | 461 | 292k | for (i=0; i<ILen; i+=v) | 462 | 291k | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 1.06k | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 1.06k | std::memcpy(derived, Ai, segmentLen); | 470 | 1.06k | #endif | 471 | | | 472 | 1.06k | derived += segmentLen; | 473 | 1.06k | derivedLen -= segmentLen; | 474 | 1.06k | } | 475 | | | 476 | 56 | return iterations; | 477 | 56 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<28u> >::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 55 | { | 408 | 55 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 55 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 55 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 55 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 55 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 55 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 55 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 55 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 55 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 55 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 55 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 55 | if (D) // GCC analyzer | 425 | 55 | std::memset(D, purpose, DLen); | 426 | | | 427 | 55 | size_t i; | 428 | 332k | for (i=0; i<SLen; i++) | 429 | 332k | S[i] = salt[i % saltLen]; | 430 | 358k | for (i=0; i<PLen; i++) | 431 | 358k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 55 | T hash; | 434 | 55 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 55 | ThreadUserTimer timer; | 436 | | | 437 | 931 | while (derivedLen > 0) | 438 | 876 | { | 439 | 876 | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 876 | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 2.18k | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 1.30k | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 876 | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 127k | for (i=0; i<B.size(); i++) | 457 | 126k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 876 | Integer B1(B, B.size()); | 460 | 876 | ++B1; | 461 | 77.6k | for (i=0; i<ILen; i+=v) | 462 | 76.7k | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 876 | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 876 | std::memcpy(derived, Ai, segmentLen); | 470 | 876 | #endif | 471 | | | 472 | 876 | derived += segmentLen; | 473 | 876 | derivedLen -= segmentLen; | 474 | 876 | } | 475 | | | 476 | 55 | return iterations; | 477 | 55 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<32u> >::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 57 | { | 408 | 57 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 57 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 57 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 57 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 57 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 57 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 57 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 57 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 57 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 57 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 57 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 57 | if (D) // GCC analyzer | 425 | 57 | std::memset(D, purpose, DLen); | 426 | | | 427 | 57 | size_t i; | 428 | 600k | for (i=0; i<SLen; i++) | 429 | 600k | S[i] = salt[i % saltLen]; | 430 | 392k | for (i=0; i<PLen; i++) | 431 | 392k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 57 | T hash; | 434 | 57 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 57 | ThreadUserTimer timer; | 436 | | | 437 | 941 | while (derivedLen > 0) | 438 | 884 | { | 439 | 884 | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 884 | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 2.00k | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 1.12k | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 884 | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 121k | for (i=0; i<B.size(); i++) | 457 | 120k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 884 | Integer B1(B, B.size()); | 460 | 884 | ++B1; | 461 | 110k | for (i=0; i<ILen; i+=v) | 462 | 109k | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 884 | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 884 | std::memcpy(derived, Ai, segmentLen); | 470 | 884 | #endif | 471 | | | 472 | 884 | derived += segmentLen; | 473 | 884 | derivedLen -= segmentLen; | 474 | 884 | } | 475 | | | 476 | 57 | return iterations; | 477 | 57 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<48u> >::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 51 | { | 408 | 51 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 51 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 51 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 51 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 51 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 51 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 51 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 51 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 51 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 51 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 51 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 51 | if (D) // GCC analyzer | 425 | 51 | std::memset(D, purpose, DLen); | 426 | | | 427 | 51 | size_t i; | 428 | 439k | for (i=0; i<SLen; i++) | 429 | 438k | S[i] = salt[i % saltLen]; | 430 | 439k | for (i=0; i<PLen; i++) | 431 | 439k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 51 | T hash; | 434 | 51 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 51 | ThreadUserTimer timer; | 436 | | | 437 | 510 | while (derivedLen > 0) | 438 | 459 | { | 439 | 459 | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 459 | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 1.04k | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 586 | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 459 | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 48.1k | for (i=0; i<B.size(); i++) | 457 | 47.7k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 459 | Integer B1(B, B.size()); | 460 | 459 | ++B1; | 461 | 69.2k | for (i=0; i<ILen; i+=v) | 462 | 68.7k | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 459 | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 459 | std::memcpy(derived, Ai, segmentLen); | 470 | 459 | #endif | 471 | | | 472 | 459 | derived += segmentLen; | 473 | 459 | derivedLen -= segmentLen; | 474 | 459 | } | 475 | | | 476 | 51 | return iterations; | 477 | 51 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::Keccak_Final<64u> >::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 55 | { | 408 | 55 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 55 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 55 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 55 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 55 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 55 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 55 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 55 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 55 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 55 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 55 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 55 | if (D) // GCC analyzer | 425 | 55 | std::memset(D, purpose, DLen); | 426 | | | 427 | 55 | size_t i; | 428 | 516k | for (i=0; i<SLen; i++) | 429 | 516k | S[i] = salt[i % saltLen]; | 430 | 389k | for (i=0; i<PLen; i++) | 431 | 389k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 55 | T hash; | 434 | 55 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 55 | ThreadUserTimer timer; | 436 | | | 437 | 445 | while (derivedLen > 0) | 438 | 390 | { | 439 | 390 | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 390 | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 915 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 525 | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 390 | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 28.4k | for (i=0; i<B.size(); i++) | 457 | 28.0k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 390 | Integer B1(B, B.size()); | 460 | 390 | ++B1; | 461 | 108k | for (i=0; i<ILen; i+=v) | 462 | 107k | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 390 | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 390 | std::memcpy(derived, Ai, segmentLen); | 470 | 390 | #endif | 471 | | | 472 | 390 | derived += segmentLen; | 473 | 390 | derivedLen -= segmentLen; | 474 | 390 | } | 475 | | | 476 | 55 | return iterations; | 477 | 55 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::LSH224>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 50 | { | 408 | 50 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 50 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 50 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 50 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 50 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 50 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 50 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 50 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 50 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 50 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 50 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 50 | if (D) // GCC analyzer | 425 | 50 | std::memset(D, purpose, DLen); | 426 | | | 427 | 50 | size_t i; | 428 | 438k | for (i=0; i<SLen; i++) | 429 | 438k | S[i] = salt[i % saltLen]; | 430 | 388k | for (i=0; i<PLen; i++) | 431 | 388k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 50 | T hash; | 434 | 50 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 50 | ThreadUserTimer timer; | 436 | | | 437 | 834 | while (derivedLen > 0) | 438 | 784 | { | 439 | 784 | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 784 | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 1.73k | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 954 | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 784 | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 101k | for (i=0; i<B.size(); i++) | 457 | 100k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 784 | Integer B1(B, B.size()); | 460 | 784 | ++B1; | 461 | 98.2k | for (i=0; i<ILen; i+=v) | 462 | 97.5k | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 784 | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 784 | std::memcpy(derived, Ai, segmentLen); | 470 | 784 | #endif | 471 | | | 472 | 784 | derived += segmentLen; | 473 | 784 | derivedLen -= segmentLen; | 474 | 784 | } | 475 | | | 476 | 50 | return iterations; | 477 | 50 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::LSH256>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 45 | { | 408 | 45 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 45 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 45 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 45 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 45 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 45 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 45 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 45 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 45 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 45 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 45 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 45 | if (D) // GCC analyzer | 425 | 45 | std::memset(D, purpose, DLen); | 426 | | | 427 | 45 | size_t i; | 428 | 298k | for (i=0; i<SLen; i++) | 429 | 298k | S[i] = salt[i % saltLen]; | 430 | 253k | for (i=0; i<PLen; i++) | 431 | 253k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 45 | T hash; | 434 | 45 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 45 | ThreadUserTimer timer; | 436 | | | 437 | 756 | while (derivedLen > 0) | 438 | 711 | { | 439 | 711 | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 711 | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 1.67k | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 964 | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 711 | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 91.7k | for (i=0; i<B.size(); i++) | 457 | 91.0k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 711 | Integer B1(B, B.size()); | 460 | 711 | ++B1; | 461 | 66.6k | for (i=0; i<ILen; i+=v) | 462 | 65.9k | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 711 | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 711 | std::memcpy(derived, Ai, segmentLen); | 470 | 711 | #endif | 471 | | | 472 | 711 | derived += segmentLen; | 473 | 711 | derivedLen -= segmentLen; | 474 | 711 | } | 475 | | | 476 | 45 | return iterations; | 477 | 45 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::LSH384>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 40 | { | 408 | 40 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 40 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 40 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 40 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 40 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 40 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 40 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 40 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 40 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 40 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 40 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 40 | if (D) // GCC analyzer | 425 | 40 | std::memset(D, purpose, DLen); | 426 | | | 427 | 40 | size_t i; | 428 | 333k | for (i=0; i<SLen; i++) | 429 | 333k | S[i] = salt[i % saltLen]; | 430 | 325k | for (i=0; i<PLen; i++) | 431 | 325k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 40 | T hash; | 434 | 40 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 40 | ThreadUserTimer timer; | 436 | | | 437 | 431 | while (derivedLen > 0) | 438 | 391 | { | 439 | 391 | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 391 | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 893 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 502 | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 391 | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 100k | for (i=0; i<B.size(); i++) | 457 | 100k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 391 | Integer B1(B, B.size()); | 460 | 391 | ++B1; | 461 | 25.7k | for (i=0; i<ILen; i+=v) | 462 | 25.3k | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 391 | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 391 | std::memcpy(derived, Ai, segmentLen); | 470 | 391 | #endif | 471 | | | 472 | 391 | derived += segmentLen; | 473 | 391 | derivedLen -= segmentLen; | 474 | 391 | } | 475 | | | 476 | 40 | return iterations; | 477 | 40 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::LSH512>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 50 | { | 408 | 50 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 50 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 50 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 50 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 50 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 50 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 50 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 50 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 50 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 50 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 50 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 50 | if (D) // GCC analyzer | 425 | 50 | std::memset(D, purpose, DLen); | 426 | | | 427 | 50 | size_t i; | 428 | 363k | for (i=0; i<SLen; i++) | 429 | 363k | S[i] = salt[i % saltLen]; | 430 | 385k | for (i=0; i<PLen; i++) | 431 | 385k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 50 | T hash; | 434 | 50 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 50 | ThreadUserTimer timer; | 436 | | | 437 | 459 | while (derivedLen > 0) | 438 | 409 | { | 439 | 409 | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 409 | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 833 | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 424 | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 409 | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 105k | for (i=0; i<B.size(); i++) | 457 | 104k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 409 | Integer B1(B, B.size()); | 460 | 409 | ++B1; | 461 | 20.4k | for (i=0; i<ILen; i+=v) | 462 | 20.0k | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 409 | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 409 | std::memcpy(derived, Ai, segmentLen); | 470 | 409 | #endif | 471 | | | 472 | 409 | derived += segmentLen; | 473 | 409 | derivedLen -= segmentLen; | 474 | 409 | } | 475 | | | 476 | 50 | return iterations; | 477 | 50 | } |
CryptoPP::PKCS12_PBKDF<CryptoPP::LSH512_256>::DeriveKey(unsigned char*, unsigned long, unsigned char, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned int, double) const Line | Count | Source | 407 | 43 | { | 408 | 43 | CRYPTOPP_ASSERT(secret /*&& secretLen*/); | 409 | 43 | CRYPTOPP_ASSERT(derived && derivedLen); | 410 | 43 | CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); | 411 | 43 | CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); | 412 | | | 413 | 43 | ThrowIfInvalidDerivedKeyLength(derivedLen); | 414 | | | 415 | | // Business logic | 416 | 43 | if (!iterations) { iterations = 1; } | 417 | | | 418 | 43 | const size_t v = T::BLOCKSIZE; // v is in bytes rather than bits as in PKCS #12 | 419 | 43 | const size_t DLen = v, SLen = RoundUpToMultipleOf(saltLen, v); | 420 | 43 | const size_t PLen = RoundUpToMultipleOf(secretLen, v), ILen = SLen + PLen; | 421 | 43 | SecByteBlock buffer(DLen + SLen + PLen); | 422 | 43 | byte *D = buffer, *S = buffer+DLen, *P = buffer+DLen+SLen, *I = S; | 423 | | | 424 | 43 | if (D) // GCC analyzer | 425 | 43 | std::memset(D, purpose, DLen); | 426 | | | 427 | 43 | size_t i; | 428 | 260k | for (i=0; i<SLen; i++) | 429 | 260k | S[i] = salt[i % saltLen]; | 430 | 368k | for (i=0; i<PLen; i++) | 431 | 368k | P[i] = secret[i % secretLen]; | 432 | | | 433 | 43 | T hash; | 434 | 43 | SecByteBlock Ai(T::DIGESTSIZE), B(v); | 435 | 43 | ThreadUserTimer timer; | 436 | | | 437 | 688 | while (derivedLen > 0) | 438 | 645 | { | 439 | 645 | hash.CalculateDigest(Ai, buffer, buffer.size()); | 440 | | | 441 | 645 | if (timeInSeconds) | 442 | 0 | { | 443 | 0 | timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size()); | 444 | 0 | timer.StartTimer(); | 445 | 0 | } | 446 | | | 447 | 1.30k | for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); i++) | 448 | 658 | hash.CalculateDigest(Ai, Ai, Ai.size()); | 449 | | | 450 | 645 | if (timeInSeconds) | 451 | 0 | { | 452 | 0 | iterations = (unsigned int)i; | 453 | 0 | timeInSeconds = 0; | 454 | 0 | } | 455 | | | 456 | 165k | for (i=0; i<B.size(); i++) | 457 | 165k | B[i] = Ai[i % Ai.size()]; | 458 | | | 459 | 645 | Integer B1(B, B.size()); | 460 | 645 | ++B1; | 461 | 33.8k | for (i=0; i<ILen; i+=v) | 462 | 33.2k | (Integer(I+i, v) + B1).Encode(I+i, v); | 463 | | | 464 | | #if CRYPTOPP_MSC_VERSION | 465 | | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 466 | | memcpy_s(derived, segmentLen, Ai, segmentLen); | 467 | | #else | 468 | 645 | const size_t segmentLen = STDMIN(derivedLen, Ai.size()); | 469 | 645 | std::memcpy(derived, Ai, segmentLen); | 470 | 645 | #endif | 471 | | | 472 | 645 | derived += segmentLen; | 473 | 645 | derivedLen -= segmentLen; | 474 | 645 | } | 475 | | | 476 | 43 | return iterations; | 477 | 43 | } |
|
478 | | |
479 | | NAMESPACE_END |
480 | | |
481 | | #endif |