diff options
Diffstat (limited to 'src/lib/hash')
26 files changed, 143 insertions, 67 deletions
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 */ |