Botan 1.10.17

lookup.h
Go to the documentation of this file.
1 /*
2 * Algorithm Lookup
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #ifndef BOTAN_LOOKUP_H__
9 #define BOTAN_LOOKUP_H__
10
11 #include <botan/libstate.h>
12 #include <botan/engine.h>
13 #include <botan/filters.h>
14 #include <botan/mode_pad.h>
15 #include <botan/kdf.h>
16 #include <botan/eme.h>
17 #include <botan/emsa.h>
18 #include <botan/pbkdf.h>
19
20 namespace Botan {
21
22 /**
23 * Retrieve an object prototype from the global factory
24 * @param algo_spec an algorithm name
25 * @return constant prototype object (use clone to create usable object),
26 library retains ownership
27 */
28 inline const BlockCipher*
29 retrieve_block_cipher(const std::string& algo_spec)
30 {
31 Algorithm_Factory& af = global_state().algorithm_factory();
32 return af.prototype_block_cipher(algo_spec);
33 }
34
35 /**
36 * Retrieve an object prototype from the global factory
37 * @param algo_spec an algorithm name
38 * @return constant prototype object (use clone to create usable object),
39 library retains ownership
40 */
41 inline const StreamCipher*
42 retrieve_stream_cipher(const std::string& algo_spec)
43 {
44 Algorithm_Factory& af = global_state().algorithm_factory();
45 return af.prototype_stream_cipher(algo_spec);
46 }
47
48 /**
49 * Retrieve an object prototype from the global factory
50 * @param algo_spec an algorithm name
51 * @return constant prototype object (use clone to create usable object),
52 library retains ownership
53 */
54 inline const HashFunction*
55 retrieve_hash(const std::string& algo_spec)
56 {
57 Algorithm_Factory& af = global_state().algorithm_factory();
58 return af.prototype_hash_function(algo_spec);
59 }
60
61 /**
62 * Retrieve an object prototype from the global factory
63 * @param algo_spec an algorithm name
64 * @return constant prototype object (use clone to create usable object),
65 library retains ownership
66 */
67 inline const MessageAuthenticationCode*
68 retrieve_mac(const std::string& algo_spec)
69 {
70 Algorithm_Factory& af = global_state().algorithm_factory();
71 return af.prototype_mac(algo_spec);
72 }
73
74 /*
75 * Get an algorithm object
76 * NOTE: these functions create and return new objects, letting the
77 * caller assume ownership of them
78 */
79
80 /**
81 * Block cipher factory method.
82 * @deprecated Call algorithm_factory() directly
83 *
84 * @param algo_spec the name of the desired block cipher
85 * @return pointer to the block cipher object
86 */
87 inline BlockCipher* get_block_cipher(const std::string& algo_spec)
88 {
89 Algorithm_Factory& af = global_state().algorithm_factory();
90 return af.make_block_cipher(algo_spec);
91 }
92
93 /**
94 * Stream cipher factory method.
95 * @deprecated Call algorithm_factory() directly
96 *
97 * @param algo_spec the name of the desired stream cipher
98 * @return pointer to the stream cipher object
99 */
100 inline StreamCipher* get_stream_cipher(const std::string& algo_spec)
101 {
102 Algorithm_Factory& af = global_state().algorithm_factory();
103 return af.make_stream_cipher(algo_spec);
104 }
105
106 /**
107 * Hash function factory method.
108 * @deprecated Call algorithm_factory() directly
109 *
110 * @param algo_spec the name of the desired hash function
111 * @return pointer to the hash function object
112 */
113 inline HashFunction* get_hash(const std::string& algo_spec)
114 {
115 Algorithm_Factory& af = global_state().algorithm_factory();
116 return af.make_hash_function(algo_spec);
117 }
118
119 /**
120 * MAC factory method.
121 * @deprecated Call algorithm_factory() directly
122 *
123 * @param algo_spec the name of the desired MAC
124 * @return pointer to the MAC object
125 */
126 inline MessageAuthenticationCode* get_mac(const std::string& algo_spec)
127 {
128 Algorithm_Factory& af = global_state().algorithm_factory();
129 return af.make_mac(algo_spec);
130 }
131
132 /**
133 * Password based key derivation function factory method
134 * @param algo_spec the name of the desired PBKDF algorithm
135 * @return pointer to newly allocated object of that type
136 */
137 BOTAN_DLL PBKDF* get_pbkdf(const std::string& algo_spec);
138
139 /**
140 * @deprecated Use get_pbkdf
141 * @param algo_spec the name of the desired algorithm
142 * @return pointer to newly allocated object of that type
143 */
144 inline PBKDF* get_s2k(const std::string& algo_spec)
145 {
146 return get_pbkdf(algo_spec);
147 }
148
149 /*
150 * Get an EMSA/EME/KDF/MGF function
151 */
152 // NOTE: these functions create and return new objects, letting the
153 // caller assume ownership of them
154
155 /**
156 * Factory method for EME (message-encoding methods for encryption) objects
157 * @param algo_spec the name of the EME to create
158 * @return pointer to newly allocated object of that type
159 */
160 BOTAN_DLL EME* get_eme(const std::string& algo_spec);
161
162 /**
163 * Factory method for EMSA (message-encoding methods for signatures
164 * with appendix) objects
165 * @param algo_spec the name of the EME to create
166 * @return pointer to newly allocated object of that type
167 */
168 BOTAN_DLL EMSA* get_emsa(const std::string& algo_spec);
169
170 /**
171 * Factory method for KDF (key derivation function)
172 * @param algo_spec the name of the KDF to create
173 * @return pointer to newly allocated object of that type
174 */
175 BOTAN_DLL KDF* get_kdf(const std::string& algo_spec);
176
177 /*
178 * Get a cipher object
179 */
180
181 /**
182 * Factory method for general symmetric cipher filters.
183 * @param algo_spec the name of the desired cipher
184 * @param key the key to be used for encryption/decryption performed by
185 * the filter
186 * @param iv the initialization vector to be used
187 * @param direction determines whether the filter will be an encrypting
188 * or decrypting filter
189 * @return pointer to newly allocated encryption or decryption filter
190 */
191 BOTAN_DLL Keyed_Filter* get_cipher(const std::string& algo_spec,
192 const SymmetricKey& key,
193 const InitializationVector& iv,
194 Cipher_Dir direction);
195
196 /**
197 * Factory method for general symmetric cipher filters.
198 * @param algo_spec the name of the desired cipher
199 * @param key the key to be used for encryption/decryption performed by
200 * the filter
201 * @param direction determines whether the filter will be an encrypting
202 * or decrypting filter
203 * @return pointer to the encryption or decryption filter
204 */
205 BOTAN_DLL Keyed_Filter* get_cipher(const std::string& algo_spec,
206 const SymmetricKey& key,
207 Cipher_Dir direction);
208
209 /**
210 * Factory method for general symmetric cipher filters. No key will be
211 * set in the filter.
212 *
213 * @param algo_spec the name of the desired cipher
214 * @param direction determines whether the filter will be an encrypting or
215 * decrypting filter
216 * @return pointer to the encryption or decryption filter
217 */
218 BOTAN_DLL Keyed_Filter* get_cipher(const std::string& algo_spec,
219 Cipher_Dir direction);
220
221 /**
222 * Check if an algorithm exists.
223 * @param algo_spec the name of the algorithm to check for
224 * @return true if the algorithm exists, false otherwise
225 */
226 BOTAN_DLL bool have_algorithm(const std::string& algo_spec);
227
228 /**
229 * Check if a block cipher algorithm exists.
230 * @deprecated Call algorithm_factory() directly
231 *
232 * @param algo_spec the name of the algorithm to check for
233 * @return true if the algorithm exists, false otherwise
234 */
235 inline bool have_block_cipher(const std::string& algo_spec)
236 {
237 Algorithm_Factory& af = global_state().algorithm_factory();
238 return (af.prototype_block_cipher(algo_spec) != 0);
239 }
240
241 /**
242 * Check if a stream cipher algorithm exists.
243 * @deprecated Call algorithm_factory() directly
244 *
245 * @param algo_spec the name of the algorithm to check for
246 * @return true if the algorithm exists, false otherwise
247 */
248 inline bool have_stream_cipher(const std::string& algo_spec)
249 {
250 Algorithm_Factory& af = global_state().algorithm_factory();
251 return (af.prototype_stream_cipher(algo_spec) != 0);
252 }
253
254 /**
255 * Check if a hash algorithm exists.
256 * @deprecated Call algorithm_factory() directly
257 *
258 * @param algo_spec the name of the algorithm to check for
259 * @return true if the algorithm exists, false otherwise
260 */
261 inline bool have_hash(const std::string& algo_spec)
262 {
263 Algorithm_Factory& af = global_state().algorithm_factory();
264 return (af.prototype_hash_function(algo_spec) != 0);
265 }
266
267 /**
268 * Check if a MAC algorithm exists.
269 * @deprecated Call algorithm_factory() directly
270 *
271 * @param algo_spec the name of the algorithm to check for
272 * @return true if the algorithm exists, false otherwise
273 */
274 inline bool have_mac(const std::string& algo_spec)
275 {
276 Algorithm_Factory& af = global_state().algorithm_factory();
277 return (af.prototype_mac(algo_spec) != 0);
278 }
279
280 /*
281 * Query information about an algorithm
282 */
283
284 /**
285 * Find out the block size of a certain symmetric algorithm.
286 * @deprecated Call algorithm_factory() directly
287 *
288 * @param algo_spec the name of the algorithm
289 * @return block size of the specified algorithm
290 */
291 BOTAN_DLL size_t block_size_of(const std::string& algo_spec);
292
293 /**
294 * Find out the output length of a certain symmetric algorithm.
295 * @deprecated Call algorithm_factory() directly
296 *
297 * @param algo_spec the name of the algorithm
298 * @return output length of the specified algorithm
299 */
300 BOTAN_DLL size_t output_length_of(const std::string& algo_spec);
301
302 /**
303 * Find out the minimum key size of a certain symmetric algorithm.
304 * @deprecated Call algorithm_factory() directly
305 *
306 * @param algo_spec the name of the algorithm
307 * @return minimum key length of the specified algorithm
308 */
309 BOTAN_DEPRECATED("Retrieve object you want and then call key_spec")
310 BOTAN_DLL size_t min_keylength_of(const std::string& algo_spec);
311
312 /**
313 * Find out the maximum key size of a certain symmetric algorithm.
314 * @deprecated Call algorithm_factory() directly
315 *
316 * @param algo_spec the name of the algorithm
317 * @return maximum key length of the specified algorithm
318 */
319 BOTAN_DEPRECATED("Retrieve object you want and then call key_spec")
320 BOTAN_DLL size_t max_keylength_of(const std::string& algo_spec);
321
322 /**
323 * Find out the size any valid key is a multiple of for a certain algorithm.
324 * @deprecated Call algorithm_factory() directly
325 *
326 * @param algo_spec the name of the algorithm
327 * @return size any valid key is a multiple of
328 */
329 BOTAN_DEPRECATED("Retrieve object you want and then call key_spec")
330 BOTAN_DLL size_t keylength_multiple_of(const std::string& algo_spec);
331
332 }
333
334 #endif
Botan::retrieve_block_cipher
const BlockCipher * retrieve_block_cipher(const std::string &algo_spec)
Definition: lookup.h:29
Botan::get_mac
MessageAuthenticationCode * get_mac(const std::string &algo_spec)
Definition: lookup.h:126
Botan::get_emsa
EMSA * get_emsa(const std::string &algo_spec)
Definition: get_enc.cpp:86
Botan::Algorithm_Factory
Definition: algo_factory.h:34
Botan::get_hash
HashFunction * get_hash(const std::string &algo_spec)
Definition: lookup.h:113
Botan::Library_State::algorithm_factory
Algorithm_Factory & algorithm_factory() const
Definition: libstate.cpp:173
Botan::get_stream_cipher
StreamCipher * get_stream_cipher(const std::string &algo_spec)
Definition: lookup.h:100
Botan::Algorithm_Factory::prototype_block_cipher
const BlockCipher * prototype_block_cipher(const std::string &algo_spec, const std::string &provider="")
Definition: algo_factory.cpp:193
Botan::get_s2k
PBKDF * get_s2k(const std::string &algo_spec)
Definition: lookup.h:144
std
Definition: secmem.h:435
Botan::Algorithm_Factory::make_block_cipher
BlockCipher * make_block_cipher(const std::string &algo_spec, const std::string &provider="")
Definition: algo_factory.cpp:250
Botan::MessageAuthenticationCode
Definition: mac.h:20
Botan::Algorithm_Factory::make_mac
MessageAuthenticationCode * make_mac(const std::string &algo_spec, const std::string &provider="")
Definition: algo_factory.cpp:286
Botan::Algorithm_Factory::make_stream_cipher
StreamCipher * make_stream_cipher(const std::string &algo_spec, const std::string &provider="")
Definition: algo_factory.cpp:262
Botan::min_keylength_of
size_t min_keylength_of(const std::string &name)
Definition: lookup.cpp:67
Botan::max_keylength_of
size_t max_keylength_of(const std::string &name)
Definition: lookup.cpp:86
Botan::Algorithm_Factory::prototype_hash_function
const HashFunction * prototype_hash_function(const std::string &algo_spec, const std::string &provider="")
Definition: algo_factory.cpp:215
Botan::SymmetricKey
OctetString SymmetricKey
Definition: symkey.h:147
Botan::have_mac
bool have_mac(const std::string &algo_spec)
Definition: lookup.h:274
Botan::Global_State_Management::global_state
Library_State & global_state()
Definition: global_state.cpp:32
Botan::StreamCipher
Definition: stream_cipher.h:18
Botan::have_algorithm
bool have_algorithm(const std::string &name)
Definition: lookup.cpp:17
Botan::retrieve_mac
const MessageAuthenticationCode * retrieve_mac(const std::string &algo_spec)
Definition: lookup.h:68
Botan::Algorithm_Factory::prototype_mac
const MessageAuthenticationCode * prototype_mac(const std::string &algo_spec, const std::string &provider="")
Definition: algo_factory.cpp:226
Botan::block_size_of
size_t block_size_of(const std::string &name)
Definition: lookup.cpp:35
Botan::retrieve_stream_cipher
const StreamCipher * retrieve_stream_cipher(const std::string &algo_spec)
Definition: lookup.h:42
Botan
Definition: algo_base.h:14
Botan::get_eme
EME * get_eme(const std::string &algo_spec)
Definition: get_enc.cpp:143
Botan::Algorithm_Factory::make_hash_function
HashFunction * make_hash_function(const std::string &algo_spec, const std::string &provider="")
Definition: algo_factory.cpp:274
Botan::get_block_cipher
BlockCipher * get_block_cipher(const std::string &algo_spec)
Definition: lookup.h:87
Botan::have_stream_cipher
bool have_stream_cipher(const std::string &algo_spec)
Definition: lookup.h:248
Botan::HashFunction
Definition: hash.h:20
Botan::keylength_multiple_of
size_t keylength_multiple_of(const std::string &name)
Definition: lookup.cpp:105
Botan::have_hash
bool have_hash(const std::string &algo_spec)
Definition: lookup.h:261
Botan::have_block_cipher
bool have_block_cipher(const std::string &algo_spec)
Definition: lookup.h:235
Botan::retrieve_hash
const HashFunction * retrieve_hash(const std::string &algo_spec)
Definition: lookup.h:55
Botan::get_pbkdf
PBKDF * get_pbkdf(const std::string &algo_spec)
Definition: get_enc.cpp:73
Botan::Cipher_Dir
Cipher_Dir
Definition: sym_algo.h:87
Botan::get_kdf
KDF * get_kdf(const std::string &algo_spec)
Definition: get_enc.cpp:174
Botan::output_length_of
size_t output_length_of(const std::string &name)
Definition: lookup.cpp:51
Botan::get_cipher
Keyed_Filter * get_cipher(const std::string &algo_spec, Cipher_Dir direction)
Definition: lookup.cpp:124
Botan::InitializationVector
OctetString InitializationVector
Definition: symkey.h:152
Botan::Algorithm_Factory::prototype_stream_cipher
const StreamCipher * prototype_stream_cipher(const std::string &algo_spec, const std::string &provider="")
Definition: algo_factory.cpp:204
Botan::BlockCipher
Definition: block_cipher.h:18
Botan::PBKDF
Definition: pbkdf.h:21