[CRYPTO] api: Add crypto_alg reference counting
[pandora-kernel.git] / include / linux / crypto.h
index 7f94624..7f57ff8 100644 (file)
 #ifndef _LINUX_CRYPTO_H
 #define _LINUX_CRYPTO_H
 
+#include <asm/atomic.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/list.h>
+#include <linux/slab.h>
 #include <linux/string.h>
-#include <asm/page.h>
+#include <linux/uaccess.h>
 
 /*
  * Algorithm masks and types.
 #define CRYPTO_DIR_ENCRYPT             1
 #define CRYPTO_DIR_DECRYPT             0
 
+/*
+ * The macro CRYPTO_MINALIGN_ATTR (along with the void * type in the actual
+ * declaration) is used to ensure that the crypto_tfm context structure is
+ * aligned correctly for the given architecture so that there are no alignment
+ * faults for C data types.  In particular, this is required on platforms such
+ * as arm where pointers are 32-bit aligned but there are data types such as
+ * u64 which require 64-bit alignment.
+ */
+#if defined(ARCH_KMALLOC_MINALIGN)
+#define CRYPTO_MINALIGN ARCH_KMALLOC_MINALIGN
+#elif defined(ARCH_SLAB_MINALIGN)
+#define CRYPTO_MINALIGN ARCH_SLAB_MINALIGN
+#endif
+
+#ifdef CRYPTO_MINALIGN
+#define CRYPTO_MINALIGN_ATTR __attribute__ ((__aligned__(CRYPTO_MINALIGN)))
+#else
+#define CRYPTO_MINALIGN_ATTR
+#endif
+
 struct scatterlist;
 struct crypto_tfm;
 
@@ -127,6 +149,7 @@ struct crypto_alg {
        unsigned int cra_alignmask;
 
        int cra_priority;
+       atomic_t cra_refcnt;
 
        char cra_name[CRYPTO_MAX_ALG_NAME];
        char cra_driver_name[CRYPTO_MAX_ALG_NAME];
@@ -139,6 +162,7 @@ struct crypto_alg {
 
        int (*cra_init)(struct crypto_tfm *tfm);
        void (*cra_exit)(struct crypto_tfm *tfm);
+       void (*cra_destroy)(struct crypto_alg *alg);
        
        struct module *cra_module;
 };
@@ -231,7 +255,7 @@ struct crypto_tfm {
        
        struct crypto_alg *__crt_alg;
 
-       char __crt_ctx[] __attribute__ ((__aligned__));
+       void *__crt_ctx[] CRYPTO_MINALIGN_ATTR;
 };
 
 /*