8#include <botan/cipher_mode.h>
9#include <botan/internal/stream_mode.h>
10#include <botan/internal/scan_name.h>
11#include <botan/internal/parsing.h>
14#if defined(BOTAN_HAS_BLOCK_CIPHER)
15 #include <botan/block_cipher.h>
18#if defined(BOTAN_HAS_AEAD_MODES)
19 #include <botan/aead.h>
22#if defined(BOTAN_HAS_MODE_CBC)
23 #include <botan/internal/cbc.h>
26#if defined(BOTAN_HAS_MODE_CFB)
27 #include <botan/internal/cfb.h>
30#if defined(BOTAN_HAS_MODE_XTS)
31 #include <botan/internal/xts.h>
34#if defined(BOTAN_HAS_COMMONCRYPTO)
35 #include <botan/internal/commoncrypto.h>
42 std::string_view provider)
52 std::string_view provider)
54#if defined(BOTAN_HAS_COMMONCRYPTO)
59 if(commoncrypto_cipher)
60 return commoncrypto_cipher;
63 return std::unique_ptr<Cipher_Mode>();
67#if defined(BOTAN_HAS_STREAM_CIPHER)
70 return std::make_unique<Stream_Cipher_Mode>(std::move(sc));
74#if defined(BOTAN_HAS_AEAD_MODES)
81 if(algo.find(
'/') != std::string::npos)
83 const std::vector<std::string> algo_parts =
split_on(algo,
'/');
84 std::string_view cipher_name = algo_parts[0];
88 return std::unique_ptr<Cipher_Mode>();
90 std::ostringstream mode_name;
92 mode_name << mode_info[0] <<
'(' << cipher_name;
93 for(
size_t i = 1; i < mode_info.size(); ++i)
94 mode_name <<
',' << mode_info[i];
95 for(
size_t i = 2; i < algo_parts.size(); ++i)
96 mode_name <<
',' << algo_parts[i];
102#if defined(BOTAN_HAS_BLOCK_CIPHER)
108 return std::unique_ptr<Cipher_Mode>();
115 return std::unique_ptr<Cipher_Mode>();
118#if defined(BOTAN_HAS_MODE_CBC)
121 const std::string padding = spec.
arg(1,
"PKCS7");
126 return std::make_unique<CTS_Encryption>(std::move(bc));
128 return std::make_unique<CTS_Decryption>(std::move(bc));
137 return std::make_unique<CBC_Encryption>(std::move(bc), std::move(pad));
139 return std::make_unique<CBC_Decryption>(std::move(bc), std::move(pad));
145#if defined(BOTAN_HAS_MODE_XTS)
149 return std::make_unique<XTS_Encryption>(std::move(bc));
151 return std::make_unique<XTS_Decryption>(std::move(bc));
155#if defined(BOTAN_HAS_MODE_CFB)
158 const size_t feedback_bits = spec.
arg_as_integer(1, 8*bc->block_size());
160 return std::make_unique<CFB_Encryption>(std::move(bc), feedback_bits);
162 return std::make_unique<CFB_Decryption>(std::move(bc), feedback_bits);
168 return std::unique_ptr<Cipher_Mode>();
174 const std::vector<std::string>& possible = {
"base",
"commoncrypto" };
176 for(
auto&& prov : possible)
static std::unique_ptr< AEAD_Mode > create(std::string_view algo, Cipher_Dir direction, std::string_view provider="")
static std::unique_ptr< BlockCipherModePaddingMethod > create(std::string_view algo_spec)
static std::unique_ptr< BlockCipher > create(std::string_view algo_spec, std::string_view provider="")
static std::unique_ptr< Cipher_Mode > create(std::string_view algo, Cipher_Dir direction, std::string_view provider="")
virtual std::string provider() const
static std::unique_ptr< Cipher_Mode > create_or_throw(std::string_view algo, Cipher_Dir direction, std::string_view provider="")
static std::vector< std::string > providers(std::string_view algo_spec)
std::string arg(size_t i) const
const std::string algo_name() const
size_t arg_as_integer(size_t i, size_t def_value) const
static std::unique_ptr< StreamCipher > create(std::string_view algo_spec, std::string_view provider="")
std::vector< std::string > split_on(std::string_view str, char delim)
std::unique_ptr< Cipher_Mode > make_commoncrypto_cipher_mode(std::string_view name, Cipher_Dir direction)
std::vector< std::string > parse_algorithm_name(std::string_view namex)