]> git.ipfire.org Git - people/ms/strongswan.git/blob - src/libstrongswan/crypto/crypto_factory.h
crypto-factory: Remove obsolete transform testing functions
[people/ms/strongswan.git] / src / libstrongswan / crypto / crypto_factory.h
1 /*
2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup crypto_factory crypto_factory
18 * @{ @ingroup crypto
19 */
20
21 #ifndef CRYPTO_FACTORY_H_
22 #define CRYPTO_FACTORY_H_
23
24 typedef struct crypto_factory_t crypto_factory_t;
25
26 #include <library.h>
27 #include <collections/enumerator.h>
28 #include <crypto/crypters/crypter.h>
29 #include <crypto/aead.h>
30 #include <crypto/signers/signer.h>
31 #include <crypto/hashers/hasher.h>
32 #include <crypto/prfs/prf.h>
33 #include <crypto/rngs/rng.h>
34 #include <crypto/nonce_gen.h>
35 #include <crypto/diffie_hellman.h>
36 #include <crypto/transform.h>
37
38 #define CRYPTO_MAX_ALG_LINE 120 /* characters */
39
40 /**
41 * Constructor function for crypters
42 */
43 typedef crypter_t* (*crypter_constructor_t)(encryption_algorithm_t algo,
44 size_t key_size);
45 /**
46 * Constructor function for aead transforms
47 */
48 typedef aead_t* (*aead_constructor_t)(encryption_algorithm_t algo,
49 size_t key_size, size_t salt_size);
50 /**
51 * Constructor function for signers
52 */
53 typedef signer_t* (*signer_constructor_t)(integrity_algorithm_t algo);
54
55 /**
56 * Constructor function for hashers
57 */
58 typedef hasher_t* (*hasher_constructor_t)(hash_algorithm_t algo);
59
60 /**
61 * Constructor function for pseudo random functions
62 */
63 typedef prf_t* (*prf_constructor_t)(pseudo_random_function_t algo);
64
65 /**
66 * Constructor function for source of randomness
67 */
68 typedef rng_t* (*rng_constructor_t)(rng_quality_t quality);
69
70 /**
71 * Constructor function for nonce generators
72 */
73 typedef nonce_gen_t* (*nonce_gen_constructor_t)();
74
75 /**
76 * Constructor function for diffie hellman
77 *
78 * The DH constructor accepts additional arguments for:
79 * - MODP_CUSTOM: chunk_t generator, chunk_t prime
80 */
81 typedef diffie_hellman_t* (*dh_constructor_t)(diffie_hellman_group_t group, ...);
82
83 /**
84 * Handles crypto modules and creates instances.
85 */
86 struct crypto_factory_t {
87
88 /**
89 * Create a crypter instance.
90 *
91 * @param algo encryption algorithm
92 * @param key_size length of the key in bytes
93 * @return crypter_t instance, NULL if not supported
94 */
95 crypter_t* (*create_crypter)(crypto_factory_t *this,
96 encryption_algorithm_t algo, size_t key_size);
97
98 /**
99 * Create a aead instance.
100 *
101 * @param algo encryption algorithm
102 * @param key_size length of the key in bytes
103 * @param salt_size size of salt, implicit part of the nonce
104 * @return aead_t instance, NULL if not supported
105 */
106 aead_t* (*create_aead)(crypto_factory_t *this,
107 encryption_algorithm_t algo,
108 size_t key_size, size_t salt_size);
109
110 /**
111 * Create a symmetric signer instance.
112 *
113 * @param algo MAC algorithm to use
114 * @return signer_t instance, NULL if not supported
115 */
116 signer_t* (*create_signer)(crypto_factory_t *this,
117 integrity_algorithm_t algo);
118
119 /**
120 * Create a hasher instance.
121 *
122 * @param algo hash algorithm
123 * @return hasher_t instance, NULL if not supported
124 */
125 hasher_t* (*create_hasher)(crypto_factory_t *this, hash_algorithm_t algo);
126
127 /**
128 * Create a pseudo random function instance.
129 *
130 * @param algo PRF algorithm to use
131 * @return prf_t instance, NULL if not supported
132 */
133 prf_t* (*create_prf)(crypto_factory_t *this, pseudo_random_function_t algo);
134
135 /**
136 * Create a source of randomness.
137 *
138 * @param quality required randomness quality
139 * @return rng_t instance, NULL if no RNG with such a quality
140 */
141 rng_t* (*create_rng)(crypto_factory_t *this, rng_quality_t quality);
142
143 /**
144 * Create a nonce generator instance.
145 *
146 * @return nonce_gen_t instance, NULL if not supported
147 */
148 nonce_gen_t* (*create_nonce_gen)(crypto_factory_t *this);
149
150 /**
151 * Create a diffie hellman instance.
152 *
153 * Additional arguments are passed to the DH constructor.
154 *
155 * @param group diffie hellman group
156 * @return diffie_hellman_t instance, NULL if not supported
157 */
158 diffie_hellman_t* (*create_dh)(crypto_factory_t *this,
159 diffie_hellman_group_t group, ...);
160
161 /**
162 * Register a crypter constructor.
163 *
164 * @param algo algorithm to constructor
165 * @param key size key size to peform benchmarking for
166 * @param plugin_name plugin that registered this algorithm
167 * @param create constructor function for that algorithm
168 * @return TRUE if registered, FALSE if test vector failed
169 */
170 bool (*add_crypter)(crypto_factory_t *this, encryption_algorithm_t algo,
171 size_t key_size, const char *plugin_name,
172 crypter_constructor_t create);
173
174 /**
175 * Unregister a crypter constructor.
176 *
177 * @param create constructor function to unregister
178 */
179 void (*remove_crypter)(crypto_factory_t *this, crypter_constructor_t create);
180
181 /**
182 * Unregister a aead constructor.
183 *
184 * @param create constructor function to unregister
185 */
186 void (*remove_aead)(crypto_factory_t *this, aead_constructor_t create);
187
188 /**
189 * Register a aead constructor.
190 *
191 * @param algo algorithm to constructor
192 * @param key size key size to peform benchmarking for
193 * @param plugin_name plugin that registered this algorithm
194 * @param create constructor function for that algorithm
195 * @return TRUE if registered, FALSE if test vector failed
196 */
197 bool (*add_aead)(crypto_factory_t *this, encryption_algorithm_t algo,
198 size_t key_size, const char *plugin_name,
199 aead_constructor_t create);
200
201 /**
202 * Register a signer constructor.
203 *
204 * @param algo algorithm to constructor
205 * @param plugin_name plugin that registered this algorithm
206 * @param create constructor function for that algorithm
207 * @return TRUE if registered, FALSE if test vector failed
208 */
209 bool (*add_signer)(crypto_factory_t *this, integrity_algorithm_t algo,
210 const char *plugin_name, signer_constructor_t create);
211
212 /**
213 * Unregister a signer constructor.
214 *
215 * @param create constructor function to unregister
216 */
217 void (*remove_signer)(crypto_factory_t *this, signer_constructor_t create);
218
219 /**
220 * Register a hasher constructor.
221 *
222 * @param algo algorithm to constructor
223 * @param plugin_name plugin that registered this algorithm
224 * @param create constructor function for that algorithm
225 * @return TRUE if registered, FALSE if test vector failed
226 */
227 bool (*add_hasher)(crypto_factory_t *this, hash_algorithm_t algo,
228 const char *plugin_name, hasher_constructor_t create);
229
230 /**
231 * Unregister a hasher constructor.
232 *
233 * @param create constructor function to unregister
234 */
235 void (*remove_hasher)(crypto_factory_t *this, hasher_constructor_t create);
236
237 /**
238 * Register a prf constructor.
239 *
240 * @param algo algorithm to constructor
241 * @param plugin_name plugin that registered this algorithm
242 * @param create constructor function for that algorithm
243 * @return TRUE if registered, FALSE if test vector failed
244 */
245 bool (*add_prf)(crypto_factory_t *this, pseudo_random_function_t algo,
246 const char *plugin_name, prf_constructor_t create);
247
248 /**
249 * Unregister a prf constructor.
250 *
251 * @param create constructor function to unregister
252 */
253 void (*remove_prf)(crypto_factory_t *this, prf_constructor_t create);
254
255 /**
256 * Register a source of randomness.
257 *
258 * @param quality quality of randomness this RNG serves
259 * @param plugin_name plugin that registered this algorithm
260 * @param create constructor function for such a quality
261 * @return TRUE if registered, FALSE if test vector failed
262 */
263 bool (*add_rng)(crypto_factory_t *this, rng_quality_t quality,
264 const char *plugin_name, rng_constructor_t create);
265
266 /**
267 * Unregister a source of randomness.
268 *
269 * @param create constructor function to unregister
270 */
271 void (*remove_rng)(crypto_factory_t *this, rng_constructor_t create);
272
273 /**
274 * Register a nonce generator.
275 *
276 * @param plugin_name plugin that registered this algorithm
277 * @param create constructor function for that nonce generator
278 * @return TRUE if registered, FALSE if test vector failed
279 */
280 bool (*add_nonce_gen)(crypto_factory_t *this, const char *plugin_name,
281 nonce_gen_constructor_t create);
282
283 /**
284 * Unregister a nonce generator.
285 *
286 * @param create constructor function to unregister
287 */
288 void (*remove_nonce_gen)(crypto_factory_t *this,
289 nonce_gen_constructor_t create);
290
291 /**
292 * Register a diffie hellman constructor.
293 *
294 * @param group dh group to constructor
295 * @param plugin_name plugin that registered this algorithm
296 * @param create constructor function for that algorithm
297 * @return TRUE if registered, FALSE if test vector failed
298 */
299 bool (*add_dh)(crypto_factory_t *this, diffie_hellman_group_t group,
300 const char *plugin_name, dh_constructor_t create);
301
302 /**
303 * Unregister a diffie hellman constructor.
304 *
305 * @param create constructor function to unregister
306 */
307 void (*remove_dh)(crypto_factory_t *this, dh_constructor_t create);
308
309 /**
310 * Create an enumerator over all registered crypter algorithms.
311 *
312 * @return enumerator over encryption_algorithm_t, plugin
313 */
314 enumerator_t* (*create_crypter_enumerator)(crypto_factory_t *this);
315
316 /**
317 * Create an enumerator over all registered aead algorithms.
318 *
319 * @return enumerator over encryption_algorithm_t, plugin
320 */
321 enumerator_t* (*create_aead_enumerator)(crypto_factory_t *this);
322
323 /**
324 * Create an enumerator over all registered signer algorithms.
325 *
326 * @return enumerator over integrity_algorithm_t, plugin
327 */
328 enumerator_t* (*create_signer_enumerator)(crypto_factory_t *this);
329
330 /**
331 * Create an enumerator over all registered hasher algorithms.
332 *
333 * @return enumerator over hash_algorithm_t, plugin
334 */
335 enumerator_t* (*create_hasher_enumerator)(crypto_factory_t *this);
336
337 /**
338 * Create an enumerator over all registered PRFs.
339 *
340 * @return enumerator over pseudo_random_function_t, plugin
341 */
342 enumerator_t* (*create_prf_enumerator)(crypto_factory_t *this);
343
344 /**
345 * Create an enumerator over all registered diffie hellman groups.
346 *
347 * @return enumerator over diffie_hellman_group_t, plugin
348 */
349 enumerator_t* (*create_dh_enumerator)(crypto_factory_t *this);
350
351 /**
352 * Create an enumerator over all registered random generators.
353 *
354 * @return enumerator over rng_quality_t, plugin
355 */
356 enumerator_t* (*create_rng_enumerator)(crypto_factory_t *this);
357
358 /**
359 * Create an enumerator over all registered nonce generators.
360 *
361 * @return enumerator over plugin
362 */
363 enumerator_t* (*create_nonce_gen_enumerator)(crypto_factory_t *this);
364
365 /**
366 * Add a test vector to the crypto factory.
367 *
368 * @param type type of the test vector
369 * @param vector pointer to a test vector, defined in crypto_tester.h
370 */
371 void (*add_test_vector)(crypto_factory_t *this, transform_type_t type,
372 void *vector);
373
374 /**
375 * Create an enumerator verifying transforms using known test vectors.
376 *
377 * The resulting enumerator enumerates over an u_int with the type
378 * specific transform identifier, the plugin name providing the transform,
379 * and a boolean value indicating success/failure for the given transform.
380 *
381 * @param type transform type to test
382 * @return enumerator over (u_int, char*, bool)
383 */
384 enumerator_t* (*create_verify_enumerator)(crypto_factory_t *this,
385 transform_type_t type);
386
387 /**
388 * Destroy a crypto_factory instance.
389 */
390 void (*destroy)(crypto_factory_t *this);
391 };
392
393 /**
394 * Create a crypto_factory instance.
395 */
396 crypto_factory_t *crypto_factory_create();
397
398 #endif /** CRYPTO_FACTORY_H_ @}*/