make use of the crypto_tester in the crypto_factory
[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 <crypto/crypters/crypter.h>
28 #include <crypto/signers/signer.h>
29 #include <crypto/hashers/hasher.h>
30 #include <crypto/prfs/prf.h>
31 #include <crypto/rngs/rng.h>
32 #include <crypto/diffie_hellman.h>
33 #include <crypto/transform.h>
34
35 /**
36 * Constructor function for crypters
37 */
38 typedef crypter_t* (*crypter_constructor_t)(encryption_algorithm_t algo,
39 size_t key_size);
40 /**
41 * Constructor function for signers
42 */
43 typedef signer_t* (*signer_constructor_t)(integrity_algorithm_t algo);
44
45 /**
46 * Constructor function for hashers
47 */
48 typedef hasher_t* (*hasher_constructor_t)(hash_algorithm_t algo);
49
50 /**
51 * Constructor function for pseudo random functions
52 */
53 typedef prf_t* (*prf_constructor_t)(pseudo_random_function_t algo);
54
55 /**
56 * Constructor function for source of randomness
57 */
58 typedef rng_t* (*rng_constructor_t)(rng_quality_t quality);
59
60 /**
61 * Constructor function for diffie hellman
62 */
63 typedef diffie_hellman_t* (*dh_constructor_t)(diffie_hellman_group_t group);
64
65 /**
66 * Handles crypto modules and creates instances.
67 */
68 struct crypto_factory_t {
69
70 /**
71 * Create a crypter instance.
72 *
73 * @param algo encryption algorithm
74 * @param key_size length of the key in bytes
75 * @return crypter_t instance, NULL if not supported
76 */
77 crypter_t* (*create_crypter)(crypto_factory_t *this,
78 encryption_algorithm_t algo, size_t key_size);
79
80 /**
81 * Create a symmetric signer instance.
82 *
83 * @param algo MAC algorithm to use
84 * @return signer_t instance, NULL if not supported
85 */
86 signer_t* (*create_signer)(crypto_factory_t *this,
87 integrity_algorithm_t algo);
88
89 /**
90 * Create a hasher instance.
91 *
92 * @param algo hash algorithm
93 * @return hasher_t instance, NULL if not supported
94 */
95 hasher_t* (*create_hasher)(crypto_factory_t *this, hash_algorithm_t algo);
96
97 /**
98 * Create a pseudo random function instance.
99 *
100 * @param algo PRF algorithm to use
101 * @return prf_t instance, NULL if not supported
102 */
103 prf_t* (*create_prf)(crypto_factory_t *this, pseudo_random_function_t algo);
104
105 /**
106 * Create a source of randomness.
107 *
108 * @param quality required randomness quality
109 * @return rng_t instance, NULL if no RNG with such a quality
110 */
111 rng_t* (*create_rng)(crypto_factory_t *this, rng_quality_t quality);
112
113 /**
114 * Create a diffie hellman instance.
115 *
116 * @param group diffie hellman group
117 * @return diffie_hellman_t instance, NULL if not supported
118 */
119 diffie_hellman_t* (*create_dh)(crypto_factory_t *this,
120 diffie_hellman_group_t group);
121
122 /**
123 * Register a crypter constructor.
124 *
125 * @param algo algorithm to constructor
126 * @param create constructor function for that algorithm
127 * @return
128 */
129 void (*add_crypter)(crypto_factory_t *this, encryption_algorithm_t algo,
130 crypter_constructor_t create);
131
132 /**
133 * Unregister a crypter constructor.
134 *
135 * @param create constructor function to unregister
136 */
137 void (*remove_crypter)(crypto_factory_t *this, crypter_constructor_t create);
138
139 /**
140 * Register a signer constructor.
141 *
142 * @param algo algorithm to constructor
143 * @param create constructor function for that algorithm
144 * @return
145 */
146 void (*add_signer)(crypto_factory_t *this, integrity_algorithm_t algo,
147 signer_constructor_t create);
148
149 /**
150 * Unregister a signer constructor.
151 *
152 * @param create constructor function to unregister
153 */
154 void (*remove_signer)(crypto_factory_t *this, signer_constructor_t create);
155
156 /**
157 * Register a hasher constructor.
158 *
159 * The first added hasher is the preferred hasher returned on
160 * create_hasher(HASH_PREFERRED).
161 *
162 * @param algo algorithm to constructor
163 * @param create constructor function for that algorithm
164 * @return
165 */
166 void (*add_hasher)(crypto_factory_t *this, hash_algorithm_t algo,
167 hasher_constructor_t create);
168
169 /**
170 * Unregister a hasher constructor.
171 *
172 * @param create constructor function to unregister
173 */
174 void (*remove_hasher)(crypto_factory_t *this, hasher_constructor_t create);
175
176 /**
177 * Register a prf constructor.
178 *
179 * @param algo algorithm to constructor
180 * @param create constructor function for that algorithm
181 * @return
182 */
183 void (*add_prf)(crypto_factory_t *this, pseudo_random_function_t algo,
184 prf_constructor_t create);
185
186 /**
187 * Unregister a prf constructor.
188 *
189 * @param create constructor function to unregister
190 */
191 void (*remove_prf)(crypto_factory_t *this, prf_constructor_t create);
192
193 /**
194 * Register a source of randomness.
195 *
196 * @param quality quality of randomness this RNG serves
197 * @param create constructor function for such a quality
198 */
199 void (*add_rng)(crypto_factory_t *this, rng_quality_t quality, rng_constructor_t create);
200
201 /**
202 * Unregister a source of randomness.
203 *
204 * @param create constructor function to unregister
205 */
206 void (*remove_rng)(crypto_factory_t *this, rng_constructor_t create);
207
208 /**
209 * Register a diffie hellman constructor.
210 *
211 * @param group dh group to constructor
212 * @param create constructor function for that algorithm
213 * @return
214 */
215 void (*add_dh)(crypto_factory_t *this, diffie_hellman_group_t group,
216 dh_constructor_t create);
217
218 /**
219 * Unregister a diffie hellman constructor.
220 *
221 * @param create constructor function to unregister
222 */
223 void (*remove_dh)(crypto_factory_t *this, dh_constructor_t create);
224
225 /**
226 * Create an enumerator over all registered crypter algorithms.
227 *
228 * @return enumerator over encryption_algorithm_t
229 */
230 enumerator_t* (*create_crypter_enumerator)(crypto_factory_t *this);
231
232 /**
233 * Create an enumerator over all registered signer algorithms.
234 *
235 * @return enumerator over integrity_algorithm_t
236 */
237 enumerator_t* (*create_signer_enumerator)(crypto_factory_t *this);
238
239 /**
240 * Create an enumerator over all registered hasher algorithms.
241 *
242 * @return enumerator over hash_algorithm_t
243 */
244 enumerator_t* (*create_hasher_enumerator)(crypto_factory_t *this);
245
246 /**
247 * Create an enumerator over all registered PRFs.
248 *
249 * @return enumerator over pseudo_random_function_t
250 */
251 enumerator_t* (*create_prf_enumerator)(crypto_factory_t *this);
252
253 /**
254 * Create an enumerator over all registered diffie hellman groups.
255 *
256 * @return enumerator over diffie_hellman_group_t
257 */
258 enumerator_t* (*create_dh_enumerator)(crypto_factory_t *this);
259
260 /**
261 * Add a test vector to the crypto factory.
262 *
263 * @param type type of the test vector
264 * @param ... pointer to a test vector, defined in crypto_tester.h
265 */
266 void (*add_test_vector)(crypto_factory_t *this, transform_type_t type, ...);
267
268 /**
269 * Destroy a crypto_factory instance.
270 */
271 void (*destroy)(crypto_factory_t *this);
272 };
273
274 /**
275 * Create a crypto_factory instance.
276 */
277 crypto_factory_t *crypto_factory_create();
278
279 #endif /** CRYPTO_FACTORY_H_ @}*/