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

Botan 1.10.16

lookup_mac.cpp
Go to the documentation of this file.
1 /*
2 * MAC Lookup
3 * (C) 1999-2007 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_CBC_MAC)
13 #include <botan/cbc_mac.h>
14 #endif
15
16 #if defined(BOTAN_HAS_CMAC)
17 #include <botan/cmac.h>
18 #endif
19
20 #if defined(BOTAN_HAS_HMAC)
21 #include <botan/hmac.h>
22 #endif
23
24 #if defined(BOTAN_HAS_SSL3_MAC)
25 #include <botan/ssl3_mac.h>
26 #endif
27
28 #if defined(BOTAN_HAS_ANSI_X919_MAC)
29 #include <botan/x919_mac.h>
30 #endif
31
32 namespace Botan {
33
34 /*
35 * Look for an algorithm with this name
36 */
37 MessageAuthenticationCode*
38 Core_Engine::find_mac(const SCAN_Name& request,
39 Algorithm_Factory& af) const
40 {
41
42 #if defined(BOTAN_HAS_CBC_MAC)
43 if(request.algo_name() == "CBC-MAC" && request.arg_count() == 1)
44 return new CBC_MAC(af.make_block_cipher(request.arg(0)));
45 #endif
46
47 #if defined(BOTAN_HAS_CMAC)
48 if(request.algo_name() == "CMAC" && request.arg_count() == 1)
49 return new CMAC(af.make_block_cipher(request.arg(0)));
50 #endif
51
52 #if defined(BOTAN_HAS_HMAC)
53 if(request.algo_name() == "HMAC" && request.arg_count() == 1)
54 return new HMAC(af.make_hash_function(request.arg(0)));
55 #endif
56
57 #if defined(BOTAN_HAS_SSL3_MAC)
58 if(request.algo_name() == "SSL3-MAC" && request.arg_count() == 1)
59 return new SSL3_MAC(af.make_hash_function(request.arg(0)));
60 #endif
61
62 #if defined(BOTAN_HAS_ANSI_X919_MAC)
63 if(request.algo_name() == "X9.19-MAC" && request.arg_count() == 0)
64 return new ANSI_X919_MAC(af.make_block_cipher("DES"));
65 #endif
66
67 return 0;
68 }
69
70 }
Botan::Algorithm_Factory
Definition: algo_factory.h:34
Botan::SCAN_Name::arg_count
size_t arg_count() const
Definition: scan_name.h:47
Botan::CBC_MAC
Definition: cbc_mac.h:19
Botan::Algorithm_Factory::make_block_cipher
BlockCipher * make_block_cipher(const std::string &algo_spec, const std::string &provider="")
Definition: algo_factory.cpp:250
Botan::ANSI_X919_MAC
Definition: x919_mac.h:19
Botan::SCAN_Name::arg
std::string arg(size_t i) const
Definition: scan_name.cpp:153
Botan::Core_Engine::find_mac
MessageAuthenticationCode * find_mac(const SCAN_Name &request, Algorithm_Factory &) const
Definition: lookup_mac.cpp:38
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::CMAC
Definition: cmac.h:19
Botan::HMAC
Definition: hmac.h:19
Botan::SSL3_MAC
Definition: ssl3_mac.h:19
Botan::SCAN_Name::algo_name
std::string algo_name() const
Definition: scan_name.h:37