aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/engine/simd_engine/simd_engine.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2015-01-28 04:32:10 +0000
committerlloyd <[email protected]>2015-01-28 04:32:10 +0000
commit7b56f1bd570dc684ffd7c945dee0d9b5480354ff (patch)
tree0c50ad534280a292a1b76daee9a19b34cfd96367 /src/lib/engine/simd_engine/simd_engine.cpp
parentb8fa304ec981d273c45d7ef31705d65ccfb00cc1 (diff)
Add a runtime map of string->func() which when called return
Transforms and BlockCiphers. Registration for all types is done at startup but is very cheap as just a std::function and a std::map entry are created, no actual objects are created until needed. This is a huge improvement over Algorithm_Factory which used T::clone() as the function and thus kept a prototype object of each type in memory. Replace existing lookup mechanisms for ciphers, AEADs, and compression to use the transform lookup. The existing Engine framework remains in place for BlockCipher, but the engines now just call to the registry instead of having hardcoded lookups. s/Transformation/Transform/ with typedefs for compatability. Remove lib/selftest code (for runtime selftesting): not the right approach.
Diffstat (limited to 'src/lib/engine/simd_engine/simd_engine.cpp')
-rw-r--r--src/lib/engine/simd_engine/simd_engine.cpp64
1 files changed, 10 insertions, 54 deletions
diff --git a/src/lib/engine/simd_engine/simd_engine.cpp b/src/lib/engine/simd_engine/simd_engine.cpp
index af5f5d524..35d9cdad4 100644
--- a/src/lib/engine/simd_engine/simd_engine.cpp
+++ b/src/lib/engine/simd_engine/simd_engine.cpp
@@ -6,33 +6,9 @@
*/
#include <botan/internal/simd_engine.h>
-#include <botan/internal/simd_32.h>
+#include <botan/algo_registry.h>
#include <botan/cpuid.h>
-#if defined(BOTAN_HAS_AES_SSSE3)
- #include <botan/aes_ssse3.h>
-#endif
-
-#if defined(BOTAN_HAS_SERPENT_SIMD)
- #include <botan/serp_simd.h>
-#endif
-
-#if defined(BOTAN_HAS_THREEFISH_512_AVX2)
- #include <botan/threefish_avx2.h>
-#endif
-
-#if defined(BOTAN_HAS_NOEKEON_SIMD)
- #include <botan/noekeon_simd.h>
-#endif
-
-#if defined(BOTAN_HAS_XTEA_SIMD)
- #include <botan/xtea_simd.h>
-#endif
-
-#if defined(BOTAN_HAS_IDEA_SSE2)
- #include <botan/idea_sse2.h>
-#endif
-
#if defined(BOTAN_HAS_SHA1_SSE2)
#include <botan/sha1_sse2.h>
#endif
@@ -43,39 +19,19 @@ BlockCipher*
SIMD_Engine::find_block_cipher(const SCAN_Name& request,
Algorithm_Factory&) const
{
-#if defined(BOTAN_HAS_AES_SSSE3)
- if(request.algo_name() == "AES-128" && CPUID::has_ssse3())
- return new AES_128_SSSE3;
- if(request.algo_name() == "AES-192" && CPUID::has_ssse3())
- return new AES_192_SSSE3;
- if(request.algo_name() == "AES-256" && CPUID::has_ssse3())
- return new AES_256_SSSE3;
-#endif
+ auto& block_cipher = Algo_Registry<BlockCipher>::global_registry();
-#if defined(BOTAN_HAS_IDEA_SSE2)
- if(request.algo_name() == "IDEA" && CPUID::has_sse2())
- return new IDEA_SSE2;
-#endif
+ if(BlockCipher* c = block_cipher.make(request, "avx2"))
+ return c;
-#if defined(BOTAN_HAS_NOEKEON_SIMD)
- if(request.algo_name() == "Noekeon" && SIMD_32::enabled())
- return new Noekeon_SIMD;
-#endif
+ if(BlockCipher* c = block_cipher.make(request, "ssse3"))
+ return c;
-#if defined(BOTAN_HAS_THREEFISH_512_AVX2)
- if(request.algo_name() == "Threefish-512" && CPUID::has_avx2())
- return new Threefish_512_AVX2;
-#endif
-
-#if defined(BOTAN_HAS_SERPENT_SIMD)
- if(request.algo_name() == "Serpent" && SIMD_32::enabled())
- return new Serpent_SIMD;
-#endif
+ if(BlockCipher* c = block_cipher.make(request, "sse2"))
+ return c;
-#if defined(BOTAN_HAS_XTEA_SIMD)
- if(request.algo_name() == "XTEA" && SIMD_32::enabled())
- return new XTEA_SIMD;
-#endif
+ if(BlockCipher* c = block_cipher.make(request, "simd32"))
+ return c;
return nullptr;
}