Botan  1.10.9
Classes | Public Member Functions | Friends | List of all members
Botan::Algorithm_Factory Class Reference

#include <algo_factory.h>

Classes

class  Engine_Iterator
 

Public Member Functions

void add_block_cipher (BlockCipher *algo, const std::string &provider)
 
void add_engine (Engine *engine)
 
void add_hash_function (HashFunction *algo, const std::string &provider)
 
void add_mac (MessageAuthenticationCode *algo, const std::string &provider)
 
void add_pbkdf (PBKDF *algo, const std::string &provider)
 
void add_stream_cipher (StreamCipher *algo, const std::string &provider)
 
 Algorithm_Factory (Mutex_Factory &mf)
 
void clear_caches ()
 
BlockCiphermake_block_cipher (const std::string &algo_spec, const std::string &provider="")
 
HashFunctionmake_hash_function (const std::string &algo_spec, const std::string &provider="")
 
MessageAuthenticationCodemake_mac (const std::string &algo_spec, const std::string &provider="")
 
PBKDFmake_pbkdf (const std::string &algo_spec, const std::string &provider="")
 
StreamCiphermake_stream_cipher (const std::string &algo_spec, const std::string &provider="")
 
const BlockCipherprototype_block_cipher (const std::string &algo_spec, const std::string &provider="")
 
const HashFunctionprototype_hash_function (const std::string &algo_spec, const std::string &provider="")
 
const MessageAuthenticationCodeprototype_mac (const std::string &algo_spec, const std::string &provider="")
 
const PBKDFprototype_pbkdf (const std::string &algo_spec, const std::string &provider="")
 
const StreamCipherprototype_stream_cipher (const std::string &algo_spec, const std::string &provider="")
 
std::vector< std::string > providers_of (const std::string &algo_spec)
 
void set_preferred_provider (const std::string &algo_spec, const std::string &provider)
 
 ~Algorithm_Factory ()
 

Friends

class Engine_Iterator
 

Detailed Description

Algorithm Factory

Definition at line 34 of file algo_factory.h.

Constructor & Destructor Documentation

Botan::Algorithm_Factory::Algorithm_Factory ( Mutex_Factory mf)

Constructor

Parameters
mfa mutex factory

Definition at line 97 of file algo_factory.cpp.

References Botan::Mutex_Factory::make().

98  {
99  block_cipher_cache = new Algorithm_Cache<BlockCipher>(mf.make());
100  stream_cipher_cache = new Algorithm_Cache<StreamCipher>(mf.make());
101  hash_cache = new Algorithm_Cache<HashFunction>(mf.make());
102  mac_cache = new Algorithm_Cache<MessageAuthenticationCode>(mf.make());
103  pbkdf_cache = new Algorithm_Cache<PBKDF>(mf.make());
104  }
Botan::Algorithm_Factory::~Algorithm_Factory ( )

Destructor

Definition at line 109 of file algo_factory.cpp.

110  {
111  delete block_cipher_cache;
112  delete stream_cipher_cache;
113  delete hash_cache;
114  delete mac_cache;
115  delete pbkdf_cache;
116 
117  std::for_each(engines.begin(), engines.end(), del_fun<Engine>());
118  }

Member Function Documentation

void Botan::Algorithm_Factory::add_block_cipher ( BlockCipher algo,
const std::string &  provider 
)
Parameters
algothe algorithm to add
providerthe provider of this algorithm

Definition at line 309 of file algo_factory.cpp.

References Botan::Algorithm::name().

311  {
312  block_cipher_cache->add(block_cipher, block_cipher->name(), provider);
313  }
void Botan::Algorithm_Factory::add_engine ( Engine engine)
Parameters
engineto add (Algorithm_Factory takes ownership)

Definition at line 129 of file algo_factory.cpp.

References clear_caches().

Referenced by Botan::Library_State::initialize().

130  {
131  clear_caches();
132  engines.push_back(engine);
133  }
void Botan::Algorithm_Factory::add_hash_function ( HashFunction algo,
const std::string &  provider 
)
Parameters
algothe algorithm to add
providerthe provider of this algorithm

Definition at line 327 of file algo_factory.cpp.

References Botan::Algorithm::name().

329  {
330  hash_cache->add(hash, hash->name(), provider);
331  }
void Botan::Algorithm_Factory::add_mac ( MessageAuthenticationCode algo,
const std::string &  provider 
)
Parameters
algothe algorithm to add
providerthe provider of this algorithm

