aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/api.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2006-08-21 07:08:13 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2006-09-20 21:16:30 -0400
commitcce9e06d100df19a327b19f23adad76e7bf63edd (patch)
treece10f50679db9ed8db92912c104eef1f05efc3c5 /crypto/api.c
parent9409f38a0c8773c04bff8dda8c552d7ea013d956 (diff)
[CRYPTO] api: Split out low-level API
The crypto API is made up of the part facing users such as IPsec and the low-level part which is used by cryptographic entities such as algorithms. This patch splits out the latter so that the two APIs are more clearly delineated. As a bonus the low-level API can now be modularised if all algorithms are built as modules. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/api.c')
-rw-r--r--crypto/api.c97
1 files changed, 2 insertions, 95 deletions
diff --git a/crypto/api.c b/crypto/api.c
index 5994a58ef954..c922090b4842 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -15,19 +15,17 @@
15 * 15 *
16 */ 16 */
17 17
18#include <linux/compiler.h>
19#include <linux/init.h>
20#include <linux/crypto.h>
21#include <linux/errno.h> 18#include <linux/errno.h>
22#include <linux/kernel.h> 19#include <linux/kernel.h>
23#include <linux/kmod.h> 20#include <linux/kmod.h>
24#include <linux/rwsem.h>
25#include <linux/slab.h> 21#include <linux/slab.h>
26#include <linux/string.h> 22#include <linux/string.h>
27#include "internal.h" 23#include "internal.h"
28 24
29LIST_HEAD(crypto_alg_list); 25LIST_HEAD(crypto_alg_list);
26EXPORT_SYMBOL_GPL(crypto_alg_list);
30DECLARE_RWSEM(crypto_alg_sem); 27DECLARE_RWSEM(crypto_alg_sem);
28EXPORT_SYMBOL_GPL(crypto_alg_sem);
31 29
32static inline struct crypto_alg *crypto_alg_get(struct crypto_alg *alg) 30static inline struct crypto_alg *crypto_alg_get(struct crypto_alg *alg)
33{ 31{
@@ -239,86 +237,6 @@ void crypto_free_tfm(struct crypto_tfm *tfm)
239 kfree(tfm); 237 kfree(tfm);
240} 238}
241 239
242static inline int crypto_set_driver_name(struct crypto_alg *alg)
243{
244 static const char suffix[] = "-generic";
245 char *driver_name = alg->cra_driver_name;
246 int len;
247
248 if (*driver_name)
249 return 0;
250
251 len = strlcpy(driver_name, alg->cra_name, CRYPTO_MAX_ALG_NAME);
252 if (len + sizeof(suffix) > CRYPTO_MAX_ALG_NAME)
253 return -ENAMETOOLONG;
254
255 memcpy(driver_name + len, suffix, sizeof(suffix));
256 return 0;
257}
258
259int crypto_register_alg(struct crypto_alg *alg)
260{
261 int ret;
262 struct crypto_alg *q;
263
264 if (alg->cra_alignmask & (alg->cra_alignmask + 1))
265 return -EINVAL;
266
267 if (alg->cra_alignmask & alg->cra_blocksize)
268 return -EINVAL;
269
270 if (alg->cra_blocksize > PAGE_SIZE / 8)
271 return -EINVAL;
272
273 if (alg->cra_priority < 0)
274 return -EINVAL;
275
276 ret = crypto_set_driver_name(alg);
277 if (unlikely(ret))
278 return ret;
279
280 down_write(&crypto_alg_sem);
281
282 list_for_each_entry(q, &crypto_alg_list, cra_list) {
283 if (q == alg) {
284 ret = -EEXIST;
285 goto out;
286 }
287 }
288
289 list_add(&alg->cra_list, &crypto_alg_list);
290 atomic_set(&alg->cra_refcnt, 1);
291out:
292 up_write(&crypto_alg_sem);
293 return ret;
294}
295
296int crypto_unregister_alg(struct crypto_alg *alg)
297{
298 int ret = -ENOENT;
299 struct crypto_alg *q;
300
301 down_write(&crypto_alg_sem);
302 list_for_each_entry(q, &crypto_alg_list, cra_list) {
303 if (alg == q) {
304 list_del(&alg->cra_list);
305 ret = 0;
306 goto out;
307 }
308 }
309out:
310 up_write(&crypto_alg_sem);
311
312 if (ret)
313 return ret;
314
315 BUG_ON(atomic_read(&alg->cra_refcnt) != 1);
316 if (alg->cra_destroy)
317 alg->cra_destroy(alg);
318
319 return 0;
320}
321
322int crypto_alg_available(const char *name, u32 flags) 240int crypto_alg_available(const char *name, u32 flags)
323{ 241{
324 int ret = 0; 242 int ret = 0;
@@ -332,17 +250,6 @@ int crypto_alg_available(const char *name, u32 flags)
332 return ret; 250 return ret;
333} 251}
334 252
335static int __init init_crypto(void)
336{
337 printk(KERN_INFO "Initializing Cryptographic API\n");
338 crypto_init_proc();
339 return 0;
340}
341
342__initcall(init_crypto);
343
344EXPORT_SYMBOL_GPL(crypto_register_alg);
345EXPORT_SYMBOL_GPL(crypto_unregister_alg);
346EXPORT_SYMBOL_GPL(crypto_alloc_tfm); 253EXPORT_SYMBOL_GPL(crypto_alloc_tfm);
347EXPORT_SYMBOL_GPL(crypto_free_tfm); 254EXPORT_SYMBOL_GPL(crypto_free_tfm);
348EXPORT_SYMBOL_GPL(crypto_alg_available); 255EXPORT_SYMBOL_GPL(crypto_alg_available);