Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[CRYPTO] gcm: Use crypto_grab_skcipher

This patch converts the gcm algorithm over to crypto_grab_skcipher
which is a prerequisite for IV generation.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

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