[CRYPTO] all: Pass tfm instead of ctx to algorithms
[linux-block.git] / include / linux / crypto.h
index 3c89df6e7768451acf625236790753f2ab7f5139..ef918803ec30771ec7d64788ce5adff28c9b1a40 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
  * Copyright (c) 2002 David S. Miller (davem@redhat.com)
+ * Copyright (c) 2005 Herbert Xu <herbert@gondor.apana.org.au>
  *
  * Portions derived from Cryptoapi, by Alexander Kjeldaas <astor@fast.no>
  * and Nettle, by Niels Möller.
@@ -16,7 +17,6 @@
 #ifndef _LINUX_CRYPTO_H
 #define _LINUX_CRYPTO_H
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/types.h>
@@ -66,7 +66,7 @@ struct crypto_tfm;
 
 struct cipher_desc {
        struct crypto_tfm *tfm;
-       void (*crfn)(void *ctx, u8 *dst, const u8 *src);
+       void (*crfn)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
        unsigned int (*prfn)(const struct cipher_desc *desc, u8 *dst,
                             const u8 *src, unsigned int nbytes);
        void *info;
@@ -79,10 +79,10 @@ struct cipher_desc {
 struct cipher_alg {
        unsigned int cia_min_keysize;
        unsigned int cia_max_keysize;
-       int (*cia_setkey)(void *ctx, const u8 *key,
+       int (*cia_setkey)(struct crypto_tfm *tfm, const u8 *key,
                          unsigned int keylen, u32 *flags);
-       void (*cia_encrypt)(void *ctx, u8 *dst, const u8 *src);
-       void (*cia_decrypt)(void *ctx, u8 *dst, const u8 *src);
+       void (*cia_encrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
+       void (*cia_decrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
 
        unsigned int (*cia_encrypt_ecb)(const struct cipher_desc *desc,
                                        u8 *dst, const u8 *src,
@@ -100,20 +100,21 @@ struct cipher_alg {
 
 struct digest_alg {
        unsigned int dia_digestsize;
-       void (*dia_init)(void *ctx);
-       void (*dia_update)(void *ctx, const u8 *data, unsigned int len);
-       void (*dia_final)(void *ctx, u8 *out);
-       int (*dia_setkey)(void *ctx, const u8 *key,
+       void (*dia_init)(struct crypto_tfm *tfm);
+       void (*dia_update)(struct crypto_tfm *tfm, const u8 *data,
+                          unsigned int len);
+       void (*dia_final)(struct crypto_tfm *tfm, u8 *out);
+       int (*dia_setkey)(struct crypto_tfm *tfm, const u8 *key,
                          unsigned int keylen, u32 *flags);
 };
 
 struct compress_alg {
-       int (*coa_init)(void *ctx);
-       void (*coa_exit)(void *ctx);
-       int (*coa_compress)(void *ctx, const u8 *src, unsigned int slen,
-                           u8 *dst, unsigned int *dlen);
-       int (*coa_decompress)(void *ctx, const u8 *src, unsigned int slen,
-                             u8 *dst, unsigned int *dlen);
+       int (*coa_init)(struct crypto_tfm *tfm);
+       void (*coa_exit)(struct crypto_tfm *tfm);
+       int (*coa_compress)(struct crypto_tfm *tfm, const u8 *src,
+                           unsigned int slen, u8 *dst, unsigned int *dlen);
+       int (*coa_decompress)(struct crypto_tfm *tfm, const u8 *src,
+                             unsigned int slen, u8 *dst, unsigned int *dlen);
 };
 
 #define cra_cipher     cra_u.cipher
@@ -126,7 +127,11 @@ struct crypto_alg {
        unsigned int cra_blocksize;
        unsigned int cra_ctxsize;
        unsigned int cra_alignmask;
+
+       int cra_priority;
+
        const char cra_name[CRYPTO_MAX_ALG_NAME];
+       const char cra_driver_name[CRYPTO_MAX_ALG_NAME];
 
        union {
                struct cipher_alg cipher;
@@ -224,6 +229,8 @@ struct crypto_tfm {
        } crt_u;
        
        struct crypto_alg *__crt_alg;
+
+       char __crt_ctx[] __attribute__ ((__aligned__));
 };
 
 /* 
@@ -296,7 +303,13 @@ static inline unsigned int crypto_tfm_alg_alignmask(struct crypto_tfm *tfm)
 
 static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm)
 {
-       return (void *)&tfm[1];
+       return tfm->__crt_ctx;
+}
+
+static inline unsigned int crypto_tfm_ctx_alignment(void)
+{
+       struct crypto_tfm *tfm;
+       return __alignof__(tfm->__crt_ctx);
 }
 
 /*