blob: 052df0b6a88f44d18310fc56769704e024d0909f (
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
37
38
39
40
|
/*
* KDF2
* (C) 1999-2007 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include <botan/kdf2.h>
namespace Botan {
/*
* KDF2 Key Derivation Mechanism
*/
secure_vector<byte> KDF2::derive(size_t out_len,
const byte secret[], size_t secret_len,
const byte P[], size_t P_len) const
{
secure_vector<byte> output;
u32bit counter = 1;
while(out_len && counter)
{
hash->update(secret, secret_len);
hash->update_be(counter);
hash->update(P, P_len);
secure_vector<byte> hash_result = hash->final();
size_t added = std::min(hash_result.size(), out_len);
output += std::make_pair(&hash_result[0], added);
out_len -= added;
++counter;
}
return output;
}
}
|