11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Cryptographic API. 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> 55cb1454bSHerbert Xu * Copyright (c) 2005 Herbert Xu <herbert@gondor.apana.org.au> 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify it 81da177e4SLinus Torvalds * under the terms of the GNU General Public License as published by the Free 91da177e4SLinus Torvalds * Software Foundation; either version 2 of the License, or (at your option) 101da177e4SLinus Torvalds * any later version. 111da177e4SLinus Torvalds * 121da177e4SLinus Torvalds */ 131da177e4SLinus Torvalds #ifndef _CRYPTO_INTERNAL_H 141da177e4SLinus Torvalds #define _CRYPTO_INTERNAL_H 15cce9e06dSHerbert Xu 16cce9e06dSHerbert Xu #include <crypto/algapi.h> 172825982dSHerbert Xu #include <linux/completion.h> 181da177e4SLinus Torvalds #include <linux/mm.h> 191da177e4SLinus Torvalds #include <linux/highmem.h> 201da177e4SLinus Torvalds #include <linux/interrupt.h> 211da177e4SLinus Torvalds #include <linux/init.h> 225cb1454bSHerbert Xu #include <linux/list.h> 234cc7720cSHerbert Xu #include <linux/module.h> 24fbdae9f3SHerbert Xu #include <linux/kernel.h> 252825982dSHerbert Xu #include <linux/notifier.h> 265cb1454bSHerbert Xu #include <linux/rwsem.h> 2764baf3cfSHerbert Xu #include <linux/slab.h> 285b739ef8SNeil Horman #include <linux/fips.h> 29ccb778e1SNeil Horman 302825982dSHerbert Xu /* Crypto notification events. */ 312825982dSHerbert Xu enum { 322825982dSHerbert Xu CRYPTO_MSG_ALG_REQUEST, 332825982dSHerbert Xu CRYPTO_MSG_ALG_REGISTER, 342825982dSHerbert Xu CRYPTO_MSG_ALG_UNREGISTER, 352825982dSHerbert Xu CRYPTO_MSG_TMPL_REGISTER, 362825982dSHerbert Xu CRYPTO_MSG_TMPL_UNREGISTER, 372825982dSHerbert Xu }; 382825982dSHerbert Xu 394cc7720cSHerbert Xu struct crypto_instance; 404cc7720cSHerbert Xu struct crypto_template; 414cc7720cSHerbert Xu 422825982dSHerbert Xu struct crypto_larval { 432825982dSHerbert Xu struct crypto_alg alg; 442825982dSHerbert Xu struct crypto_alg *adult; 452825982dSHerbert Xu struct completion completion; 46492e2b63SHerbert Xu u32 mask; 472825982dSHerbert Xu }; 482825982dSHerbert Xu 495cb1454bSHerbert Xu extern struct list_head crypto_alg_list; 505cb1454bSHerbert Xu extern struct rw_semaphore crypto_alg_sem; 512825982dSHerbert Xu extern struct blocking_notifier_head crypto_chain; 525cb1454bSHerbert Xu 531da177e4SLinus Torvalds #ifdef CONFIG_PROC_FS 541da177e4SLinus Torvalds void __init crypto_init_proc(void); 55cce9e06dSHerbert Xu void __exit crypto_exit_proc(void); 561da177e4SLinus Torvalds #else 571da177e4SLinus Torvalds static inline void crypto_init_proc(void) 581da177e4SLinus Torvalds { } 59cce9e06dSHerbert Xu static inline void crypto_exit_proc(void) 60cce9e06dSHerbert Xu { } 611da177e4SLinus Torvalds #endif 621da177e4SLinus Torvalds 63f1ddcaf3SHerbert Xu static inline unsigned int crypto_cipher_ctxsize(struct crypto_alg *alg) 64fbdae9f3SHerbert Xu { 65f1ddcaf3SHerbert Xu return alg->cra_ctxsize; 66fbdae9f3SHerbert Xu } 67fbdae9f3SHerbert Xu 68f1ddcaf3SHerbert Xu static inline unsigned int crypto_compress_ctxsize(struct crypto_alg *alg) 69fbdae9f3SHerbert Xu { 70fbdae9f3SHerbert Xu return alg->cra_ctxsize; 71fbdae9f3SHerbert Xu } 72fbdae9f3SHerbert Xu 732825982dSHerbert Xu struct crypto_alg *crypto_mod_get(struct crypto_alg *alg); 74c51b6c81SHerbert Xu struct crypto_alg *crypto_alg_lookup(const char *name, u32 type, u32 mask); 75492e2b63SHerbert Xu struct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask); 762825982dSHerbert Xu 771da177e4SLinus Torvalds int crypto_init_cipher_ops(struct crypto_tfm *tfm); 781da177e4SLinus Torvalds int crypto_init_compress_ops(struct crypto_tfm *tfm); 791da177e4SLinus Torvalds 801da177e4SLinus Torvalds void crypto_exit_cipher_ops(struct crypto_tfm *tfm); 811da177e4SLinus Torvalds void crypto_exit_compress_ops(struct crypto_tfm *tfm); 821da177e4SLinus Torvalds 8373d3864aSHerbert Xu struct crypto_larval *crypto_larval_alloc(const char *name, u32 type, u32 mask); 84b9c55aa4SHerbert Xu void crypto_larval_kill(struct crypto_alg *alg); 85b9c55aa4SHerbert Xu struct crypto_alg *crypto_larval_lookup(const char *name, u32 type, u32 mask); 86492e2b63SHerbert Xu void crypto_larval_error(const char *name, u32 type, u32 mask); 8773d3864aSHerbert Xu void crypto_alg_tested(const char *name, int err); 882825982dSHerbert Xu 8989b596baSSteffen Klassert void crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list, 9089b596baSSteffen Klassert struct crypto_alg *nalg); 91*22e5b20bSSteffen Klassert void crypto_remove_final(struct list_head *list); 926bfd4809SHerbert Xu void crypto_shoot_alg(struct crypto_alg *alg); 9327d2a330SHerbert Xu struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type, 9427d2a330SHerbert Xu u32 mask); 953f683d61SHerbert Xu void *crypto_create_tfm(struct crypto_alg *alg, 967b0bac64SHerbert Xu const struct crypto_type *frontend); 97d06854f0SHerbert Xu struct crypto_alg *crypto_find_alg(const char *alg_name, 98d06854f0SHerbert Xu const struct crypto_type *frontend, 99d06854f0SHerbert Xu u32 type, u32 mask); 1003f683d61SHerbert Xu void *crypto_alloc_tfm(const char *alg_name, 1013f683d61SHerbert Xu const struct crypto_type *frontend, u32 type, u32 mask); 1026bfd4809SHerbert Xu 1032825982dSHerbert Xu int crypto_register_notifier(struct notifier_block *nb); 1042825982dSHerbert Xu int crypto_unregister_notifier(struct notifier_block *nb); 10573d3864aSHerbert Xu int crypto_probing_notify(unsigned long val, void *v); 1062825982dSHerbert Xu 1076bfd4809SHerbert Xu static inline void crypto_alg_put(struct crypto_alg *alg) 1086bfd4809SHerbert Xu { 1096bfd4809SHerbert Xu if (atomic_dec_and_test(&alg->cra_refcnt) && alg->cra_destroy) 1106bfd4809SHerbert Xu alg->cra_destroy(alg); 1116bfd4809SHerbert Xu } 1126bfd4809SHerbert Xu 1134cc7720cSHerbert Xu static inline int crypto_tmpl_get(struct crypto_template *tmpl) 1144cc7720cSHerbert Xu { 1154cc7720cSHerbert Xu return try_module_get(tmpl->module); 1164cc7720cSHerbert Xu } 1174cc7720cSHerbert Xu 1184cc7720cSHerbert Xu static inline void crypto_tmpl_put(struct crypto_template *tmpl) 1194cc7720cSHerbert Xu { 1204cc7720cSHerbert Xu module_put(tmpl->module); 1214cc7720cSHerbert Xu } 1224cc7720cSHerbert Xu 1232825982dSHerbert Xu static inline int crypto_is_larval(struct crypto_alg *alg) 1242825982dSHerbert Xu { 1252825982dSHerbert Xu return alg->cra_flags & CRYPTO_ALG_LARVAL; 1262825982dSHerbert Xu } 1272825982dSHerbert Xu 1286bfd4809SHerbert Xu static inline int crypto_is_dead(struct crypto_alg *alg) 1296bfd4809SHerbert Xu { 1306bfd4809SHerbert Xu return alg->cra_flags & CRYPTO_ALG_DEAD; 1316bfd4809SHerbert Xu } 1326bfd4809SHerbert Xu 1336bfd4809SHerbert Xu static inline int crypto_is_moribund(struct crypto_alg *alg) 1346bfd4809SHerbert Xu { 1356bfd4809SHerbert Xu return alg->cra_flags & (CRYPTO_ALG_DEAD | CRYPTO_ALG_DYING); 1366bfd4809SHerbert Xu } 1376bfd4809SHerbert Xu 13873d3864aSHerbert Xu static inline void crypto_notify(unsigned long val, void *v) 1392825982dSHerbert Xu { 14073d3864aSHerbert Xu blocking_notifier_call_chain(&crypto_chain, val, v); 1412825982dSHerbert Xu } 1422825982dSHerbert Xu 1431da177e4SLinus Torvalds #endif /* _CRYPTO_INTERNAL_H */ 1441da177e4SLinus Torvalds 145