From a4be9296531e66b3d40b5ff195bfd9ba9b9c070f Mon Sep 17 00:00:00 2001 From: lloyd Date: Mon, 10 Nov 2008 02:22:54 +0000 Subject: Split lookup_cipher.cpp into lookup_{block,stream,bc_pad}.cpp --- src/libstate/engine/def_engine/info.txt | 8 +- src/libstate/engine/def_engine/lookup_bc_pad.cpp | 40 +++ src/libstate/engine/def_engine/lookup_block.cpp | 268 ++++++++++++++++++ src/libstate/engine/def_engine/lookup_cipher.cpp | 346 ----------------------- src/libstate/engine/def_engine/lookup_stream.cpp | 85 ++++++ 5 files changed, 398 insertions(+), 349 deletions(-) create mode 100644 src/libstate/engine/def_engine/lookup_bc_pad.cpp create mode 100644 src/libstate/engine/def_engine/lookup_block.cpp delete mode 100644 src/libstate/engine/def_engine/lookup_cipher.cpp create mode 100644 src/libstate/engine/def_engine/lookup_stream.cpp (limited to 'src/libstate') diff --git a/src/libstate/engine/def_engine/info.txt b/src/libstate/engine/def_engine/info.txt index 0de7f37ab..823df1559 100644 --- a/src/libstate/engine/def_engine/info.txt +++ b/src/libstate/engine/def_engine/info.txt @@ -5,12 +5,14 @@ define DEFAULT_ENGINE load_on auto +def_eng.h def_mode.cpp +def_pk_ops.cpp def_powm.cpp -def_eng.h -lookup_cipher.cpp +lookup_bc_pad.cpp +lookup_block.cpp lookup_hash.cpp lookup_mac.cpp lookup_s2k.cpp -def_pk_ops.cpp +lookup_stream.cpp diff --git a/src/libstate/engine/def_engine/lookup_bc_pad.cpp b/src/libstate/engine/def_engine/lookup_bc_pad.cpp new file mode 100644 index 000000000..0ed5267f6 --- /dev/null +++ b/src/libstate/engine/def_engine/lookup_bc_pad.cpp @@ -0,0 +1,40 @@ +/************************************************* +* Block Cipher Padding Lookup * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include + +#if defined(BOTAN_HAS_CIPHER_MODE_PADDING) + #include +#endif + +namespace Botan { + +/************************************************* +* Look for an algorithm with this name * +*************************************************/ +BlockCipherModePaddingMethod* +Default_Engine::find_bc_pad(const std::string& algo_spec) const + { + SCAN_Name request(algo_spec); + +#if defined(BOTAN_HAS_CIPHER_MODE_PADDING) + if(request.algo_name() == "PKCS7") + return new PKCS7_Padding; + + if(request.algo_name() == "OneAndZeros") + return new OneAndZeros_Padding; + + if(request.algo_name() == "X9.23") + return new ANSI_X923_Padding; + + if(request.algo_name() == "NoPadding") + return new Null_Padding; +#endif + + return 0; + } + +} diff --git a/src/libstate/engine/def_engine/lookup_block.cpp b/src/libstate/engine/def_engine/lookup_block.cpp new file mode 100644 index 000000000..00d9ad03c --- /dev/null +++ b/src/libstate/engine/def_engine/lookup_block.cpp @@ -0,0 +1,268 @@ +/************************************************* +* Block Cipher Lookup * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include +#include +#include + +#if defined(BOTAN_HAS_AES) + #include +#endif + +#if defined(BOTAN_HAS_BLOWFISH) + #include +#endif + +#if defined(BOTAN_HAS_CAST) + #include + #include +#endif + +#if defined(BOTAN_HAS_DES) + #include + #include +#endif + +#if defined(BOTAN_HAS_GOST) + #include +#endif + +#if defined(BOTAN_HAS_IDEA) + #include +#endif + +#if defined(BOTAN_HAS_KASUMI) + #include +#endif + +#if defined(BOTAN_HAS_LION) + #include +#endif + +#if defined(BOTAN_HAS_LUBY_RACKOFF) + #include +#endif + +#if defined(BOTAN_HAS_MARS) + #include +#endif + +#if defined(BOTAN_HAS_MISTY1) + #include +#endif + +#if defined(BOTAN_HAS_NOEKEON) + #include +#endif + +#if defined(BOTAN_HAS_RC2) + #include +#endif + +#if defined(BOTAN_HAS_RC5) + #include +#endif + +#if defined(BOTAN_HAS_RC6) + #include +#endif + +#if defined(BOTAN_HAS_SAFER) + #include +#endif + +#if defined(BOTAN_HAS_SEED) + #include +#endif + +#if defined(BOTAN_HAS_SERPENT) + #include +#endif + +#if defined(BOTAN_HAS_SERPENT_IA32) + #include +#endif + +#if defined(BOTAN_HAS_SKIPJACK) + #include +#endif + +#if defined(BOTAN_HAS_SQUARE) + #include +#endif + +#if defined(BOTAN_HAS_TEA) + #include +#endif + +#if defined(BOTAN_HAS_TWOFISH) + #include +#endif + +#if defined(BOTAN_HAS_XTEA) + #include +#endif + +namespace Botan { + +/************************************************* +* Look for an algorithm with this name * +*************************************************/ +BlockCipher* +Default_Engine::find_block_cipher(const std::string& algo_spec) const + { + SCAN_Name request(algo_spec); + +#if defined(BOTAN_HAS_AES) + if(request.algo_name() == "AES") + return new AES; + if(request.algo_name() == "AES-128") + return new AES_128; + if(request.algo_name() == "AES-192") + return new AES_192; + if(request.algo_name() == "AES-256") + return new AES_256; +#endif + +#if defined(BOTAN_HAS_BLOWFISH) + if(request.algo_name() == "Blowfish") + return new Blowfish; +#endif + +#if defined(BOTAN_HAS_CAST) + if(request.algo_name() == "CAST-128") + return new CAST_128; + if(request.algo_name() == "CAST-256") + return new CAST_256; +#endif + +#if defined(BOTAN_HAS_DES) + if(request.algo_name() == "DES") + return new DES; + if(request.algo_name() == "DESX") + return new DESX; + if(request.algo_name() == "TripleDES") + return new TripleDES; +#endif + +#if defined(BOTAN_HAS_GOST) + if(request.algo_name() == "GOST") + return new GOST; +#endif + +#if defined(BOTAN_HAS_IDEA) + if(request.algo_name() == "IDEA") + return new IDEA; +#endif + +#if defined(BOTAN_HAS_KASUMI) + if(request.algo_name() == "KASUMI") + return new KASUMI; +#endif + +#if defined(BOTAN_HAS_MARS) + if(request.algo_name() == "MARS") + return new MARS; +#endif + +#if defined(BOTAN_HAS_MISTY1) + if(request.algo_name() == "MISTY1") + return new MISTY1(request.argument_as_u32bit(0, 8)); +#endif + +#if defined(BOTAN_HAS_NOEKEON) + if(request.algo_name() == "Noekeon") + return new Noekeon; +#endif + +#if defined(BOTAN_HAS_RC2) + if(request.algo_name() == "RC2") + return new RC2; +#endif + +#if defined(BOTAN_HAS_RC5) + if(request.algo_name() == "RC5") + return new RC5(request.argument_as_u32bit(0, 12)); +#endif + +#if defined(BOTAN_HAS_RC6) + if(request.algo_name() == "RC6") + return new RC6; +#endif + +#if defined(BOTAN_HAS_SAFER) + if(request.algo_name() == "SAFER-SK") + return new SAFER_SK(request.argument_as_u32bit(0, 10)); +#endif + +#if defined(BOTAN_HAS_SEED) + if(request.algo_name() == "SEED") + return new SEED; +#endif + +#if defined(BOTAN_HAS_SERPENT_IA32) + if(request.algo_name() == "Serpent") + return new Serpent_IA32; +#elif defined(BOTAN_HAS_SERPENT) + if(request.algo_name() == "Serpent") + return new Serpent; +#endif + +#if defined(BOTAN_HAS_SKIPJACK) + if(request.algo_name() == "Skipjack") + return new Skipjack; +#endif + +#if defined(BOTAN_HAS_SQUARE) + if(request.algo_name() == "Square") + return new Square; +#endif + +#if defined(BOTAN_HAS_TEA) + if(request.algo_name() == "TEA") + return new TEA; +#endif + +#if defined(BOTAN_HAS_TWOFISH) + if(request.algo_name() == "Twofish") + return new Twofish; +#endif + +#if defined(BOTAN_HAS_XTEA) + if(request.algo_name() == "XTEA") + return new XTEA; +#endif + +#if defined(BOTAN_HAS_LUBY_RACKOFF) + if(request.algo_name() == "Luby-Rackoff" && request.arg_count() == 1) + { + HashFunction* hash = get_hash(request.argument(0)); + if(hash) + return new LubyRackoff(hash); + } +#endif + +#if defined(BOTAN_HAS_LION) + if(request.algo_name() == "Lion" && request.arg_count_between(2, 3)) + { + const u32bit block_size = request.argument_as_u32bit(2, 1024); + + std::auto_ptr hash(get_hash(request.argument(0))); + if(!hash.get()) + return 0; + + std::auto_ptr sc(get_stream_cipher(request.argument(1))); + if(!sc.get()) + return 0; + + return new Lion(hash.release(), sc.release(), block_size); + } +#endif + + return 0; + } + +} diff --git a/src/libstate/engine/def_engine/lookup_cipher.cpp b/src/libstate/engine/def_engine/lookup_cipher.cpp deleted file mode 100644 index bba8a6c3c..000000000 --- a/src/libstate/engine/def_engine/lookup_cipher.cpp +++ /dev/null @@ -1,346 +0,0 @@ -/************************************************* -* Cipher Lookup * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include -#include -#include -#include - -#if defined(BOTAN_HAS_AES) - #include -#endif - -#if defined(BOTAN_HAS_BLOWFISH) - #include -#endif - -#if defined(BOTAN_HAS_CAST) - #include - #include -#endif - -#if defined(BOTAN_HAS_DES) - #include - #include -#endif - -#if defined(BOTAN_HAS_GOST) - #include -#endif - -#if defined(BOTAN_HAS_IDEA) - #include -#endif - -#if defined(BOTAN_HAS_KASUMI) - #include -#endif - -#if defined(BOTAN_HAS_LION) - #include -#endif - -#if defined(BOTAN_HAS_LUBY_RACKOFF) - #include -#endif - -#if defined(BOTAN_HAS_MARS) - #include -#endif - -#if defined(BOTAN_HAS_MISTY1) - #include -#endif - -#if defined(BOTAN_HAS_NOEKEON) - #include -#endif - -#if defined(BOTAN_HAS_RC2) - #include -#endif - -#if defined(BOTAN_HAS_RC5) - #include -#endif - -#if defined(BOTAN_HAS_RC6) - #include -#endif - -#if defined(BOTAN_HAS_SAFER) - #include -#endif - -#if defined(BOTAN_HAS_SEED) - #include -#endif - -#if defined(BOTAN_HAS_SERPENT) - #include -#endif - -#if defined(BOTAN_HAS_SERPENT_IA32) - #include -#endif - -#if defined(BOTAN_HAS_SKIPJACK) - #include -#endif - -#if defined(BOTAN_HAS_SQUARE) - #include -#endif - -#if defined(BOTAN_HAS_TEA) - #include -#endif - -#if defined(BOTAN_HAS_TWOFISH) - #include -#endif - -#if defined(BOTAN_HAS_XTEA) - #include -#endif - -#if defined(BOTAN_HAS_ARC4) - #include -#endif - -#if defined(BOTAN_HAS_SALSA20) - #include -#endif - -#if defined(BOTAN_HAS_TURING) - #include -#endif - -#if defined(BOTAN_HAS_WID_WAKE) - #include -#endif - -#if defined(BOTAN_HAS_CIPHER_MODE_PADDING) - #include -#endif - -namespace Botan { - -/************************************************* -* Look for an algorithm with this name * -*************************************************/ -BlockCipher* -Default_Engine::find_block_cipher(const std::string& algo_spec) const - { - SCAN_Name request(algo_spec); - -#if defined(BOTAN_HAS_AES) - if(request.algo_name() == "AES") - return new AES; - if(request.algo_name() == "AES-128") - return new AES_128; - if(request.algo_name() == "AES-192") - return new AES_192; - if(request.algo_name() == "AES-256") - return new AES_256; -#endif - -#if defined(BOTAN_HAS_BLOWFISH) - if(request.algo_name() == "Blowfish") - return new Blowfish; -#endif - -#if defined(BOTAN_HAS_CAST) - if(request.algo_name() == "CAST-128") - return new CAST_128; - if(request.algo_name() == "CAST-256") - return new CAST_256; -#endif - -#if defined(BOTAN_HAS_DES) - if(request.algo_name() == "DES") - return new DES; - if(request.algo_name() == "DESX") - return new DESX; - if(request.algo_name() == "TripleDES") - return new TripleDES; -#endif - -#if defined(BOTAN_HAS_GOST) - if(request.algo_name() == "GOST") - return new GOST; -#endif - -#if defined(BOTAN_HAS_IDEA) - if(request.algo_name() == "IDEA") - return new IDEA; -#endif - -#if defined(BOTAN_HAS_KASUMI) - if(request.algo_name() == "KASUMI") - return new KASUMI; -#endif - -#if defined(BOTAN_HAS_MARS) - if(request.algo_name() == "MARS") - return new MARS; -#endif - -#if defined(BOTAN_HAS_MISTY1) - if(request.algo_name() == "MISTY1") - return new MISTY1(request.argument_as_u32bit(0, 8)); -#endif - -#if defined(BOTAN_HAS_NOEKEON) - if(request.algo_name() == "Noekeon") - return new Noekeon; -#endif - -#if defined(BOTAN_HAS_RC2) - if(request.algo_name() == "RC2") - return new RC2; -#endif - -#if defined(BOTAN_HAS_RC5) - if(request.algo_name() == "RC5") - return new RC5(request.argument_as_u32bit(0, 12)); -#endif - -#if defined(BOTAN_HAS_RC6) - if(request.algo_name() == "RC6") - return new RC6; -#endif - -#if defined(BOTAN_HAS_SAFER) - if(request.algo_name() == "SAFER-SK") - return new SAFER_SK(request.argument_as_u32bit(0, 10)); -#endif - -#if defined(BOTAN_HAS_SEED) - if(request.algo_name() == "SEED") - return new SEED; -#endif - -#if defined(BOTAN_HAS_SERPENT_IA32) - if(request.algo_name() == "Serpent") - return new Serpent_IA32; -#elif defined(BOTAN_HAS_SERPENT) - if(request.algo_name() == "Serpent") - return new Serpent; -#endif - -#if defined(BOTAN_HAS_SKIPJACK) - if(request.algo_name() == "Skipjack") - return new Skipjack; -#endif - -#if defined(BOTAN_HAS_SQUARE) - if(request.algo_name() == "Square") - return new Square; -#endif - -#if defined(BOTAN_HAS_TEA) - if(request.algo_name() == "TEA") - return new TEA; -#endif - -#if defined(BOTAN_HAS_TWOFISH) - if(request.algo_name() == "Twofish") - return new Twofish; -#endif - -#if defined(BOTAN_HAS_XTEA) - if(request.algo_name() == "XTEA") - return new XTEA; -#endif - -#if defined(BOTAN_HAS_LUBY_RACKOFF) - if(request.algo_name() == "Luby-Rackoff" && request.arg_count() == 1) - { - HashFunction* hash = get_hash(request.argument(0)); - if(hash) - return new LubyRackoff(hash); - } -#endif - -#if defined(BOTAN_HAS_LION) - if(request.algo_name() == "Lion" && request.arg_count_between(2, 3)) - { - const u32bit block_size = request.argument_as_u32bit(2, 1024); - - std::auto_ptr hash(get_hash(request.argument(0))); - if(!hash.get()) - return 0; - - std::auto_ptr sc(get_stream_cipher(request.argument(1))); - if(!sc.get()) - return 0; - - return new Lion(hash.release(), sc.release(), block_size); - } -#endif - - return 0; - } - -/************************************************* -* Look for an algorithm with this name * -*************************************************/ -StreamCipher* -Default_Engine::find_stream_cipher(const std::string& algo_spec) const - { - SCAN_Name request(algo_spec); - -#if defined(BOTAN_HAS_ARC4) - if(request.algo_name() == "ARC4") - return new ARC4(request.argument_as_u32bit(0, 0)); - if(request.algo_name() == "RC4_drop") - return new ARC4(768); -#endif - -#if defined(BOTAN_HAS_SALSA20) - if(request.algo_name() == "Salsa20") - return new Salsa20; -#endif - -#if defined(BOTAN_HAS_TURING) - if(request.algo_name() == "Turing") - return new Turing; -#endif - -#if defined(BOTAN_HAS_WID_WAKE) - if(request.algo_name() == "WiderWake4+1-BE") - return new WiderWake_41_BE; -#endif - - return 0; - } - -/************************************************* -* Look for an algorithm with this name * -*************************************************/ -BlockCipherModePaddingMethod* -Default_Engine::find_bc_pad(const std::string& algo_spec) const - { - SCAN_Name request(algo_spec); - -#if defined(BOTAN_HAS_CIPHER_MODE_PADDING) - if(request.algo_name() == "PKCS7") - return new PKCS7_Padding; - - if(request.algo_name() == "OneAndZeros") - return new OneAndZeros_Padding; - - if(request.algo_name() == "X9.23") - return new ANSI_X923_Padding; - - if(request.algo_name() == "NoPadding") - return new Null_Padding; -#endif - - return 0; - } - -} diff --git a/src/libstate/engine/def_engine/lookup_stream.cpp b/src/libstate/engine/def_engine/lookup_stream.cpp new file mode 100644 index 000000000..a19b6572c --- /dev/null +++ b/src/libstate/engine/def_engine/lookup_stream.cpp @@ -0,0 +1,85 @@ +/************************************************* +* Stream Cipher Lookup * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include + +#if defined(BOTAN_HAS_ARC4) + #include +#endif + +#if defined(BOTAN_HAS_SALSA20) + #include +#endif + +#if defined(BOTAN_HAS_TURING) + #include +#endif + +#if defined(BOTAN_HAS_WID_WAKE) + #include +#endif + +namespace Botan { + +/************************************************* +* Look for an algorithm with this name * +*************************************************/ +StreamCipher* +Default_Engine::find_stream_cipher(const std::string& algo_spec) const + { + SCAN_Name request(algo_spec); + +#if defined(BOTAN_HAS_ARC4) + if(request.algo_name() == "ARC4") + return new ARC4(request.argument_as_u32bit(0, 0)); + if(request.algo_name() == "RC4_drop") + return new ARC4(768); +#endif + +#if defined(BOTAN_HAS_SALSA20) + if(request.algo_name() == "Salsa20") + return new Salsa20; +#endif + +#if defined(BOTAN_HAS_TURING) + if(request.algo_name() == "Turing") + return new Turing; +#endif + +#if defined(BOTAN_HAS_WID_WAKE) + if(request.algo_name() == "WiderWake4+1-BE") + return new WiderWake_41_BE; +#endif + + return 0; + } + +/************************************************* +* Look for an algorithm with this name * +*************************************************/ +BlockCipherModePaddingMethod* +Default_Engine::find_bc_pad(const std::string& algo_spec) const + { + SCAN_Name request(algo_spec); + +#if defined(BOTAN_HAS_CIPHER_MODE_PADDING) + if(request.algo_name() == "PKCS7") + return new PKCS7_Padding; + + if(request.algo_name() == "OneAndZeros") + return new OneAndZeros_Padding; + + if(request.algo_name() == "X9.23") + return new ANSI_X923_Padding; + + if(request.algo_name() == "NoPadding") + return new Null_Padding; +#endif + + return 0; + } + +} -- cgit v1.2.3