diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2007-11-15 09:36:07 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2008-01-10 16:16:15 -0500 |
commit | 332f8840f7095d294f9bb066b175a100bcde214c (patch) | |
tree | fa2e610da8e943765dfdb8f23817027424a1339d | |
parent | 86f578de5ba6ea11ead9284d9f036fee01ba5893 (diff) |
[CRYPTO] ablkcipher: Add distinct ABLKCIPHER type
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>
-rw-r--r-- | crypto/authenc.c | 2 | ||||
-rw-r--r-- | crypto/blkcipher.c | 9 | ||||
-rw-r--r-- | crypto/cryptd.c | 4 | ||||
-rw-r--r-- | drivers/crypto/hifn_795x.c | 2 | ||||
-rw-r--r-- | include/crypto/algapi.h | 4 | ||||
-rw-r--r-- | include/linux/crypto.h | 18 |
6 files changed, 19 insertions, 20 deletions
diff --git a/crypto/authenc.c b/crypto/authenc.c index 126a529b496d..bc4e608ca841 100644 --- a/crypto/authenc.c +++ b/crypto/authenc.c | |||
@@ -292,7 +292,7 @@ static struct crypto_instance *crypto_authenc_alloc(struct rtattr **tb) | |||
292 | goto out_put_auth; | 292 | goto out_put_auth; |
293 | 293 | ||
294 | enc = crypto_attr_alg(tb[3], CRYPTO_ALG_TYPE_BLKCIPHER, | 294 | enc = crypto_attr_alg(tb[3], CRYPTO_ALG_TYPE_BLKCIPHER, |
295 | CRYPTO_ALG_TYPE_MASK); | 295 | CRYPTO_ALG_TYPE_BLKCIPHER_MASK); |
296 | inst = ERR_PTR(PTR_ERR(enc)); | 296 | inst = ERR_PTR(PTR_ERR(enc)); |
297 | if (IS_ERR(enc)) | 297 | if (IS_ERR(enc)) |
298 | goto out_put_auth; | 298 | goto out_put_auth; |
diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c index f6c67f9d4e5c..180d91451476 100644 --- a/crypto/blkcipher.c +++ b/crypto/blkcipher.c | |||
@@ -433,9 +433,8 @@ static unsigned int crypto_blkcipher_ctxsize(struct crypto_alg *alg, u32 type, | |||
433 | struct blkcipher_alg *cipher = &alg->cra_blkcipher; | 433 | struct blkcipher_alg *cipher = &alg->cra_blkcipher; |
434 | unsigned int len = alg->cra_ctxsize; | 434 | unsigned int len = alg->cra_ctxsize; |
435 | 435 | ||
436 | type ^= CRYPTO_ALG_ASYNC; | 436 | if ((mask & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_MASK && |
437 | mask &= CRYPTO_ALG_ASYNC; | 437 | cipher->ivsize) { |
438 | if ((type & mask) && cipher->ivsize) { | ||
439 | len = ALIGN(len, (unsigned long)alg->cra_alignmask + 1); | 438 | len = ALIGN(len, (unsigned long)alg->cra_alignmask + 1); |
440 | len += cipher->ivsize; | 439 | len += cipher->ivsize; |
441 | } | 440 | } |
@@ -482,9 +481,7 @@ static int crypto_init_blkcipher_ops(struct crypto_tfm *tfm, u32 type, u32 mask) | |||
482 | if (alg->ivsize > PAGE_SIZE / 8) | 481 | if (alg->ivsize > PAGE_SIZE / 8) |
483 | return -EINVAL; | 482 | return -EINVAL; |
484 | 483 | ||
485 | type ^= CRYPTO_ALG_ASYNC; | 484 | if ((mask & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_MASK) |
486 | mask &= CRYPTO_ALG_ASYNC; | ||
487 | if (type & mask) | ||
488 | return crypto_init_blkcipher_ops_sync(tfm); | 485 | return crypto_init_blkcipher_ops_sync(tfm); |
489 | else | 486 | else |
490 | return crypto_init_blkcipher_ops_async(tfm); | 487 | return crypto_init_blkcipher_ops_async(tfm); |
diff --git a/crypto/cryptd.c b/crypto/cryptd.c index 8bf2da835f7b..1a5c45b96852 100644 --- a/crypto/cryptd.c +++ b/crypto/cryptd.c | |||
@@ -228,7 +228,7 @@ static struct crypto_instance *cryptd_alloc_blkcipher( | |||
228 | struct crypto_alg *alg; | 228 | struct crypto_alg *alg; |
229 | 229 | ||
230 | alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_BLKCIPHER, | 230 | alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_BLKCIPHER, |
231 | CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC); | 231 | CRYPTO_ALG_TYPE_MASK); |
232 | if (IS_ERR(alg)) | 232 | if (IS_ERR(alg)) |
233 | return ERR_PTR(PTR_ERR(alg)); | 233 | return ERR_PTR(PTR_ERR(alg)); |
234 | 234 | ||
@@ -236,7 +236,7 @@ static struct crypto_instance *cryptd_alloc_blkcipher( | |||
236 | if (IS_ERR(inst)) | 236 | if (IS_ERR(inst)) |
237 | goto out_put_alg; | 237 | goto out_put_alg; |
238 | 238 | ||
239 | inst->alg.cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | CRYPTO_ALG_ASYNC; | 239 | inst->alg.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC; |
240 | inst->alg.cra_type = &crypto_ablkcipher_type; | 240 | inst->alg.cra_type = &crypto_ablkcipher_type; |
241 | 241 | ||
242 | inst->alg.cra_ablkcipher.ivsize = alg->cra_blkcipher.ivsize; | 242 | inst->alg.cra_ablkcipher.ivsize = alg->cra_blkcipher.ivsize; |
diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c index fec32aa1ec52..bf817d4ecae2 100644 --- a/drivers/crypto/hifn_795x.c +++ b/drivers/crypto/hifn_795x.c | |||
@@ -2361,7 +2361,7 @@ static int hifn_alg_alloc(struct hifn_device *dev, struct hifn_alg_template *t) | |||
2361 | snprintf(alg->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s", t->drv_name); | 2361 | snprintf(alg->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s", t->drv_name); |
2362 | 2362 | ||
2363 | alg->alg.cra_priority = 300; | 2363 | alg->alg.cra_priority = 300; |
2364 | alg->alg.cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | CRYPTO_ALG_ASYNC; | 2364 | alg->alg.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC; |
2365 | alg->alg.cra_blocksize = t->bsize; | 2365 | alg->alg.cra_blocksize = t->bsize; |
2366 | alg->alg.cra_ctxsize = sizeof(struct hifn_context); | 2366 | alg->alg.cra_ctxsize = sizeof(struct hifn_context); |
2367 | alg->alg.cra_alignmask = 15; | 2367 | alg->alg.cra_alignmask = 15; |
diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index b9b05d399d2b..88619f902c10 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h | |||
@@ -191,7 +191,7 @@ static inline struct crypto_ablkcipher *crypto_spawn_ablkcipher( | |||
191 | struct crypto_spawn *spawn) | 191 | struct crypto_spawn *spawn) |
192 | { | 192 | { |
193 | u32 type = CRYPTO_ALG_TYPE_BLKCIPHER; | 193 | u32 type = CRYPTO_ALG_TYPE_BLKCIPHER; |
194 | u32 mask = CRYPTO_ALG_TYPE_MASK; | 194 | u32 mask = CRYPTO_ALG_TYPE_BLKCIPHER_MASK; |
195 | 195 | ||
196 | return __crypto_ablkcipher_cast(crypto_spawn_tfm(spawn, type, mask)); | 196 | return __crypto_ablkcipher_cast(crypto_spawn_tfm(spawn, type, mask)); |
197 | } | 197 | } |
@@ -200,7 +200,7 @@ static inline struct crypto_blkcipher *crypto_spawn_blkcipher( | |||
200 | struct crypto_spawn *spawn) | 200 | struct crypto_spawn *spawn) |
201 | { | 201 | { |
202 | u32 type = CRYPTO_ALG_TYPE_BLKCIPHER; | 202 | u32 type = CRYPTO_ALG_TYPE_BLKCIPHER; |
203 | u32 mask = CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC; | 203 | u32 mask = CRYPTO_ALG_TYPE_MASK; |
204 | 204 | ||
205 | return __crypto_blkcipher_cast(crypto_spawn_tfm(spawn, type, mask)); | 205 | return __crypto_blkcipher_cast(crypto_spawn_tfm(spawn, type, mask)); |
206 | } | 206 | } |
diff --git a/include/linux/crypto.h b/include/linux/crypto.h index f3110ebe894a..f56ae8721bc9 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h | |||
@@ -33,10 +33,12 @@ | |||
33 | #define CRYPTO_ALG_TYPE_DIGEST 0x00000002 | 33 | #define CRYPTO_ALG_TYPE_DIGEST 0x00000002 |
34 | #define CRYPTO_ALG_TYPE_HASH 0x00000003 | 34 | #define CRYPTO_ALG_TYPE_HASH 0x00000003 |
35 | #define CRYPTO_ALG_TYPE_BLKCIPHER 0x00000004 | 35 | #define CRYPTO_ALG_TYPE_BLKCIPHER 0x00000004 |
36 | #define CRYPTO_ALG_TYPE_COMPRESS 0x00000005 | 36 | #define CRYPTO_ALG_TYPE_ABLKCIPHER 0x00000005 |
37 | #define CRYPTO_ALG_TYPE_AEAD 0x00000006 | 37 | #define CRYPTO_ALG_TYPE_COMPRESS 0x00000008 |
38 | #define CRYPTO_ALG_TYPE_AEAD 0x00000009 | ||
38 | 39 | ||
39 | #define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e | 40 | #define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e |
41 | #define CRYPTO_ALG_TYPE_BLKCIPHER_MASK 0x0000000c | ||
40 | 42 | ||
41 | #define CRYPTO_ALG_LARVAL 0x00000010 | 43 | #define CRYPTO_ALG_LARVAL 0x00000010 |
42 | #define CRYPTO_ALG_DEAD 0x00000020 | 44 | #define CRYPTO_ALG_DEAD 0x00000020 |
@@ -530,7 +532,7 @@ static inline struct crypto_ablkcipher *crypto_alloc_ablkcipher( | |||
530 | { | 532 | { |
531 | type &= ~CRYPTO_ALG_TYPE_MASK; | 533 | type &= ~CRYPTO_ALG_TYPE_MASK; |
532 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; | 534 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; |
533 | mask |= CRYPTO_ALG_TYPE_MASK; | 535 | mask |= CRYPTO_ALG_TYPE_BLKCIPHER_MASK; |
534 | 536 | ||
535 | return __crypto_ablkcipher_cast( | 537 | return __crypto_ablkcipher_cast( |
536 | crypto_alloc_base(alg_name, type, mask)); | 538 | crypto_alloc_base(alg_name, type, mask)); |
@@ -552,7 +554,7 @@ static inline int crypto_has_ablkcipher(const char *alg_name, u32 type, | |||
552 | { | 554 | { |
553 | type &= ~CRYPTO_ALG_TYPE_MASK; | 555 | type &= ~CRYPTO_ALG_TYPE_MASK; |
554 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; | 556 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; |
555 | mask |= CRYPTO_ALG_TYPE_MASK; | 557 | mask |= CRYPTO_ALG_TYPE_BLKCIPHER_MASK; |
556 | 558 | ||
557 | return crypto_has_alg(alg_name, type, mask); | 559 | return crypto_has_alg(alg_name, type, mask); |
558 | } | 560 | } |
@@ -841,9 +843,9 @@ static inline struct crypto_blkcipher *crypto_blkcipher_cast( | |||
841 | static inline struct crypto_blkcipher *crypto_alloc_blkcipher( | 843 | static inline struct crypto_blkcipher *crypto_alloc_blkcipher( |
842 | const char *alg_name, u32 type, u32 mask) | 844 | const char *alg_name, u32 type, u32 mask) |
843 | { | 845 | { |
844 | type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC); | 846 | type &= ~CRYPTO_ALG_TYPE_MASK; |
845 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; | 847 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; |
846 | mask |= CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC; | 848 | mask |= CRYPTO_ALG_TYPE_MASK; |
847 | 849 | ||
848 | return __crypto_blkcipher_cast(crypto_alloc_base(alg_name, type, mask)); | 850 | return __crypto_blkcipher_cast(crypto_alloc_base(alg_name, type, mask)); |
849 | } | 851 | } |
@@ -861,9 +863,9 @@ static inline void crypto_free_blkcipher(struct crypto_blkcipher *tfm) | |||
861 | 863 | ||
862 | static inline int crypto_has_blkcipher(const char *alg_name, u32 type, u32 mask) | 864 | static inline int crypto_has_blkcipher(const char *alg_name, u32 type, u32 mask) |
863 | { | 865 | { |
864 | type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC); | 866 | type &= ~CRYPTO_ALG_TYPE_MASK; |
865 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; | 867 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; |
866 | mask |= CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC; | 868 | mask |= CRYPTO_ALG_TYPE_MASK; |
867 | 869 | ||
868 | return crypto_has_alg(alg_name, type, mask); | 870 | return crypto_has_alg(alg_name, type, mask); |
869 | } | 871 | } |