2 * Cryptographic API for algorithms (i.e., low-level API).
4 * Copyright (c) 2006 Herbert Xu <herbert@gondor.apana.org.au>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
13 #include <linux/errno.h>
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/string.h>
21 static inline int crypto_set_driver_name(struct crypto_alg *alg)
23 static const char suffix[] = "-generic";
24 char *driver_name = alg->cra_driver_name;
30 len = strlcpy(driver_name, alg->cra_name, CRYPTO_MAX_ALG_NAME);
31 if (len + sizeof(suffix) > CRYPTO_MAX_ALG_NAME)
34 memcpy(driver_name + len, suffix, sizeof(suffix));
38 int crypto_register_alg(struct crypto_alg *alg)
43 if (alg->cra_alignmask & (alg->cra_alignmask + 1))
46 if (alg->cra_alignmask & alg->cra_blocksize)
49 if (alg->cra_blocksize > PAGE_SIZE / 8)
52 if (alg->cra_priority < 0)
55 ret = crypto_set_driver_name(alg);
59 down_write(&crypto_alg_sem);
61 list_for_each_entry(q, &crypto_alg_list, cra_list) {
68 list_add(&alg->cra_list, &crypto_alg_list);
69 atomic_set(&alg->cra_refcnt, 1);
71 up_write(&crypto_alg_sem);
74 EXPORT_SYMBOL_GPL(crypto_register_alg);
76 int crypto_unregister_alg(struct crypto_alg *alg)
81 down_write(&crypto_alg_sem);
82 list_for_each_entry(q, &crypto_alg_list, cra_list) {
84 list_del(&alg->cra_list);
90 up_write(&crypto_alg_sem);
95 BUG_ON(atomic_read(&alg->cra_refcnt) != 1);
97 alg->cra_destroy(alg);
101 EXPORT_SYMBOL_GPL(crypto_unregister_alg);
103 static int __init crypto_algapi_init(void)
109 static void __exit crypto_algapi_exit(void)
114 module_init(crypto_algapi_init);
115 module_exit(crypto_algapi_exit);
117 MODULE_LICENSE("GPL");
118 MODULE_DESCRIPTION("Cryptographic algorithms API");