Definition at line 336 of file algo_factory.cpp.

References Botan::MessageAuthenticationCode::name().

338  {
339  mac_cache->add(mac, mac->name(), provider);
340  }
MessageAuthenticationCode * mac
Definition: fpe_fe1.cpp:94
void Botan::Algorithm_Factory::add_pbkdf ( PBKDF algo,
const std::string &  provider 
)
Parameters
algothe algorithm to add
providerthe provider of this algorithm

Definition at line 345 of file algo_factory.cpp.

References Botan::Algorithm::name().

347  {
348  pbkdf_cache->add(pbkdf, pbkdf->name(), provider);
349  }
void Botan::Algorithm_Factory::add_stream_cipher ( StreamCipher algo,
const std::string &  provider 
)
Parameters
algothe algorithm to add
providerthe provider of this algorithm

Definition at line 318 of file algo_factory.cpp.

References Botan::Algorithm::name().

320  {
321  stream_cipher_cache->add(stream_cipher, stream_cipher->name(), provider);
322  }
void Botan::Algorithm_Factory::clear_caches ( )

Clear out any cached objects

Definition at line 120 of file algo_factory.cpp.

Referenced by add_engine().

121  {
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();
127  }
BlockCipher * Botan::Algorithm_Factory::make_block_cipher ( const std::string &  algo_spec,
const std::string &  provider = "" 
)
Parameters
algo_specthe algorithm we want
providerthe provider we would like to use
Returns
pointer to freshly created instance of the request algorithm

Definition at line 250 of file algo_factory.cpp.

References Botan::BlockCipher::clone(), and prototype_block_cipher().

Referenced by Botan::Core_Engine::find_mac(), and Botan::get_block_cipher().

252  {
253  if(const BlockCipher* proto = prototype_block_cipher(algo_spec, provider))
254  return proto->clone();
255  throw Algorithm_Not_Found(algo_spec);
256  }
const BlockCipher * prototype_block_cipher(const std::string &algo_spec, const std::string &provider="")
HashFunction * Botan::Algorithm_Factory::make_hash_function ( const std::string &  algo_spec,
const std::string &  provider = "" 
)
Parameters
algo_specthe algorithm we want
providerthe provider we would like to use
Returns
pointer to freshly created instance of the request algorithm

Definition at line 274 of file algo_factory.cpp.

References Botan::HashFunction::clone(), and prototype_hash_function().

Referenced by Botan::Core_Engine::find_mac(), Botan::Core_Engine::find_pbkdf(), Botan::generate_dsa_primes(), Botan::get_eme(), Botan::get_emsa(), Botan::get_hash(), Botan::get_kdf(), and Botan::Hash_Filter::Hash_Filter().

276  {
277  if(const HashFunction* proto = prototype_hash_function(algo_spec, provider))
278  return proto->clone();
279  throw Algorithm_Not_Found(algo_spec);
280  }
const HashFunction * prototype_hash_function(const std::string &algo_spec, const std::string &provider="")
MessageAuthenticationCode * Botan::Algorithm_Factory::make_mac ( const std::string &  algo_spec,
const std::string &  provider = "" 
)
Parameters
algo_specthe algorithm we want
providerthe provider we would like to use
Returns
pointer to freshly created instance of the request algorithm

Definition at line 286 of file algo_factory.cpp.

References Botan::MessageAuthenticationCode::clone(), and prototype_mac().

Referenced by Botan::Core_Engine::find_pbkdf(), Botan::get_mac(), Botan::MAC_Filter::MAC_Filter(), Botan::Record_Writer::set_keys(), and Botan::Record_Reader::set_keys().

288  {
289  if(const MessageAuthenticationCode* proto = prototype_mac(algo_spec, provider))
290  return proto->clone();
291  throw Algorithm_Not_Found(algo_spec);
292  }
const MessageAuthenticationCode * prototype_mac(const std::string &algo_spec, const std::string &provider="")
PBKDF * Botan::Algorithm_Factory::make_pbkdf ( const std::string &  algo_spec,
const std::string &  provider = "" 
)
Parameters
algo_specthe algorithm we want
providerthe provider we would like to use
Returns
pointer to freshly created instance of the request algorithm

Definition at line 298 of file algo_factory.cpp.

References Botan::PBKDF::clone(), and prototype_pbkdf().

Referenced by Botan::get_pbkdf().

