[CRYPTO] api: Allow multiple frontends per backend
authorHerbert Xu <herbert@gondor.apana.org.au>
Wed, 24 Jan 2007 09:50:26 +0000 (20:50 +1100)
committerHerbert Xu <herbert@gondor.apana.org.au>
Tue, 6 Feb 2007 22:21:01 +0000 (09:21 +1100)
This patch adds support for multiple frontend types for each backend
algorithm by passing the type and mask through to the backend type
init function.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/algapi.c
crypto/api.c
crypto/blkcipher.c
crypto/hash.c
crypto/internal.h
include/crypto/algapi.h

index 0f1abca1b98ce296f796fcb1d59998cb260bcae7..f7d2185b2c8fbac94cf6f6736b5f1a965f224bb9 100644 (file)
@@ -401,7 +401,7 @@ struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type,
        if (unlikely((alg->cra_flags ^ type) & mask))
                goto out_put_alg;
 
-       tfm = __crypto_alloc_tfm(alg);
+       tfm = __crypto_alloc_tfm(alg, type, mask);
        if (IS_ERR(tfm))
                goto out_put_alg;
 
index 8b80baec853a7042acb5ad055b340556b78b1240..55af8bb0f0502eb7f80f3ed2c71fb21518319252 100644 (file)
@@ -212,12 +212,12 @@ struct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask)
 }
 EXPORT_SYMBOL_GPL(crypto_alg_mod_lookup);
 
-static int crypto_init_ops(struct crypto_tfm *tfm)
+static int crypto_init_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
 {
-       const struct crypto_type *type = tfm->__crt_alg->cra_type;
+       const struct crypto_type *type_obj = tfm->__crt_alg->cra_type;
 
-       if (type)
-               return type->init(tfm);
+       if (type_obj)
+               return type_obj->init(tfm, type, mask);
 
        switch (crypto_tfm_alg_type(tfm)) {
        case CRYPTO_ALG_TYPE_CIPHER:
@@ -266,14 +266,14 @@ static void crypto_exit_ops(struct crypto_tfm *tfm)
        }
 }
 
-static unsigned int crypto_ctxsize(struct crypto_alg *alg)
+static unsigned int crypto_ctxsize(struct crypto_alg *alg, u32 type, u32 mask)
 {
-       const struct crypto_type *type = alg->cra_type;
+       const struct crypto_type *type_obj = alg->cra_type;
        unsigned int len;
 
        len = alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1);
-       if (type)
-               return len + type->ctxsize(alg);
+       if (type_obj)
+               return len + type_obj->ctxsize(alg, type, mask);
 
        switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) {
        default:
@@ -303,20 +303,21 @@ void crypto_shoot_alg(struct crypto_alg *alg)
 }
 EXPORT_SYMBOL_GPL(crypto_shoot_alg);
 
-struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg)
+struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type,
+                                     u32 mask)
 {
        struct crypto_tfm *tfm = NULL;
        unsigned int tfm_size;
        int err = -ENOMEM;
 
-       tfm_size = sizeof(*tfm) + crypto_ctxsize(alg);
+       tfm_size = sizeof(*tfm) + crypto_ctxsize(alg, type, mask);
        tfm = kzalloc(tfm_size, GFP_KERNEL);
        if (tfm == NULL)
                goto out_err;
 
        tfm->__crt_alg = alg;
 
-       err = crypto_init_ops(tfm);
+       err = crypto_init_ops(tfm, type, mask);
        if (err)
                goto out_free_tfm;
 
@@ -372,7 +373,7 @@ struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask)
                        goto err;
                }
 
-               tfm = __crypto_alloc_tfm(alg);
+               tfm = __crypto_alloc_tfm(alg, type, mask);
                if (!IS_ERR(tfm))
                        return tfm;
 
index cbb4c4e5c229ca2ecd52b4ebdebb9027e4b42503..b5befe8c3a96ee1a4c73b708823b76a2f9bb06bc 100644 (file)
@@ -349,7 +349,8 @@ static int setkey(struct crypto_tfm *tfm, const u8 *key,
        return cipher->setkey(tfm, key, keylen);
 }
 
-static unsigned int crypto_blkcipher_ctxsize(struct crypto_alg *alg)
+static unsigned int crypto_blkcipher_ctxsize(struct crypto_alg *alg, u32 type,
+                                            u32 mask)
 {
        struct blkcipher_alg *cipher = &alg->cra_blkcipher;
        unsigned int len = alg->cra_ctxsize;
@@ -362,7 +363,7 @@ static unsigned int crypto_blkcipher_ctxsize(struct crypto_alg *alg)
        return len;
 }
 
-static int crypto_init_blkcipher_ops(struct crypto_tfm *tfm)
+static int crypto_init_blkcipher_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
 {
        struct blkcipher_tfm *crt = &tfm->crt_blkcipher;
        struct blkcipher_alg *alg = &tfm->__crt_alg->cra_blkcipher;
index cdec23d885fed5630ddec0c347869d507b50fae5..12c4514f3478df49786e7fe36009bb1e4fa95fd6 100644 (file)
 
 #include "internal.h"
 
-static unsigned int crypto_hash_ctxsize(struct crypto_alg *alg)
+static unsigned int crypto_hash_ctxsize(struct crypto_alg *alg, u32 type,
+                                       u32 mask)
 {
        return alg->cra_ctxsize;
 }
 
-static int crypto_init_hash_ops(struct crypto_tfm *tfm)
+static int crypto_init_hash_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
 {
        struct hash_tfm *crt = &tfm->crt_hash;
        struct hash_alg *alg = &tfm->__crt_alg->cra_hash;
index 784a7745315f10b19a70c32d5b16a3f9373dc130..60acad9788c50104b7e627aafbb3cd4c0ab57998 100644 (file)
@@ -120,7 +120,8 @@ void crypto_exit_compress_ops(struct crypto_tfm *tfm);
 void crypto_larval_error(const char *name, u32 type, u32 mask);
 
 void crypto_shoot_alg(struct crypto_alg *alg);
-struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg);
+struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type,
+                                     u32 mask);
 
 int crypto_register_instance(struct crypto_template *tmpl,
                             struct crypto_instance *inst);
index 99c534d573d28222cf061569768380b302e7c6e1..4e05e93ff6811248002485475e8a624fa1209cf1 100644 (file)
@@ -18,8 +18,8 @@ struct module;
 struct seq_file;
 
 struct crypto_type {
-       unsigned int (*ctxsize)(struct crypto_alg *alg);
-       int (*init)(struct crypto_tfm *tfm);
+       unsigned int (*ctxsize)(struct crypto_alg *alg, u32 type, u32 mask);
+       int (*init)(struct crypto_tfm *tfm, u32 type, u32 mask);
        void (*exit)(struct crypto_tfm *tfm);
        void (*show)(struct seq_file *m, struct crypto_alg *alg);
 };