diff options
author | lloyd <[email protected]> | 2015-01-28 06:20:39 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2015-01-28 06:20:39 +0000 |
commit | 710229be83cdbc061949c61942896b5af9e134d8 (patch) | |
tree | 5a28c6d2cd456a5a686a332b7466ed9f326cc5f8 /src/lib/engine | |
parent | 7b56f1bd570dc684ffd7c945dee0d9b5480354ff (diff) |
Use Algo_Registry also for hashes.
Diffstat (limited to 'src/lib/engine')
-rw-r--r-- | src/lib/engine/asm_engine/asm_engine.cpp | 53 | ||||
-rw-r--r-- | src/lib/engine/core_engine/lookup_hash.cpp | 212 | ||||
-rw-r--r-- | src/lib/engine/simd_engine/simd_engine.cpp | 12 |
3 files changed, 16 insertions, 261 deletions
diff --git a/src/lib/engine/asm_engine/asm_engine.cpp b/src/lib/engine/asm_engine/asm_engine.cpp index 59be4a826..d30bae035 100644 --- a/src/lib/engine/asm_engine/asm_engine.cpp +++ b/src/lib/engine/asm_engine/asm_engine.cpp @@ -6,26 +6,7 @@ */ #include <botan/internal/asm_engine.h> - -#if defined(BOTAN_HAS_SERPENT_X86_32) - #include <botan/serp_x86_32.h> -#endif - -#if defined(BOTAN_HAS_MD4_X86_32) - #include <botan/md4_x86_32.h> -#endif - -#if defined(BOTAN_HAS_MD5_X86_32) - #include <botan/md5_x86_32.h> -#endif - -#if defined(BOTAN_HAS_SHA1_X86_64) - #include <botan/sha1_x86_64.h> -#endif - -#if defined(BOTAN_HAS_SHA1_X86_32) - #include <botan/sha1_x86_32.h> -#endif +#include <botan/algo_registry.h> namespace Botan { @@ -33,12 +14,10 @@ BlockCipher* Assembler_Engine::find_block_cipher(const SCAN_Name& request, Algorithm_Factory&) const { - if(request.algo_name() == "Serpent") - { -#if defined(BOTAN_HAS_SERPENT_X86_32) - return new Serpent_X86_32; -#endif - } + auto& block_cipher = Algo_Registry<BlockCipher>::global_registry(); + + if(BlockCipher* c = block_cipher.make(request, "x86-32")) + return c; return nullptr; } @@ -47,24 +26,12 @@ HashFunction* Assembler_Engine::find_hash(const SCAN_Name& request, Algorithm_Factory&) const { -#if defined(BOTAN_HAS_MD4_X86_32) - if(request.algo_name() == "MD4") - return new MD4_X86_32; -#endif - -#if defined(BOTAN_HAS_MD5_X86_32) - if(request.algo_name() == "MD5") - return new MD5_X86_32; -#endif + auto& hash_fns = Algo_Registry<HashFunction>::global_registry(); + if(HashFunction* c = hash_fns.make(request, "x86-64")) + return c; - if(request.algo_name() == "SHA-160") - { -#if defined(BOTAN_HAS_SHA1_X86_64) - return new SHA_160_X86_64; -#elif defined(BOTAN_HAS_SHA1_X86_32) - return new SHA_160_X86_32; -#endif - } + if(HashFunction* c = hash_fns.make(request, "x86-32")) + return c; return nullptr; } diff --git a/src/lib/engine/core_engine/lookup_hash.cpp b/src/lib/engine/core_engine/lookup_hash.cpp index 446851bff..ed48c3549 100644 --- a/src/lib/engine/core_engine/lookup_hash.cpp +++ b/src/lib/engine/core_engine/lookup_hash.cpp @@ -7,83 +7,7 @@ #include <botan/internal/core_engine.h> #include <botan/scan_name.h> -#include <botan/algo_factory.h> - -#if defined(BOTAN_HAS_ADLER32) - #include <botan/adler32.h> -#endif - -#if defined(BOTAN_HAS_CRC24) - #include <botan/crc24.h> -#endif - -#if defined(BOTAN_HAS_CRC32) - #include <botan/crc32.h> -#endif - -#if defined(BOTAN_HAS_GOST_34_11) - #include <botan/gost_3411.h> -#endif - -#if defined(BOTAN_HAS_HAS_160) - #include <botan/has160.h> -#endif - -#if defined(BOTAN_HAS_KECCAK) - #include <botan/keccak.h> -#endif - -#if defined(BOTAN_HAS_MD2) - #include <botan/md2.h> -#endif - -#if defined(BOTAN_HAS_MD4) - #include <botan/md4.h> -#endif - -#if defined(BOTAN_HAS_MD5) - #include <botan/md5.h> -#endif - -#if defined(BOTAN_HAS_RIPEMD_128) - #include <botan/rmd128.h> -#endif - -#if defined(BOTAN_HAS_RIPEMD_160) - #include <botan/rmd160.h> -#endif - -#if defined(BOTAN_HAS_SHA1) - #include <botan/sha160.h> -#endif - -#if defined(BOTAN_HAS_SHA2_32) - #include <botan/sha2_32.h> -#endif - -#if defined(BOTAN_HAS_SHA2_64) - #include <botan/sha2_64.h> -#endif - -#if defined(BOTAN_HAS_SKEIN_512) - #include <botan/skein_512.h> -#endif - -#if defined(BOTAN_HAS_TIGER) - #include <botan/tiger.h> -#endif - -#if defined(BOTAN_HAS_WHIRLPOOL) - #include <botan/whrlpool.h> -#endif - -#if defined(BOTAN_HAS_PARALLEL_HASH) - #include <botan/par_hash.h> -#endif - -#if defined(BOTAN_HAS_COMB4P) - #include <botan/comb4p.h> -#endif +#include <botan/algo_registry.h> namespace Botan { @@ -91,138 +15,10 @@ namespace Botan { * Look for an algorithm with this name */ HashFunction* Core_Engine::find_hash(const SCAN_Name& request, - Algorithm_Factory& af) const + Algorithm_Factory&) const { -#if defined(BOTAN_HAS_ADLER32) - if(request.algo_name() == "Adler32") - return new Adler32; -#endif - -#if defined(BOTAN_HAS_CRC24) - if(request.algo_name() == "CRC24") - return new CRC24; -#endif - -#if defined(BOTAN_HAS_CRC32) - if(request.algo_name() == "CRC32") - return new CRC32; -#endif - -#if defined(BOTAN_HAS_GOST_34_11) - if(request.algo_name() == "GOST-R-34.11-94") - return new GOST_34_11; -#endif - -#if defined(BOTAN_HAS_HAS_160) - if(request.algo_name() == "HAS-160") - return new HAS_160; -#endif - -#if defined(BOTAN_HAS_KECCAK) - if(request.algo_name() == "Keccak-1600") - return new Keccak_1600(request.arg_as_integer(0, 512)); -#endif - -#if defined(BOTAN_HAS_MD2) - if(request.algo_name() == "MD2") - return new MD2; -#endif - -#if defined(BOTAN_HAS_MD4) - if(request.algo_name() == "MD4") - return new MD4; -#endif - -#if defined(BOTAN_HAS_MD5) - if(request.algo_name() == "MD5") - return new MD5; -#endif - -#if defined(BOTAN_HAS_RIPEMD_128) - if(request.algo_name() == "RIPEMD-128") - return new RIPEMD_128; -#endif - -#if defined(BOTAN_HAS_RIPEMD_160) - if(request.algo_name() == "RIPEMD-160") - return new RIPEMD_160; -#endif - -#if defined(BOTAN_HAS_SHA1) - if(request.algo_name() == "SHA-160") - return new SHA_160; -#endif - -#if defined(BOTAN_HAS_SHA2_32) - if(request.algo_name() == "SHA-224") - return new SHA_224; - if(request.algo_name() == "SHA-256") - return new SHA_256; -#endif - -#if defined(BOTAN_HAS_SHA2_64) - if(request.algo_name() == "SHA-384") - return new SHA_384; - if(request.algo_name() == "SHA-512") - return new SHA_512; - if(request.algo_name() == "SHA-512-256") - return new SHA_512_256; -#endif - -#if defined(BOTAN_HAS_TIGER) - if(request.algo_name() == "Tiger") - return new Tiger(request.arg_as_integer(0, 24), // hash output - request.arg_as_integer(1, 3)); // # passes -#endif - -#if defined(BOTAN_HAS_SKEIN_512) - if(request.algo_name() == "Skein-512") - return new Skein_512(request.arg_as_integer(0, 512), - request.arg(1, "")); -#endif - -#if defined(BOTAN_HAS_WHIRLPOOL) - if(request.algo_name() == "Whirlpool") - return new Whirlpool; -#endif - -#if defined(BOTAN_HAS_COMB4P) - if(request.algo_name() == "Comb4P" && request.arg_count() == 2) - { - const HashFunction* h1 = af.prototype_hash_function(request.arg(0)); - const HashFunction* h2 = af.prototype_hash_function(request.arg(1)); - - if(h1 && h2) - return new Comb4P(h1->clone(), h2->clone()); - } -#endif - -#if defined(BOTAN_HAS_PARALLEL_HASH) - - if(request.algo_name() == "Parallel") - { - std::vector<const HashFunction*> hash_prototypes; - - /* First pass, just get the prototypes (no memory allocation). Then - if all were found, replace each prototype with a newly created clone - */ - for(size_t i = 0; i != request.arg_count(); ++i) - { - const HashFunction* hash = af.prototype_hash_function(request.arg(i)); - if(!hash) - return nullptr; - - hash_prototypes.push_back(hash); - } - - std::vector<HashFunction*> hashes; - for(size_t i = 0; i != hash_prototypes.size(); ++i) - hashes.push_back(hash_prototypes[i]->clone()); - - return new Parallel(hashes); - } - -#endif + if(HashFunction* c = Algo_Registry<HashFunction>::global_registry().make(request, "builtin")) + return c; return nullptr; } diff --git a/src/lib/engine/simd_engine/simd_engine.cpp b/src/lib/engine/simd_engine/simd_engine.cpp index 35d9cdad4..f60c5beb2 100644 --- a/src/lib/engine/simd_engine/simd_engine.cpp +++ b/src/lib/engine/simd_engine/simd_engine.cpp @@ -9,10 +9,6 @@ #include <botan/algo_registry.h> #include <botan/cpuid.h> -#if defined(BOTAN_HAS_SHA1_SSE2) - #include <botan/sha1_sse2.h> -#endif - namespace Botan { BlockCipher* @@ -40,12 +36,8 @@ HashFunction* SIMD_Engine::find_hash(const SCAN_Name& request, Algorithm_Factory&) const { -#if defined(BOTAN_HAS_SHA1_SSE2) - if(request.algo_name() == "SHA-160" && CPUID::has_sse2()) - return new SHA_160_SSE2; -#endif - - BOTAN_UNUSED(request); + if(HashFunction* c = Algo_Registry<HashFunction>::global_registry().make(request, "sse2")) + return c; return nullptr; } |