Botan 1.10.17
kdf2.cpp
Go to the documentation of this file.
1/*
2* KDF2
3* (C) 1999-2007 Jack Lloyd
4*
5* Distributed under the terms of the Botan license
6*/
7
8#include <botan/kdf2.h>
9
10namespace Botan {
11
12/*
13* KDF2 Key Derivation Mechanism
14*/
16 const byte secret[], size_t secret_len,
17 const byte P[], size_t P_len) const
18 {
19 SecureVector<byte> output;
20 u32bit counter = 1;
21
22 while(out_len && counter)
23 {
24 hash->update(secret, secret_len);
25 hash->update_be(counter);
26 hash->update(P, P_len);
27
28 SecureVector<byte> hash_result = hash->final();
29
30 size_t added = std::min(hash_result.size(), out_len);
31 output += std::make_pair(&hash_result[0], added);
32 out_len -= added;
33
34 ++counter;
35 }
36
37 return output;
38 }
39
40}
SecureVector< byte > derive(size_t, const byte[], size_t, const byte[], size_t) const
Definition kdf2.cpp:15
size_t size() const
Definition secmem.h:29
unsigned int u32bit
Definition types.h:32