]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
[CRYPTO] ablkcipher: Add distinct ABLKCIPHER type
authorHerbert Xu <herbert@gondor.apana.org.au>
Thu, 15 Nov 2007 14:36:07 +0000 (22:36 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Thu, 10 Jan 2008 21:16:15 +0000 (08:16 +1100)
Up until now we have ablkcipher algorithms have been identified as
type BLKCIPHER with the ASYNC bit set.  This is suboptimal because
ablkcipher refers to two things.  On the one hand it refers to the
top-level ablkcipher interface with requests.  On the other hand it
refers to and algorithm type underneath.

As it is you cannot request a synchronous block cipher algorithm
with the ablkcipher interface on top.  This is a problem because
we want to be able to eventually phase out the blkcipher top-level
interface.

This patch fixes this by making ABLKCIPHER its own type, just as
we have distinct types for HASH and DIGEST.  The type it associated
with the algorithm implementation only.

Which top-level interface is used for synchronous block ciphers is
then determined by the mask that's used.  If it's a specific mask
then the old blkcipher interface is given, otherwise we go with the
new ablkcipher interface.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/authenc.c
crypto/blkcipher.c
crypto/cryptd.c
drivers/crypto/hifn_795x.c
include/crypto/algapi.h
include/linux/crypto.h

index 126a529b496d5df32959499ff22739767eca52a3..bc4e608ca84101e274969f03d7066921c43c3444 100644 (file)
@@ -292,7 +292,7 @@ static struct crypto_instance *crypto_authenc_alloc(struct rtattr **tb)
                goto out_put_auth;
 
        enc = crypto_attr_alg(tb[3], CRYPTO_ALG_TYPE_BLKCIPHER,
-                             CRYPTO_ALG_TYPE_MASK);
+                             CRYPTO_ALG_TYPE_BLKCIPHER_MASK);
        inst = ERR_PTR(PTR_ERR(enc));
        if (IS_ERR(enc))
                goto out_put_auth;
