diff options
Diffstat (limited to 'crypto/api.c')
| -rw-r--r-- | crypto/api.c | 97 |
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 | ||
| 29 | LIST_HEAD(crypto_alg_list); | 25 | LIST_HEAD(crypto_alg_list); |
| 26 | EXPORT_SYMBOL_GPL(crypto_alg_list); | ||
| 30 | DECLARE_RWSEM(crypto_alg_sem); | 27 | DECLARE_RWSEM(crypto_alg_sem); |
| 28 | EXPORT_SYMBOL_GPL(crypto_alg_sem); | ||
| 31 | 29 | ||
| 32 | static inline struct crypto_alg *crypto_alg_get(struct crypto_alg *alg) | 30 | static 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 | ||
| 242 | static 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 | |||
| 259 | int 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); | ||
| 291 | out: | ||
| 292 | up_write(&crypto_alg_sem); | ||
| 293 | return ret; | ||
| 294 | } | ||
| 295 | |||
| 296 | int 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 | } | ||
| 309 | out: | ||
| 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 | |||
| 322 | int crypto_alg_available(const char *name, u32 flags) | 240 | int 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 | ||
| 335 | static 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 | |||
| 344 | EXPORT_SYMBOL_GPL(crypto_register_alg); | ||
| 345 | EXPORT_SYMBOL_GPL(crypto_unregister_alg); | ||
| 346 | EXPORT_SYMBOL_GPL(crypto_alloc_tfm); | 253 | EXPORT_SYMBOL_GPL(crypto_alloc_tfm); |
| 347 | EXPORT_SYMBOL_GPL(crypto_free_tfm); | 254 | EXPORT_SYMBOL_GPL(crypto_free_tfm); |
| 348 | EXPORT_SYMBOL_GPL(crypto_alg_available); | 255 | EXPORT_SYMBOL_GPL(crypto_alg_available); |
