diff options
author | lloyd <[email protected]> | 2008-09-28 19:29:24 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-28 19:29:24 +0000 |
commit | 9bcfe627321ddc81691b835dffaa6324ac4684a4 (patch) | |
tree | fe5e8ae9813b853549558b59833022e87e83981b /src/kdf/kdf2/kdf2.cpp | |
parent | 9822a701516396b7de4e41339faecd48ff8dc8ff (diff) |
Move all modules into src/ directory
Diffstat (limited to 'src/kdf/kdf2/kdf2.cpp')
-rw-r--r-- | src/kdf/kdf2/kdf2.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/kdf/kdf2/kdf2.cpp b/src/kdf/kdf2/kdf2.cpp new file mode 100644 index 000000000..fa975ccb9 --- /dev/null +++ b/src/kdf/kdf2/kdf2.cpp @@ -0,0 +1,51 @@ +/************************************************* +* KDF2 Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include <botan/kdf2.h> +#include <botan/lookup.h> +#include <botan/loadstor.h> +#include <memory> + +namespace Botan { + +/************************************************* +* KDF2 Key Derivation Mechanism * +*************************************************/ +SecureVector<byte> KDF2::derive(u32bit out_len, + const byte secret[], u32bit secret_len, + const byte P[], u32bit P_len) const + { + SecureVector<byte> output; + u32bit counter = 1; + + std::auto_ptr<HashFunction> hash(get_hash(hash_name)); + while(out_len && counter) + { + hash->update(secret, secret_len); + for(u32bit j = 0; j != 4; ++j) + hash->update(get_byte(j, counter)); + hash->update(P, P_len); + SecureVector<byte> hash_result = hash->final(); + + u32bit added = std::min(hash_result.size(), out_len); + output.append(hash_result, added); + out_len -= added; + + ++counter; + } + + return output; + } + +/************************************************* +* KDF2 Constructor * +*************************************************/ +KDF2::KDF2(const std::string& h_name) : hash_name(h_name) + { + if(!have_hash(hash_name)) + throw Algorithm_Not_Found(hash_name); + } + +} |