aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstate/engine/def_engine/lookup_s2k.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-11-09 19:49:23 +0000
committerlloyd <[email protected]>2008-11-09 19:49:23 +0000
commitcec305c17354fca9c426d76a78f7088f60607afb (patch)
tree1bf7b53a76617339d67523d34be34f903ced28fc /src/libstate/engine/def_engine/lookup_s2k.cpp
parentb01c1d79f02de8ca5c02f08e73cedeadc4d0753a (diff)
Move engine to libstate/ directory, since there is a mutual dependency
(messy). Remove unused libstate.h includes from a few files.
Diffstat (limited to 'src/libstate/engine/def_engine/lookup_s2k.cpp')
-rw-r--r--src/libstate/engine/def_engine/lookup_s2k.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/libstate/engine/def_engine/lookup_s2k.cpp b/src/libstate/engine/def_engine/lookup_s2k.cpp
new file mode 100644
index 000000000..2f33ef6fc
--- /dev/null
+++ b/src/libstate/engine/def_engine/lookup_s2k.cpp
@@ -0,0 +1,67 @@
+/*************************************************
+* S2K Lookup *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/def_eng.h>
+#include <botan/lookup.h>
+#include <botan/libstate.h>
+#include <botan/parsing.h>
+
+#if defined(BOTAN_HAS_PBKDF1)
+ #include <botan/pbkdf1.h>
+#endif
+
+#if defined(BOTAN_HAS_PBKDF2)
+ #include <botan/pbkdf2.h>
+ #include <botan/hmac.h>
+#endif
+
+#if defined(BOTAN_HAS_PGPS2K)
+ #include <botan/pgp_s2k.h>
+#endif
+
+namespace Botan {
+
+/*************************************************
+* Look for an algorithm with this name *
+*************************************************/
+S2K* Default_Engine::find_s2k(const std::string& algo_spec) const
+ {
+ std::vector<std::string> name = parse_algorithm_name(algo_spec);
+ if(name.empty())
+ return 0;
+
+ const std::string algo_name = global_state().deref_alias(name[0]);
+
+#if defined(BOTAN_HAS_PBKDF1)
+ if(algo_name == "PBKDF1")
+ {
+ if(name.size() == 2)
+ return new PKCS5_PBKDF1(get_hash(name[1]));
+ throw Invalid_Algorithm_Name(algo_spec);
+ }
+#endif
+
+#if defined(BOTAN_HAS_PBKDF2)
+ if(algo_name == "PBKDF2")
+ {
+ if(name.size() == 2)
+ return new PKCS5_PBKDF2(new HMAC(get_hash(name[1])));
+ throw Invalid_Algorithm_Name(algo_spec);
+ }
+#endif
+
+#if defined(BOTAN_HAS_PGPS2K)
+ if(algo_name == "OpenPGP-S2K")
+ {
+ if(name.size() == 2)
+ return new OpenPGP_S2K(get_hash(name[1]));
+ throw Invalid_Algorithm_Name(algo_spec);
+ }
+#endif
+
+ return 0;
+ }
+
+}