Back to home page

LXR

 
 

    


0001 /*
0002  * Cryptographic API.
0003  *
0004  * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
0005  * Copyright (c) 2005 Herbert Xu <herbert@gondor.apana.org.au>
0006  *
0007  * This program is free software; you can redistribute it and/or modify it
0008  * under the terms of the GNU General Public License as published by the Free
0009  * Software Foundation; either version 2 of the License, or (at your option)
0010  * any later version.
0011  *
0012  */
0013 #ifndef _CRYPTO_INTERNAL_H
0014 #define _CRYPTO_INTERNAL_H
0015 
0016 #include <crypto/algapi.h>
0017 #include <linux/completion.h>
0018 #include <linux/mm.h>
0019 #include <linux/highmem.h>
0020 #include <linux/interrupt.h>
0021 #include <linux/init.h>
0022 #include <linux/list.h>
0023 #include <linux/module.h>
0024 #include <linux/kernel.h>
0025 #include <linux/notifier.h>
0026 #include <linux/rwsem.h>
0027 #include <linux/slab.h>
0028 
0029 /* Crypto notification events. */
0030 enum {
0031     CRYPTO_MSG_ALG_REQUEST,
0032     CRYPTO_MSG_ALG_REGISTER,
0033     CRYPTO_MSG_ALG_UNREGISTER,
0034     CRYPTO_MSG_TMPL_REGISTER,
0035     CRYPTO_MSG_TMPL_UNREGISTER,
0036 };
0037 
0038 struct crypto_instance;
0039 struct crypto_template;
0040 
0041 struct crypto_larval {
0042     struct crypto_alg alg;
0043     struct crypto_alg *adult;
0044     struct completion completion;
0045     u32 mask;
0046 };
0047 
0048 extern struct list_head crypto_alg_list;
0049 extern struct rw_semaphore crypto_alg_sem;
0050 extern struct blocking_notifier_head crypto_chain;
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_lookup(const char *name, u32 type, u32 mask);
0074 struct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask);
0075 
0076 int crypto_init_cipher_ops(struct crypto_tfm *tfm);
0077 int crypto_init_compress_ops(struct crypto_tfm *tfm);
0078 
0079 struct crypto_larval *crypto_larval_alloc(const char *name, u32 type, u32 mask);
0080 void crypto_larval_kill(struct crypto_alg *alg);
0081 struct crypto_alg *crypto_larval_lookup(const char *name, u32 type, u32 mask);
0082 void crypto_alg_tested(const char *name, int err);
0083 
0084 void crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list,
0085               struct crypto_alg *nalg);
0086 void crypto_remove_final(struct list_head *list);
0087 void crypto_shoot_alg(struct crypto_alg *alg);
0088 struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type,
0089                       u32 mask);
0090 void *crypto_create_tfm(struct crypto_alg *alg,
0091             const struct crypto_type *frontend);
0092 struct crypto_alg *crypto_find_alg(const char *alg_name,
0093                    const struct crypto_type *frontend,
0094                    u32 type, u32 mask);
0095 void *crypto_alloc_tfm(const char *alg_name,
0096                const struct crypto_type *frontend, u32 type, u32 mask);
0097 
0098 int crypto_register_notifier(struct notifier_block *nb);
0099 int crypto_unregister_notifier(struct notifier_block *nb);
0100 int crypto_probing_notify(unsigned long val, void *v);
0101 
0102 unsigned int crypto_alg_extsize(struct crypto_alg *alg);
0103 
0104 int crypto_type_has_alg(const char *name, const struct crypto_type *frontend,
0105             u32 type, u32 mask);
0106 
0107 static inline struct crypto_alg *crypto_alg_get(struct crypto_alg *alg)
0108 {
0109     atomic_inc(&alg->cra_refcnt);
0110     return alg;
0111 }
0112 
0113 static inline void crypto_alg_put(struct crypto_alg *alg)
0114 {
0115     if (atomic_dec_and_test(&alg->cra_refcnt) && alg->cra_destroy)
0116         alg->cra_destroy(alg);
0117 }
0118 
0119 static inline int crypto_tmpl_get(struct crypto_template *tmpl)
0120 {
0121     return try_module_get(tmpl->module);
0122 }
0123 
0124 static inline void crypto_tmpl_put(struct crypto_template *tmpl)
0125 {
0126     module_put(tmpl->module);
0127 }
0128 
0129 static inline int crypto_is_larval(struct crypto_alg *alg)
0130 {
0131     return alg->cra_flags & CRYPTO_ALG_LARVAL;
0132 }
0133 
0134 static inline int crypto_is_dead(struct crypto_alg *alg)
0135 {
0136     return alg->cra_flags & CRYPTO_ALG_DEAD;
0137 }
0138 
0139 static inline int crypto_is_moribund(struct crypto_alg *alg)
0140 {
0141     return alg->cra_flags & (CRYPTO_ALG_DEAD | CRYPTO_ALG_DYING);
0142 }
0143 
0144 static inline void crypto_notify(unsigned long val, void *v)
0145 {
0146     blocking_notifier_call_chain(&crypto_chain, val, v);
0147 }
0148 
0149 #endif  /* _CRYPTO_INTERNAL_H */
0150