8#include <botan/cipher_mode.h>
10#include <botan/exceptn.h>
11#include <botan/internal/algorithm_spec.h>
12#include <botan/internal/stream_mode.h>
16#if defined(BOTAN_HAS_BLOCK_CIPHER)
17 #include <botan/block_cipher.h>
20#if defined(BOTAN_HAS_AEAD_MODES)
21 #include <botan/aead.h>
24#if defined(BOTAN_HAS_MODE_CBC)
25 #include <botan/internal/cbc.h>
28#if defined(BOTAN_HAS_MODE_CFB)
29 #include <botan/internal/cfb.h>
32#if defined(BOTAN_HAS_MODE_XTS)
33 #include <botan/internal/xts.h>
36#if defined(BOTAN_HAS_COMMONCRYPTO)
37 #include <botan/internal/commoncrypto.h>
55#if defined(BOTAN_HAS_COMMONCRYPTO)
71#if defined(BOTAN_HAS_STREAM_CIPHER)
74 return std::make_unique<Stream_Cipher_Mode>(std::move(sc));
78#if defined(BOTAN_HAS_AEAD_MODES)
84#if defined(BOTAN_HAS_BLOCK_CIPHER)
85 #if defined(BOTAN_HAS_MODE_CBC)
86 if(
auto m = spec.
match(
"CBC({cipher},{padding:str=PKCS7})")) {
88 const auto padding = m->str(
"padding");
90 if(padding ==
"CTS") {
92 return std::make_unique<CTS_Encryption>(std::move(bc));
94 return std::make_unique<CTS_Decryption>(std::move(bc));
98 return std::make_unique<CBC_Encryption>(std::move(bc), std::move(pad));
100 return std::make_unique<CBC_Decryption>(std::move(bc), std::move(pad));
107 #if defined(BOTAN_HAS_MODE_XTS)
108 if(
auto m = spec.
match(
"XTS({cipher})")) {
111 return std::make_unique<XTS_Encryption>(std::move(bc));
113 return std::make_unique<XTS_Decryption>(std::move(bc));
119 #if defined(BOTAN_HAS_MODE_CFB)
120 if(
auto m = spec.
match(
"CFB({cipher},{feedback_bits:int?})")) {
122 const size_t feedback_bits = m->has(
"feedback_bits") ? m->integer(
"feedback_bits") : 8 * bc->block_size();
124 return std::make_unique<CFB_Encryption>(std::move(bc), feedback_bits);
126 return std::make_unique<CFB_Decryption>(std::move(bc), feedback_bits);
136 return std::unique_ptr<Cipher_Mode>();
141 const std::vector<std::string>& possible = {
"base",
"commoncrypto"};
143 for(
auto&& prov : possible) {
static std::unique_ptr< AEAD_Mode > create(std::string_view algo, Cipher_Dir direction, std::string_view provider="")
std::string canonical_form() const
std::optional< AlgorithmMatch > match(const AlgorithmPattern &pattern) const &
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)
static std::unique_ptr< StreamCipher > create(std::string_view algo_spec, std::string_view provider="")
std::unique_ptr< Cipher_Mode > make_commoncrypto_cipher_mode(std::string_view name, Cipher_Dir direction)