Botan: src/engine/core_engine/lookup_pbkdf.cpp Source File

Botan 1.10.16

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
26 PBKDF* Core_Engine::find_pbkdf(const SCAN_Name& algo_spec,
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 }
Botan::Algorithm_Factory
Definition: algo_factory.h:34
Botan::SCAN_Name::arg_count
size_t arg_count() const
Definition: scan_name.h:47
Botan::PKCS5_PBKDF2
Definition: pbkdf2.h:19
Botan::MessageAuthenticationCode
Definition: mac.h:20
Botan::Core_Engine::find_pbkdf
PBKDF * find_pbkdf(const SCAN_Name &algo_spec, Algorithm_Factory &af) const
Definition: lookup_pbkdf.cpp:26
Botan::Algorithm_Factory::make_mac
MessageAuthenticationCode * make_mac(const std::string &algo_spec, const std::string &provider="")
Definition: algo_factory.cpp:286
Botan::PKCS5_PBKDF1
Definition: pbkdf1.h:21
Botan::SCAN_Name::arg
std::string arg(size_t i) const
Definition: scan_name.cpp:153
Botan::Algorithm_Factory::prototype_mac
const MessageAuthenticationCode * prototype_mac(const std::string &algo_spec, const std::string &provider="")
Definition: algo_factory.cpp:226
Botan
Definition: algo_base.h:14
Botan::Algorithm_Factory::make_hash_function
HashFunction * make_hash_function(const std::string &algo_spec, const std::string &provider="")
Definition: algo_factory.cpp:274
Botan::SCAN_Name
Definition: scan_name.h:21
Botan::OpenPGP_S2K
Definition: pgp_s2k.h:19
Botan::SCAN_Name::algo_name
std::string algo_name() const
Definition: scan_name.h:37
Botan::PBKDF
Definition: pbkdf.h:21