aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/gcm.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/gcm.c')
-rw-r--r--crypto/gcm.c49
1 files changed, 23 insertions, 26 deletions
diff --git a/crypto/gcm.c b/crypto/gcm.c
index e87e5de8e7b3..d539f5e56879 100644
--- a/crypto/gcm.c
+++ b/crypto/gcm.c
@@ -8,8 +8,8 @@
8 * by the Free Software Foundation. 8 * by the Free Software Foundation.
9 */ 9 */
10 10
11#include <crypto/algapi.h>
12#include <crypto/gf128mul.h> 11#include <crypto/gf128mul.h>
12#include <crypto/internal/skcipher.h>
13#include <crypto/scatterwalk.h> 13#include <crypto/scatterwalk.h>
14#include <linux/completion.h> 14#include <linux/completion.h>
15#include <linux/err.h> 15#include <linux/err.h>
@@ -18,10 +18,8 @@
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20 20
21#include "internal.h"
22
23struct gcm_instance_ctx { 21struct gcm_instance_ctx {
24 struct crypto_spawn ctr; 22 struct crypto_skcipher_spawn ctr;
25}; 23};
26 24
27struct crypto_gcm_ctx { 25struct crypto_gcm_ctx {
@@ -386,7 +384,7 @@ static int crypto_gcm_init_tfm(struct crypto_tfm *tfm)
386 unsigned long align; 384 unsigned long align;
387 int err; 385 int err;
388 386
389 ctr = crypto_spawn_ablkcipher(&ictx->ctr); 387 ctr = crypto_spawn_skcipher(&ictx->ctr);
390 err = PTR_ERR(ctr); 388 err = PTR_ERR(ctr);
391 if (IS_ERR(ctr)) 389 if (IS_ERR(ctr))
392 return err; 390 return err;
@@ -431,15 +429,22 @@ static struct crypto_instance *crypto_gcm_alloc_common(struct rtattr **tb,
431 if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask) 429 if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
432 return ERR_PTR(-EINVAL); 430 return ERR_PTR(-EINVAL);
433 431
434 ctr = crypto_alg_mod_lookup(ctr_name, CRYPTO_ALG_TYPE_BLKCIPHER, 432 inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
435 CRYPTO_ALG_TYPE_MASK); 433 if (!inst)
434 return ERR_PTR(-ENOMEM);
436 435
437 if (IS_ERR(ctr)) 436 ctx = crypto_instance_ctx(inst);
438 return ERR_PTR(PTR_ERR(ctr)); 437 crypto_set_skcipher_spawn(&ctx->ctr, inst);
438 err = crypto_grab_skcipher(&ctx->ctr, ctr_name, 0,
439 crypto_requires_sync(algt->type,
440 algt->mask));
441 if (err)
442 goto err_free_inst;
443
444 ctr = crypto_skcipher_spawn_alg(&ctx->ctr);
439 445
440 /* We only support 16-byte blocks. */ 446 /* We only support 16-byte blocks. */
441 if ((ctr->cra_type == &crypto_blkcipher_type ? 447 if (ctr->cra_ablkcipher.ivsize != 16)
442 ctr->cra_blkcipher.ivsize : ctr->cra_ablkcipher.ivsize) != 16)
443 goto out_put_ctr; 448 goto out_put_ctr;
444 449
445 /* Not a stream cipher? */ 450 /* Not a stream cipher? */
@@ -447,25 +452,16 @@ static struct crypto_instance *crypto_gcm_alloc_common(struct rtattr **tb,
447 if (ctr->cra_blocksize != 1) 452 if (ctr->cra_blocksize != 1)
448 goto out_put_ctr; 453 goto out_put_ctr;
449 454
450 inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
451 err = -ENOMEM;
452 if (!inst)
453 goto out_put_ctr;
454
455 err = -ENAMETOOLONG; 455 err = -ENAMETOOLONG;
456 if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, 456 if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME,
457 "gcm_base(%s)", ctr->cra_driver_name) >= 457 "gcm_base(%s)", ctr->cra_driver_name) >=
458 CRYPTO_MAX_ALG_NAME) 458 CRYPTO_MAX_ALG_NAME)
459 goto err_free_inst; 459 goto out_put_ctr;
460
461 ctx = crypto_instance_ctx(inst);
462 err = crypto_init_spawn(&ctx->ctr, ctr, inst, CRYPTO_ALG_TYPE_MASK);
463 if (err)
464 goto err_free_inst;
465 460
466 memcpy(inst->alg.cra_name, full_name, CRYPTO_MAX_ALG_NAME); 461 memcpy(inst->alg.cra_name, full_name, CRYPTO_MAX_ALG_NAME);
467 462
468 inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC; 463 inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD;
464 inst->alg.cra_flags |= ctr->cra_flags & CRYPTO_ALG_ASYNC;
469 inst->alg.cra_priority = ctr->cra_priority; 465 inst->alg.cra_priority = ctr->cra_priority;
470 inst->alg.cra_blocksize = 1; 466 inst->alg.cra_blocksize = 1;
471 inst->alg.cra_alignmask = ctr->cra_alignmask | (__alignof__(u64) - 1); 467 inst->alg.cra_alignmask = ctr->cra_alignmask | (__alignof__(u64) - 1);
@@ -480,11 +476,12 @@ static struct crypto_instance *crypto_gcm_alloc_common(struct rtattr **tb,
480 inst->alg.cra_aead.decrypt = crypto_gcm_decrypt; 476 inst->alg.cra_aead.decrypt = crypto_gcm_decrypt;
481 477
482out: 478out:
483 crypto_mod_put(ctr);
484 return inst; 479 return inst;
480
481out_put_ctr:
482 crypto_drop_skcipher(&ctx->ctr);
485err_free_inst: 483err_free_inst:
486 kfree(inst); 484 kfree(inst);
487out_put_ctr:
488 inst = ERR_PTR(err); 485 inst = ERR_PTR(err);
489 goto out; 486 goto out;
490} 487}
@@ -516,7 +513,7 @@ static void crypto_gcm_free(struct crypto_instance *inst)
516{ 513{
517 struct gcm_instance_ctx *ctx = crypto_instance_ctx(inst); 514 struct gcm_instance_ctx *ctx = crypto_instance_ctx(inst);
518 515
519 crypto_drop_spawn(&ctx->ctr); 516 crypto_drop_skcipher(&ctx->ctr);
520 kfree(inst); 517 kfree(inst);
521} 518}
522 519