blob: 1b1c3638af70b22d5dafc4fb10f102198977b53d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
/*
* KDF2
* (C) 1999-2007 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include <botan/internal/kdf_utils.h>
#include <botan/kdf2.h>
namespace Botan {
size_t KDF2::kdf(byte key[], size_t key_len,
const byte secret[], size_t secret_len,
const byte salt[], size_t salt_len) const
{
u32bit counter = 1;
secure_vector<byte> h;
size_t offset = 0;
while(offset != key_len && counter != 0)
{
m_hash->update(secret, secret_len);
m_hash->update_be(counter++);
m_hash->update(salt, salt_len);
m_hash->final(h);
const size_t added = std::min(h.size(), key_len - offset);
copy_mem(&key[offset], h.data(), added);
offset += added;
}
return offset;
}
}
|