2
Copyright (C) 2000-2007 MySQL AB
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; version 2 of the License.
8
This program is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License
14
along with this program; see the file COPYING. If not, write to the
15
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19
/* pwdbased.hpp defines PBKDF2 from PKCS #5
23
#ifndef TAO_CRYPT_PWDBASED_HPP
24
#define TAO_CRYPT_PWDBASED_HPP
34
// From PKCS #5, T must be type suitable for HMAC<T>
38
word32 MaxDerivedKeyLength() const { return 0xFFFFFFFFU;} // avoid overflow
40
word32 DeriveKey(byte* derived, word32 dLen, const byte* pwd, word32 pLen,
41
const byte* salt, word32 sLen, word32 iterations) const;
47
word32 PBKDF2_HMAC<T>::DeriveKey(byte* derived, word32 dLen, const byte* pwd,
48
word32 pLen, const byte* salt, word32 sLen,
49
word32 iterations) const
51
assert(dLen <= MaxDerivedKeyLength());
52
assert(iterations > 0);
54
ByteBlock buffer(T::DIGEST_SIZE);
57
hmac.SetKey(pwd, pLen);
62
hmac.Update(salt, sLen);
64
for (j = 0; j < 4; j++) {
65
byte b = i >> ((3-j)*8);
68
hmac.Final(buffer.get_buffer());
70
word32 segmentLen = min(dLen, buffer.size());
71
memcpy(derived, buffer.get_buffer(), segmentLen);
73
for (j = 1; j < iterations; j++) {
74
hmac.Update(buffer.get_buffer(), buffer.size());
75
hmac.Final(buffer.get_buffer());
76
xorbuf(derived, buffer.get_buffer(), segmentLen);
78
derived += segmentLen;
90
#endif // TAO_CRYPT_PWDBASED_HPP