diff options
Diffstat (limited to 'src/lib/modes/cbc')
-rw-r--r-- | src/lib/modes/cbc/cbc.cpp | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/lib/modes/cbc/cbc.cpp b/src/lib/modes/cbc/cbc.cpp index e89635a5d..e54553d16 100644 --- a/src/lib/modes/cbc/cbc.cpp +++ b/src/lib/modes/cbc/cbc.cpp @@ -5,13 +5,34 @@ * Botan is released under the Simplified BSD License (see license.txt) */ +#include <botan/internal/mode_utils.h> #include <botan/cbc.h> -#include <botan/loadstor.h> -#include <botan/internal/xor_buf.h> -#include <botan/internal/rounding.h> +#include <botan/mode_pad.h> namespace Botan { +template<typename CBC_T, typename CTS_T> +Transform* make_cbc_mode(const Transform::Spec& spec) + { + Algorithm_Factory& af = global_state().algorithm_factory(); + const BlockCipher* bc = af.prototype_block_cipher(spec.arg(0)); + + if(bc) + { + const std::string padding = spec.arg(1, "PKCS7"); + + if(padding == "CTS") + return new CTS_T(bc->clone()); + else + return new CBC_T(bc->clone(), get_bc_pad(padding)); + } + + return nullptr; + } + +BOTAN_REGISTER_TRANSFORM(CBC_Encryption, (make_cbc_mode<CBC_Encryption,CTS_Encryption>)); +BOTAN_REGISTER_TRANSFORM(CBC_Decryption, (make_cbc_mode<CBC_Decryption,CTS_Decryption>)); + CBC_Mode::CBC_Mode(BlockCipher* cipher, BlockCipherModePaddingMethod* padding) : m_cipher(cipher), m_padding(padding), |