From 9bcfe627321ddc81691b835dffaa6324ac4684a4 Mon Sep 17 00:00:00 2001 From: lloyd Date: Sun, 28 Sep 2008 19:29:24 +0000 Subject: Move all modules into src/ directory --- src/kdf/kdf2/kdf2.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ src/kdf/kdf2/kdf2.h | 29 +++++++++++++++++++++++++++ src/kdf/kdf2/modinfo.txt | 10 ++++++++++ 3 files changed, 90 insertions(+) create mode 100644 src/kdf/kdf2/kdf2.cpp create mode 100644 src/kdf/kdf2/kdf2.h create mode 100644 src/kdf/kdf2/modinfo.txt (limited to 'src/kdf/kdf2') 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 +#include +#include +#include + +namespace Botan { + +/************************************************* +* KDF2 Key Derivation Mechanism * +*************************************************/ +SecureVector KDF2::derive(u32bit out_len, + const byte secret[], u32bit secret_len, + const byte P[], u32bit P_len) const + { + SecureVector output; + u32bit counter = 1; + + std::auto_ptr 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 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); + } + +} diff --git a/src/kdf/kdf2/kdf2.h b/src/kdf/kdf2/kdf2.h new file mode 100644 index 000000000..003f0fc45 --- /dev/null +++ b/src/kdf/kdf2/kdf2.h @@ -0,0 +1,29 @@ +/************************************************* +* KDF2 Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_KDF2_H__ +#define BOTAN_KDF2_H__ + +#include + +namespace Botan { + +/************************************************* +* KDF2 * +*************************************************/ +class BOTAN_DLL KDF2 : public KDF + { + public: + SecureVector derive(u32bit, const byte[], u32bit, + const byte[], u32bit) const; + + KDF2(const std::string&); + private: + const std::string hash_name; + }; + +} + +#endif diff --git a/src/kdf/kdf2/modinfo.txt b/src/kdf/kdf2/modinfo.txt new file mode 100644 index 000000000..7fceffb18 --- /dev/null +++ b/src/kdf/kdf2/modinfo.txt @@ -0,0 +1,10 @@ +realname "KDF2" + +define KDF2 + +load_on auto + + +kdf2.cpp +kdf2.h + -- cgit v1.2.3