9#include <botan/internal/parsing.h>
10#include <botan/internal/scan_name.h>
13#if defined(BOTAN_HAS_BLOCK_CIPHER)
14 #include <botan/block_cipher.h>
17#if defined(BOTAN_HAS_AEAD_CCM)
18 #include <botan/internal/ccm.h>
21#if defined(BOTAN_HAS_AEAD_CHACHA20_POLY1305)
22 #include <botan/internal/chacha20poly1305.h>
25#if defined(BOTAN_HAS_AEAD_EAX)
26 #include <botan/internal/eax.h>
29#if defined(BOTAN_HAS_AEAD_GCM)
30 #include <botan/internal/gcm.h>
33#if defined(BOTAN_HAS_AEAD_OCB)
34 #include <botan/internal/ocb.h>
37#if defined(BOTAN_HAS_AEAD_SIV)
38 #include <botan/internal/siv.h>
45 std::string_view provider) {
55#if defined(BOTAN_HAS_AEAD_CHACHA20_POLY1305)
56 if(algo ==
"ChaCha20Poly1305") {
58 return std::make_unique<ChaCha20Poly1305_Encryption>();
60 return std::make_unique<ChaCha20Poly1305_Decryption>();
65 if(algo.find(
'/') != std::string::npos) {
66 const std::vector<std::string> algo_parts =
split_on(algo,
'/');
67 std::string_view cipher_name = algo_parts[0];
70 if(mode_info.empty()) {
71 return std::unique_ptr<AEAD_Mode>();
74 std::ostringstream mode_name;
76 mode_name << mode_info[0] <<
'(' << cipher_name;
77 for(
size_t i = 1; i < mode_info.size(); ++i) {
78 mode_name <<
',' << mode_info[i];
80 for(
size_t i = 2; i < algo_parts.size(); ++i) {
81 mode_name <<
',' << algo_parts[i];
88#if defined(BOTAN_HAS_BLOCK_CIPHER)
93 return std::unique_ptr<AEAD_Mode>();
99 return std::unique_ptr<AEAD_Mode>();
102 #if defined(BOTAN_HAS_AEAD_CCM)
107 return std::make_unique<CCM_Encryption>(std::move(bc), tag_len, L_len);
109 return std::make_unique<CCM_Decryption>(std::move(bc), tag_len, L_len);
114 #if defined(BOTAN_HAS_AEAD_GCM)
118 return std::make_unique<GCM_Encryption>(std::move(bc), tag_len);
120 return std::make_unique<GCM_Decryption>(std::move(bc), tag_len);
125 #if defined(BOTAN_HAS_AEAD_OCB)
129 return std::make_unique<OCB_Encryption>(std::move(bc), tag_len);
131 return std::make_unique<OCB_Decryption>(std::move(bc), tag_len);
136 #if defined(BOTAN_HAS_AEAD_EAX)
140 return std::make_unique<EAX_Encryption>(std::move(bc), tag_len);
142 return std::make_unique<EAX_Decryption>(std::move(bc), tag_len);
147 #if defined(BOTAN_HAS_AEAD_SIV)
150 return std::make_unique<SIV_Encryption>(std::move(bc));
152 return std::make_unique<SIV_Decryption>(std::move(bc));
159 return std::unique_ptr<AEAD_Mode>();
static std::unique_ptr< AEAD_Mode > create_or_throw(std::string_view algo, Cipher_Dir direction, std::string_view provider="")
static std::unique_ptr< AEAD_Mode > create(std::string_view algo, Cipher_Dir direction, std::string_view provider="")
static std::unique_ptr< BlockCipher > create(std::string_view algo_spec, std::string_view provider="")
virtual std::string provider() const
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
std::vector< std::string > split_on(std::string_view str, char delim)
std::vector< std::string > parse_algorithm_name(std::string_view namex)