aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/kdf/kdf2
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-01-10 03:41:59 +0000
committerlloyd <[email protected]>2014-01-10 03:41:59 +0000
commit6894dca64c04936d07048c0e8cbf7e25858548c3 (patch)
tree5d572bfde9fe667dab14e3f04b5285a85d8acd95 /src/lib/kdf/kdf2
parent9efa3be92442afb3d0b69890a36c7f122df18eda (diff)
Move lib into src
Diffstat (limited to 'src/lib/kdf/kdf2')
-rw-r--r--src/lib/kdf/kdf2/info.txt5
-rw-r--r--src/lib/kdf/kdf2/kdf2.cpp40
-rw-r--r--src/lib/kdf/kdf2/kdf2.h37
3 files changed, 82 insertions, 0 deletions
diff --git a/src/lib/kdf/kdf2/info.txt b/src/lib/kdf/kdf2/info.txt
new file mode 100644
index 000000000..3481ff04f
--- /dev/null
+++ b/src/lib/kdf/kdf2/info.txt
@@ -0,0 +1,5 @@
+define KDF2 20131128
+
+<requires>
+hash
+</requires>
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;
+ }
+
+}
diff --git a/src/lib/kdf/kdf2/kdf2.h b/src/lib/kdf/kdf2/kdf2.h
new file mode 100644
index 000000000..e33939df9
--- /dev/null
+++ b/src/lib/kdf/kdf2/kdf2.h
@@ -0,0 +1,37 @@
+/*
+* KDF2
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_KDF2_H__
+#define BOTAN_KDF2_H__
+
+#include <botan/kdf.h>
+#include <botan/hash.h>
+
+namespace Botan {
+
+/**
+* KDF2, from IEEE 1363
+*/
+class BOTAN_DLL KDF2 : public KDF
+ {
+ public:
+ secure_vector<byte> derive(size_t, const byte[], size_t,
+ const byte[], size_t) const;
+
+ std::string name() const { return "KDF2(" + hash->name() + ")"; }
+ KDF* clone() const { return new KDF2(hash->clone()); }
+
+ KDF2(HashFunction* h) : hash(h) {}
+ KDF2(const KDF2& other) : KDF(), hash(other.hash->clone()) {}
+ ~KDF2() { delete hash; }
+ private:
+ HashFunction* hash;
+ };
+
+}
+
+#endif