00001 /* 00002 * Algorithm Lookup 00003 * (C) 1999-2007 Jack Lloyd 00004 * 00005 * Distributed under the terms of the Botan license 00006 */ 00007 00008 #ifndef BOTAN_LOOKUP_H__ 00009 #define BOTAN_LOOKUP_H__ 00010 00011 #include <botan/libstate.h> 00012 #include <botan/engine.h> 00013 #include <botan/filters.h> 00014 #include <botan/mode_pad.h> 00015 #include <botan/kdf.h> 00016 #include <botan/eme.h> 00017 #include <botan/emsa.h> 00018 #include <botan/pbkdf.h> 00019 00020 namespace Botan { 00021 00022 /** 00023 * Retrieve an object prototype from the global factory 00024 * @param algo_spec an algorithm name 00025 * @return constant prototype object (use clone to create usable object), 00026 library retains ownership 00027 */ 00028 inline const BlockCipher* 00029 retrieve_block_cipher(const std::string& algo_spec) 00030 { 00031 Algorithm_Factory& af = global_state().algorithm_factory(); 00032 return af.prototype_block_cipher(algo_spec); 00033 } 00034 00035 /** 00036 * Retrieve an object prototype from the global factory 00037 * @param algo_spec an algorithm name 00038 * @return constant prototype object (use clone to create usable object), 00039 library retains ownership 00040 */ 00041 inline const StreamCipher* 00042 retrieve_stream_cipher(const std::string& algo_spec) 00043 { 00044 Algorithm_Factory& af = global_state().algorithm_factory(); 00045 return af.prototype_stream_cipher(algo_spec); 00046 } 00047 00048 /** 00049 * Retrieve an object prototype from the global factory 00050 * @param algo_spec an algorithm name 00051 * @return constant prototype object (use clone to create usable object), 00052 library retains ownership 00053 */ 00054 inline const HashFunction* 00055 retrieve_hash(const std::string& algo_spec) 00056 { 00057 Algorithm_Factory& af = global_state().algorithm_factory(); 00058 return af.prototype_hash_function(algo_spec); 00059 } 00060 00061 /** 00062 * Retrieve an object prototype from the global factory 00063 * @param algo_spec an algorithm name 00064 * @return constant prototype object (use clone to create usable object), 00065 library retains ownership 00066 */ 00067 inline const MessageAuthenticationCode* 00068 retrieve_mac(const std::string& algo_spec) 00069 { 00070 Algorithm_Factory& af = global_state().algorithm_factory(); 00071 return af.prototype_mac(algo_spec); 00072 } 00073 00074 /* 00075 * Get an algorithm object 00076 * NOTE: these functions create and return new objects, letting the 00077 * caller assume ownership of them 00078 */ 00079 00080 /** 00081 * Block cipher factory method. 00082 * @deprecated Call algorithm_factory() directly 00083 * 00084 * @param algo_spec the name of the desired block cipher 00085 * @return pointer to the block cipher object 00086 */ 00087 inline BlockCipher* get_block_cipher(const std::string& algo_spec) 00088 { 00089 Algorithm_Factory& af = global_state().algorithm_factory(); 00090 return af.make_block_cipher(algo_spec); 00091 } 00092 00093 /** 00094 * Stream cipher factory method. 00095 * @deprecated Call algorithm_factory() directly 00096 * 00097 * @param algo_spec the name of the desired stream cipher 00098 * @return pointer to the stream cipher object 00099 */ 00100 inline StreamCipher* get_stream_cipher(const std::string& algo_spec) 00101 { 00102 Algorithm_Factory& af = global_state().algorithm_factory(); 00103 return af.make_stream_cipher(algo_spec); 00104 } 00105 00106 /** 00107 * Hash function factory method. 00108 * @deprecated Call algorithm_factory() directly 00109 * 00110 * @param algo_spec the name of the desired hash function 00111 * @return pointer to the hash function object 00112 */ 00113 inline HashFunction* get_hash(const std::string& algo_spec) 00114 { 00115 Algorithm_Factory& af = global_state().algorithm_factory(); 00116 return af.make_hash_function(algo_spec); 00117 } 00118 00119 /** 00120 * MAC factory method. 00121 * @deprecated Call algorithm_factory() directly 00122 * 00123 * @param algo_spec the name of the desired MAC 00124 * @return pointer to the MAC object 00125 */ 00126 inline MessageAuthenticationCode* get_mac(const std::string& algo_spec) 00127 { 00128 Algorithm_Factory& af = global_state().algorithm_factory(); 00129 return af.make_mac(algo_spec); 00130 } 00131 00132 /** 00133 * Password based key derivation function factory method 00134 * @param algo_spec the name of the desired PBKDF algorithm 00135 * @return pointer to newly allocated object of that type 00136 */ 00137 BOTAN_DLL PBKDF* get_pbkdf(const std::string& algo_spec); 00138 00139 /** 00140 * @deprecated Use get_pbkdf 00141 * @param algo_spec the name of the desired algorithm 00142 * @return pointer to newly allocated object of that type 00143 */ 00144 inline PBKDF* get_s2k(const std::string& algo_spec) 00145 { 00146 return get_pbkdf(algo_spec); 00147 } 00148 00149 /* 00150 * Get an EMSA/EME/KDF/MGF function 00151 */ 00152 // NOTE: these functions create and return new objects, letting the 00153 // caller assume ownership of them 00154 00155 /** 00156 * Factory method for EME (message-encoding methods for encryption) objects 00157 * @param algo_spec the name of the EME to create 00158 * @return pointer to newly allocated object of that type 00159 */ 00160 BOTAN_DLL EME* get_eme(const std::string& algo_spec); 00161 00162 /** 00163 * Factory method for EMSA (message-encoding methods for signatures 00164 * with appendix) objects 00165 * @param algo_spec the name of the EME to create 00166 * @return pointer to newly allocated object of that type 00167 */ 00168 BOTAN_DLL EMSA* get_emsa(const std::string& algo_spec); 00169 00170 /** 00171 * Factory method for KDF (key derivation function) 00172 * @param algo_spec the name of the KDF to create 00173 * @return pointer to newly allocated object of that type 00174 */ 00175 BOTAN_DLL KDF* get_kdf(const std::string& algo_spec); 00176 00177 /* 00178 * Get a cipher object 00179 */ 00180 00181 /** 00182 * Factory method for general symmetric cipher filters. 00183 * @param algo_spec the name of the desired cipher 00184 * @param key the key to be used for encryption/decryption performed by 00185 * the filter 00186 * @param iv the initialization vector to be used 00187 * @param direction determines whether the filter will be an encrypting 00188 * or decrypting filter 00189 * @return pointer to newly allocated encryption or decryption filter 00190 */ 00191 BOTAN_DLL Keyed_Filter* get_cipher(const std::string& algo_spec, 00192 const SymmetricKey& key, 00193 const InitializationVector& iv, 00194 Cipher_Dir direction); 00195 00196 /** 00197 * Factory method for general symmetric cipher filters. 00198 * @param algo_spec the name of the desired cipher 00199 * @param key the key to be used for encryption/decryption performed by 00200 * the filter 00201 * @param direction determines whether the filter will be an encrypting 00202 * or decrypting filter 00203 * @return pointer to the encryption or decryption filter 00204 */ 00205 BOTAN_DLL Keyed_Filter* get_cipher(const std::string& algo_spec, 00206 const SymmetricKey& key, 00207 Cipher_Dir direction); 00208 00209 /** 00210 * Factory method for general symmetric cipher filters. No key will be 00211 * set in the filter. 00212 * 00213 * @param algo_spec the name of the desired cipher 00214 * @param direction determines whether the filter will be an encrypting or 00215 * decrypting filter 00216 * @return pointer to the encryption or decryption filter 00217 */ 00218 BOTAN_DLL Keyed_Filter* get_cipher(const std::string& algo_spec, 00219 Cipher_Dir direction); 00220 00221 /** 00222 * Check if an algorithm exists. 00223 * @param algo_spec the name of the algorithm to check for 00224 * @return true if the algorithm exists, false otherwise 00225 */ 00226 BOTAN_DLL bool have_algorithm(const std::string& algo_spec); 00227 00228 /** 00229 * Check if a block cipher algorithm exists. 00230 * @deprecated Call algorithm_factory() directly 00231 * 00232 * @param algo_spec the name of the algorithm to check for 00233 * @return true if the algorithm exists, false otherwise 00234 */ 00235 inline bool have_block_cipher(const std::string& algo_spec) 00236 { 00237 Algorithm_Factory& af = global_state().algorithm_factory(); 00238 return (af.prototype_block_cipher(algo_spec) != 0); 00239 } 00240 00241 /** 00242 * Check if a stream cipher algorithm exists. 00243 * @deprecated Call algorithm_factory() directly 00244 * 00245 * @param algo_spec the name of the algorithm to check for 00246 * @return true if the algorithm exists, false otherwise 00247 */ 00248 inline bool have_stream_cipher(const std::string& algo_spec) 00249 { 00250 Algorithm_Factory& af = global_state().algorithm_factory(); 00251 return (af.prototype_stream_cipher(algo_spec) != 0); 00252 } 00253 00254 /** 00255 * Check if a hash algorithm exists. 00256 * @deprecated Call algorithm_factory() directly 00257 * 00258 * @param algo_spec the name of the algorithm to check for 00259 * @return true if the algorithm exists, false otherwise 00260 */ 00261 inline bool have_hash(const std::string& algo_spec) 00262 { 00263 Algorithm_Factory& af = global_state().algorithm_factory(); 00264 return (af.prototype_hash_function(algo_spec) != 0); 00265 } 00266 00267 /** 00268 * Check if a MAC algorithm exists. 00269 * @deprecated Call algorithm_factory() directly 00270 * 00271 * @param algo_spec the name of the algorithm to check for 00272 * @return true if the algorithm exists, false otherwise 00273 */ 00274 inline bool have_mac(const std::string& algo_spec) 00275 { 00276 Algorithm_Factory& af = global_state().algorithm_factory(); 00277 return (af.prototype_mac(algo_spec) != 0); 00278 } 00279 00280 /* 00281 * Query information about an algorithm 00282 */ 00283 00284 /** 00285 * Find out the block size of a certain symmetric algorithm. 00286 * @deprecated Call algorithm_factory() directly 00287 * 00288 * @param algo_spec the name of the algorithm 00289 * @return block size of the specified algorithm 00290 */ 00291 BOTAN_DLL u32bit block_size_of(const std::string& algo_spec); 00292 00293 /** 00294 * Find out the output length of a certain symmetric algorithm. 00295 * @deprecated Call algorithm_factory() directly 00296 * 00297 * @param algo_spec the name of the algorithm 00298 * @return output length of the specified algorithm 00299 */ 00300 BOTAN_DLL u32bit output_length_of(const std::string& algo_spec); 00301 00302 /** 00303 * Find out the whether a certain key length is allowd for a given 00304 * symmetric algorithm. 00305 * @deprecated Call algorithm_factory() directly 00306 * 00307 * @param key_len the key length in question 00308 * @param algo_spec the name of the algorithm 00309 * @return true if the key length is valid for that algorithm, false otherwise 00310 */ 00311 BOTAN_DLL bool valid_keylength_for(u32bit key_len, 00312 const std::string& algo_spec); 00313 00314 /** 00315 * Find out the minimum key size of a certain symmetric algorithm. 00316 * @deprecated Call algorithm_factory() directly 00317 * 00318 * @param algo_spec the name of the algorithm 00319 * @return minimum key length of the specified algorithm 00320 */ 00321 BOTAN_DLL u32bit min_keylength_of(const std::string& algo_spec); 00322 00323 /** 00324 * Find out the maximum key size of a certain symmetric algorithm. 00325 * @deprecated Call algorithm_factory() directly 00326 * 00327 * @param algo_spec the name of the algorithm 00328 * @return maximum key length of the specified algorithm 00329 */ 00330 BOTAN_DLL u32bit max_keylength_of(const std::string& algo_spec); 00331 00332 /** 00333 * Find out the size any valid key is a multiple of for a certain algorithm. 00334 * @deprecated Call algorithm_factory() directly 00335 * 00336 * @param algo_spec the name of the algorithm 00337 * @return size any valid key is a multiple of 00338 */ 00339 BOTAN_DLL u32bit keylength_multiple_of(const std::string& algo_spec); 00340 00341 } 00342 00343 #endif
1.5.8