6 #ifndef CRYPTOPP_PWDBASED_H 7 #define CRYPTOPP_PWDBASED_H 24 virtual size_t MaxDerivedKeyLength()
const =0;
28 virtual bool UsesPurposeByte()
const =0;
44 virtual unsigned int DeriveKey(
byte *derived,
size_t derivedLen,
byte purpose,
const byte *password,
size_t passwordLen,
const byte *salt,
size_t saltLen,
unsigned int iterations,
double timeInSeconds=0)
const =0;
56 unsigned int DeriveKey(
byte *derived,
size_t derivedLen,
byte purpose,
const byte *password,
size_t passwordLen,
const byte *salt,
size_t saltLen,
unsigned int iterations,
double timeInSeconds=0)
const;
67 unsigned int DeriveKey(
byte *derived,
size_t derivedLen,
byte purpose,
const byte *password,
size_t passwordLen,
const byte *salt,
size_t saltLen,
unsigned int iterations,
double timeInSeconds=0)
const;
91 hash.Update(password, passwordLen);
92 hash.Update(salt, saltLen);
103 for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.
ElapsedTimeAsDouble() < timeInSeconds)); i++)
104 hash.CalculateDigest(buffer, buffer, buffer.size());
106 memcpy(derived, buffer, derivedLen);
120 HMAC<T> hmac(password, passwordLen);
125 while (derivedLen > 0)
127 hmac.
Update(salt, saltLen);
136 #if CRYPTOPP_MSC_VERSION 137 const size_t segmentLen =
STDMIN(derivedLen, buffer.size());
138 memcpy_s(derived, segmentLen, buffer, segmentLen);
140 const size_t segmentLen =
STDMIN(derivedLen, buffer.size());
141 memcpy(derived, buffer, segmentLen);
146 timeInSeconds = timeInSeconds / ((derivedLen + buffer.size() - 1) / buffer.size());
150 for (j=1; j<iterations || (timeInSeconds && (j%128!=0 || timer.ElapsedTimeAsDouble() < timeInSeconds)); j++)
153 xorbuf(derived, buffer, segmentLen);
162 derived += segmentLen;
163 derivedLen -= segmentLen;
178 unsigned int DeriveKey(
byte *derived,
size_t derivedLen,
byte purpose,
const byte *password,
size_t passwordLen,
const byte *salt,
size_t saltLen,
unsigned int iterations,
double timeInSeconds)
const;
190 const size_t v = T::BLOCKSIZE;
194 byte *D = buffer, *
S = buffer+DLen, *
P = buffer+DLen+SLen, *
I =
S;
196 memset(D, purpose, DLen);
198 for (i=0; i<SLen; i++)
199 S[i] = salt[i % saltLen];
200 for (i=0; i<PLen; i++)
201 P[i] = password[i % passwordLen];
208 while (derivedLen > 0)
210 hash.CalculateDigest(Ai, buffer, buffer.
size());
214 timeInSeconds = timeInSeconds / ((derivedLen + Ai.size() - 1) / Ai.size());
218 for (i=1; i<iterations || (timeInSeconds && (i%128!=0 || timer.
ElapsedTimeAsDouble() < timeInSeconds)); i++)
219 hash.CalculateDigest(Ai, Ai, Ai.size());
223 iterations = (
unsigned int)i;
227 for (i=0; i<B.
size(); i++)
228 B[i] = Ai[i % Ai.size()];
232 for (i=0; i<ILen; i+=v)
235 #if CRYPTOPP_MSC_VERSION 236 const size_t segmentLen =
STDMIN(derivedLen, Ai.size());
237 memcpy_s(derived, segmentLen, Ai, segmentLen);
239 const size_t segmentLen =
STDMIN(derivedLen, Ai.size());
243 derived += segmentLen;
244 derivedLen -= segmentLen;
unsigned int DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *password, size_t passwordLen, const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds=0) const
Derive key from the password.
unsigned int DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *password, size_t passwordLen, const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds) const
Derive key from the password.
#define NAMESPACE_BEGIN(x)
Abstract base class for password based key derivation function.
Abstract base classes that provide a uniform interface to this library.
void memcpy_s(void *dest, size_t sizeInBytes, const void *src, size_t count)
Bounds checking replacement for memcpy()
size_type size() const
Provides the count of elements in the SecBlock.
size_t MaxDerivedKeyLength() const
Provides the maximum derived key length.
bool UsesPurposeByte() const
Determines if the derivation function uses the purpose byte.
size_t MaxDerivedKeyLength() const
Provides the maximum derived key length.
bool UsesPurposeByte() const
Determines if the derivation function uses the purpose byte.
size_t MaxDerivedKeyLength() const
Provides the maximum derived key length.
Classes for HMAC message authentication codes.
unsigned int DeriveKey(byte *derived, size_t derivedLen, byte purpose, const byte *password, size_t passwordLen, const byte *salt, size_t saltLen, unsigned int iterations, double timeInSeconds=0) const
Derive key from the password.
PBKDF from PKCS #12, appendix B.
unsigned int DigestSize() const
Provides the digest size of the hash.
bool UsesPurposeByte() const
Determines if the derivation function uses the purpose byte.
Multiple precision integer with arithmetic operations.
void Update(const byte *input, size_t length)
Updates a hash with additional input.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
#define CRYPTOPP_ASSERT(exp)
void xorbuf(byte *buf, const byte *mask, size_t count)
Performs an XOR of a buffer with a mask.
double ElapsedTimeAsDouble()
void * memcpy(void *a, const void *b, size_t c)
#define CRYPTOPP_UNUSED(x)
Multiple precision integer with arithmetic operations.
T1 RoundUpToMultipleOf(const T1 &n, const T2 &m)
Rounds a value up to a multiple of a second value.
Measure CPU time spent executing instructions of this thread (if supported by OS) ...
virtual ~PasswordBasedKeyDerivationFunction()