aboutsummaryrefslogtreecommitdiffstats
path: root/src/kdf.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-28 18:03:20 +0000
committerlloyd <[email protected]>2008-09-28 18:03:20 +0000
commit47ffeed7f8270855596c4f1d7b2d405172d78e8c (patch)
tree371535473f023f310a9c9c0281d5f62b3faedad0 /src/kdf.cpp
parent389dd2cdf55a57960581f686a8a766475a1f5d38 (diff)
Modularize KDFs, PBKDFs, and PRFs
Diffstat (limited to 'src/kdf.cpp')
-rw-r--r--src/kdf.cpp65
1 files changed, 2 insertions, 63 deletions
diff --git a/src/kdf.cpp b/src/kdf.cpp
index 9d60a1839..dca56e1a6 100644
--- a/src/kdf.cpp
+++ b/src/kdf.cpp
@@ -1,9 +1,9 @@
/*************************************************
-* KDF1/KDF2 Source File *
+* KDF Base Class Source File *
* (C) 1999-2007 Jack Lloyd *
*************************************************/
-#include <botan/kdf.h>
+#include <botan/pk_util.h>
#include <botan/lookup.h>
#include <botan/loadstor.h>
#include <algorithm>
@@ -67,65 +67,4 @@ SecureVector<byte> KDF::derive_key(u32bit key_len,
return derive(key_len, secret, secret_len, salt, salt_len);
}
-/*************************************************
-* KDF1 Key Derivation Mechanism *
-*************************************************/
-SecureVector<byte> KDF1::derive(u32bit,
- const byte secret[], u32bit secret_len,
- const byte P[], u32bit P_len) const
- {
- std::auto_ptr<HashFunction> hash(get_hash(hash_name));
-
- hash->update(secret, secret_len);
- hash->update(P, P_len);
- return hash->final();
- }
-
-/*************************************************
-* KDF1 Constructor *
-*************************************************/
-KDF1::KDF1(const std::string& h_name) : hash_name(h_name)
- {
- if(!have_hash(hash_name))
- throw Algorithm_Not_Found(hash_name);
- }
-
-/*************************************************
-* 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);
- }
-
}