Botan 1.10.17
algo_factory.h
Go to the documentation of this file.
1/*
2* Algorithm Factory
3* (C) 2008 Jack Lloyd
4*
5* Distributed under the terms of the Botan license
6*/
7
8#ifndef BOTAN_ALGORITHM_FACTORY_H__
9#define BOTAN_ALGORITHM_FACTORY_H__
10
11#include <botan/types.h>
12#include <string>
13#include <vector>
14
15namespace Botan {
16
17/**
18* Forward declarations (don't need full definitions here)
19*/
20class BlockCipher;
21class StreamCipher;
22class HashFunction;
24class PBKDF;
25
26template<typename T> class Algorithm_Cache;
27
28class Engine;
29class Mutex_Factory;
30
31/**
32* Algorithm Factory
33*/
34class BOTAN_DLL Algorithm_Factory
35 {
36 public:
37 /**
38 * Constructor
39 * @param mf a mutex factory
40 */
42
43 /**
44 * Destructor
45 */
47
48 /**
49 * @param engine to add (Algorithm_Factory takes ownership)
50 */
51 void add_engine(Engine* engine);
52
53 /**
54 * Clear out any cached objects
55 */
56 void clear_caches();
57
58 /**
59 * @param algo_spec the algorithm we are querying
60 * @returns list of providers of this algorithm
61 */
62 std::vector<std::string> providers_of(const std::string& algo_spec);
63
64 /**
65 * @param algo_spec the algorithm we are setting a provider for
66 * @param provider the provider we would like to use
67 */
68 void set_preferred_provider(const std::string& algo_spec,
69 const std::string& provider);
70
71 /**
72 * @param algo_spec the algorithm we want
73 * @param provider the provider we would like to use
74 * @returns pointer to const prototype object, ready to clone(), or NULL
75 */
76 const BlockCipher*
77 prototype_block_cipher(const std::string& algo_spec,
78 const std::string& provider = "");
79
80 /**
81 * @param algo_spec the algorithm we want
82 * @param provider the provider we would like to use
83 * @returns pointer to freshly created instance of the request algorithm
84 */
85 BlockCipher* make_block_cipher(const std::string& algo_spec,
86 const std::string& provider = "");
87
88 /**
89 * @param algo the algorithm to add
90 * @param provider the provider of this algorithm
91 */
92 void add_block_cipher(BlockCipher* algo, const std::string& provider);
93
94 /**
95 * @param algo_spec the algorithm we want
96 * @param provider the provider we would like to use
97 * @returns pointer to const prototype object, ready to clone(), or NULL
98 */
99 const StreamCipher*
100 prototype_stream_cipher(const std::string& algo_spec,
101 const std::string& provider = "");
102
103 /**
104 * @param algo_spec the algorithm we want
105 * @param provider the provider we would like to use
106 * @returns pointer to freshly created instance of the request algorithm
107 */
108 StreamCipher* make_stream_cipher(const std::string& algo_spec,
109 const std::string& provider = "");
110
111 /**
112 * @param algo the algorithm to add
113 * @param provider the provider of this algorithm
114 */
115 void add_stream_cipher(StreamCipher* algo, const std::string& provider);
116
117 /**
118 * @param algo_spec the algorithm we want
119 * @param provider the provider we would like to use
120 * @returns pointer to const prototype object, ready to clone(), or NULL
121 */
122 const HashFunction*
123 prototype_hash_function(const std::string& algo_spec,
124 const std::string& provider = "");
125
126 /**
127 * @param algo_spec the algorithm we want
128 * @param provider the provider we would like to use
129 * @returns pointer to freshly created instance of the request algorithm
130 */
131 HashFunction* make_hash_function(const std::string& algo_spec,
132 const std::string& provider = "");
133
134 /**
135 * @param algo the algorithm to add
136 * @param provider the provider of this algorithm
137 */
138 void add_hash_function(HashFunction* algo, const std::string& provider);
139
140 /**
141 * @param algo_spec the algorithm we want
142 * @param provider the provider we would like to use
143 * @returns pointer to const prototype object, ready to clone(), or NULL
144 */
146 prototype_mac(const std::string& algo_spec,
147 const std::string& provider = "");
148
149 /**
150 * @param algo_spec the algorithm we want
151 * @param provider the provider we would like to use
152 * @returns pointer to freshly created instance of the request algorithm
153 */
154 MessageAuthenticationCode* make_mac(const std::string& algo_spec,
155 const std::string& provider = "");
156
157 /**
158 * @param algo the algorithm to add
159 * @param provider the provider of this algorithm
160 */
162 const std::string& provider);
163
164 /**
165 * @param algo_spec the algorithm we want
166 * @param provider the provider we would like to use
167 * @returns pointer to const prototype object, ready to clone(), or NULL
168 */
169 const PBKDF* prototype_pbkdf(const std::string& algo_spec,
170 const std::string& provider = "");
171
172 /**
173 * @param algo_spec the algorithm we want
174 * @param provider the provider we would like to use
175 * @returns pointer to freshly created instance of the request algorithm
176 */
177 PBKDF* make_pbkdf(const std::string& algo_spec,
178 const std::string& provider = "");
179
180 /**
181 * @param algo the algorithm to add
182 * @param provider the provider of this algorithm
183 */
184 void add_pbkdf(PBKDF* algo, const std::string& provider);
185
186 /**
187 * An iterator for the engines in this factory
188 * @deprecated Avoid in new code
189 */
190 class BOTAN_DLL Engine_Iterator
191 {
192 public:
193 /**
194 * @return next engine in the sequence
195 */
196 Engine* next() { return af.get_engine_n(n++); }
197
198 /**
199 * @param a an algorithm factory
200 */
202 af(a) { n = 0; }
203 private:
204 const Algorithm_Factory& af;
205 size_t n;
206 };
207 friend class Engine_Iterator;
208
209 private:
211 Algorithm_Factory& operator=(const Algorithm_Factory&)
212 { return (*this); }
213
214 Engine* get_engine_n(size_t n) const;
215
216 std::vector<Engine*> engines;
217
218 Algorithm_Cache<BlockCipher>* block_cipher_cache;
219 Algorithm_Cache<StreamCipher>* stream_cipher_cache;
220 Algorithm_Cache<HashFunction>* hash_cache;
221 Algorithm_Cache<MessageAuthenticationCode>* mac_cache;
222 Algorithm_Cache<PBKDF>* pbkdf_cache;
223 };
224
225}
226
227#endif
Engine_Iterator(const Algorithm_Factory &a)
StreamCipher * make_stream_cipher(const std::string &algo_spec, const std::string &provider="")
void add_hash_function(HashFunction *algo, const std::string &provider)
std::vector< std::string > providers_of(const std::string &algo_spec)
PBKDF * make_pbkdf(const std::string &algo_spec, const std::string &provider="")
void set_preferred_provider(const std::string &algo_spec, const std::string &provider)
const HashFunction * prototype_hash_function(const std::string &algo_spec, const std::string &provider="")
HashFunction * make_hash_function(const std::string &algo_spec, 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)
void add_engine(Engine *engine)
MessageAuthenticationCode * make_mac(const std::string &algo_spec, const std::string &provider="")
const BlockCipher * prototype_block_cipher(const std::string &algo_spec, const std::string &provider="")
const MessageAuthenticationCode * prototype_mac(const std::string &algo_spec, const std::string &provider="")
void add_block_cipher(BlockCipher *algo, const std::string &provider)
const PBKDF * prototype_pbkdf(const std::string &algo_spec, const std::string &provider="")
const StreamCipher * prototype_stream_cipher(const std::string &algo_spec, const std::string &provider="")
Algorithm_Factory(Mutex_Factory &mf)
BlockCipher * make_block_cipher(const std::string &algo_spec, const std::string &provider="")