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