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>
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"))
61 if(algo_spec ==
"PKCS7" || (algo_spec ==
"" && def_if_empty ==
"PKCS7"))
64 if(algo_spec ==
"OneAndZeros")
67 if(algo_spec ==
"X9.23")
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())
189 const std::string cipher_name = algo_parts[0];
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")
const BlockCipher * prototype_block_cipher(const std::string &algo_spec, const std::string &provider="")
const StreamCipher * prototype_stream_cipher(const std::string &algo_spec, const std::string &provider="")
virtual BlockCipher * clone() const =0
virtual size_t block_size() const =0
CBC_Decryption(BlockCipher *cipher, BlockCipherModePaddingMethod *padding)
CBC_Encryption(BlockCipher *cipher, BlockCipherModePaddingMethod *padding)
CFB_Decryption(BlockCipher *cipher, size_t feedback=0)
CFB_Encryption(BlockCipher *cipher, size_t feedback=0)
CTR_BE(BlockCipher *cipher)
CTS_Decryption(BlockCipher *cipher)
CTS_Encryption(BlockCipher *cipher)
Keyed_Filter * get_cipher(const std::string &, Cipher_Dir, Algorithm_Factory &)
EAX_Decryption(BlockCipher *ciph, size_t tag_size=0)
EAX_Encryption(BlockCipher *ciph, size_t tag_size=0)
ECB_Decryption(BlockCipher *ciph, BlockCipherModePaddingMethod *pad)
ECB_Encryption(BlockCipher *ciph, BlockCipherModePaddingMethod *pad)
StreamCipher_Filter(StreamCipher *cipher_obj)
virtual StreamCipher * clone() const =0
XTS_Decryption(BlockCipher *ciph)
XTS_Encryption(BlockCipher *ciph)
std::vector< std::string > parse_algorithm_name(const std::string &namex)
u32bit to_u32bit(const std::string &number)
std::vector< std::string > split_on(const std::string &str, char delim)
Keyed_Filter * get_cipher_mode(const BlockCipher *block_cipher, Cipher_Dir direction, const std::string &mode, const std::string &padding)
Algorithm_Not_Found(const std::string &name)
Invalid_Algorithm_Name(const std::string &name)
Lookup_Error(const std::string &err)