The introduced SHA1_NOFINAL hasher was not sufficient for EAP-AKA,
[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/diffie_hellman.h>
32
33 /**
34 * Constructor function for crypters
35 */
36 typedef crypter_t* (*crypter_constructor_t)(encryption_algorithm_t algo,
37 size_t key_size);
38 /**
39 * Constructor function for signers
40 */
41 typedef signer_t* (*signer_constructor_t)(integrity_algorithm_t algo);
42
43 /**
44 * Constructor function for hashers
45 */
46 typedef hasher_t* (*hasher_constructor_t)(hash_algorithm_t algo);
47
48 /**
49 * Constructor function for pseudo random fucntions
50 */
51 typedef prf_t* (*prf_constructor_t)(pseudo_random_function_t algo);
52
53 /**
54 * Constructor function for diffie hellman
55 */
56 typedef diffie_hellman_t* (*dh_constructor_t)(diffie_hellman_group_t group);
57
58 /**
59 * Handles crypto modules and creates instances.
60 */
61 struct crypto_factory_t {
62
63 /**
64 * Create a crypter instance.
65 *
66 * @param algo encryption algorithm
67 * @param key_size length of the key in bytes
68 * @return crypter_t instance, NULL if not supported
69 */
70 crypter_t* (*create_crypter)(crypto_factory_t *this,
71 encryption_algorithm_t algo, size_t key_size);
72
73 /**
74 * Create a symmetric signer instance.
75 *
76 * @param algo MAC algorithm to use
77 * @return signer_t instance, NULL if not supported
78 */
79 signer_t* (*create_signer)(crypto_factory_t *this,
80 integrity_algorithm_t algo);
81
82 /**
83 * Create a hasher instance.
84 *
85 * @param algo hash algorithm
86 * @return hasher_t instance, NULL if not supported
87 */
88 hasher_t* (*create_hasher)(crypto_factory_t *this, hash_algorithm_t algo);
89
90 /**
91 * Create a pseudo random function instance.
92 *
93 * @param algo PRF algorithm to use
94 * @return prf_t instance, NULL if not supported
95 */
96 prf_t* (*create_prf)(crypto_factory_t *this, pseudo_random_function_t algo);
97
98 /**
99 * Create a diffie hellman instance.
100 *
101 * @param group diffie hellman group
102 * @return diffie_hellman_t instance, NULL if not supported
103 */
104 diffie_hellman_t* (*create_dh)(crypto_factory_t *this,
105 diffie_hellman_group_t group);
106
107 /**
108 * Register a crypter constructor.
109 *
110 * @param algo algorithm to constructor
111 * @param create constructor function for that algorithm
112 * @return
113 */
114 void (*add_crypter)(crypto_factory_t *this, encryption_algorithm_t algo,
115 crypter_constructor_t create);
116
117 /**
118 * Unregister a crypter constructor.
119 *
120 * @param create constructor function to unregister
121 */
122 void (*remove_crypter)(crypto_factory_t *this, crypter_constructor_t create);
123
124 /**
125 * Register a signer constructor.
126 *
127 * @param algo algorithm to constructor
128 * @param create constructor function for that algorithm
129 * @return
130 */
131 void (*add_signer)(crypto_factory_t *this, integrity_algorithm_t algo,
132 signer_constructor_t create);
133
134 /**
135 * Unregister a signer constructor.
136 *
137 * @param create constructor function to unregister
138 */
139 void (*remove_signer)(crypto_factory_t *this, signer_constructor_t create);
140
141 /**
142 * Register a hasher constructor.
143 *
144 * The first added hasher is the preferred hasher returned on
145 * create_hasher(HASH_PREFERRED).
146 *
147 * @param algo algorithm to constructor
148 * @param create constructor function for that algorithm
149 * @return
150 */
151 void (*add_hasher)(crypto_factory_t *this, hash_algorithm_t algo,
152 hasher_constructor_t create);
153
154 /**
155 * Unregister a hasher constructor.
156 *
157 * @param create constructor function to unregister
158 */
159 void (*remove_hasher)(crypto_factory_t *this, hasher_constructor_t create);
160
161 /**
162 * Register a prf constructor.
163 *
164 * @param algo algorithm to constructor
165 * @param create constructor function for that algorithm
166 * @return
167 */
168 void (*add_prf)(crypto_factory_t *this, pseudo_random_function_t algo,
169 prf_constructor_t create);
170
171 /**
172 * Unregister a prf constructor.
173 *
174 * @param create constructor function to unregister
175 */
176 void (*remove_prf)(crypto_factory_t *this, prf_constructor_t create);
177
178 /**
179 * Register a diffie hellman constructor.
180 *
181 * @param group dh group to constructor
182 * @param create constructor function for that algorithm
183 * @return
184 */
185 void (*add_dh)(crypto_factory_t *this, diffie_hellman_group_t group,
186 dh_constructor_t create);
187
188 /**
189 * Unregister a diffie hellman constructor.
190 *
191 * @param create constructor function to unregister
192 */
193 void (*remove_dh)(crypto_factory_t *this, dh_constructor_t create);
194
195 /**
196 * Destroy a crypto_factory instance.
197 */
198 void (*destroy)(crypto_factory_t *this);
199 };
200
201 /**
202 * Create a crypto_factory instance.
203 */
204 crypto_factory_t *crypto_factory_create();
205
206 #endif /* CRYPTO_FACTORY_H_ @}*/