Botan 1.10.17
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

◆ Algorithm_Factory()

Botan::Algorithm_Factory::Algorithm_Factory ( Mutex_Factory & mf)

Constructor

Parameters
mfa mutex factory

Definition at line 97 of file algo_factory.cpp.

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 }
Algorithm_Cache(Mutex *m)
Definition algo_cache.h:74

References Botan::Algorithm_Cache< T >::Algorithm_Cache(), and Botan::Mutex_Factory::make().

Referenced by Engine_Iterator, Botan::Algorithm_Factory::Engine_Iterator::Engine_Iterator(), and Botan::Library_State::initialize().

◆ ~Algorithm_Factory()

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

◆ add_block_cipher()

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.

311 {
312 block_cipher_cache->add(block_cipher, block_cipher->name(), provider);
313 }

References Botan::Algorithm::name().

◆ add_engine()

void Botan::Algorithm_Factory::add_engine ( Engine * engine)
Parameters
engineto add (Algorithm_Factory takes ownership)

Definition at line 129 of file algo_factory.cpp.

130 {
131 clear_caches();
132 engines.push_back(engine);
133 }

References clear_caches().

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

◆ add_hash_function()

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.

329 {
330 hash_cache->add(hash, hash->name(), provider);
331 }

References Botan::Algorithm::name().

◆ add_mac()

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.

338 {
339 mac_cache->add(mac, mac->name(), provider);
340 }

References Botan::MessageAuthenticationCode::name().

◆ add_pbkdf()

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.

347 {
348 pbkdf_cache->add(pbkdf, pbkdf->name(), provider);
349 }

References Botan::Algorithm::name().

◆ add_stream_cipher()

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.

320 {
321 stream_cipher_cache->add(stream_cipher, stream_cipher->name(), provider);
322 }

References Botan::Algorithm::name().

◆ clear_caches()

void Botan::Algorithm_Factory::clear_caches ( )

Clear out any cached objects

Definition at line 120 of file algo_factory.cpp.

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 }

Referenced by add_engine().

◆ make_block_cipher()

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.

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="")
Algorithm_Not_Found(const std::string &name)
Definition exceptn.h:111

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

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

◆ make_hash_function()

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.

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="")

References Botan::Algorithm_Not_Found::Algorithm_Not_Found(), 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().

◆ make_mac()

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.

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="")

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

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

◆ make_pbkdf()

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.

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="")

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

Referenced by Botan::get_pbkdf().

◆ make_stream_cipher()

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.

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="")

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

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

◆ prototype_block_cipher()

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.

195 {
196 return factory_prototype<BlockCipher>(algo_spec, provider, engines,
197 *this, block_cipher_cache);
198 }

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::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().

◆ prototype_hash_function()

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.

217 {
218 return factory_prototype<HashFunction>(algo_spec, provider, engines,
219 *this, hash_cache);
220 }

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::get_pbe(), Botan::have_algorithm(), Botan::have_hash(), make_hash_function(), Botan::output_length_of(), providers_of(), Botan::retrieve_hash(), and set_preferred_provider().

◆ prototype_mac()

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.

228 {
229 return factory_prototype<MessageAuthenticationCode>(algo_spec, provider,
230 engines,
231 *this, mac_cache);
232 }

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().

◆ prototype_pbkdf()

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.

240 {
241 return factory_prototype<PBKDF>(algo_spec, provider,
242 engines,
243 *this, pbkdf_cache);
244 }

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

◆ prototype_stream_cipher()

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.

206 {
207 return factory_prototype<StreamCipher>(algo_spec, provider, engines,
208 *this, stream_cipher_cache);
209 }

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().

◆ providers_of()

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.

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 }

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

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

◆ set_preferred_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.

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 }

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

◆ Engine_Iterator

friend class Engine_Iterator
friend

Definition at line 207 of file algo_factory.h.

References Algorithm_Factory().


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