diff options
author | lloyd <[email protected]> | 2014-01-10 03:41:59 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-01-10 03:41:59 +0000 |
commit | 6894dca64c04936d07048c0e8cbf7e25858548c3 (patch) | |
tree | 5d572bfde9fe667dab14e3f04b5285a85d8acd95 /src/lib/kdf/kdf2/kdf2.cpp | |
parent | 9efa3be92442afb3d0b69890a36c7f122df18eda (diff) |
Move lib into src
Diffstat (limited to 'src/lib/kdf/kdf2/kdf2.cpp')
-rw-r--r-- | src/lib/kdf/kdf2/kdf2.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/lib/kdf/kdf2/kdf2.cpp b/src/lib/kdf/kdf2/kdf2.cpp new file mode 100644 index 000000000..39a929b58 --- /dev/null +++ b/src/lib/kdf/kdf2/kdf2.cpp @@ -0,0 +1,40 @@ +/* +* KDF2 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#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; + } + +} |