diff options
author | Jack Lloyd <[email protected]> | 2015-09-21 16:09:36 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2015-09-21 16:09:36 -0400 |
commit | 7ebe7511496b8a6950acced513a81516565354ed (patch) | |
tree | add1163c2afbd1ae3d163aaac8375a3b56bd6c9c /src/lib/block | |
parent | 8f732dccce692eaca509fc9732702df62cfa5c87 (diff) | |
parent | 04319af23bf8ed467b17f9b74c814343e051ab6b (diff) |
Merge pull request #279 from randombit/fix-static-lib-registration
Move the algorithm factory functions to T::create and move object registration to the source file for its base class. These resolve the issues which prevented successful use of a static library that was built with individual object files. Removes the restriction in configure.py which prevented building non-amalgamation static libs.
Diffstat (limited to 'src/lib/block')
37 files changed, 365 insertions, 164 deletions
diff --git a/src/lib/block/aes/aes.cpp b/src/lib/block/aes/aes.cpp index b9e00fe6c..61cc9d777 100644 --- a/src/lib/block/aes/aes.cpp +++ b/src/lib/block/aes/aes.cpp @@ -7,15 +7,11 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/aes.h> +#include <botan/loadstor.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(AES_128, "AES-128"); -BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(AES_192, "AES-192"); -BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(AES_256, "AES-256"); - namespace { const byte SE[256] = { diff --git a/src/lib/block/aes_ni/aes_ni.cpp b/src/lib/block/aes_ni/aes_ni.cpp index 29e729da4..d359ec772 100644 --- a/src/lib/block/aes_ni/aes_ni.cpp +++ b/src/lib/block/aes_ni/aes_ni.cpp @@ -5,17 +5,13 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/aes_ni.h> +#include <botan/loadstor.h> #include <botan/cpuid.h> #include <wmmintrin.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_aes_ni(), AES_128_NI, "AES-128", "aes_ni", 200); -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_aes_ni(), AES_192_NI, "AES-192", "aes_ni", 200); -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_aes_ni(), AES_256_NI, "AES-256", "aes_ni", 200); - namespace { __m128i aes_128_key_expansion(__m128i key, __m128i key_with_rcon) diff --git a/src/lib/block/aes_ssse3/aes_ssse3.cpp b/src/lib/block/aes_ssse3/aes_ssse3.cpp index 50acd7668..bfc76ecee 100644 --- a/src/lib/block/aes_ssse3/aes_ssse3.cpp +++ b/src/lib/block/aes_ssse3/aes_ssse3.cpp @@ -10,20 +10,12 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/aes_ssse3.h> #include <botan/cpuid.h> #include <tmmintrin.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_ssse3(), AES_128_SSSE3, "AES-128", - "ssse3", BOTAN_SIMD_ALGORITHM_PRIO); -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_ssse3(), AES_192_SSSE3, "AES-192", - "ssse3", BOTAN_SIMD_ALGORITHM_PRIO); -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_ssse3(), AES_256_SSSE3, "AES-256", - "ssse3", BOTAN_SIMD_ALGORITHM_PRIO); - namespace { const __m128i low_nibs = _mm_set1_epi8(0x0F); diff --git a/src/lib/block/block_cipher.cpp b/src/lib/block/block_cipher.cpp new file mode 100644 index 000000000..5b9c4f0ba --- /dev/null +++ b/src/lib/block/block_cipher.cpp @@ -0,0 +1,319 @@ +/* +* Block Ciphers +* (C) 2015 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#include <botan/block_cipher.h> +#include <botan/cpuid.h> +#include <botan/internal/algo_registry.h> + +#if defined(BOTAN_HAS_SIMD_32) + #include <botan/internal/simd_32.h> +#endif + +#if defined(BOTAN_HAS_AES) + #include <botan/aes.h> +#endif + +#if defined(BOTAN_HAS_AES_SSSE3) + #include <botan/aes_ssse3.h> +#endif + +#if defined(BOTAN_HAS_AES_NI) + #include <botan/aes_ni.h> +#endif + +#if defined(BOTAN_HAS_BLOWFISH) + #include <botan/blowfish.h> +#endif + +#if defined(BOTAN_HAS_CAMELLIA) + #include <botan/camellia.h> +#endif + +#if defined(BOTAN_HAS_CAST) + #include <botan/cast128.h> + #include <botan/cast256.h> +#endif + +#if defined(BOTAN_HAS_CASCADE) + #include <botan/cascade.h> +#endif + +#if defined(BOTAN_HAS_DES) + #include <botan/des.h> + #include <botan/desx.h> +#endif + +#if defined(BOTAN_HAS_GOST_28147_89) + #include <botan/gost_28147.h> +#endif + +#if defined(BOTAN_HAS_IDEA) + #include <botan/idea.h> +#endif + +#if defined(BOTAN_HAS_IDEA_SSE2) + #include <botan/idea_sse2.h> +#endif + +#if defined(BOTAN_HAS_KASUMI) + #include <botan/kasumi.h> +#endif + +#if defined(BOTAN_HAS_LION) + #include <botan/lion.h> +#endif + +#if defined(BOTAN_HAS_LUBY_RACKOFF) + #include <botan/lubyrack.h> +#endif + +#if defined(BOTAN_HAS_MARS) + #include <botan/mars.h> +#endif + +#if defined(BOTAN_HAS_MISTY1) + #include <botan/misty1.h> +#endif + +#if defined(BOTAN_HAS_NOEKEON) + #include <botan/noekeon.h> +#endif + +#if defined(BOTAN_HAS_NOEKEON_SIMD) + #include <botan/noekeon_simd.h> +#endif + +#if defined(BOTAN_HAS_RC2) + #include <botan/rc2.h> +#endif + +#if defined(BOTAN_HAS_RC5) + #include <botan/rc5.h> +#endif + +#if defined(BOTAN_HAS_RC6) + #include <botan/rc6.h> +#endif + +#if defined(BOTAN_HAS_SAFER) + #include <botan/safer_sk.h> +#endif + +#if defined(BOTAN_HAS_SEED) + #include <botan/seed.h> +#endif + +#if defined(BOTAN_HAS_SERPENT) + #include <botan/serpent.h> +#endif + +#if defined(BOTAN_HAS_SERPENT_SIMD) + #include <botan/serp_simd.h> +#endif + +#if defined(BOTAN_HAS_SKIPJACK) + #include <botan/skipjack.h> +#endif + +#if defined(BOTAN_HAS_SQUARE) + #include <botan/square.h> +#endif + +#if defined(BOTAN_HAS_TEA) + #include <botan/tea.h> +#endif + +#if defined(BOTAN_HAS_TWOFISH) + #include <botan/twofish.h> +#endif + +#if defined(BOTAN_HAS_THREEFISH_512) + #include <botan/threefish.h> +#endif + +#if defined(BOTAN_HAS_THREEFISH_512_AVX2) + #include <botan/threefish_avx2.h> +#endif + +#if defined(BOTAN_HAS_XTEA) + #include <botan/xtea.h> +#endif + +#if defined(BOTAN_HAS_XTEA_SIMD) + #include <botan/xtea_simd.h> +#endif + +namespace Botan { + +BlockCipher::~BlockCipher() {} + +std::unique_ptr<BlockCipher> BlockCipher::create(const std::string& algo_spec, + const std::string& provider) + { + return std::unique_ptr<BlockCipher>(make_a<BlockCipher>(algo_spec, provider)); + } + +std::vector<std::string> BlockCipher::providers(const std::string& algo_spec) + { + return providers_of<BlockCipher>(BlockCipher::Spec(algo_spec)); + } + +#define BOTAN_REGISTER_BLOCK_CIPHER(name, maker) BOTAN_REGISTER_T(BlockCipher, name, maker) +#define BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(name) BOTAN_REGISTER_T_NOARGS(BlockCipher, name) + +#define BOTAN_REGISTER_BLOCK_CIPHER_1LEN(name, def) BOTAN_REGISTER_T_1LEN(BlockCipher, name, def) + +#define BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(type, name) \ + BOTAN_REGISTER_NAMED_T(BlockCipher, name, type, make_new_T<type>) +#define BOTAN_REGISTER_BLOCK_CIPHER_NAMED_1LEN(type, name, def) \ + BOTAN_REGISTER_NAMED_T(BlockCipher, name, type, (make_new_T_1len<type,def>)) +#define BOTAN_REGISTER_BLOCK_CIPHER_NAMED_1STR(type, name, def) \ + BOTAN_REGISTER_NAMED_T(BlockCipher, name, type, std::bind(make_new_T_1str<type>, std::placeholders::_1, def)) + +#define BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(cond, type, name, provider, pref) \ + BOTAN_COND_REGISTER_NAMED_T_NOARGS(cond, BlockCipher, type, name, provider, pref) + +#if defined(BOTAN_HAS_AES) +BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(AES_128, "AES-128"); +BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(AES_192, "AES-192"); +BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(AES_256, "AES-256"); +#endif + +#if defined(BOTAN_HAS_AES_NI) +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_aes_ni(), AES_128_NI, "AES-128", "aes_ni", 200); +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_aes_ni(), AES_192_NI, "AES-192", "aes_ni", 200); +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_aes_ni(), AES_256_NI, "AES-256", "aes_ni", 200); +#endif + +#if defined(BOTAN_HAS_AES_SSSE3) +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_ssse3(), AES_128_SSSE3, "AES-128", + "ssse3", BOTAN_SIMD_ALGORITHM_PRIO); +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_ssse3(), AES_192_SSSE3, "AES-192", + "ssse3", BOTAN_SIMD_ALGORITHM_PRIO); +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_ssse3(), AES_256_SSSE3, "AES-256", + "ssse3", BOTAN_SIMD_ALGORITHM_PRIO); +#endif + +#if defined(BOTAN_HAS_BLOWFISH) +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(Blowfish); +#endif + +#if defined(BOTAN_HAS_CAMELLIA) +BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(Camellia_128, "Camellia-128"); +BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(Camellia_192, "Camellia-192"); +BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(Camellia_256, "Camellia-256"); +#endif + +#if defined(BOTAN_HAS_CAST) +BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(CAST_128, "CAST-128"); +BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(CAST_256, "CAST-256"); +#endif + +#if defined(BOTAN_HAS_DES) +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(DES); +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(TripleDES); +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(DESX); +#endif + +#if defined(BOTAN_HAS_GOST_28147_89) +BOTAN_REGISTER_BLOCK_CIPHER_NAMED_1STR(GOST_28147_89, "GOST-28147-89", "R3411_94_TestParam"); +#endif + +#if defined(BOTAN_HAS_IDEA) +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(IDEA); +#endif + +#if defined(BOTAN_HAS_IDEA_SSE2) +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_sse2(), IDEA_SSE2, "IDEA", + "sse2", BOTAN_SIMD_ALGORITHM_PRIO); +#endif + +#if defined(BOTAN_HAS_KASUMI) +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(KASUMI); +#endif + +#if defined(BOTAN_HAS_MARS) +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(MARS); +#endif + +#if defined(BOTAN_HAS_MISTY1) +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(MISTY1); +#endif + +#if defined(BOTAN_HAS_NOEKEON) +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(Noekeon); +#endif + +#if defined(BOTAN_HAS_NOEKEON_SIMD) +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(SIMD_32::enabled(), Noekeon_SIMD, "Noekeon", + "simd32", BOTAN_SIMD_ALGORITHM_PRIO); +#endif + +#if defined(BOTAN_HAS_RC2) +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(RC2); +#endif + +#if defined(BOTAN_HAS_RC5) +BOTAN_REGISTER_BLOCK_CIPHER_1LEN(RC5, 12); +#endif + +#if defined(BOTAN_HAS_RC6) +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(RC6); +#endif + +#if defined(BOTAN_HAS_SAFER) +BOTAN_REGISTER_BLOCK_CIPHER_NAMED_1LEN(SAFER_SK, "SAFER-SK", 10); +#endif + +#if defined(BOTAN_HAS_SEED) +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(SEED); +#endif + +#if defined(BOTAN_HAS_SERPENT) +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(Serpent); +#endif + +#if defined(BOTAN_HAS_SERPENT_SIMD) +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(SIMD_32::enabled(), Serpent_SIMD, "Serpent", + "simd32", BOTAN_SIMD_ALGORITHM_PRIO); +#endif + +#if defined(BOTAN_HAS_TEA) +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(TEA); +#endif + +#if defined(BOTAN_HAS_TWOFISH) +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(Twofish); +#endif + +#if defined(BOTAN_HAS_THREEFISH_512) +BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(Threefish_512, "Threefish-512"); +#endif + +#if defined(BOTAN_HAS_THREEFISH_512_AVX2) +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_avx2(), Threefish_512_AVX2, "Threefish-512", + "avx2", BOTAN_SIMD_ALGORITHM_PRIO); +#endif + +#if defined(BOTAN_HAS_XTEA) +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(XTEA); +#endif + +#if defined(BOTAN_HAS_XTEA_SIMD) +BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(SIMD_32::enabled(), XTEA_SIMD, "XTEA", + "simd32", BOTAN_SIMD_ALGORITHM_PRIO); +#endif + +#if defined(BOTAN_HAS_CASCADE) +BOTAN_REGISTER_NAMED_T(BlockCipher, "Cascade", Cascade_Cipher, Cascade_Cipher::make); +#endif + +#if defined(BOTAN_HAS_LION) +BOTAN_REGISTER_NAMED_T(BlockCipher, "Lion", Lion, Lion::make); +#endif + +} diff --git a/src/lib/block/block_cipher.h b/src/lib/block/block_cipher.h index 08bf18fd3..0f4c2c1c5 100644 --- a/src/lib/block/block_cipher.h +++ b/src/lib/block/block_cipher.h @@ -22,6 +22,19 @@ class BOTAN_DLL BlockCipher : public SymmetricAlgorithm typedef SCAN_Name Spec; /** + * Create an instance based on a name + * Will return a null pointer if the algo/provider combination cannot + * be found. If provider is empty then best available is chosen. + */ + static std::unique_ptr<BlockCipher> create(const std::string& algo_spec, + const std::string& provider = ""); + + /** + * Returns the list of available providers for this algorithm, empty if not available + */ + static std::vector<std::string> providers(const std::string& algo_spec); + + /** * @return block size of this algorithm */ virtual size_t block_size() const = 0; @@ -141,6 +154,8 @@ class BOTAN_DLL BlockCipher : public SymmetricAlgorithm * @return new object representing the same algorithm as *this */ virtual BlockCipher* clone() const = 0; + + virtual ~BlockCipher(); }; /** diff --git a/src/lib/block/block_utils.h b/src/lib/block/block_utils.h deleted file mode 100644 index 89f8a3dd3..000000000 --- a/src/lib/block/block_utils.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -* Block Cipher Utility Header -* (C) 2015 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#ifndef BOTAN_BLOCK_CIPHER_UTILS_H__ -#define BOTAN_BLOCK_CIPHER_UTILS_H__ - -#include <botan/block_cipher.h> -#include <botan/internal/algo_registry.h> -#include <botan/loadstor.h> -#include <botan/rotate.h> -#include <botan/internal/xor_buf.h> -#include <algorithm> -#include <functional> - -namespace Botan { - -#define BOTAN_REGISTER_BLOCK_CIPHER(name, maker) BOTAN_REGISTER_T(BlockCipher, name, maker) -#define BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(name) BOTAN_REGISTER_T_NOARGS(BlockCipher, name) - -#define BOTAN_REGISTER_BLOCK_CIPHER_1LEN(name, def) BOTAN_REGISTER_T_1LEN(BlockCipher, name, def) - -#define BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(type, name) \ - BOTAN_REGISTER_NAMED_T(BlockCipher, name, type, make_new_T<type>) -#define BOTAN_REGISTER_BLOCK_CIPHER_NAMED_1LEN(type, name, def) \ - BOTAN_REGISTER_NAMED_T(BlockCipher, name, type, (make_new_T_1len<type,def>)) -#define BOTAN_REGISTER_BLOCK_CIPHER_NAMED_1STR(type, name, def) \ - BOTAN_REGISTER_NAMED_T(BlockCipher, name, type, std::bind(make_new_T_1str<type>, std::placeholders::_1, def)) - -#define BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(cond, type, name, provider, pref) \ - BOTAN_COND_REGISTER_NAMED_T_NOARGS(cond, BlockCipher, type, name, provider, pref) - -} - -#endif diff --git a/src/lib/block/blowfish/blowfish.cpp b/src/lib/block/blowfish/blowfish.cpp index 63838929d..2488838c3 100644 --- a/src/lib/block/blowfish/blowfish.cpp +++ b/src/lib/block/blowfish/blowfish.cpp @@ -5,13 +5,11 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/blowfish.h> +#include <botan/loadstor.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(Blowfish); - /* * Blowfish Encryption */ diff --git a/src/lib/block/camellia/camellia.cpp b/src/lib/block/camellia/camellia.cpp index 887878910..dc57e26bc 100644 --- a/src/lib/block/camellia/camellia.cpp +++ b/src/lib/block/camellia/camellia.cpp @@ -5,16 +5,12 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/camellia.h> #include <botan/internal/camellia_sbox.h> +#include <botan/loadstor.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(Camellia_128, "Camellia-128"); -BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(Camellia_192, "Camellia-192"); -BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(Camellia_256, "Camellia-256"); - namespace Camellia_F { namespace { diff --git a/src/lib/block/cascade/cascade.cpp b/src/lib/block/cascade/cascade.cpp index 3b59a4362..100fb33ab 100644 --- a/src/lib/block/cascade/cascade.cpp +++ b/src/lib/block/cascade/cascade.cpp @@ -5,17 +5,14 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/cascade.h> namespace Botan { -BOTAN_REGISTER_NAMED_T(BlockCipher, "Cascade", Cascade_Cipher, Cascade_Cipher::make); - Cascade_Cipher* Cascade_Cipher::make(const BlockCipher::Spec& spec) { - std::unique_ptr<BlockCipher> c1(get_block_cipher(spec.arg(0))); - std::unique_ptr<BlockCipher> c2(get_block_cipher(spec.arg(1))); + std::unique_ptr<BlockCipher> c1(BlockCipher::create(spec.arg(0))); + std::unique_ptr<BlockCipher> c2(BlockCipher::create(spec.arg(1))); if(c1 && c2) return new Cascade_Cipher(c1.release(), c2.release()); diff --git a/src/lib/block/cast/cast128.cpp b/src/lib/block/cast/cast128.cpp index e19c6dcb1..3973418a3 100644 --- a/src/lib/block/cast/cast128.cpp +++ b/src/lib/block/cast/cast128.cpp @@ -5,14 +5,12 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/cast128.h> #include <botan/internal/cast_sboxes.h> +#include <botan/loadstor.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(CAST_128, "CAST-128"); - namespace { /* diff --git a/src/lib/block/cast/cast256.cpp b/src/lib/block/cast/cast256.cpp index bbb9894e7..7178dc5c1 100644 --- a/src/lib/block/cast/cast256.cpp +++ b/src/lib/block/cast/cast256.cpp @@ -5,14 +5,12 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/cast256.h> #include <botan/internal/cast_sboxes.h> +#include <botan/loadstor.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(CAST_256, "CAST-256"); - namespace { /* diff --git a/src/lib/block/des/des.cpp b/src/lib/block/des/des.cpp index c1013b9af..6d2bcfe1e 100644 --- a/src/lib/block/des/des.cpp +++ b/src/lib/block/des/des.cpp @@ -8,14 +8,11 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/des.h> +#include <botan/loadstor.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(DES); -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(TripleDES); - namespace { /* diff --git a/src/lib/block/des/desx.cpp b/src/lib/block/des/desx.cpp index 0e19460fc..f6538748c 100644 --- a/src/lib/block/des/desx.cpp +++ b/src/lib/block/des/desx.cpp @@ -5,13 +5,10 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/desx.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(DESX); - /* * DESX Encryption */ diff --git a/src/lib/block/gost_28147/gost_28147.cpp b/src/lib/block/gost_28147/gost_28147.cpp index 90bf9328d..b8c3b7280 100644 --- a/src/lib/block/gost_28147/gost_28147.cpp +++ b/src/lib/block/gost_28147/gost_28147.cpp @@ -5,13 +5,11 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/gost_28147.h> +#include <botan/loadstor.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NAMED_1STR(GOST_28147_89, "GOST-28147-89", "R3411_94_TestParam"); - byte GOST_28147_89_Params::sbox_entry(size_t row, size_t col) const { byte x = sboxes[4 * col + (row / 2)]; diff --git a/src/lib/block/idea/idea.cpp b/src/lib/block/idea/idea.cpp index 764115013..ddfd8e5fb 100644 --- a/src/lib/block/idea/idea.cpp +++ b/src/lib/block/idea/idea.cpp @@ -5,13 +5,11 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/idea.h> +#include <botan/loadstor.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(IDEA); - namespace { /* diff --git a/src/lib/block/idea_sse2/idea_sse2.cpp b/src/lib/block/idea_sse2/idea_sse2.cpp index 8549d74d7..a2a54ac32 100644 --- a/src/lib/block/idea_sse2/idea_sse2.cpp +++ b/src/lib/block/idea_sse2/idea_sse2.cpp @@ -5,16 +5,12 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/idea_sse2.h> #include <botan/cpuid.h> #include <emmintrin.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_sse2(), IDEA_SSE2, "IDEA", - "sse2", BOTAN_SIMD_ALGORITHM_PRIO); - namespace { inline __m128i mul(__m128i X, u16bit K_16) diff --git a/src/lib/block/info.txt b/src/lib/block/info.txt index e1aa52d85..30f7392ef 100644 --- a/src/lib/block/info.txt +++ b/src/lib/block/info.txt @@ -3,7 +3,3 @@ define BLOCK_CIPHER 20131128 <header:public> block_cipher.h </header:public> - -<header:internal> -block_utils.h -</header:internal> diff --git a/src/lib/block/kasumi/kasumi.cpp b/src/lib/block/kasumi/kasumi.cpp index d0233cf5c..604d2d21a 100644 --- a/src/lib/block/kasumi/kasumi.cpp +++ b/src/lib/block/kasumi/kasumi.cpp @@ -5,13 +5,11 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/kasumi.h> +#include <botan/loadstor.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(KASUMI); - namespace { /* diff --git a/src/lib/block/lion/lion.cpp b/src/lib/block/lion/lion.cpp index a487e3eb0..559816aea 100644 --- a/src/lib/block/lion/lion.cpp +++ b/src/lib/block/lion/lion.cpp @@ -5,20 +5,17 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/lion.h> #include <botan/parsing.h> namespace Botan { -namespace { - -Lion* make_lion(const BlockCipher::Spec& spec) +Lion* Lion::make(const BlockCipher::Spec& spec) { if(spec.arg_count_between(2, 3)) { - std::unique_ptr<HashFunction> hash(get_hash_function(spec.arg(0))); - std::unique_ptr<StreamCipher> stream(get_stream_cipher(spec.arg(1))); + std::unique_ptr<HashFunction> hash(HashFunction::create(spec.arg(0))); + std::unique_ptr<StreamCipher> stream(StreamCipher::create(spec.arg(1))); if(hash && stream) { @@ -29,10 +26,6 @@ Lion* make_lion(const BlockCipher::Spec& spec) return nullptr; } -} - -BOTAN_REGISTER_NAMED_T(BlockCipher, "Lion", Lion, make_lion); - /* * Lion Encryption */ diff --git a/src/lib/block/lion/lion.h b/src/lib/block/lion/lion.h index d03d1d1a0..116fa911b 100644 --- a/src/lib/block/lion/lion.h +++ b/src/lib/block/lion/lion.h @@ -39,6 +39,8 @@ class BOTAN_DLL Lion : public BlockCipher std::string name() const override; BlockCipher* clone() const override; + static Lion* make(const Spec&); + /** * @param hash the hash to use internally * @param cipher the stream cipher to use internally diff --git a/src/lib/block/mars/mars.cpp b/src/lib/block/mars/mars.cpp index 50f264861..becbbf2db 100644 --- a/src/lib/block/mars/mars.cpp +++ b/src/lib/block/mars/mars.cpp @@ -5,13 +5,11 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/mars.h> +#include <botan/loadstor.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(MARS); - namespace { /** diff --git a/src/lib/block/misty1/misty1.cpp b/src/lib/block/misty1/misty1.cpp index 23233e02f..490eec826 100644 --- a/src/lib/block/misty1/misty1.cpp +++ b/src/lib/block/misty1/misty1.cpp @@ -5,14 +5,12 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/misty1.h> +#include <botan/loadstor.h> #include <botan/parsing.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(MISTY1); - namespace { static const byte MISTY1_SBOX_S7[128] = { diff --git a/src/lib/block/noekeon/noekeon.cpp b/src/lib/block/noekeon/noekeon.cpp index fb1a215fe..d63ec3129 100644 --- a/src/lib/block/noekeon/noekeon.cpp +++ b/src/lib/block/noekeon/noekeon.cpp @@ -5,13 +5,11 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/noekeon.h> +#include <botan/loadstor.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(Noekeon); - namespace { /* diff --git a/src/lib/block/noekeon_simd/noekeon_simd.cpp b/src/lib/block/noekeon_simd/noekeon_simd.cpp index a51c6bc8f..07fcf19ff 100644 --- a/src/lib/block/noekeon_simd/noekeon_simd.cpp +++ b/src/lib/block/noekeon_simd/noekeon_simd.cpp @@ -5,15 +5,11 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/noekeon_simd.h> #include <botan/internal/simd_32.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(SIMD_32::enabled(), Noekeon_SIMD, "Noekeon", - "simd32", BOTAN_SIMD_ALGORITHM_PRIO); - /* * Noekeon's Theta Operation */ diff --git a/src/lib/block/rc2/rc2.cpp b/src/lib/block/rc2/rc2.cpp index d1fc8a2e6..bcd8475e3 100644 --- a/src/lib/block/rc2/rc2.cpp +++ b/src/lib/block/rc2/rc2.cpp @@ -5,13 +5,11 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/rc2.h> +#include <botan/loadstor.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(RC2); - /* * RC2 Encryption */ diff --git a/src/lib/block/rc5/rc5.cpp b/src/lib/block/rc5/rc5.cpp index 27fa0e14d..a32efd775 100644 --- a/src/lib/block/rc5/rc5.cpp +++ b/src/lib/block/rc5/rc5.cpp @@ -5,14 +5,12 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/rc5.h> +#include <botan/loadstor.h> #include <botan/parsing.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_1LEN(RC5, 12); - /* * RC5 Encryption */ diff --git a/src/lib/block/rc6/rc6.cpp b/src/lib/block/rc6/rc6.cpp index e9aa5fe8b..48fb1c32e 100644 --- a/src/lib/block/rc6/rc6.cpp +++ b/src/lib/block/rc6/rc6.cpp @@ -5,13 +5,11 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/rc6.h> +#include <botan/loadstor.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(RC6); - /* * RC6 Encryption */ diff --git a/src/lib/block/safer/safer_sk.cpp b/src/lib/block/safer/safer_sk.cpp index f5996a986..a8781697d 100644 --- a/src/lib/block/safer/safer_sk.cpp +++ b/src/lib/block/safer/safer_sk.cpp @@ -5,16 +5,14 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/safer_sk.h> +#include <botan/rotate.h> #include <botan/parsing.h> namespace Botan { namespace { -BOTAN_REGISTER_BLOCK_CIPHER_NAMED_1LEN(SAFER_SK, "SAFER-SK", 10); - const byte EXP[256] = { 0x01, 0x2D, 0xE2, 0x93, 0xBE, 0x45, 0x15, 0xAE, 0x78, 0x03, 0x87, 0xA4, 0xB8, 0x38, 0xCF, 0x3F, 0x08, 0x67, 0x09, 0x94, 0xEB, 0x26, 0xA8, 0x6B, diff --git a/src/lib/block/seed/seed.cpp b/src/lib/block/seed/seed.cpp index 316ef1e04..833f9943f 100644 --- a/src/lib/block/seed/seed.cpp +++ b/src/lib/block/seed/seed.cpp @@ -5,13 +5,11 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/seed.h> +#include <botan/loadstor.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(SEED); - /* * SEED G Function */ diff --git a/src/lib/block/serpent/serpent.cpp b/src/lib/block/serpent/serpent.cpp index b809e602c..c0a65ed33 100644 --- a/src/lib/block/serpent/serpent.cpp +++ b/src/lib/block/serpent/serpent.cpp @@ -5,14 +5,12 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/serpent.h> +#include <botan/loadstor.h> #include <botan/internal/serpent_sbox.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(Serpent); - namespace { /* diff --git a/src/lib/block/serpent_simd/serp_simd.cpp b/src/lib/block/serpent_simd/serp_simd.cpp index 56747dd16..02fe7d6d9 100644 --- a/src/lib/block/serpent_simd/serp_simd.cpp +++ b/src/lib/block/serpent_simd/serp_simd.cpp @@ -5,16 +5,12 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/serp_simd.h> #include <botan/internal/serpent_sbox.h> #include <botan/internal/simd_32.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(SIMD_32::enabled(), Serpent_SIMD, "Serpent", - "simd32", BOTAN_SIMD_ALGORITHM_PRIO); - namespace { #define key_xor(round, B0, B1, B2, B3) \ diff --git a/src/lib/block/tea/tea.cpp b/src/lib/block/tea/tea.cpp index ef630f715..01f342607 100644 --- a/src/lib/block/tea/tea.cpp +++ b/src/lib/block/tea/tea.cpp @@ -5,13 +5,11 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/tea.h> +#include <botan/loadstor.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(TEA); - /* * TEA Encryption */ diff --git a/src/lib/block/threefish/threefish.cpp b/src/lib/block/threefish/threefish.cpp index 322f54881..93fd122c2 100644 --- a/src/lib/block/threefish/threefish.cpp +++ b/src/lib/block/threefish/threefish.cpp @@ -5,13 +5,11 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/threefish.h> +#include <botan/loadstor.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NAMED_NOARGS(Threefish_512, "Threefish-512"); - #define THREEFISH_ROUND(X0,X1,X2,X3,X4,X5,X6,X7,ROT1,ROT2,ROT3,ROT4) \ do { \ X0 += X4; \ diff --git a/src/lib/block/threefish_avx2/threefish_avx2.cpp b/src/lib/block/threefish_avx2/threefish_avx2.cpp index 435c75dbf..bed98fafa 100644 --- a/src/lib/block/threefish_avx2/threefish_avx2.cpp +++ b/src/lib/block/threefish_avx2/threefish_avx2.cpp @@ -5,16 +5,12 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/threefish_avx2.h> #include <botan/cpuid.h> #include <immintrin.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(CPUID::has_avx2(), Threefish_512_AVX2, "Threefish-512", - "avx2", BOTAN_SIMD_ALGORITHM_PRIO); - namespace { inline void interleave_epi64(__m256i& X0, __m256i& X1) diff --git a/src/lib/block/twofish/twofish.cpp b/src/lib/block/twofish/twofish.cpp index 43ea41bfd..ffdf4b198 100644 --- a/src/lib/block/twofish/twofish.cpp +++ b/src/lib/block/twofish/twofish.cpp @@ -8,13 +8,12 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/twofish.h> +#include <botan/loadstor.h> +#include <botan/rotate.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(Twofish); - /* * Twofish Encryption */ diff --git a/src/lib/block/xtea/xtea.cpp b/src/lib/block/xtea/xtea.cpp index 9fe265457..59060dff7 100644 --- a/src/lib/block/xtea/xtea.cpp +++ b/src/lib/block/xtea/xtea.cpp @@ -5,13 +5,11 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/xtea.h> +#include <botan/loadstor.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(XTEA); - namespace { void xtea_encrypt_4(const byte in[32], byte out[32], const u32bit EK[64]) diff --git a/src/lib/block/xtea_simd/xtea_simd.cpp b/src/lib/block/xtea_simd/xtea_simd.cpp index a9984ce23..6e50f4ff7 100644 --- a/src/lib/block/xtea_simd/xtea_simd.cpp +++ b/src/lib/block/xtea_simd/xtea_simd.cpp @@ -5,15 +5,11 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/internal/block_utils.h> #include <botan/xtea_simd.h> #include <botan/internal/simd_32.h> namespace Botan { -BOTAN_REGISTER_BLOCK_CIPHER_NOARGS_IF(SIMD_32::enabled(), XTEA_SIMD, "XTEA", - "simd32", BOTAN_SIMD_ALGORITHM_PRIO); - namespace { void xtea_encrypt_8(const byte in[64], byte out[64], const u32bit EK[64]) |