300  {
301  if(const PBKDF* proto = prototype_pbkdf(algo_spec, provider))
302  return proto->clone();
303  throw Algorithm_Not_Found(algo_spec);
304  }
const PBKDF * prototype_pbkdf(const std::string &algo_spec, const std::string &provider="")
StreamCipher * Botan::Algorithm_Factory::make_stream_cipher ( const std::string &  algo_spec,
const std::string &  provider = "" 
)
Parameters
algo_specthe algorithm we want
providerthe provider we would like to use
Returns
pointer to freshly created instance of the request algorithm

Definition at line 262 of file algo_factory.cpp.

References Botan::StreamCipher::clone(), and prototype_stream_cipher().

Referenced by Botan::get_stream_cipher(), and Botan::StreamCipher_Filter::StreamCipher_Filter().

264  {
265  if(const StreamCipher* proto = prototype_stream_cipher(algo_spec, provider))
266  return proto->clone();
267  throw Algorithm_Not_Found(algo_spec);
268  }
const StreamCipher * prototype_stream_cipher(const std::string &algo_spec, const std::string &provider="")
const BlockCipher * Botan::Algorithm_Factory::prototype_block_cipher ( const std::string &  algo_spec,
const std::string &  provider = "" 
)
Parameters
algo_specthe algorithm we want
providerthe provider we would like to use
Returns
pointer to const prototype object, ready to clone(), or NULL

Definition at line 193 of file algo_factory.cpp.

Referenced by Botan::algorithm_benchmark(), Botan::algorithm_kat(), Botan::block_size_of(), Botan::Core_Engine::find_block_cipher(), Botan::Core_Engine::get_cipher(), Botan::get_pbe(), Botan::have_algorithm(), Botan::have_block_cipher(), Botan::keylength_multiple_of(), make_block_cipher(), Botan::max_keylength_of(), Botan::min_keylength_of(), providers_of(), Botan::retrieve_block_cipher(), and set_preferred_provider().

195  {
196  return factory_prototype<BlockCipher>(algo_spec, provider, engines,
197  *this, block_cipher_cache);
198  }
const HashFunction * Botan::Algorithm_Factory::prototype_hash_function ( const std::string &  algo_spec,
const std::string &  provider = "" 
)
Parameters
algo_specthe algorithm we want
providerthe provider we would like to use
Returns
pointer to const prototype object, ready to clone(), or NULL

Definition at line 215 of file algo_factory.cpp.

Referenced by Botan::algorithm_benchmark(), Botan::algorithm_kat(), Botan::block_size_of(), Botan::Core_Engine::find_block_cipher(), Botan::Core_Engine::find_hash(), Botan::get_pbe(), Botan::have_algorithm(), Botan::have_hash(), make_hash_function(), Botan::output_length_of(), providers_of(), Botan::retrieve_hash(), and set_preferred_provider().

217  {
218  return factory_prototype<HashFunction>(algo_spec, provider, engines,
219  *this, hash_cache);
220  }
const MessageAuthenticationCode * Botan::Algorithm_Factory::prototype_mac ( const std::string &  algo_spec,
const std::string &  provider = "" 
)
Parameters
algo_specthe algorithm we want
providerthe provider we would like to use
Returns
pointer to const prototype object, ready to clone(), or NULL

Definition at line 226 of file algo_factory.cpp.

Referenced by Botan::algorithm_benchmark(), Botan::algorithm_kat(), Botan::Core_Engine::find_pbkdf(), Botan::have_algorithm(), Botan::have_mac(), Botan::keylength_multiple_of(), make_mac(), Botan::max_keylength_of(), Botan::min_keylength_of(), Botan::output_length_of(), providers_of(), Botan::retrieve_mac(), and set_preferred_provider().

228  {
229  return factory_prototype<MessageAuthenticationCode>(algo_spec, provider,
230  engines,
231  *this, mac_cache);
232  }
const PBKDF * Botan::Algorithm_Factory::prototype_pbkdf ( const std::string &  algo_spec,
const std::string &  provider = "" 
)
Parameters
algo_specthe algorithm we want
providerthe provider we would like to use
Returns
pointer to const prototype object, ready to clone(), or NULL

Definition at line 238 of file algo_factory.cpp.

Referenced by make_pbkdf(), providers_of(), and set_preferred_provider().

