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
10 namespace Botan {
11
12 /*
13 * KDF2 Key Derivation Mechanism
14 */
15 SecureVector<byte> KDF2::derive(size_t out_len,
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 }
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::Buffered_Computation::update
void update(const byte in[], size_t length)
Definition: buf_comp.h:33
Botan
Definition: algo_base.h:14
Botan::Buffered_Computation::final
void final(byte out[])
Definition: buf_comp.h:80
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29
Botan::CT::min
T min(T a, T b)
Definition: ct_utils.h:127
Botan::KDF2::derive
SecureVector< byte > derive(size_t, const byte[], size_t, const byte[], size_t) const
Definition: kdf2.cpp:15
Botan::SecureVector< byte >
Botan::Buffered_Computation::update_be
void update_be(const T in)
Definition: buf_comp.h:48
Botan::u32bit
unsigned int u32bit
Definition: types.h:32