monotone

monotone Mtn Source Tree

Root/botan/eng_base.cpp

1/*************************************************
2* Basic No-Op Engine Source File *
3* (C) 1999-2005 The Botan Project *
4*************************************************/
5
6#include <botan/engine.h>
7#include <botan/lookup.h>
8
9namespace Botan {
10
11/*************************************************
12* Basic No-Op Engine Implementation *
13*************************************************/
14IF_Operation* Engine::if_op(const BigInt&, const BigInt&, const BigInt&,
15 const BigInt&, const BigInt&, const BigInt&,
16 const BigInt&, const BigInt&) const
17 {
18 return 0;
19 }
20
21/*************************************************
22* Basic No-Op Engine Implementation *
23*************************************************/
24DSA_Operation* Engine::dsa_op(const DL_Group&, const BigInt&,
25 const BigInt&) const
26 {
27 return 0;
28 }
29
30/*************************************************
31* Basic No-Op Engine Implementation *
32*************************************************/
33NR_Operation* Engine::nr_op(const DL_Group&, const BigInt&,
34 const BigInt&) const
35 {
36 return 0;
37 }
38
39/*************************************************
40* Basic No-Op Engine Implementation *
41*************************************************/
42ELG_Operation* Engine::elg_op(const DL_Group&, const BigInt&,
43 const BigInt&) const
44 {
45 return 0;
46 }
47
48/*************************************************
49* Basic No-Op Engine Implementation *
50*************************************************/
51DH_Operation* Engine::dh_op(const DL_Group&, const BigInt&) const
52 {
53 return 0;
54 }
55
56/*************************************************
57* Basic No-Op Engine Implementation *
58*************************************************/
59ModularReducer* Engine::reducer(const BigInt&, bool) const
60 {
61 return 0;
62 }
63
64/*************************************************
65* Acquire a BlockCipher *
66*************************************************/
67const BlockCipher* Engine::block_cipher(const std::string& name) const
68 {
69 BlockCipher* retval = 0;
70 bc_map_lock->lock();
71 std::map<std::string, BlockCipher*>::const_iterator algo;
72 algo = bc_map.find(deref_alias(name));
73 if(algo != bc_map.end())
74 retval = algo->second;
75 bc_map_lock->unlock();
76 if(!retval)
77 {
78 retval = find_block_cipher(deref_alias(name));
79 add_algorithm(retval);
80 }
81 return retval;
82 }
83
84/*************************************************
85* Acquire a StreamCipher *
86*************************************************/
87const StreamCipher* Engine::stream_cipher(const std::string& name) const
88 {
89 StreamCipher* retval = 0;
90 sc_map_lock->lock();
91 std::map<std::string, StreamCipher*>::const_iterator algo;
92 algo = sc_map.find(deref_alias(name));
93 if(algo != sc_map.end())
94 retval = algo->second;
95 sc_map_lock->unlock();
96 if(!retval)
97 {
98 retval = find_stream_cipher(deref_alias(name));
99 add_algorithm(retval);
100 }
101 return retval;
102 }
103
104/*************************************************
105* Acquire a HashFunction *
106*************************************************/
107const HashFunction* Engine::hash(const std::string& name) const
108 {
109 HashFunction* retval = 0;
110 hf_map_lock->lock();
111 std::map<std::string, HashFunction*>::const_iterator algo;
112 algo = hf_map.find(deref_alias(name));
113 if(algo != hf_map.end())
114 retval = algo->second;
115 hf_map_lock->unlock();
116 if(!retval)
117 {
118 retval = find_hash(deref_alias(name));
119 add_algorithm(retval);
120 }
121 return retval;
122 }
123
124/*************************************************
125* Acquire a MessageAuthenticationCode *
126*************************************************/
127const MessageAuthenticationCode* Engine::mac(const std::string& name) const
128 {
129 MessageAuthenticationCode* retval = 0;
130 mac_map_lock->lock();
131 std::map<std::string, MessageAuthenticationCode*>::const_iterator algo;
132 algo = mac_map.find(deref_alias(name));
133 if(algo != mac_map.end())
134 retval = algo->second;
135 mac_map_lock->unlock();
136 if(!retval)
137 {
138 retval = find_mac(deref_alias(name));
139 add_algorithm(retval);
140 }
141 return retval;
142 }
143
144/*************************************************
145* Add a block cipher to the lookup table *
146*************************************************/
147void Engine::add_algorithm(BlockCipher* algo) const
148 {
149 if(!algo) return;
150 bc_map_lock->lock();
151 if(bc_map.find(algo->name()) != bc_map.end())
152 delete bc_map[algo->name()];
153 bc_map[algo->name()] = algo;
154 bc_map_lock->unlock();
155 }
156
157/*************************************************
158* Add a stream cipher to the lookup table *
159*************************************************/
160void Engine::add_algorithm(StreamCipher* algo) const
161 {
162 if(!algo) return;
163 sc_map_lock->lock();
164 if(sc_map.find(algo->name()) != sc_map.end())
165 delete sc_map[algo->name()];
166 sc_map[algo->name()] = algo;
167 sc_map_lock->unlock();
168 }
169
170/*************************************************
171* Add a hash function to the lookup table *
172*************************************************/
173void Engine::add_algorithm(HashFunction* algo) const
174 {
175 if(!algo) return;
176 hf_map_lock->lock();
177 if(hf_map.find(algo->name()) != hf_map.end())
178 delete hf_map[algo->name()];
179 hf_map[algo->name()] = algo;
180 hf_map_lock->unlock();
181 }
182
183/*************************************************
184* Add a MAC to the lookup table *
185*************************************************/
186void Engine::add_algorithm(MessageAuthenticationCode* algo) const
187 {
188 if(!algo) return;
189 mac_map_lock->lock();
190 if(mac_map.find(algo->name()) != mac_map.end())
191 delete mac_map[algo->name()];
192 mac_map[algo->name()] = algo;
193 mac_map_lock->unlock();
194 }
195
196/*************************************************
197* Create an Engine *
198*************************************************/
199Engine::Engine()
200 {
201 bc_map_lock = get_mutex();
202 sc_map_lock = get_mutex();
203 hf_map_lock = get_mutex();
204 mac_map_lock = get_mutex();
205 }
206
207/*************************************************
208* Destroy an Engine *
209*************************************************/
210Engine::~Engine()
211 {
212 std::map<std::string, BlockCipher*>::iterator bc_iter;
213 for(bc_iter = bc_map.begin(); bc_iter != bc_map.end(); bc_iter++)
214 delete bc_iter->second;
215
216 std::map<std::string, StreamCipher*>::iterator sc_iter;
217 for(sc_iter = sc_map.begin(); sc_iter != sc_map.end(); sc_iter++)
218 delete sc_iter->second;
219
220 std::map<std::string, HashFunction*>::iterator hf_iter;
221 for(hf_iter = hf_map.begin(); hf_iter != hf_map.end(); hf_iter++)
222 delete hf_iter->second;
223
224 std::map<std::string, MessageAuthenticationCode*>::iterator mac_iter;
225 for(mac_iter = mac_map.begin(); mac_iter != mac_map.end(); mac_iter++)
226 delete mac_iter->second;
227
228 delete bc_map_lock;
229 delete sc_map_lock;
230 delete hf_map_lock;
231 delete mac_map_lock;
232 }
233
234/*************************************************
235* Basic No-Op Engine Implementation *
236*************************************************/
237BlockCipher* Engine::find_block_cipher(const std::string&) const
238 {
239 return 0;
240 }
241
242/*************************************************
243* Basic No-Op Engine Implementation *
244*************************************************/
245StreamCipher* Engine::find_stream_cipher(const std::string&) const
246 {
247 return 0;
248 }
249
250/*************************************************
251* Basic No-Op Engine Implementation *
252*************************************************/
253HashFunction* Engine::find_hash(const std::string&) const
254 {
255 return 0;
256 }
257
258/*************************************************
259* Basic No-Op Engine Implementation *
260*************************************************/
261MessageAuthenticationCode* Engine::find_mac(const std::string&) const
262 {
263 return 0;
264 }
265
266/*************************************************
267* Basic No-Op Engine Implementation *
268*************************************************/
269Keyed_Filter* Engine::get_cipher(const std::string&, Cipher_Dir)
270 {
271 return 0;
272 }
273
274}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status