8 #include <botan/internal/core_engine.h>
9 #include <botan/parsing.h>
10 #include <botan/filters.h>
11 #include <botan/algo_factory.h>
12 #include <botan/mode_pad.h>
15 #if defined(BOTAN_HAS_ECB)
16 #include <botan/ecb.h>
19 #if defined(BOTAN_HAS_CBC)
20 #include <botan/cbc.h>
23 #if defined(BOTAN_HAS_CTS)
24 #include <botan/cts.h>
27 #if defined(BOTAN_HAS_CFB)
28 #include <botan/cfb.h>
31 #if defined(BOTAN_HAS_OFB)
32 #include <botan/ofb.h>
35 #if defined(BOTAN_HAS_CTR_BE)
36 #include <botan/ctr.h>
39 #if defined(BOTAN_HAS_EAX)
40 #include <botan/eax.h>
43 #if defined(BOTAN_HAS_XTS)
44 #include <botan/xts.h>
54 BlockCipherModePaddingMethod* get_bc_pad(
const std::string& algo_spec,
55 const std::string& def_if_empty)
57 #if defined(BOTAN_HAS_CIPHER_MODE_PADDING)
58 if(algo_spec ==
"NoPadding" || (algo_spec ==
"" && def_if_empty ==
"NoPadding"))
59 return new Null_Padding;
61 if(algo_spec ==
"PKCS7" || (algo_spec ==
"" && def_if_empty ==
"PKCS7"))
62 return new PKCS7_Padding;
64 if(algo_spec ==
"OneAndZeros")
65 return new OneAndZeros_Padding;
67 if(algo_spec ==
"X9.23")
68 return new ANSI_X923_Padding;
72 throw Algorithm_Not_Found(algo_spec);
79 const std::string& mode,
80 const std::string& padding)
82 #if defined(BOTAN_HAS_OFB)
87 #if defined(BOTAN_HAS_CTR_BE)
92 #if defined(BOTAN_HAS_ECB)
93 if(mode ==
"ECB" || mode ==
"")
97 get_bc_pad(padding,
"NoPadding"));
100 get_bc_pad(padding,
"NoPadding"));
108 #if defined(BOTAN_HAS_CTS)
118 #if defined(BOTAN_HAS_CBC)
121 get_bc_pad(padding,
"PKCS7"));
124 get_bc_pad(padding,
"PKCS7"));
130 #if defined(BOTAN_HAS_XTS)
140 if(mode.find(
"CFB") != std::string::npos ||
141 mode.find(
"EAX") != std::string::npos)
146 std::string mode_name = algo_info[0];
147 if(algo_info.size() == 1)
149 else if(algo_info.size() == 2)
154 #if defined(BOTAN_HAS_CFB)
155 if(mode_name ==
"CFB")
164 #if defined(BOTAN_HAS_EAX)
165 if(mode_name ==
"EAX")
185 std::vector<std::string> algo_parts =
split_on(algo_spec,
'/');
186 if(algo_parts.empty())
200 if(algo_parts.size() >= 4)
203 if(algo_parts.size() < 2)
204 throw Lookup_Error(
"Cipher specification '" + algo_spec +
205 "' is missing mode identifier");
207 std::string mode = algo_parts[1];
210 if(algo_parts.size() == 3)
211 padding = algo_parts[2];
213 padding = (mode ==
"CBC") ?
"PKCS7" :
"NoPadding";
215 if(mode ==
"ECB" && padding ==
"CTS")
217 else if((mode !=
"CBC" && mode !=
"ECB") && padding !=
"NoPadding")
std::vector< std::string > parse_algorithm_name(const std::string &namex)
Keyed_Filter * get_cipher(const std::string &, Cipher_Dir, Algorithm_Factory &)
virtual BlockCipher * clone() const =0
const BlockCipher * prototype_block_cipher(const std::string &algo_spec, const std::string &provider="")
std::vector< std::string > split_on(const std::string &str, char delim)
virtual StreamCipher * clone() const =0
u32bit to_u32bit(const std::string &number)
Keyed_Filter * get_cipher_mode(const BlockCipher *block_cipher, Cipher_Dir direction, const std::string &mode, const std::string &padding)
virtual size_t block_size() const =0
const StreamCipher * prototype_stream_cipher(const std::string &algo_spec, const std::string &provider="")