index f6c67f9d4e5c2f9085558991a6fc87893e269670..180d91451476faf0e65f5195963b46015fa21bb2 100644 (file)
@@ -433,9 +433,8 @@ static unsigned int crypto_blkcipher_ctxsize(struct crypto_alg *alg, u32 type,
        struct blkcipher_alg *cipher = &alg->cra_blkcipher;
        unsigned int len = alg->cra_ctxsize;
 
-       type ^= CRYPTO_ALG_ASYNC;
-       mask &= CRYPTO_ALG_ASYNC;
-       if ((type & mask) && cipher->ivsize) {
+       if ((mask & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_MASK &&
+           cipher->ivsize) {
                len = ALIGN(len, (unsigned long)alg->cra_alignmask + 1);
                len += cipher->ivsize;
        }
@@ -482,9 +481,7 @@ static int crypto_init_blkcipher_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
        if (alg->ivsize > PAGE_SIZE / 8)
                return -EINVAL;
 
-       type ^= CRYPTO_ALG_ASYNC;
-       mask &= CRYPTO_ALG_ASYNC;
-       if (type & mask)
+       if ((mask & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_MASK)
                return crypto_init_blkcipher_ops_sync(tfm);
        else
                return crypto_init_blkcipher_ops_async(tfm);
index 8bf2da835f7beae4513e164b59622d56e0387a76..1a5c45b968520a9786f6da391c341a74751a081d 100644 (file)
@@ -228,7 +228,7 @@ static struct crypto_instance *cryptd_alloc_blkcipher(
        struct crypto_alg *alg;
 
        alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_BLKCIPHER,
-                                 CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC);
+                                 CRYPTO_ALG_TYPE_MASK);
        if (IS_ERR(alg))
                return ERR_PTR(PTR_ERR(alg));
 
@@ -236,7 +236,7 @@ static struct crypto_instance *cryptd_alloc_blkcipher(
        if (IS_ERR(inst))
                goto out_put_alg;
 
-       inst->alg.cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | CRYPTO_ALG_ASYNC;
+       inst->alg.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC;
        inst->alg.cra_type = &crypto_ablkcipher_type;
 
        inst->alg.cra_ablkcipher.ivsize = alg->cra_blkcipher.ivsize;
index fec32aa1ec529323bece6475f68d34d6590d7fae..bf817d4ecae2ac1a718768c489635e2b059e4b26 100644 (file)
@@ -2361,7 +2361,7 @@ static int hifn_alg_alloc(struct hifn_device *dev, struct hifn_alg_template *t)
        snprintf(alg->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s", t->drv_name);
 
        alg->alg.cra_priority = 300;
-       alg->alg.cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | CRYPTO_ALG_ASYNC;
+       alg->alg.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC;
        alg->alg.cra_blocksize = t->bsize;
        alg->alg.cra_ctxsize = sizeof(struct hifn_context);
        alg->alg.cra_alignmask = 15;
index b9b05d399d2b49bbbe304fbb608336db94d58784..88619f902c10c02835aa001b7c83870e9f571ceb 100644 (file)
@@ -191,7 +191,7 @@ static inline struct crypto_ablkcipher *crypto_spawn_ablkcipher(
        struct crypto_spawn *spawn)
 {
        u32 type = CRYPTO_ALG_TYPE_BLKCIPHER;
-       u32 mask = CRYPTO_ALG_TYPE_MASK;
+       u32 mask = CRYPTO_ALG_TYPE_BLKCIPHER_MASK;
 
        return __crypto_ablkcipher_cast(crypto_spawn_tfm(spawn, type, mask));
 }
@@ -200,7 +200,7 @@ static inline struct crypto_blkcipher *crypto_spawn_blkcipher(
        struct crypto_spawn *spawn)
 {
        u32 type = CRYPTO_ALG_TYPE_BLKCIPHER;
-       u32 mask = CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC;
+       u32 mask = CRYPTO_ALG_TYPE_MASK;
 
        return __crypto_blkcipher_cast(crypto_spawn_tfm(spawn, type, mask));
 }
index f3110ebe894a090254ac4b48f0d9ef98205c5eaf..f56ae8721bc96280f1a3c14418dd41e6e394679f 100644 (file)
 #define CRYPTO_ALG_TYPE_DIGEST         0x00000002
 #define CRYPTO_ALG_TYPE_HASH           0x00000003
 #define CRYPTO_ALG_TYPE_BLKCIPHER      0x00000004
-#define CRYPTO_ALG_TYPE_COMPRESS       0x00000005
-#define CRYPTO_ALG_TYPE_AEAD           0x00000006
+#define CRYPTO_ALG_TYPE_ABLKCIPHER     0x00000005
+#define CRYPTO_ALG_TYPE_COMPRESS       0x00000008
+#define CRYPTO_ALG_TYPE_AEAD           0x00000009
 
 #define CRYPTO_ALG_TYPE_HASH_MASK      0x0000000e
+#define CRYPTO_ALG_TYPE_BLKCIPHER_MASK 0x0000000c
 
 #define CRYPTO_ALG_LARVAL              0x00000010
 #define CRYPTO_ALG_DEAD                        0x00000020
@@ -530,7 +532,7 @@ static inline struct crypto_ablkcipher *crypto_alloc_ablkcipher(
 {
        type &= ~CRYPTO_ALG_TYPE_MASK;
        type |= CRYPTO_ALG_TYPE_BLKCIPHER;
-       mask |= CRYPTO_ALG_TYPE_MASK;
+       mask |= CRYPTO_ALG_TYPE_BLKCIPHER_MASK;
 
        return __crypto_ablkcipher_cast(
                crypto_alloc_base(alg_name, type, mask));
@@ -552,7 +554,7 @@ static inline int crypto_has_ablkcipher(const char *alg_name, u32 type,
 {
        type &= ~CRYPTO_ALG_TYPE_MASK;
        type |= CRYPTO_ALG_TYPE_BLKCIPHER;
-       mask |= CRYPTO_ALG_TYPE_MASK;
+       mask |= CRYPTO_ALG_TYPE_BLKCIPHER_MASK;
 
        return crypto_has_alg(alg_name, type, mask);
 }
@@ -841,9 +843,9 @@ static inline struct crypto_blkcipher *crypto_blkcipher_cast(
 static inline struct crypto_blkcipher *crypto_alloc_blkcipher(
        const char *alg_name, u32 type, u32 mask)
 {
-       type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC);
+       type &= ~CRYPTO_ALG_TYPE_MASK;
        type |= CRYPTO_ALG_TYPE_BLKCIPHER;
-       mask |= CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC;
+       mask |= CRYPTO_ALG_TYPE_MASK;
 
        return __crypto_blkcipher_cast(crypto_alloc_base(alg_name, type, mask));
 }
@@ -861,9 +863,9 @@ static inline void crypto_free_blkcipher(struct crypto_blkcipher *tfm)
 
 static inline int crypto_has_blkcipher(const char *alg_name, u32 type, u32 mask)
 {
-       type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC);
+       type &= ~CRYPTO_ALG_TYPE_MASK;
        type |= CRYPTO_ALG_TYPE_BLKCIPHER;
-       mask |= CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC;
+       mask |= CRYPTO_ALG_TYPE_MASK;
 
        return crypto_has_alg(alg_name, type, mask);
 }