0001
0002
0003
0004
0005
0006
0007
0008 #ifndef _CRYPTO_INTERNAL_H
0009 #define _CRYPTO_INTERNAL_H
0010
0011 #include <crypto/algapi.h>
0012 #include <linux/completion.h>
0013 #include <linux/jump_label.h>
0014 #include <linux/list.h>
0015 #include <linux/module.h>
0016 #include <linux/notifier.h>
0017 #include <linux/numa.h>
0018 #include <linux/refcount.h>
0019 #include <linux/rwsem.h>
0020 #include <linux/sched.h>
0021 #include <linux/types.h>
0022
0023 struct crypto_instance;
0024 struct crypto_template;
0025
0026 struct crypto_larval {
0027 struct crypto_alg alg;
0028 struct crypto_alg *adult;
0029 struct completion completion;
0030 u32 mask;
0031 bool test_started;
0032 };
0033
0034 enum {
0035 CRYPTOA_UNSPEC,
0036 CRYPTOA_ALG,
0037 CRYPTOA_TYPE,
0038 __CRYPTOA_MAX,
0039 };
0040
0041 #define CRYPTOA_MAX (__CRYPTOA_MAX - 1)
0042
0043
0044 #define CRYPTO_MAX_ATTRS 32
0045
0046 extern struct list_head crypto_alg_list;
0047 extern struct rw_semaphore crypto_alg_sem;
0048 extern struct blocking_notifier_head crypto_chain;
0049
0050 DECLARE_STATIC_KEY_FALSE(crypto_boot_test_finished);
0051
0052 #ifdef CONFIG_PROC_FS
0053 void __init crypto_init_proc(void);
0054 void __exit crypto_exit_proc(void);
0055 #else
0056 static inline void crypto_init_proc(void)
0057 { }
0058 static inline void crypto_exit_proc(void)
0059 { }
0060 #endif
0061
0062 static inline unsigned int crypto_cipher_ctxsize(struct crypto_alg *alg)
0063 {
0064 return alg->cra_ctxsize;
0065 }
0066
0067 static inline unsigned int crypto_compress_ctxsize(struct crypto_alg *alg)
0068 {
0069 return alg->cra_ctxsize;
0070 }
0071
0072 struct crypto_alg *crypto_mod_get(struct crypto_alg *alg);
0073 struct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask);
0074
0075 struct crypto_larval *crypto_larval_alloc(const char *name, u32 type, u32 mask);
0076 void crypto_larval_kill(struct crypto_alg *alg);
0077 void crypto_wait_for_test(struct crypto_larval *larval);
0078 void crypto_alg_tested(const char *name, int err);
0079
0080 void crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list,
0081 struct crypto_alg *nalg);
0082 void crypto_remove_final(struct list_head *list);
0083 void crypto_shoot_alg(struct crypto_alg *alg);
0084 struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type,
0085 u32 mask);
0086 void *crypto_create_tfm_node(struct crypto_alg *alg,
0087 const struct crypto_type *frontend, int node);
0088
0089 static inline void *crypto_create_tfm(struct crypto_alg *alg,
0090 const struct crypto_type *frontend)
0091 {
0092 return crypto_create_tfm_node(alg, frontend, NUMA_NO_NODE);
0093 }
0094
0095 struct crypto_alg *crypto_find_alg(const char *alg_name,
0096 const struct crypto_type *frontend,
0097 u32 type, u32 mask);
0098
0099 void *crypto_alloc_tfm_node(const char *alg_name,
0100 const struct crypto_type *frontend, u32 type, u32 mask,
0101 int node);
0102
0103 static inline void *crypto_alloc_tfm(const char *alg_name,
0104 const struct crypto_type *frontend, u32 type, u32 mask)
0105 {
0106 return crypto_alloc_tfm_node(alg_name, frontend, type, mask, NUMA_NO_NODE);
0107 }
0108
0109 int crypto_probing_notify(unsigned long val, void *v);
0110
0111 unsigned int crypto_alg_extsize(struct crypto_alg *alg);
0112
0113 int crypto_type_has_alg(const char *name, const struct crypto_type *frontend,
0114 u32 type, u32 mask);
0115
0116 static inline struct crypto_alg *crypto_alg_get(struct crypto_alg *alg)
0117 {
0118 refcount_inc(&alg->cra_refcnt);
0119 return alg;
0120 }
0121
0122 static inline void crypto_alg_put(struct crypto_alg *alg)
0123 {
0124 if (refcount_dec_and_test(&alg->cra_refcnt) && alg->cra_destroy)
0125 alg->cra_destroy(alg);
0126 }
0127
0128 static inline int crypto_tmpl_get(struct crypto_template *tmpl)
0129 {
0130 return try_module_get(tmpl->module);
0131 }
0132
0133 static inline void crypto_tmpl_put(struct crypto_template *tmpl)
0134 {
0135 module_put(tmpl->module);
0136 }
0137
0138 static inline int crypto_is_larval(struct crypto_alg *alg)
0139 {
0140 return alg->cra_flags & CRYPTO_ALG_LARVAL;
0141 }
0142
0143 static inline int crypto_is_dead(struct crypto_alg *alg)
0144 {
0145 return alg->cra_flags & CRYPTO_ALG_DEAD;
0146 }
0147
0148 static inline int crypto_is_moribund(struct crypto_alg *alg)
0149 {
0150 return alg->cra_flags & (CRYPTO_ALG_DEAD | CRYPTO_ALG_DYING);
0151 }
0152
0153 static inline void crypto_notify(unsigned long val, void *v)
0154 {
0155 blocking_notifier_call_chain(&crypto_chain, val, v);
0156 }
0157
0158 static inline void crypto_yield(u32 flags)
0159 {
0160 if (flags & CRYPTO_TFM_REQ_MAY_SLEEP)
0161 cond_resched();
0162 }
0163
0164 static inline int crypto_is_test_larval(struct crypto_larval *larval)
0165 {
0166 return larval->alg.cra_driver_name[0];
0167 }
0168
0169 #endif
0170