240  {
241  return factory_prototype<PBKDF>(algo_spec, provider,
242  engines,
243  *this, pbkdf_cache);
244  }
const StreamCipher * Botan::Algorithm_Factory::prototype_stream_cipher ( const std::string &  algo_spec,
const std::string &  provider = "" 
)
Parameters
algo_specthe algorithm we want
providerthe provider we would like to use
Returns
pointer to const prototype object, ready to clone(), or NULL

Definition at line 204 of file algo_factory.cpp.

Referenced by Botan::algorithm_benchmark(), Botan::algorithm_kat(), Botan::Core_Engine::find_block_cipher(), Botan::Core_Engine::get_cipher(), Botan::have_algorithm(), Botan::have_stream_cipher(), Botan::keylength_multiple_of(), make_stream_cipher(), Botan::max_keylength_of(), Botan::min_keylength_of(), providers_of(), Botan::retrieve_stream_cipher(), and set_preferred_provider().

206  {
207  return factory_prototype<StreamCipher>(algo_spec, provider, engines,
208  *this, stream_cipher_cache);
209  }
std::vector< std::string > Botan::Algorithm_Factory::providers_of ( const std::string &  algo_spec)
Parameters
algo_specthe algorithm we are querying
Returns
list of providers of this algorithm

Definition at line 168 of file algo_factory.cpp.

References prototype_block_cipher(), prototype_hash_function(), prototype_mac(), prototype_pbkdf(), and prototype_stream_cipher().

Referenced by Botan::algorithm_benchmark(), and Botan::algorithm_kat().

169  {
170  /* The checks with if(prototype_X(algo_spec)) have the effect of
171  forcing a full search, since otherwise there might not be any
172  providers at all in the cache.
173  */
174 
175  if(prototype_block_cipher(algo_spec))
176  return block_cipher_cache->providers_of(algo_spec);
177  else if(prototype_stream_cipher(algo_spec))
178  return stream_cipher_cache->providers_of(algo_spec);
179  else if(prototype_hash_function(algo_spec))
180  return hash_cache->providers_of(algo_spec);
181  else if(prototype_mac(algo_spec))
182  return mac_cache->providers_of(algo_spec);
183  else if(prototype_pbkdf(algo_spec))
184  return pbkdf_cache->providers_of(algo_spec);
185  else
186  return std::vector<std::string>();
187  }
const PBKDF * prototype_pbkdf(const std::string &algo_spec, const std::string &provider="")
const BlockCipher * prototype_block_cipher(const std::string &algo_spec, const std::string &provider="")
const HashFunction * prototype_hash_function(const std::string &algo_spec, const std::string &provider="")
const MessageAuthenticationCode * prototype_mac(const std::string &algo_spec, const std::string &provider="")
const StreamCipher * prototype_stream_cipher(const std::string &algo_spec, const std::string &provider="")
void Botan::Algorithm_Factory::set_preferred_provider ( const std::string &  algo_spec,
const std::string &  provider 
)
Parameters
algo_specthe algorithm we are setting a provider for
providerthe provider we would like to use

Definition at line 138 of file algo_factory.cpp.

References prototype_block_cipher(), prototype_hash_function(), prototype_mac(), prototype_pbkdf(), and prototype_stream_cipher().

140  {
141  if(prototype_block_cipher(algo_spec))
142  block_cipher_cache->set_preferred_provider(algo_spec, provider);
143  else if(prototype_stream_cipher(algo_spec))
144  stream_cipher_cache->set_preferred_provider(algo_spec, provider);
145  else if(prototype_hash_function(algo_spec))
146  hash_cache->set_preferred_provider(algo_spec, provider);
147  else if(prototype_mac(algo_spec))
148  mac_cache->set_preferred_provider(algo_spec, provider);
149  else if(prototype_pbkdf(algo_spec))
150  pbkdf_cache->set_preferred_provider(algo_spec, provider);
151  }
const PBKDF * prototype_pbkdf(const std::string &algo_spec, const std::string &provider="")
const BlockCipher * prototype_block_cipher(const std::string &algo_spec, const std::string &provider="")
const HashFunction * prototype_hash_function(const std::string &algo_spec, const std::string &provider="")
const MessageAuthenticationCode * prototype_mac(const std::string &algo_spec, const std::string &provider="")
const StreamCipher * prototype_stream_cipher(const std::string &algo_spec, const std::string &provider="")

Friends And Related Function Documentation

friend class Engine_Iterator
friend

Definition at line 207 of file algo_factory.h.


The documentation for this class was generated from the following files: