aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2015-01-28 06:20:39 +0000
committerlloyd <[email protected]>2015-01-28 06:20:39 +0000
commit710229be83cdbc061949c61942896b5af9e134d8 (patch)
tree5a28c6d2cd456a5a686a332b7466ed9f326cc5f8
parent7b56f1bd570dc684ffd7c945dee0d9b5480354ff (diff)
Use Algo_Registry also for hashes.
-rw-r--r--src/lib/algo_base/algo_registry.h10
-rw-r--r--src/lib/block/cascade/cascade.cpp9
-rw-r--r--src/lib/block/cascade/cascade.h2
-rw-r--r--src/lib/block/serpent_x86_32/serp_x86_32.cpp2
-rw-r--r--src/lib/checksum/adler32/adler32.cpp4
-rw-r--r--src/lib/checksum/crc24/crc24.cpp3
-rw-r--r--src/lib/checksum/crc32/crc32.cpp4
-rw-r--r--src/lib/engine/asm_engine/asm_engine.cpp53
-rw-r--r--src/lib/engine/core_engine/lookup_hash.cpp212
-rw-r--r--src/lib/engine/simd_engine/simd_engine.cpp12
-rw-r--r--src/lib/hash/comb4p/comb4p.cpp17
-rw-r--r--src/lib/hash/comb4p/comb4p.h2
-rw-r--r--src/lib/hash/gost_3411/gost_3411.cpp5
-rw-r--r--src/lib/hash/has160/has160.cpp5
-rw-r--r--src/lib/hash/hash.h3
-rw-r--r--src/lib/hash/info.txt8
-rw-r--r--src/lib/hash/keccak/keccak.cpp5
-rw-r--r--src/lib/hash/md2/md2.cpp3
-rw-r--r--src/lib/hash/md4/md4.cpp5
-rw-r--r--src/lib/hash/md4_x86_32/md4_x86_32.cpp3
-rw-r--r--src/lib/hash/md5/md5.cpp5
-rw-r--r--src/lib/hash/md5_x86_32/md5_x86_32.cpp3
-rw-r--r--src/lib/hash/par_hash/par_hash.cpp75
-rw-r--r--src/lib/hash/par_hash/par_hash.h8
-rw-r--r--src/lib/hash/rmd128/rmd128.cpp5
-rw-r--r--src/lib/hash/rmd160/rmd160.cpp5
-rw-r--r--src/lib/hash/sha1/sha160.cpp5
-rw-r--r--src/lib/hash/sha1_sse2/sha1_sse2.cpp10
-rw-r--r--src/lib/hash/sha1_x86_32/sha1_x86_32.cpp3
-rw-r--r--src/lib/hash/sha1_x86_64/sha1_x86_64.cpp3
-rw-r--r--src/lib/hash/sha2_32/sha2_32.cpp6
-rw-r--r--src/lib/hash/sha2_64/sha2_64.cpp7
-rw-r--r--src/lib/hash/skein/skein_512.cpp9
-rw-r--r--src/lib/hash/skein/skein_512.h2
-rw-r--r--src/lib/hash/tiger/tiger.cpp4
-rw-r--r--src/lib/hash/whirlpool/whirlpool.cpp4
36 files changed, 183 insertions, 338 deletions
diff --git a/src/lib/algo_base/algo_registry.h b/src/lib/algo_base/algo_registry.h
index d40e9fc67..8f3bebec7 100644
--- a/src/lib/algo_base/algo_registry.h
+++ b/src/lib/algo_base/algo_registry.h
@@ -119,6 +119,12 @@ make_new_T_1len(const typename Algo_Registry<T>::Spec& spec)
return new T(spec.arg_as_integer(0, DEF_VAL));
}
+template<typename T, size_t DEF1, size_t DEF2> T*
+make_new_T_2len(const typename Algo_Registry<T>::Spec& spec)
+ {
+ return new T(spec.arg_as_integer(0, DEF1), spec.arg_as_integer(1, DEF2));
+ }
+
template<typename T> T*
make_new_T_1str(const typename Algo_Registry<T>::Spec& spec, const std::string& def)
{
@@ -134,8 +140,12 @@ make_new_T_1str(const typename Algo_Registry<T>::Spec& spec, const std::string&
#define BOTAN_REGISTER_T_1LEN(T, name, def) \
namespace { Algo_Registry<T>::Add g_ ## name ## _reg(#name, make_new_T_1len<name, def>); }
+#define BOTAN_REGISTER_NAMED_T_NOARGS(T, type, name, provider) \
+ namespace { Algo_Registry<T>::Add g_ ## type ## _reg(name, make_new_T<type>, provider); }
#define BOTAN_COND_REGISTER_NAMED_T_NOARGS(cond, T, type, name, provider) \
namespace { Algo_Registry<T>::Add g_ ## type ## _reg(cond, name, make_new_T<type>, provider); }
+#define BOTAN_REGISTER_NAMED_T_2LEN(T, type, name, provider, len1, len2) \
+ namespace { Algo_Registry<T>::Add g_ ## type ## _reg(name, make_new_T_2len<type, len1, len2>, provider); }
// TODO move elsewhere:
#define BOTAN_REGISTER_TRANSFORM(name, maker) BOTAN_REGISTER_T(Transform, name, maker)
diff --git a/src/lib/block/cascade/cascade.cpp b/src/lib/block/cascade/cascade.cpp
index 6c0458265..c80bfbc68 100644
--- a/src/lib/block/cascade/cascade.cpp
+++ b/src/lib/block/cascade/cascade.cpp
@@ -6,14 +6,13 @@
*/
#include <botan/internal/block_utils.h>
-#include <botan/algo_registry.h>
#include <botan/cascade.h>
namespace Botan {
-namespace {
+BOTAN_REGISTER_NAMED_T(BlockCipher, "Cascade", Cascade_Cipher, Cascade_Cipher::make);
-Cascade_Cipher* make_cascade(const BlockCipher::Spec& spec)
+Cascade_Cipher* Cascade_Cipher::make(const BlockCipher::Spec& spec)
{
auto& block_cipher = Algo_Registry<BlockCipher>::global_registry();
std::unique_ptr<BlockCipher> c1(block_cipher.make(spec.arg(0)));
@@ -24,10 +23,6 @@ Cascade_Cipher* make_cascade(const BlockCipher::Spec& spec)
return nullptr;
}
-}
-
-BOTAN_REGISTER_NAMED_T(BlockCipher, "Cascade", Cascade_Cipher, make_cascade);
-
void Cascade_Cipher::encrypt_n(const byte in[], byte out[],
size_t blocks) const
{
diff --git a/src/lib/block/cascade/cascade.h b/src/lib/block/cascade/cascade.h
index 440f5c8f4..e96c34549 100644
--- a/src/lib/block/cascade/cascade.h
+++ b/src/lib/block/cascade/cascade.h
@@ -33,6 +33,8 @@ class BOTAN_DLL Cascade_Cipher : public BlockCipher
std::string name() const;
BlockCipher* clone() const;
+ static Cascade_Cipher* make(const Spec& spec);
+
/**
* Create a cascade of two block ciphers
* @param cipher1 the first cipher
diff --git a/src/lib/block/serpent_x86_32/serp_x86_32.cpp b/src/lib/block/serpent_x86_32/serp_x86_32.cpp
index 3c326d084..7e52a5118 100644
--- a/src/lib/block/serpent_x86_32/serp_x86_32.cpp
+++ b/src/lib/block/serpent_x86_32/serp_x86_32.cpp
@@ -10,7 +10,7 @@
namespace Botan {
-BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(Serpent_X86_32, "Serpent", "x86-32");
+BOTAN_REGISTER_NAMED_T_NOARGS(BlockCipher, Serpent_X86_32, "Serpent", "x86-32");
extern "C" {
diff --git a/src/lib/checksum/adler32/adler32.cpp b/src/lib/checksum/adler32/adler32.cpp
index f368b627c..f2385c5b8 100644
--- a/src/lib/checksum/adler32/adler32.cpp
+++ b/src/lib/checksum/adler32/adler32.cpp
@@ -5,11 +5,13 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
+#include <botan/internal/hash_utils.h>
#include <botan/adler32.h>
-#include <botan/loadstor.h>
namespace Botan {
+BOTAN_REGISTER_HASH_NOARGS(Adler32);
+
namespace {
void adler32_update(const byte input[], size_t length,
diff --git a/src/lib/checksum/crc24/crc24.cpp b/src/lib/checksum/crc24/crc24.cpp
index 4ca942aaa..4f747c232 100644
--- a/src/lib/checksum/crc24/crc24.cpp
+++ b/src/lib/checksum/crc24/crc24.cpp
@@ -5,11 +5,14 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
+#include <botan/internal/hash_utils.h>
#include <botan/crc24.h>
#include <botan/get_byte.h>
namespace Botan {
+BOTAN_REGISTER_HASH_NOARGS(CRC24);
+
/*
* Update a CRC24 Checksum
*/
diff --git a/src/lib/checksum/crc32/crc32.cpp b/src/lib/checksum/crc32/crc32.cpp
index 10d989cc6..cb4ff7b5f 100644
--- a/src/lib/checksum/crc32/crc32.cpp
+++ b/src/lib/checksum/crc32/crc32.cpp
@@ -5,11 +5,13 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
+#include <botan/internal/hash_utils.h>
#include <botan/crc32.h>
-#include <botan/loadstor.h>
namespace Botan {
+BOTAN_REGISTER_HASH_NOARGS(CRC32);
+
/*
* Update a CRC32 Checksum
*/
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;
}
diff --git a/src/lib/hash/comb4p/comb4p.cpp b/src/lib/hash/comb4p/comb4p.cpp
index 194c4613e..4cb08eb0b 100644
--- a/src/lib/hash/comb4p/comb4p.cpp
+++ b/src/lib/hash/comb4p/comb4p.cpp
@@ -5,12 +5,15 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
+#include <botan/internal/hash_utils.h>
#include <botan/comb4p.h>
#include <botan/internal/xor_buf.h>
#include <stdexcept>
namespace Botan {
+BOTAN_REGISTER_NAMED_T(HashFunction, "Comb4P", Comb4P, Comb4P::make);
+
namespace {
void comb4p_round(secure_vector<byte>& out,
@@ -34,6 +37,20 @@ void comb4p_round(secure_vector<byte>& out,
}
+Comb4P* Comb4P::make(const Spec& spec)
+ {
+ if(spec.arg_count() == 2)
+ {
+ auto& hashes = Algo_Registry<HashFunction>::global_registry();
+ std::unique_ptr<HashFunction> h1(hashes.make(spec.arg(0)));
+ std::unique_ptr<HashFunction> h2(hashes.make(spec.arg(1)));
+
+ if(h1 && h2)
+ return new Comb4P(h1.release(), h2.release());
+ }
+ return nullptr;
+ }
+
Comb4P::Comb4P(HashFunction* h1, HashFunction* h2) :
m_hash1(h1), m_hash2(h2)
{
diff --git a/src/lib/hash/comb4p/comb4p.h b/src/lib/hash/comb4p/comb4p.h
index ba745aefa..d2e9587c2 100644
--- a/src/lib/hash/comb4p/comb4p.h
+++ b/src/lib/hash/comb4p/comb4p.h
@@ -32,6 +32,8 @@ class BOTAN_DLL Comb4P : public HashFunction
return m_hash1->output_length() + m_hash2->output_length();
}
+ static Comb4P* make(const Spec& spec);
+
HashFunction* clone() const
{
return new Comb4P(m_hash1->clone(), m_hash2->clone());
diff --git a/src/lib/hash/gost_3411/gost_3411.cpp b/src/lib/hash/gost_3411/gost_3411.cpp
index abe8adb66..ad1ee3b98 100644
--- a/src/lib/hash/gost_3411/gost_3411.cpp
+++ b/src/lib/hash/gost_3411/gost_3411.cpp
@@ -5,13 +5,14 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
+#include <botan/internal/hash_utils.h>
#include <botan/gost_3411.h>
-#include <botan/loadstor.h>
-#include <botan/rotate.h>
#include <botan/internal/xor_buf.h>
namespace Botan {
+BOTAN_REGISTER_HASH_NAMED_NOARGS(GOST_34_11, "GOST-R-34.11-94");
+
/**
* GOST 34.11 Constructor
*/
diff --git a/src/lib/hash/has160/has160.cpp b/src/lib/hash/has160/has160.cpp
index 4510ddbfc..2e6981657 100644
--- a/src/lib/hash/has160/has160.cpp
+++ b/src/lib/hash/has160/has160.cpp
@@ -5,12 +5,13 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
+#include <botan/internal/hash_utils.h>
#include <botan/has160.h>
-#include <botan/loadstor.h>
-#include <botan/rotate.h>
namespace Botan {
+BOTAN_REGISTER_HASH_NAMED_NOARGS(HAS_160, "HAS-160");
+
namespace HAS_160_F {
/*
diff --git a/src/lib/hash/hash.h b/src/lib/hash/hash.h
index 174324c10..9b2ca0d3b 100644
--- a/src/lib/hash/hash.h
+++ b/src/lib/hash/hash.h
@@ -8,6 +8,7 @@
#ifndef BOTAN_HASH_FUNCTION_BASE_CLASS_H__
#define BOTAN_HASH_FUNCTION_BASE_CLASS_H__
+#include <botan/scan_name.h>
#include <botan/buf_comp.h>
#include <string>
@@ -32,6 +33,8 @@ class BOTAN_DLL HashFunction : public Buffered_Computation
* @return hash block size as defined for this algorithm
*/
virtual size_t hash_block_size() const { return 0; }
+
+ typedef SCAN_Name Spec;
};
}
diff --git a/src/lib/hash/info.txt b/src/lib/hash/info.txt
index d991577f7..58ff1b99f 100644
--- a/src/lib/hash/info.txt
+++ b/src/lib/hash/info.txt
@@ -1,3 +1,11 @@
<requires>
algo_base
</requires>
+
+<header:internal>
+hash_utils.h
+</header:internal>
+
+<header:public>
+hash.h
+</header:public>
diff --git a/src/lib/hash/keccak/keccak.cpp b/src/lib/hash/keccak/keccak.cpp
index 67a8ed204..842b199a5 100644
--- a/src/lib/hash/keccak/keccak.cpp
+++ b/src/lib/hash/keccak/keccak.cpp
@@ -5,15 +5,16 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
+#include <botan/internal/hash_utils.h>
#include <botan/keccak.h>
-#include <botan/loadstor.h>
#include <botan/parsing.h>
#include <botan/exceptn.h>
-#include <botan/rotate.h>
#include <botan/internal/xor_buf.h>
namespace Botan {
+BOTAN_REGISTER_HASH_NAMED_1LEN(Keccak_1600, "Keccak-1600", 512);
+
namespace {
void keccak_f_1600(u64bit A[25])
diff --git a/src/lib/hash/md2/md2.cpp b/src/lib/hash/md2/md2.cpp
index 223619ebb..91d8154cf 100644
--- a/src/lib/hash/md2/md2.cpp
+++ b/src/lib/hash/md2/md2.cpp
@@ -5,11 +5,14 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
+#include <botan/internal/hash_utils.h>
#include <botan/md2.h>
#include <botan/internal/xor_buf.h>
namespace Botan {
+BOTAN_REGISTER_HASH_NOARGS(MD2);
+
/**
* MD2 Compression Function
*/
diff --git a/src/lib/hash/md4/md4.cpp b/src/lib/hash/md4/md4.cpp
index 65934bf0b..d9a47315e 100644
--- a/src/lib/hash/md4/md4.cpp
+++ b/src/lib/hash/md4/md4.cpp
@@ -5,12 +5,13 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
+#include <botan/internal/hash_utils.h>
#include <botan/md4.h>
-#include <botan/loadstor.h>
-#include <botan/rotate.h>
namespace Botan {
+BOTAN_REGISTER_HASH_NOARGS(MD4);
+
namespace {
/*
diff --git a/src/lib/hash/md4_x86_32/md4_x86_32.cpp b/src/lib/hash/md4_x86_32/md4_x86_32.cpp
index 6deb75f51..5cf7fd896 100644
--- a/src/lib/hash/md4_x86_32/md4_x86_32.cpp
+++ b/src/lib/hash/md4_x86_32/md4_x86_32.cpp
@@ -5,10 +5,13 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
+#include <botan/internal/hash_utils.h>
#include <botan/md4_x86_32.h>
namespace Botan {
+BOTAN_REGISTER_NAMED_T_NOARGS(HashFunction, MD4_X86_32, "MD4", "x86-32");
+
/**
* MD4 compression function in x86-32 asm
* @param digest the current digest
diff --git a/src/lib/hash/md5/md5.cpp b/src/lib/hash/md5/md5.cpp
index 0808d0140..772e51478 100644
--- a/src/lib/hash/md5/md5.cpp
+++ b/src/lib/hash/md5/md5.cpp
@@ -5,12 +5,13 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
+#include <botan/internal/hash_utils.h>
#include <botan/md5.h>
-#include <botan/loadstor.h>
-#include <botan/rotate.h>
namespace Botan {
+BOTAN_REGISTER_HASH_NOARGS(MD5);
+
namespace {
/*
diff --git a/src/lib/hash/md5_x86_32/md5_x86_32.cpp b/src/lib/hash/md5_x86_32/md5_x86_32.cpp
index ea69b8bcc..40da7fe92 100644
--- a/src/lib/hash/md5_x86_32/md5_x86_32.cpp
+++ b/src/lib/hash/md5_x86_32/md5_x86_32.cpp
@@ -5,10 +5,13 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
+#include <botan/internal/hash_util.h>
#include <botan/md5_x86_32.h>
namespace Botan {
+BOTAN_REGISTER_NAMED_T_NOARGS(HashFunction, MD5_X86_32, "MD5", "x86-32");
+
namespace {
extern "C"
diff --git a/src/lib/hash/par_hash/par_hash.cpp b/src/lib/hash/par_hash/par_hash.cpp
index 437d0c485..c58b01e72 100644
--- a/src/lib/hash/par_hash/par_hash.cpp
+++ b/src/lib/hash/par_hash/par_hash.cpp
@@ -1,100 +1,99 @@
/*
-* Parallel
+* Parallel Hash
* (C) 1999-2009 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
+#include <botan/internal/hash_utils.h>
#include <botan/par_hash.h>
#include <botan/parsing.h>
+#include <botan/algo_registry.h>
namespace Botan {
-/*
-* Update the hash
-*/
+BOTAN_REGISTER_NAMED_T(HashFunction, "Parallel", Parallel, Parallel::make);
+
+Parallel* Parallel::make(const Spec& spec)
+ {
+ auto& hash_fns = Algo_Registry<HashFunction>::global_registry();
+
+ std::vector<std::unique_ptr<HashFunction>> hashes;
+
+ for(size_t i = 0; i != spec.arg_count(); ++i)
+ {
+ std::unique_ptr<HashFunction> h(hash_fns.make(spec.arg(i)));
+
+ if(!h)
+ return nullptr;
+ hashes.push_back(std::move(h));
+ }
+
+ Parallel* p = new Parallel;
+ std::swap(p->hashes, hashes);
+ return p;
+ }
+
void Parallel::add_data(const byte input[], size_t length)
{
- for(auto hash : hashes)
+ for(auto&& hash : hashes)
hash->update(input, length);
}
-/*
-* Finalize the hash
-*/
void Parallel::final_result(byte out[])
{
u32bit offset = 0;
- for(auto hash : hashes)
+ for(auto&& hash : hashes)
{
hash->final(out + offset);
offset += hash->output_length();
}
}
-/*
-* Return output size
-*/
size_t Parallel::output_length() const
{
size_t sum = 0;
- for(auto hash : hashes)
+ for(auto&& hash : hashes)
sum += hash->output_length();
return sum;
}
-/*
-* Return the name of this type
-*/
std::string Parallel::name() const
{
std::vector<std::string> names;
- for(auto hash : hashes)
+ for(auto&& hash : hashes)
names.push_back(hash->name());
return "Parallel(" + string_join(names, ',') + ")";
}
-/*
-* Return a clone of this object
-*/
HashFunction* Parallel::clone() const
{
std::vector<HashFunction*> hash_copies;
- for(auto hash : hashes)
+ for(auto&& hash : hashes)
hash_copies.push_back(hash->clone());
return new Parallel(hash_copies);
}
-/*
-* Clear memory of sensitive data
-*/
void Parallel::clear()
{
- for(auto hash : hashes)
+ for(auto&& hash : hashes)
hash->clear();
}
-/*
-* Parallel Constructor
-*/
-Parallel::Parallel(const std::vector<HashFunction*>& hash_in) :
- hashes(hash_in)
+Parallel::Parallel(const std::vector<HashFunction*>& in)
{
+ for(size_t i = 0; i != in.size(); ++i)
+ {
+ std::unique_ptr<HashFunction> h(in[i]->clone());
+ hashes.push_back(std::move(h));
+ }
}
-/*
-* Parallel Destructor
-*/
-Parallel::~Parallel()
- {
- for(auto hash : hashes)
- delete hash;
- }
}
diff --git a/src/lib/hash/par_hash/par_hash.h b/src/lib/hash/par_hash/par_hash.h
index 189a67437..f67587d16 100644
--- a/src/lib/hash/par_hash/par_hash.h
+++ b/src/lib/hash/par_hash/par_hash.h
@@ -29,11 +29,15 @@ class BOTAN_DLL Parallel : public HashFunction
* @param hashes a set of hashes to compute in parallel
*/
Parallel(const std::vector<HashFunction*>& hashes);
- ~Parallel();
+
+ static Parallel* make(const Spec& spec);
private:
+ Parallel() {}
+
void add_data(const byte[], size_t);
void final_result(byte[]);
- std::vector<HashFunction*> hashes;
+
+ std::vector<std::unique_ptr<HashFunction>> hashes;
};
}
diff --git a/src/lib/hash/rmd128/rmd128.cpp b/src/lib/hash/rmd128/rmd128.cpp
index 6bdf95251..84ac393bb 100644
--- a/src/lib/hash/rmd128/rmd128.cpp
+++ b/src/lib/hash/rmd128/rmd128.cpp
@@ -5,12 +5,13 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
+#include <botan/internal/hash_utils.h>
#include <botan/rmd128.h>
-#include <botan/loadstor.h>
-#include <botan/rotate.h>
namespace Botan {
+BOTAN_REGISTER_HASH_NAMED_NOARGS(RIPEMD_128, "RIPEMD-128");
+
namespace RIPEMD_128_F {
/*
diff --git a/src/lib/hash/rmd160/rmd160.cpp b/src/lib/hash/rmd160/rmd160.cpp
index c88288cab..d58704fa0 100644
--- a/src/lib/hash/rmd160/rmd160.cpp
+++ b/src/lib/hash/rmd160/rmd160.cpp
@@ -5,12 +5,13 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
+#include <botan/internal/hash_utils.h>
#include <botan/rmd160.h>
-#include <botan/loadstor.h>
-#include <botan/rotate.h>
namespace Botan {
+BOTAN_REGISTER_HASH_NAMED_NOARGS(RIPEMD_160, "RIPEMD-160");
+
namespace {
/*
diff --git a/src/lib/hash/sha1/sha160.cpp b/src/lib/hash/sha1/sha160.cpp
index b5741489d..be52d0d57 100644
--- a/src/lib/hash/sha1/sha160.cpp
+++ b/src/lib/hash/sha1/sha160.cpp
@@ -5,12 +5,13 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
+#include <botan/internal/hash_utils.h>
#include <botan/sha160.h>
-#include <botan/loadstor.h>
-#include <botan/rotate.h>
namespace Botan {
+BOTAN_REGISTER_HASH_NAMED_NOARGS(SHA_160, "SHA-160");
+
namespace SHA1_F {
namespace {
diff --git a/src/lib/hash/sha1_sse2/sha1_sse2.cpp b/src/lib/hash/sha1_sse2/sha1_sse2.cpp
index e7684db57..13cd22eeb 100644
--- a/src/lib/hash/sha1_sse2/sha1_sse2.cpp
+++ b/src/lib/hash/sha1_sse2/sha1_sse2.cpp
@@ -1,19 +1,21 @@
/*
* SHA-1 using SSE2
+* Based on public domain code by Dean Gaudet
+* (http://arctic.org/~dean/crypto/sha1.html)
* (C) 2009-2011 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
-*
-* Based on public domain code by Dean Gaudet
-* (http://arctic.org/~dean/crypto/sha1.html)
*/
+#include <botan/internal/hash_utils.h>
#include <botan/sha1_sse2.h>
-#include <botan/rotate.h>
+#include <botan/cpuid.h>
#include <emmintrin.h>
namespace Botan {
+BOTAN_REGISTER_HASH_NOARGS_IF(CPUID::has_sse2(), SHA_160_SSE2, "SHA-160", "sse2");
+
namespace SHA1_SSE2_F {
namespace {
diff --git a/src/lib/hash/sha1_x86_32/sha1_x86_32.cpp b/src/lib/hash/sha1_x86_32/sha1_x86_32.cpp
index 521b055ad..69ce39519 100644
--- a/src/lib/hash/sha1_x86_32/sha1_x86_32.cpp
+++ b/src/lib/hash/sha1_x86_32/sha1_x86_32.cpp
@@ -5,10 +5,13 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
+#include <botan/internal/hash_util.h>
#include <botan/sha1_x86_32.h>
namespace Botan {
+BOTAN_REGISTER_NAMED_T_NOARGS(HashFunction, SHA_160_X86_32, "SHA-160", "x86-32");
+
namespace {
extern "C"
diff --git a/src/lib/hash/sha1_x86_64/sha1_x86_64.cpp b/src/lib/hash/sha1_x86_64/sha1_x86_64.cpp
index 8c8b1c9cf..2f5e063bd 100644
--- a/src/lib/hash/sha1_x86_64/sha1_x86_64.cpp
+++ b/src/lib/hash/sha1_x86_64/sha1_x86_64.cpp
@@ -5,10 +5,13 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
+#include <botan/internal/hash_utils.h>
#include <botan/sha1_x86_64.h>
namespace Botan {
+BOTAN_REGISTER_NAMED_T_NOARGS(HashFunction, SHA_160_X86_64, "SHA-160", "x86-64");
+
namespace {
extern "C"
diff --git a/src/lib/hash/sha2_32/sha2_32.cpp b/src/lib/hash/sha2_32/sha2_32.cpp
index cfdb574d3..b06d485aa 100644
--- a/src/lib/hash/sha2_32/sha2_32.cpp
+++ b/src/lib/hash/sha2_32/sha2_32.cpp
@@ -6,12 +6,14 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
+#include <botan/internal/hash_utils.h>
#include <botan/sha2_32.h>
-#include <botan/loadstor.h>
-#include <botan/rotate.h>
namespace Botan {
+BOTAN_REGISTER_HASH_NAMED_NOARGS(SHA_224, "SHA-224");
+BOTAN_REGISTER_HASH_NAMED_NOARGS(SHA_256, "SHA-256");
+
namespace {
namespace SHA2_32 {
diff --git a/src/lib/hash/sha2_64/sha2_64.cpp b/src/lib/hash/sha2_64/sha2_64.cpp
index 6f42974d6..733cf0f19 100644
--- a/src/lib/hash/sha2_64/sha2_64.cpp
+++ b/src/lib/hash/sha2_64/sha2_64.cpp
@@ -5,12 +5,15 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
+#include <botan/internal/hash_utils.h>
#include <botan/sha2_64.h>
-#include <botan/loadstor.h>
-#include <botan/rotate.h>
namespace Botan {
+BOTAN_REGISTER_HASH_NAMED_NOARGS(SHA_384, "SHA-384");
+BOTAN_REGISTER_HASH_NAMED_NOARGS(SHA_512, "SHA-512");
+BOTAN_REGISTER_HASH_NAMED_NOARGS(SHA_512_256, "SHA-512-256");
+
namespace {
namespace SHA2_64 {
diff --git a/src/lib/hash/skein/skein_512.cpp b/src/lib/hash/skein/skein_512.cpp
index 7d7d876fc..1ade6bbc5 100644
--- a/src/lib/hash/skein/skein_512.cpp
+++ b/src/lib/hash/skein/skein_512.cpp
@@ -5,8 +5,8 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
+#include <botan/internal/hash_utils.h>
#include <botan/skein_512.h>
-#include <botan/loadstor.h>
#include <botan/parsing.h>
#include <botan/exceptn.h>
#include <botan/internal/xor_buf.h>
@@ -14,6 +14,13 @@
namespace Botan {
+BOTAN_REGISTER_NAMED_T(HashFunction, "Skein-512", Skein_512, Skein_512::make);
+
+Skein_512* Skein_512::make(const Spec& spec)
+ {
+ return new Skein_512(spec.arg_as_integer(0, 512), spec.arg(1, ""));
+ }
+
Skein_512::Skein_512(size_t arg_output_bits,
const std::string& arg_personalization) :
personalization(arg_personalization),
diff --git a/src/lib/hash/skein/skein_512.h b/src/lib/hash/skein/skein_512.h
index 06e2e6ccb..0b1ba319d 100644
--- a/src/lib/hash/skein/skein_512.h
+++ b/src/lib/hash/skein/skein_512.h
@@ -32,6 +32,8 @@ class BOTAN_DLL Skein_512 : public HashFunction
size_t hash_block_size() const { return 64; }
size_t output_length() const { return output_bits / 8; }
+ static Skein_512* make(const Spec& spec);
+
HashFunction* clone() const;
std::string name() const;
void clear();
diff --git a/src/lib/hash/tiger/tiger.cpp b/src/lib/hash/tiger/tiger.cpp
index db4d38f0a..d1deb75c9 100644
--- a/src/lib/hash/tiger/tiger.cpp
+++ b/src/lib/hash/tiger/tiger.cpp
@@ -5,13 +5,15 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
+#include <botan/internal/hash_utils.h>
#include <botan/tiger.h>
#include <botan/exceptn.h>
-#include <botan/loadstor.h>
#include <botan/parsing.h>
namespace Botan {
+BOTAN_REGISTER_NAMED_T_2LEN(HashFunction, Tiger, "Tiger", "builtin", 24, 3);
+
namespace {
/*
diff --git a/src/lib/hash/whirlpool/whirlpool.cpp b/src/lib/hash/whirlpool/whirlpool.cpp
index cd4715e57..25b958e6d 100644
--- a/src/lib/hash/whirlpool/whirlpool.cpp
+++ b/src/lib/hash/whirlpool/whirlpool.cpp
@@ -5,11 +5,13 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
+#include <botan/internal/hash_utils.h>
#include <botan/whrlpool.h>
-#include <botan/loadstor.h>
namespace Botan {
+BOTAN_REGISTER_HASH_NOARGS(Whirlpool);
+
/*
* Whirlpool Compression Function
*/