aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstate/engine
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstate/engine')
-rw-r--r--src/libstate/engine/def_engine/def_eng.h7
-rw-r--r--src/libstate/engine/def_engine/lookup_hash.cpp33
-rw-r--r--src/libstate/engine/engine.cpp17
-rw-r--r--src/libstate/engine/engine.h19
-rw-r--r--src/libstate/engine/gnump/eng_gmp.h2
-rw-r--r--src/libstate/engine/openssl/eng_ossl.h7
-rw-r--r--src/libstate/engine/openssl/ossl_md.cpp5
7 files changed, 69 insertions, 21 deletions
diff --git a/src/libstate/engine/def_engine/def_eng.h b/src/libstate/engine/def_engine/def_eng.h
index 377333856..490ef1def 100644
--- a/src/libstate/engine/def_engine/def_eng.h
+++ b/src/libstate/engine/def_engine/def_eng.h
@@ -16,6 +16,8 @@ namespace Botan {
class BOTAN_DLL Default_Engine : public Engine
{
public:
+ std::string provider_name() const { return "core"; }
+
#if defined(BOTAN_HAS_IF_PUBLIC_KEY_FAMILY)
IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&,
const BigInt&, const BigInt&, const BigInt&,
@@ -61,7 +63,10 @@ class BOTAN_DLL Default_Engine : public Engine
private:
BlockCipher* find_block_cipher(const std::string&) const;
StreamCipher* find_stream_cipher(const std::string&) const;
- HashFunction* find_hash(const std::string&) const;
+
+ HashFunction* find_hash(const SCAN_Name& requst,
+ Algorithm_Factory&) const;
+
MessageAuthenticationCode* find_mac(const std::string&) const;
};
diff --git a/src/libstate/engine/def_engine/lookup_hash.cpp b/src/libstate/engine/def_engine/lookup_hash.cpp
index 78f084395..55ee922f9 100644
--- a/src/libstate/engine/def_engine/lookup_hash.cpp
+++ b/src/libstate/engine/def_engine/lookup_hash.cpp
@@ -4,8 +4,8 @@
*************************************************/
#include <botan/def_eng.h>
-#include <botan/lookup.h>
#include <botan/scan_name.h>
+#include <botan/algo_factory.h>
#include <memory>
#if defined(BOTAN_HAS_ADLER32)
@@ -95,10 +95,9 @@ namespace Botan {
* Look for an algorithm with this name *
*************************************************/
HashFunction*
-Default_Engine::find_hash(const std::string& algo_spec) const
+Default_Engine::find_hash(const SCAN_Name& request,
+ Algorithm_Factory& af) const
{
- SCAN_Name request(algo_spec);
-
#if defined(BOTAN_HAS_ADLER32)
if(request.algo_name() == "Adler32")
return new Adler32;
@@ -192,15 +191,33 @@ Default_Engine::find_hash(const std::string& algo_spec) const
#endif
#if defined(BOTAN_HAS_PARALLEL_HASH)
- if(request.algo_name() == "Parallel" && request.arg_count() > 0)
+
+ if(request.algo_name() == "Parallel")
{
- std::vector<HashFunction*> hashes;
+ 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)
+ {
+ SCAN_Name hash_request(request.argument(i),
+ request.providers_string());
- for(u32bit i = 0; i != request.arg_count(); ++i)
- hashes.push_back(get_hash(request.argument(i)));
+ const HashFunction* hash = af.prototype_hash_function(hash_request);
+ if(!hash)
+ return 0;
+
+ 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
return 0;
diff --git a/src/libstate/engine/engine.cpp b/src/libstate/engine/engine.cpp
index c55ff2a78..cbc2c9599 100644
--- a/src/libstate/engine/engine.cpp
+++ b/src/libstate/engine/engine.cpp
@@ -84,10 +84,21 @@ const StreamCipher* Engine::stream_cipher(const std::string& name) const
/*************************************************
* Acquire a HashFunction *
*************************************************/
-const HashFunction* Engine::hash(const std::string& name) const
+const HashFunction*
+Engine::prototype_hash_function(const SCAN_Name& request,
+ Algorithm_Factory& af) const
{
- return lookup_algo(cache_of_hf, global_state().deref_alias(name),
- this, &Engine::find_hash);
+ // This needs to respect provider settings
+ HashFunction* algo = cache_of_hf->get(request.as_string());
+ if(algo)
+ return algo;
+
+ // cache miss: do full search
+ algo = find_hash(request, af);
+ if(algo)
+ cache_of_hf->add(algo, request.as_string());
+
+ return algo;
}
/*************************************************
diff --git a/src/libstate/engine/engine.h b/src/libstate/engine/engine.h
index 9e83ce97f..0f61fe1e2 100644
--- a/src/libstate/engine/engine.h
+++ b/src/libstate/engine/engine.h
@@ -6,14 +6,14 @@
#ifndef BOTAN_ENGINE_H__
#define BOTAN_ENGINE_H__
+#include <botan/scan_name.h>
+#include <botan/mutex.h>
+
#include <botan/block_cipher.h>
#include <botan/stream_cipher.h>
#include <botan/hash.h>
#include <botan/mac.h>
-#include <botan/mutex.h>
-#include <botan/pow_mod.h>
-#include <botan/basefilt.h>
#include <utility>
#include <map>
@@ -49,6 +49,10 @@
namespace Botan {
+class Algorithm_Factory;
+class Keyed_Filter;
+class Modular_Exponentiator;
+
/*************************************************
* Engine Base Class *
*************************************************/
@@ -117,7 +121,10 @@ class BOTAN_DLL Engine
const BlockCipher* block_cipher(const std::string&) const;
const StreamCipher* stream_cipher(const std::string&) const;
- const HashFunction* hash(const std::string&) const;
+
+ const HashFunction* prototype_hash_function(const SCAN_Name& request,
+ Algorithm_Factory& af) const;
+
const MessageAuthenticationCode* mac(const std::string&) const;
virtual bool can_add_algorithms() { return false; }
@@ -127,6 +134,8 @@ class BOTAN_DLL Engine
void add_algorithm(HashFunction*) const;
void add_algorithm(MessageAuthenticationCode*) const;
+ virtual std::string provider_name() const = 0;
+
Engine();
virtual ~Engine();
private:
@@ -136,7 +145,7 @@ class BOTAN_DLL Engine
virtual StreamCipher* find_stream_cipher(const std::string&) const
{ return 0; }
- virtual HashFunction* find_hash(const std::string&) const
+ virtual HashFunction* find_hash(const SCAN_Name&, Algorithm_Factory&) const
{ return 0; }
virtual MessageAuthenticationCode* find_mac(const std::string&) const
diff --git a/src/libstate/engine/gnump/eng_gmp.h b/src/libstate/engine/gnump/eng_gmp.h
index a0ff2661c..8edaae374 100644
--- a/src/libstate/engine/gnump/eng_gmp.h
+++ b/src/libstate/engine/gnump/eng_gmp.h
@@ -16,6 +16,8 @@ namespace Botan {
class BOTAN_DLL GMP_Engine : public Engine
{
public:
+ std::string provider_name() const { return "gmp"; }
+
#if defined(BOTAN_HAS_IF_PUBLIC_KEY_FAMILY)
IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&,
const BigInt&, const BigInt&, const BigInt&,
diff --git a/src/libstate/engine/openssl/eng_ossl.h b/src/libstate/engine/openssl/eng_ossl.h
index c63179459..6eb5700d6 100644
--- a/src/libstate/engine/openssl/eng_ossl.h
+++ b/src/libstate/engine/openssl/eng_ossl.h
@@ -16,6 +16,11 @@ namespace Botan {
class BOTAN_DLL OpenSSL_Engine : public Engine
{
public:
+ /**
+ * Return the provider name ("openssl")
+ */
+ std::string provider_name() const { return "openssl"; }
+
#if defined(BOTAN_HAS_IF_PUBLIC_KEY_FAMILY)
IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&,
const BigInt&, const BigInt&, const BigInt&,
@@ -45,7 +50,7 @@ class BOTAN_DLL OpenSSL_Engine : public Engine
private:
BlockCipher* find_block_cipher(const std::string&) const;
StreamCipher* find_stream_cipher(const std::string&) const;
- HashFunction* find_hash(const std::string&) const;
+ HashFunction* find_hash(const SCAN_Name&, Algorithm_Factory&) const;
};
}
diff --git a/src/libstate/engine/openssl/ossl_md.cpp b/src/libstate/engine/openssl/ossl_md.cpp
index d009e4c42..04ef59f99 100644
--- a/src/libstate/engine/openssl/ossl_md.cpp
+++ b/src/libstate/engine/openssl/ossl_md.cpp
@@ -91,10 +91,9 @@ EVP_HashFunction::~EVP_HashFunction()
/*************************************************
* Look for an algorithm with this name *
*************************************************/
-HashFunction* OpenSSL_Engine::find_hash(const std::string& algo_spec) const
+HashFunction* OpenSSL_Engine::find_hash(const SCAN_Name& request,
+ Algorithm_Factory&) const
{
- SCAN_Name request(algo_spec);
-
if(request.algo_name() == "SHA-160")
return new EVP_HashFunction(EVP_sha1(), "SHA-160");