Botan  1.10.9
lookup_pbkdf.cpp
Go to the documentation of this file.
1 /*
2 * PBKDF Lookup
3 * (C) 2010 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7 
8 #include <botan/internal/core_engine.h>
9 #include <botan/scan_name.h>
10 #include <botan/algo_factory.h>
11 
12 #if defined(BOTAN_HAS_PBKDF1)
13  #include <botan/pbkdf1.h>
14 #endif
15 
16 #if defined(BOTAN_HAS_PBKDF2)
17  #include <botan/pbkdf2.h>
18 #endif
19 
20 #if defined(BOTAN_HAS_PGPS2K)
21  #include <botan/pgp_s2k.h>
22 #endif
23 
24 namespace Botan {
25 
27  Algorithm_Factory& af) const
28  {
29 #if defined(BOTAN_HAS_PBKDF1)
30  if(algo_spec.algo_name() == "PBKDF1" && algo_spec.arg_count() == 1)
31  return new PKCS5_PBKDF1(af.make_hash_function(algo_spec.arg(0)));
32 #endif
33 
34 #if defined(BOTAN_HAS_PBKDF2)
35  if(algo_spec.algo_name() == "PBKDF2" && algo_spec.arg_count() == 1)
36  {
37  if(const MessageAuthenticationCode* mac_proto = af.prototype_mac(algo_spec.arg(0)))
38  return new PKCS5_PBKDF2(mac_proto->clone());
39 
40  return new PKCS5_PBKDF2(af.make_mac("HMAC(" + algo_spec.arg(0) + ")"));
41  }
42 #endif
43 
44 #if defined(BOTAN_HAS_PGPS2K)
45  if(algo_spec.algo_name() == "OpenPGP-S2K" && algo_spec.arg_count() == 1)
46  return new OpenPGP_S2K(af.make_hash_function(algo_spec.arg(0)));
47 #endif
48 
49  return 0;
50  }
51 
52 }
std::string arg(size_t i) const
Definition: scan_name.cpp:153
size_t arg_count() const
Definition: scan_name.h:47
MessageAuthenticationCode * make_mac(const std::string &algo_spec, const std::string &provider="")
std::string algo_name() const
Definition: scan_name.h:37
const MessageAuthenticationCode * prototype_mac(const std::string &algo_spec, const std::string &provider="")
PBKDF * find_pbkdf(const SCAN_Name &algo_spec, Algorithm_Factory &af) const
HashFunction * make_hash_function(const std::string &algo_spec, const std::string &provider="")