aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine/def_engine/lookup_s2k.cpp
blob: 68a259273fa2669f8f570acc27166eb21c719e20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*************************************************
* S2K Lookup                                     *
* (C) 1999-2007 Jack Lloyd                       *
*************************************************/

#include <botan/eng_def.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;
   }

}