aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/cryptd.c
diff options
context:
space:
mode:
authorStephan Mueller <smueller@chronox.de>2015-03-30 15:57:06 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2015-03-31 09:21:04 -0400
commit466a7b9e3e7833a0cc21a69a0bea9d50daf0ca10 (patch)
treed85bd8d8415e8f79ea4fc54d329c61883a22f93e /crypto/cryptd.c
parent425a882991d9da8bfd2fe0fc495773fab5ac9988 (diff)
crypto: cryptd - process CRYPTO_ALG_INTERNAL
The cryptd is used as a wrapper around internal ciphers. Therefore, the cryptd must process the internal cipher by marking cryptd as internal if the underlying cipher is an internal cipher. Signed-off-by: Stephan Mueller <smueller@chronox.de> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/cryptd.c')
-rw-r--r--crypto/cryptd.c49
1 files changed, 41 insertions, 8 deletions
diff --git a/crypto/cryptd.c b/crypto/cryptd.c
index 650afac10fd7..b0602ba03111 100644
--- a/crypto/cryptd.c
+++ b/crypto/cryptd.c
@@ -168,6 +168,20 @@ static inline struct cryptd_queue *cryptd_get_queue(struct crypto_tfm *tfm)
168 return ictx->queue; 168 return ictx->queue;
169} 169}
170 170
171static inline void cryptd_check_internal(struct rtattr **tb, u32 *type,
172 u32 *mask)
173{
174 struct crypto_attr_type *algt;
175
176 algt = crypto_get_attr_type(tb);
177 if (IS_ERR(algt))
178 return;
179 if ((algt->type & CRYPTO_ALG_INTERNAL))
180 *type |= CRYPTO_ALG_INTERNAL;
181 if ((algt->mask & CRYPTO_ALG_INTERNAL))
182 *mask |= CRYPTO_ALG_INTERNAL;
183}
184
171static int cryptd_blkcipher_setkey(struct crypto_ablkcipher *parent, 185static int cryptd_blkcipher_setkey(struct crypto_ablkcipher *parent,
172 const u8 *key, unsigned int keylen) 186 const u8 *key, unsigned int keylen)
173{ 187{
@@ -321,10 +335,13 @@ static int cryptd_create_blkcipher(struct crypto_template *tmpl,
321 struct cryptd_instance_ctx *ctx; 335 struct cryptd_instance_ctx *ctx;
322 struct crypto_instance *inst; 336 struct crypto_instance *inst;
323 struct crypto_alg *alg; 337 struct crypto_alg *alg;
338 u32 type = CRYPTO_ALG_TYPE_BLKCIPHER;
339 u32 mask = CRYPTO_ALG_TYPE_MASK;
324 int err; 340 int err;
325 341
326 alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_BLKCIPHER, 342 cryptd_check_internal(tb, &type, &mask);
327 CRYPTO_ALG_TYPE_MASK); 343
344 alg = crypto_get_attr_alg(tb, type, mask);
328 if (IS_ERR(alg)) 345 if (IS_ERR(alg))
329 return PTR_ERR(alg); 346 return PTR_ERR(alg);
330 347
@@ -341,7 +358,10 @@ static int cryptd_create_blkcipher(struct crypto_template *tmpl,
341 if (err) 358 if (err)
342 goto out_free_inst; 359 goto out_free_inst;
343 360
344 inst->alg.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC; 361 type = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC;
362 if (alg->cra_flags & CRYPTO_ALG_INTERNAL)
363 type |= CRYPTO_ALG_INTERNAL;
364 inst->alg.cra_flags = type;
345 inst->alg.cra_type = &crypto_ablkcipher_type; 365 inst->alg.cra_type = &crypto_ablkcipher_type;
346 366
347 inst->alg.cra_ablkcipher.ivsize = alg->cra_blkcipher.ivsize; 367 inst->alg.cra_ablkcipher.ivsize = alg->cra_blkcipher.ivsize;
@@ -577,9 +597,13 @@ static int cryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb,
577 struct ahash_instance *inst; 597 struct ahash_instance *inst;
578 struct shash_alg *salg; 598 struct shash_alg *salg;
579 struct crypto_alg *alg; 599 struct crypto_alg *alg;
600 u32 type = 0;
601 u32 mask = 0;
580 int err; 602 int err;
581 603
582 salg = shash_attr_alg(tb[1], 0, 0); 604 cryptd_check_internal(tb, &type, &mask);
605
606 salg = shash_attr_alg(tb[1], type, mask);
583 if (IS_ERR(salg)) 607 if (IS_ERR(salg))
584 return PTR_ERR(salg); 608 return PTR_ERR(salg);
585 609
@@ -598,7 +622,10 @@ static int cryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb,
598 if (err) 622 if (err)
599 goto out_free_inst; 623 goto out_free_inst;
600 624
601 inst->alg.halg.base.cra_flags = CRYPTO_ALG_ASYNC; 625 type = CRYPTO_ALG_ASYNC;
626 if (alg->cra_flags & CRYPTO_ALG_INTERNAL)
627 type |= CRYPTO_ALG_INTERNAL;
628 inst->alg.halg.base.cra_flags = type;
602 629
603 inst->alg.halg.digestsize = salg->digestsize; 630 inst->alg.halg.digestsize = salg->digestsize;
604 inst->alg.halg.base.cra_ctxsize = sizeof(struct cryptd_hash_ctx); 631 inst->alg.halg.base.cra_ctxsize = sizeof(struct cryptd_hash_ctx);
@@ -719,10 +746,13 @@ static int cryptd_create_aead(struct crypto_template *tmpl,
719 struct aead_instance_ctx *ctx; 746 struct aead_instance_ctx *ctx;
720 struct crypto_instance *inst; 747 struct crypto_instance *inst;
721 struct crypto_alg *alg; 748 struct crypto_alg *alg;
749 u32 type = CRYPTO_ALG_TYPE_AEAD;
750 u32 mask = CRYPTO_ALG_TYPE_MASK;
722 int err; 751 int err;
723 752
724 alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_AEAD, 753 cryptd_check_internal(tb, &type, &mask);
725 CRYPTO_ALG_TYPE_MASK); 754
755 alg = crypto_get_attr_alg(tb, type, mask);
726 if (IS_ERR(alg)) 756 if (IS_ERR(alg))
727 return PTR_ERR(alg); 757 return PTR_ERR(alg);
728 758
@@ -739,7 +769,10 @@ static int cryptd_create_aead(struct crypto_template *tmpl,
739 if (err) 769 if (err)
740 goto out_free_inst; 770 goto out_free_inst;
741 771
742 inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC; 772 type = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC;
773 if (alg->cra_flags & CRYPTO_ALG_INTERNAL)
774 type |= CRYPTO_ALG_INTERNAL;
775 inst->alg.cra_flags = type;
743 inst->alg.cra_type = alg->cra_type; 776 inst->alg.cra_type = alg->cra_type;
744 inst->alg.cra_ctxsize = sizeof(struct cryptd_aead_ctx); 777 inst->alg.cra_ctxsize = sizeof(struct cryptd_aead_ctx);
745 inst->alg.cra_init = cryptd_aead_init_tfm; 778 inst->alg.cra_init = cryptd_aead_init_tfm;