summaryrefslogtreecommitdiffstats
path: root/botan/src/kdf/kdf2/kdf2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'botan/src/kdf/kdf2/kdf2.cpp')
-rw-r--r--botan/src/kdf/kdf2/kdf2.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/botan/src/kdf/kdf2/kdf2.cpp b/botan/src/kdf/kdf2/kdf2.cpp
new file mode 100644
index 0000000..167f644
--- /dev/null
+++ b/botan/src/kdf/kdf2/kdf2.cpp
@@ -0,0 +1,41 @@
+/*
+* KDF2
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#include <botan/kdf2.h>
+#include <botan/loadstor.h>
+
+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;
+
+ 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;
+ }
+
+}