/** * Algorithm Factory * (C) 2008 Jack Lloyd * * Distributed under the terms of the Botan license */ #ifndef BOTAN_ALGORITHM_FACTORY_H__ #define BOTAN_ALGORITHM_FACTORY_H__ #include #include #include namespace Botan { /** * Forward declarations (don't need full definitions here) */ class BlockCipher; class StreamCipher; class HashFunction; class MessageAuthenticationCode; template class Algorithm_Cache; class Engine; /** * Algorithm Factory */ class BOTAN_DLL Algorithm_Factory { public: /** * Constructor * @param engines_in the list of engines to use * @param mf a mutex factory */ Algorithm_Factory(const std::vector& engines_in); /** * Destructor */ ~Algorithm_Factory(); /** * @param algo_spec the algorithm we are querying * @returns list of providers of this algorithm */ std::vector providers_of(const std::string& algo_spec); /** * @param algo_spec the algorithm we are setting a provider for * @param provider the provider we would like to use */ void set_preferred_provider(const std::string& algo_spec, const std::string& provider); /** * @param algo_spec the algorithm we want * @param provider the provider we would like to use * @returns pointer to const prototype object, readiny for clone(), or NULL */ const BlockCipher* prototype_block_cipher(const std::string& algo_spec, const std::string& provider = ""); /** * @param algo_spec the algorithm we want * @param provider the provider we would like to use * @returns pointer to freshly created instance of the request algorithm */ BlockCipher* make_block_cipher(const std::string& algo_spec, const std::string& provider = ""); /** * @param algo the algorithm to add * @param provider the provider of this algorithm */ void add_block_cipher(BlockCipher* algo, const std::string& provider); /** * @param algo_spec the algorithm we want * @param provider the provider we would like to use * @returns pointer to const prototype object, readiny for clone(), or NULL */ const StreamCipher* prototype_stream_cipher(const std::string& algo_spec, const std::string& provider = ""); /** * @param algo_spec the algorithm we want * @param provider the provider we would like to use * @returns pointer to freshly created instance of the request algorithm */ StreamCipher* make_stream_cipher(const std::string& algo_spec, const std::string& provider = ""); /** * @param algo the algorithm to add * @param provider the provider of this algorithm */ void add_stream_cipher(StreamCipher* algo, const std::string& provider); /** * @param algo_spec the algorithm we want * @param provider the provider we would like to use * @returns pointer to const prototype object, readiny for clone(), or NULL */ const HashFunction* prototype_hash_function(const std::string& algo_spec, const std::string& provider = ""); /** * @param algo_spec the algorithm we want * @param provider the provider we would like to use * @returns pointer to freshly created instance of the request algorithm */ HashFunction* make_hash_function(const std::string& algo_spec, const std::string& provider = ""); /** * @param algo the algorithm to add * @param provider the provider of this algorithm */ void add_hash_function(HashFunction* algo, const std::string& provider); /** * @param algo_spec the algorithm we want * @param provider the provider we would like to use * @returns pointer to const prototype object, readiny for clone(), or NULL */ const MessageAuthenticationCode* prototype_mac(const std::string& algo_spec, const std::string& provider = ""); /** * @param algo_spec the algorithm we want * @param provider the provider we would like to use * @returns pointer to freshly created instance of the request algorithm */ MessageAuthenticationCode* make_mac(const std::string& algo_spec, const std::string& provider = ""); /** * @param algo the algorithm to add * @param provider the provider of this algorithm */ void add_mac(MessageAuthenticationCode* algo, const std::string& provider); /* * Deprecated */ class BOTAN_DLL Engine_Iterator { public: class Engine* next() { return af.get_engine_n(n++); } Engine_Iterator(const Algorithm_Factory& a) : af(a) { n = 0; } private: const Algorithm_Factory& af; u32bit n; }; friend class Engine_Iterator; private: class Engine* get_engine_n(u32bit) const; std::vector engines; Algorithm_Cache* block_cipher_cache; Algorithm_Cache* stream_cipher_cache; Algorithm_Cache* hash_cache; Algorithm_Cache* mac_cache; }; } #endif