8 #include <botan/algo_factory.h>     9 #include <botan/internal/algo_cache.h>    10 #include <botan/internal/stl_util.h>    11 #include <botan/engine.h>    12 #include <botan/exceptn.h>    14 #include <botan/block_cipher.h>    15 #include <botan/stream_cipher.h>    16 #include <botan/hash.h>    17 #include <botan/mac.h>    18 #include <botan/pbkdf.h>    30 T* engine_get_algo(Engine*,
    36 BlockCipher* engine_get_algo(Engine* engine,
    37                              const SCAN_Name& request,
    38                              Algorithm_Factory& af)
    39    { 
return engine->find_block_cipher(request, af); }
    42 StreamCipher* engine_get_algo(Engine* engine,
    43                               const SCAN_Name& request,
    44                               Algorithm_Factory& af)
    45    { 
return engine->find_stream_cipher(request, af); }
    48 HashFunction* engine_get_algo(Engine* engine,
    49                               const SCAN_Name& request,
    50                               Algorithm_Factory& af)
    51    { 
return engine->find_hash(request, af); }
    54 MessageAuthenticationCode* engine_get_algo(Engine* engine,
    55                                            const SCAN_Name& request,
    56                                            Algorithm_Factory& af)
    57    { 
return engine->find_mac(request, af); }
    60 PBKDF* engine_get_algo(Engine* engine,
    61                        const SCAN_Name& request,
    62                        Algorithm_Factory& af)
    63    { 
return engine->find_pbkdf(request, af); }
    66 const T* factory_prototype(
const std::string& algo_spec,
    67                            const std::string& provider,
    68                            const std::vector<Engine*>& engines,
    69                            Algorithm_Factory& af,
    70                            Algorithm_Cache<T>* cache)
    72    if(
const T* cache_hit = cache->get(algo_spec, provider))
    75    SCAN_Name scan_name(algo_spec);
    77    if(scan_name.cipher_mode() != 
"")
    80    for(
size_t i = 0; i != engines.size(); ++i)
    82       if(provider == 
"" || engines[i]->provider_name() == provider)
    84          if(T* impl = engine_get_algo<T>(engines[i], scan_name, af))
    85             cache->add(impl, algo_spec, engines[i]->provider_name());
    89    return cache->get(algo_spec, provider);
   111    delete block_cipher_cache;
   112    delete stream_cipher_cache;
   122    block_cipher_cache->clear_cache();
   123    stream_cipher_cache->clear_cache();
   124    hash_cache->clear_cache();
   125    mac_cache->clear_cache();
   126    pbkdf_cache->clear_cache();
   132    engines.push_back(engine);
   139                                                const std::string& provider)
   142       block_cipher_cache->set_preferred_provider(algo_spec, provider);
   144       stream_cipher_cache->set_preferred_provider(algo_spec, provider);
   146       hash_cache->set_preferred_provider(algo_spec, provider);
   148       mac_cache->set_preferred_provider(algo_spec, provider);
   150       pbkdf_cache->set_preferred_provider(algo_spec, provider);
   156 Engine* Algorithm_Factory::get_engine_n(
size_t n)
 const   158    if(n >= engines.size())
   167 std::vector<std::string>
   176       return block_cipher_cache->providers_of(algo_spec);
   178       return stream_cipher_cache->providers_of(algo_spec);
   180       return hash_cache->providers_of(algo_spec);
   182       return mac_cache->providers_of(algo_spec);
   184       return pbkdf_cache->providers_of(algo_spec);
   186       return std::vector<std::string>();
   194                                           const std::string& provider)
   196    return factory_prototype<BlockCipher>(algo_spec, provider, engines,
   197                                           *
this, block_cipher_cache);
   205                                            const std::string& provider)
   207    return factory_prototype<StreamCipher>(algo_spec, provider, engines,
   208                                           *
this, stream_cipher_cache);
   216                                            const std::string& provider)
   218    return factory_prototype<HashFunction>(algo_spec, provider, engines,
   227                                  const std::string& provider)
   229    return factory_prototype<MessageAuthenticationCode>(algo_spec, provider,
   239                                    const std::string& provider)
   241    return factory_prototype<PBKDF>(algo_spec, provider,
   251                                      const std::string& provider)
   254       return proto->
clone();
   263                                       const std::string& provider)
   266       return proto->
clone();
   275                                       const std::string& provider)
   278       return proto->
clone();
   287                             const std::string& provider)
   290       return proto->
clone();
   299                               const std::string& provider)
   302       return proto->
clone();
   310                                          const std::string& provider)
   312    block_cipher_cache->add(block_cipher, block_cipher->
name(), provider);
   319                                          const std::string& provider)
   321    stream_cipher_cache->add(stream_cipher, stream_cipher->
name(), provider);
   328                                           const std::string& provider)
   330    hash_cache->add(hash, hash->
name(), provider);
   337                                 const std::string& provider)
   339    mac_cache->add(mac, mac->
name(), provider);
   346                                   const std::string& provider)
   348    pbkdf_cache->add(pbkdf, pbkdf->
name(), provider);
 void add_block_cipher(BlockCipher *algo, const std::string &provider)
const PBKDF * prototype_pbkdf(const std::string &algo_spec, const std::string &provider="")
PBKDF * make_pbkdf(const std::string &algo_spec, const std::string &provider="")
virtual BlockCipher * clone() const =0
const BlockCipher * prototype_block_cipher(const std::string &algo_spec, const std::string &provider="")
void add_stream_cipher(StreamCipher *algo, const std::string &provider)
BlockCipher * make_block_cipher(const std::string &algo_spec, const std::string &provider="")
virtual HashFunction * clone() const =0
void add_hash_function(HashFunction *algo, const std::string &provider)
MessageAuthenticationCode * make_mac(const std::string &algo_spec, const std::string &provider="")
StreamCipher * make_stream_cipher(const std::string &algo_spec, const std::string &provider="")
void add_mac(MessageAuthenticationCode *algo, const std::string &provider)
const HashFunction * prototype_hash_function(const std::string &algo_spec, const std::string &provider="")
virtual std::string name() const =0
const MessageAuthenticationCode * prototype_mac(const std::string &algo_spec, const std::string &provider="")
Algorithm_Factory(Mutex_Factory &mf)
virtual std::string name() const =0
std::vector< std::string > providers_of(const std::string &algo_spec)
HashFunction * make_hash_function(const std::string &algo_spec, const std::string &provider="")
virtual PBKDF * clone() const =0
void add_engine(Engine *engine)
virtual StreamCipher * clone() const =0
virtual MessageAuthenticationCode * clone() const =0
void add_pbkdf(PBKDF *algo, const std::string &provider)
void set_preferred_provider(const std::string &algo_spec, const std::string &provider)
const StreamCipher * prototype_stream_cipher(const std::string &algo_spec, const std::string &provider="")