diff options
-rw-r--r-- | src/engine/def_engine/def_mode.cpp | 17 | ||||
-rw-r--r-- | src/modes/cbc/cbc.cpp | 37 | ||||
-rw-r--r-- | src/modes/cbc/cbc.h | 8 | ||||
-rw-r--r-- | src/modes/cfb/cfb.cpp | 21 | ||||
-rw-r--r-- | src/modes/cfb/cfb.h | 8 | ||||
-rw-r--r-- | src/modes/ecb/ecb.cpp | 50 | ||||
-rw-r--r-- | src/modes/ecb/ecb.h | 27 |
7 files changed, 63 insertions, 105 deletions
diff --git a/src/engine/def_engine/def_mode.cpp b/src/engine/def_engine/def_mode.cpp index 2d4701796..16cbcd57e 100644 --- a/src/engine/def_engine/def_mode.cpp +++ b/src/engine/def_engine/def_mode.cpp @@ -111,9 +111,12 @@ Keyed_Filter* Default_Engine::get_cipher(const std::string& algo_spec, { #if defined(BOTAN_HAS_ECB) if(direction == ENCRYPTION) - return new ECB_Encryption(cipher, padding); + return new ECB_Encryption(get_block_cipher(cipher), + get_bc_pad(padding)); else - return new ECB_Decryption(cipher, padding); + return new ECB_Decryption(get_block_cipher(cipher), + get_bc_pad(padding)); + #else return 0; #endif @@ -122,9 +125,9 @@ Keyed_Filter* Default_Engine::get_cipher(const std::string& algo_spec, { #if defined(BOTAN_HAS_CFB) if(direction == ENCRYPTION) - return new CFB_Encryption(cipher, bits); + return new CFB_Encryption(get_block_cipher(cipher), bits); else - return new CFB_Decryption(cipher, bits); + return new CFB_Decryption(get_block_cipher(cipher), bits); #else return 0; #endif @@ -145,9 +148,11 @@ Keyed_Filter* Default_Engine::get_cipher(const std::string& algo_spec, #if defined(BOTAN_HAS_CBC) if(direction == ENCRYPTION) - return new CBC_Encryption(cipher, padding); + return new CBC_Encryption(get_block_cipher(cipher), + get_bc_pad(padding)); else - return new CBC_Decryption(cipher, padding); + return new CBC_Decryption(get_block_cipher(cipher), + get_bc_pad(padding)); #else return 0; #endif diff --git a/src/modes/cbc/cbc.cpp b/src/modes/cbc/cbc.cpp index eea039ce3..ff0c417b2 100644 --- a/src/modes/cbc/cbc.cpp +++ b/src/modes/cbc/cbc.cpp @@ -4,7 +4,6 @@ *************************************************/ #include <botan/cbc.h> -#include <botan/lookup.h> #include <botan/xor_buf.h> #include <algorithm> @@ -13,11 +12,10 @@ namespace Botan { /************************************************* * CBC Encryption Constructor * *************************************************/ -CBC_Encryption::CBC_Encryption(const std::string& cipher_name, - const std::string& padding_name) : - BlockCipherMode(get_block_cipher(cipher_name), - "CBC", block_size_of(cipher_name)), - padder(get_bc_pad(padding_name)) +CBC_Encryption::CBC_Encryption(BlockCipher* ciph, + const BlockCipherModePaddingMethod* pad) : + BlockCipherMode(ciph, "CBC", ciph->BLOCK_SIZE), + padder(pad) { if(!padder->valid_blocksize(BLOCK_SIZE)) throw Invalid_Block_Size(name(), padder->name()); @@ -26,13 +24,12 @@ CBC_Encryption::CBC_Encryption(const std::string& cipher_name, /************************************************* * CBC Encryption Constructor * *************************************************/ -CBC_Encryption::CBC_Encryption(const std::string& cipher_name, - const std::string& padding_name, +CBC_Encryption::CBC_Encryption(BlockCipher* ciph, + const BlockCipherModePaddingMethod* pad, const SymmetricKey& key, const InitializationVector& iv) : - BlockCipherMode(get_block_cipher(cipher_name), - "CBC", block_size_of(cipher_name)), - padder(get_bc_pad(padding_name)) + BlockCipherMode(ciph, "CBC", ciph->BLOCK_SIZE), + padder(pad) { if(!padder->valid_blocksize(BLOCK_SIZE)) throw Invalid_Block_Size(name(), padder->name()); @@ -84,11 +81,10 @@ std::string CBC_Encryption::name() const /************************************************* * CBC Decryption Constructor * *************************************************/ -CBC_Decryption::CBC_Decryption(const std::string& cipher_name, - const std::string& padding_name) : - BlockCipherMode(get_block_cipher(cipher_name), - "CBC", block_size_of(cipher_name)), - padder(get_bc_pad(padding_name)) +CBC_Decryption::CBC_Decryption(BlockCipher* ciph, + const BlockCipherModePaddingMethod* pad) : + BlockCipherMode(ciph, "CBC", ciph->BLOCK_SIZE), + padder(pad) { if(!padder->valid_blocksize(BLOCK_SIZE)) throw Invalid_Block_Size(name(), padder->name()); @@ -98,13 +94,12 @@ CBC_Decryption::CBC_Decryption(const std::string& cipher_name, /************************************************* * CBC Decryption Constructor * *************************************************/ -CBC_Decryption::CBC_Decryption(const std::string& cipher_name, - const std::string& padding_name, +CBC_Decryption::CBC_Decryption(BlockCipher* ciph, + const BlockCipherModePaddingMethod* pad, const SymmetricKey& key, const InitializationVector& iv) : - BlockCipherMode(get_block_cipher(cipher_name), - "CBC", block_size_of(cipher_name)), - padder(get_bc_pad(padding_name)) + BlockCipherMode(ciph, "CBC", ciph->BLOCK_SIZE), + padder(pad) { if(!padder->valid_blocksize(BLOCK_SIZE)) throw Invalid_Block_Size(name(), padder->name()); diff --git a/src/modes/cbc/cbc.h b/src/modes/cbc/cbc.h index a0a30f90f..3069d6cb5 100644 --- a/src/modes/cbc/cbc.h +++ b/src/modes/cbc/cbc.h @@ -17,8 +17,8 @@ namespace Botan { class BOTAN_DLL CBC_Encryption : public BlockCipherMode { public: - CBC_Encryption(const std::string&, const std::string&); - CBC_Encryption(const std::string&, const std::string&, + CBC_Encryption(BlockCipher*, const BlockCipherModePaddingMethod*); + CBC_Encryption(BlockCipher*, const BlockCipherModePaddingMethod*, const SymmetricKey&, const InitializationVector&); private: std::string name() const; @@ -33,8 +33,8 @@ class BOTAN_DLL CBC_Encryption : public BlockCipherMode class BOTAN_DLL CBC_Decryption : public BlockCipherMode { public: - CBC_Decryption(const std::string&, const std::string&); - CBC_Decryption(const std::string&, const std::string&, + CBC_Decryption(BlockCipher*, const BlockCipherModePaddingMethod*); + CBC_Decryption(BlockCipher*, const BlockCipherModePaddingMethod*, const SymmetricKey&, const InitializationVector&); private: std::string name() const; diff --git a/src/modes/cfb/cfb.cpp b/src/modes/cfb/cfb.cpp index 60599464b..f5eb4cecf 100644 --- a/src/modes/cfb/cfb.cpp +++ b/src/modes/cfb/cfb.cpp @@ -4,7 +4,6 @@ *************************************************/ #include <botan/cfb.h> -#include <botan/lookup.h> #include <botan/parsing.h> #include <botan/xor_buf.h> #include <algorithm> @@ -29,10 +28,9 @@ void check_feedback(u32bit BLOCK_SIZE, u32bit FEEDBACK_SIZE, u32bit bits, /************************************************* * CFB Encryption Constructor * *************************************************/ -CFB_Encryption::CFB_Encryption(const std::string& cipher_name, +CFB_Encryption::CFB_Encryption(BlockCipher* ciph, u32bit fback_bits) : - BlockCipherMode(get_block_cipher(cipher_name), - "CFB", block_size_of(cipher_name), 1), + BlockCipherMode(ciph, "CFB", ciph->BLOCK_SIZE, 1), FEEDBACK_SIZE(fback_bits ? fback_bits / 8: BLOCK_SIZE) { check_feedback(BLOCK_SIZE, FEEDBACK_SIZE, fback_bits, name()); @@ -41,12 +39,11 @@ CFB_Encryption::CFB_Encryption(const std::string& cipher_name, /************************************************* * CFB Encryption Constructor * *************************************************/ -CFB_Encryption::CFB_Encryption(const std::string& cipher_name, +CFB_Encryption::CFB_Encryption(BlockCipher* ciph, const SymmetricKey& key, const InitializationVector& iv, u32bit fback_bits) : - BlockCipherMode(get_block_cipher(cipher_name), - "CFB", block_size_of(cipher_name), 1), + BlockCipherMode(ciph, "CFB", ciph->BLOCK_SIZE, 1), FEEDBACK_SIZE(fback_bits ? fback_bits / 8: BLOCK_SIZE) { check_feedback(BLOCK_SIZE, FEEDBACK_SIZE, fback_bits, name()); @@ -87,10 +84,9 @@ void CFB_Encryption::feedback() /************************************************* * CFB Decryption Constructor * *************************************************/ -CFB_Decryption::CFB_Decryption(const std::string& cipher_name, +CFB_Decryption::CFB_Decryption(BlockCipher* ciph, u32bit fback_bits) : - BlockCipherMode(get_block_cipher(cipher_name), - "CFB", block_size_of(cipher_name), 1), + BlockCipherMode(ciph, "CFB", ciph->BLOCK_SIZE, 1), FEEDBACK_SIZE(fback_bits ? fback_bits / 8 : BLOCK_SIZE) { check_feedback(BLOCK_SIZE, FEEDBACK_SIZE, fback_bits, name()); @@ -99,12 +95,11 @@ CFB_Decryption::CFB_Decryption(const std::string& cipher_name, /************************************************* * CFB Decryption Constructor * *************************************************/ -CFB_Decryption::CFB_Decryption(const std::string& cipher_name, +CFB_Decryption::CFB_Decryption(BlockCipher* ciph, const SymmetricKey& key, const InitializationVector& iv, u32bit fback_bits) : - BlockCipherMode(get_block_cipher(cipher_name), - "CFB", block_size_of(cipher_name), 1), + BlockCipherMode(ciph, "CFB", ciph->BLOCK_SIZE, 1), FEEDBACK_SIZE(fback_bits ? fback_bits / 8 : BLOCK_SIZE) { check_feedback(BLOCK_SIZE, FEEDBACK_SIZE, fback_bits, name()); diff --git a/src/modes/cfb/cfb.h b/src/modes/cfb/cfb.h index e8133bcf4..dad7ece13 100644 --- a/src/modes/cfb/cfb.h +++ b/src/modes/cfb/cfb.h @@ -16,8 +16,8 @@ namespace Botan { class BOTAN_DLL CFB_Encryption : public BlockCipherMode { public: - CFB_Encryption(const std::string&, u32bit = 0); - CFB_Encryption(const std::string&, const SymmetricKey&, + CFB_Encryption(BlockCipher*, u32bit = 0); + CFB_Encryption(BlockCipher*, const SymmetricKey&, const InitializationVector&, u32bit = 0); private: void write(const byte[], u32bit); @@ -31,8 +31,8 @@ class BOTAN_DLL CFB_Encryption : public BlockCipherMode class BOTAN_DLL CFB_Decryption : public BlockCipherMode { public: - CFB_Decryption(const std::string&, u32bit = 0); - CFB_Decryption(const std::string&, const SymmetricKey&, + CFB_Decryption(BlockCipher*, u32bit = 0); + CFB_Decryption(BlockCipher*, const SymmetricKey&, const InitializationVector&, u32bit = 0); private: void write(const byte[], u32bit); diff --git a/src/modes/ecb/ecb.cpp b/src/modes/ecb/ecb.cpp index 2d0888cea..b76e86ad9 100644 --- a/src/modes/ecb/ecb.cpp +++ b/src/modes/ecb/ecb.cpp @@ -4,20 +4,10 @@ *************************************************/ #include <botan/ecb.h> -#include <botan/lookup.h> namespace Botan { /************************************************* -* ECB Constructor * -*************************************************/ -ECB::ECB(const std::string& cipher_name, const std::string& padding_name) : - BlockCipherMode(get_block_cipher(cipher_name), - "ECB", 0), padder(get_bc_pad(padding_name)) - { - } - -/************************************************* * Verify the IV is not set * *************************************************/ bool ECB::valid_iv_size(u32bit iv_size) const @@ -36,26 +26,6 @@ std::string ECB::name() const } /************************************************* -* ECB Encryption Constructor * -*************************************************/ -ECB_Encryption::ECB_Encryption(const std::string& cipher_name, - const std::string& padding_name) : - ECB(cipher_name, padding_name) - { - } - -/************************************************* -* ECB Encryption Constructor * -*************************************************/ -ECB_Encryption::ECB_Encryption(const std::string& cipher_name, - const std::string& padding_name, - const SymmetricKey& key) : - ECB(cipher_name, padding_name) - { - set_key(key); - } - -/************************************************* * Encrypt in ECB mode * *************************************************/ void ECB_Encryption::write(const byte input[], u32bit length) @@ -93,26 +63,6 @@ void ECB_Encryption::end_msg() } /************************************************* -* ECB Decryption Constructor * -*************************************************/ -ECB_Decryption::ECB_Decryption(const std::string& cipher_name, - const std::string& padding_name) : - ECB(cipher_name, padding_name) - { - } - -/************************************************* -* ECB Decryption Constructor * -*************************************************/ -ECB_Decryption::ECB_Decryption(const std::string& cipher_name, - const std::string& padding_name, - const SymmetricKey& key) : - ECB(cipher_name, padding_name) - { - set_key(key); - } - -/************************************************* * Decrypt in ECB mode * *************************************************/ void ECB_Decryption::write(const byte input[], u32bit length) diff --git a/src/modes/ecb/ecb.h b/src/modes/ecb/ecb.h index b730a4fd4..d15d2f202 100644 --- a/src/modes/ecb/ecb.h +++ b/src/modes/ecb/ecb.h @@ -8,6 +8,7 @@ #include <botan/modebase.h> #include <botan/mode_pad.h> +#include <botan/block_cipher.h> namespace Botan { @@ -17,7 +18,9 @@ namespace Botan { class BOTAN_DLL ECB : public BlockCipherMode { protected: - ECB(const std::string&, const std::string&); + ECB(BlockCipher* ciph, const BlockCipherModePaddingMethod* pad) : + BlockCipherMode(ciph, "ECB", 0), padder(pad) {} + std::string name() const; const BlockCipherModePaddingMethod* padder; private: @@ -30,9 +33,14 @@ class BOTAN_DLL ECB : public BlockCipherMode class BOTAN_DLL ECB_Encryption : public ECB { public: - ECB_Encryption(const std::string&, const std::string&); - ECB_Encryption(const std::string&, const std::string&, - const SymmetricKey&); + ECB_Encryption(BlockCipher* ciph, + const BlockCipherModePaddingMethod* pad) : + ECB(ciph, pad) {} + + ECB_Encryption(BlockCipher* ciph, + const BlockCipherModePaddingMethod* pad, + const SymmetricKey& key) : + ECB(ciph, pad) { set_key(key); } private: void write(const byte[], u32bit); void end_msg(); @@ -44,9 +52,14 @@ class BOTAN_DLL ECB_Encryption : public ECB class BOTAN_DLL ECB_Decryption : public ECB { public: - ECB_Decryption(const std::string&, const std::string&); - ECB_Decryption(const std::string&, const std::string&, - const SymmetricKey&); + ECB_Decryption(BlockCipher* ciph, + const BlockCipherModePaddingMethod* pad) : + ECB(ciph, pad) {} + + ECB_Decryption(BlockCipher* ciph, + const BlockCipherModePaddingMethod* pad, + const SymmetricKey& key) : + ECB(ciph, pad) { set_key(key); } private: void write(const byte[], u32bit); void end_msg(); |