diff options
Diffstat (limited to 'src/lib/kdf/kdf2/kdf2.cpp')
-rw-r--r-- | src/lib/kdf/kdf2/kdf2.cpp | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/src/lib/kdf/kdf2/kdf2.cpp b/src/lib/kdf/kdf2/kdf2.cpp index c7b355580..f1a702887 100644 --- a/src/lib/kdf/kdf2/kdf2.cpp +++ b/src/lib/kdf/kdf2/kdf2.cpp @@ -12,32 +12,27 @@ namespace Botan { BOTAN_REGISTER_KDF_1HASH(KDF2, "KDF2"); -/* -* 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 +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 { - secure_vector<byte> output; u32bit counter = 1; + secure_vector<byte> h; - while(out_len && counter) + size_t offset = 0; + while(offset != key_len && counter != 0) { - 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; + 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[0], added); + offset += added; } - return output; + return offset; } } |