diff options
| author | Jussi Kivilinna <jussi.kivilinna@mbnet.fi> | 2012-06-18 07:07:08 -0400 |
|---|---|---|
| committer | Herbert Xu <herbert@gondor.apana.org.au> | 2012-06-27 02:42:01 -0400 |
| commit | a9629d7142ea22567eaa999232d8a31a7493665a (patch) | |
| tree | 6693434c4fa675478f7c3bca469f29b22670f713 | |
| parent | 30a04008827b58c4aafbd1d6a27d6b6ed239e993 (diff) | |
crypto: aes_ni - change to use shared ablk_* functions
Remove duplicate ablk_* functions and make use of ablk_helper module instead.
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
| -rw-r--r-- | arch/x86/crypto/ablk_helper.c | 19 | ||||
| -rw-r--r-- | arch/x86/crypto/aesni-intel_glue.c | 100 | ||||
| -rw-r--r-- | arch/x86/include/asm/crypto/ablk_helper.h | 2 | ||||
| -rw-r--r-- | crypto/Kconfig | 1 |
4 files changed, 20 insertions, 102 deletions
diff --git a/arch/x86/crypto/ablk_helper.c b/arch/x86/crypto/ablk_helper.c index 284ca3bc2383..43282fe04a8b 100644 --- a/arch/x86/crypto/ablk_helper.c +++ b/arch/x86/crypto/ablk_helper.c | |||
| @@ -118,32 +118,31 @@ void ablk_exit(struct crypto_tfm *tfm) | |||
| 118 | } | 118 | } |
| 119 | EXPORT_SYMBOL_GPL(ablk_exit); | 119 | EXPORT_SYMBOL_GPL(ablk_exit); |
| 120 | 120 | ||
| 121 | void ablk_init_common(struct crypto_tfm *tfm, | 121 | int ablk_init_common(struct crypto_tfm *tfm, const char *drv_name) |
| 122 | struct cryptd_ablkcipher *cryptd_tfm) | ||
| 123 | { | 122 | { |
| 124 | struct async_helper_ctx *ctx = crypto_tfm_ctx(tfm); | 123 | struct async_helper_ctx *ctx = crypto_tfm_ctx(tfm); |
| 124 | struct cryptd_ablkcipher *cryptd_tfm; | ||
| 125 | |||
| 126 | cryptd_tfm = cryptd_alloc_ablkcipher(drv_name, 0, 0); | ||
| 127 | if (IS_ERR(cryptd_tfm)) | ||
| 128 | return PTR_ERR(cryptd_tfm); | ||
| 125 | 129 | ||
| 126 | ctx->cryptd_tfm = cryptd_tfm; | 130 | ctx->cryptd_tfm = cryptd_tfm; |
| 127 | tfm->crt_ablkcipher.reqsize = sizeof(struct ablkcipher_request) + | 131 | tfm->crt_ablkcipher.reqsize = sizeof(struct ablkcipher_request) + |
| 128 | crypto_ablkcipher_reqsize(&cryptd_tfm->base); | 132 | crypto_ablkcipher_reqsize(&cryptd_tfm->base); |
| 133 | |||
| 134 | return 0; | ||
| 129 | } | 135 | } |
| 130 | EXPORT_SYMBOL_GPL(ablk_init_common); | 136 | EXPORT_SYMBOL_GPL(ablk_init_common); |
| 131 | 137 | ||
| 132 | int ablk_init(struct crypto_tfm *tfm) | 138 | int ablk_init(struct crypto_tfm *tfm) |
| 133 | { | 139 | { |
| 134 | struct cryptd_ablkcipher *cryptd_tfm; | ||
| 135 | char drv_name[CRYPTO_MAX_ALG_NAME]; | 140 | char drv_name[CRYPTO_MAX_ALG_NAME]; |
| 136 | 141 | ||
| 137 | snprintf(drv_name, sizeof(drv_name), "__driver-%s", | 142 | snprintf(drv_name, sizeof(drv_name), "__driver-%s", |
| 138 | crypto_tfm_alg_driver_name(tfm)); | 143 | crypto_tfm_alg_driver_name(tfm)); |
| 139 | 144 | ||
| 140 | cryptd_tfm = cryptd_alloc_ablkcipher(drv_name, 0, 0); | 145 | return ablk_init_common(tfm, drv_name); |
| 141 | if (IS_ERR(cryptd_tfm)) | ||
| 142 | return PTR_ERR(cryptd_tfm); | ||
| 143 | |||
| 144 | ablk_init_common(tfm, cryptd_tfm); | ||
| 145 | |||
| 146 | return 0; | ||
| 147 | } | 146 | } |
| 148 | EXPORT_SYMBOL_GPL(ablk_init); | 147 | EXPORT_SYMBOL_GPL(ablk_init); |
| 149 | 148 | ||
diff --git a/arch/x86/crypto/aesni-intel_glue.c b/arch/x86/crypto/aesni-intel_glue.c index ac7f5cd019e8..7c9d54d8dc4d 100644 --- a/arch/x86/crypto/aesni-intel_glue.c +++ b/arch/x86/crypto/aesni-intel_glue.c | |||
| @@ -31,6 +31,7 @@ | |||
| 31 | #include <asm/cpu_device_id.h> | 31 | #include <asm/cpu_device_id.h> |
| 32 | #include <asm/i387.h> | 32 | #include <asm/i387.h> |
| 33 | #include <asm/aes.h> | 33 | #include <asm/aes.h> |
| 34 | #include <asm/crypto/ablk_helper.h> | ||
| 34 | #include <crypto/scatterwalk.h> | 35 | #include <crypto/scatterwalk.h> |
| 35 | #include <crypto/internal/aead.h> | 36 | #include <crypto/internal/aead.h> |
| 36 | #include <linux/workqueue.h> | 37 | #include <linux/workqueue.h> |
| @@ -52,10 +53,6 @@ | |||
| 52 | #define HAS_XTS | 53 | #define HAS_XTS |
| 53 | #endif | 54 | #endif |
| 54 | 55 | ||
| 55 | struct async_aes_ctx { | ||
| 56 | struct cryptd_ablkcipher *cryptd_tfm; | ||
| 57 | }; | ||
| 58 | |||
| 59 | /* This data is stored at the end of the crypto_tfm struct. | 56 | /* This data is stored at the end of the crypto_tfm struct. |
| 60 | * It's a type of per "session" data storage location. | 57 | * It's a type of per "session" data storage location. |
| 61 | * This needs to be 16 byte aligned. | 58 | * This needs to be 16 byte aligned. |
| @@ -377,87 +374,6 @@ static int ctr_crypt(struct blkcipher_desc *desc, | |||
| 377 | } | 374 | } |
| 378 | #endif | 375 | #endif |
| 379 | 376 | ||
| 380 | static int ablk_set_key(struct crypto_ablkcipher *tfm, const u8 *key, | ||
| 381 | unsigned int key_len) | ||
| 382 | { | ||
| 383 | struct async_aes_ctx *ctx = crypto_ablkcipher_ctx(tfm); | ||
| 384 | struct crypto_ablkcipher *child = &ctx->cryptd_tfm->base; | ||
| 385 | int err; | ||
| 386 | |||
| 387 | crypto_ablkcipher_clear_flags(child, CRYPTO_TFM_REQ_MASK); | ||
| 388 | crypto_ablkcipher_set_flags(child, crypto_ablkcipher_get_flags(tfm) | ||
| 389 | & CRYPTO_TFM_REQ_MASK); | ||
| 390 | err = crypto_ablkcipher_setkey(child, key, key_len); | ||
| 391 | crypto_ablkcipher_set_flags(tfm, crypto_ablkcipher_get_flags(child) | ||
| 392 | & CRYPTO_TFM_RES_MASK); | ||
| 393 | return err; | ||
| 394 | } | ||
| 395 | |||
| 396 | static int ablk_encrypt(struct ablkcipher_request *req) | ||
| 397 | { | ||
| 398 | struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req); | ||
| 399 | struct async_aes_ctx *ctx = crypto_ablkcipher_ctx(tfm); | ||
| 400 | |||
| 401 | if (!irq_fpu_usable()) { | ||
| 402 | struct ablkcipher_request *cryptd_req = | ||
| 403 | ablkcipher_request_ctx(req); | ||
| 404 | memcpy(cryptd_req, req, sizeof(*req)); | ||
| 405 | ablkcipher_request_set_tfm(cryptd_req, &ctx->cryptd_tfm->base); | ||
| 406 | return crypto_ablkcipher_encrypt(cryptd_req); | ||
| 407 | } else { | ||
| 408 | struct blkcipher_desc desc; | ||
| 409 | desc.tfm = cryptd_ablkcipher_child(ctx->cryptd_tfm); | ||
| 410 | desc.info = req->info; | ||
| 411 | desc.flags = 0; | ||
| 412 | return crypto_blkcipher_crt(desc.tfm)->encrypt( | ||
| 413 | &desc, req->dst, req->src, req->nbytes); | ||
| 414 | } | ||
| 415 | } | ||
| 416 | |||
| 417 | static int ablk_decrypt(struct ablkcipher_request *req) | ||
| 418 | { | ||
| 419 | struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req); | ||
| 420 | struct async_aes_ctx *ctx = crypto_ablkcipher_ctx(tfm); | ||
| 421 | |||
| 422 | if (!irq_fpu_usable()) { | ||
| 423 | struct ablkcipher_request *cryptd_req = | ||
| 424 | ablkcipher_request_ctx(req); | ||
| 425 | memcpy(cryptd_req, req, sizeof(*req)); | ||
| 426 | ablkcipher_request_set_tfm(cryptd_req, &ctx->cryptd_tfm->base); | ||
| 427 | return crypto_ablkcipher_decrypt(cryptd_req); | ||
| 428 | } else { | ||
| 429 | struct blkcipher_desc desc; | ||
| 430 | desc.tfm = cryptd_ablkcipher_child(ctx->cryptd_tfm); | ||
| 431 | desc.info = req->info; | ||
| 432 | desc.flags = 0; | ||
| 433 | return crypto_blkcipher_crt(desc.tfm)->decrypt( | ||
| 434 | &desc, req->dst, req->src, req->nbytes); | ||
| 435 | } | ||
| 436 | } | ||
| 437 | |||
| 438 | static void ablk_exit(struct crypto_tfm *tfm) | ||
| 439 | { | ||
| 440 | struct async_aes_ctx *ctx = crypto_tfm_ctx(tfm); | ||
| 441 | |||
| 442 | cryptd_free_ablkcipher(ctx->cryptd_tfm); | ||
| 443 | } | ||
| 444 | |||
| 445 | static int ablk_init_common(struct crypto_tfm *tfm, const char *drv_name) | ||
| 446 | { | ||
| 447 | struct async_aes_ctx *ctx = crypto_tfm_ctx(tfm); | ||
| 448 | struct cryptd_ablkcipher *cryptd_tfm; | ||
| 449 | |||
| 450 | cryptd_tfm = cryptd_alloc_ablkcipher(drv_name, 0, 0); | ||
| 451 | if (IS_ERR(cryptd_tfm)) | ||
| 452 | return PTR_ERR(cryptd_tfm); | ||
| 453 | |||
| 454 | ctx->cryptd_tfm = cryptd_tfm; | ||
| 455 | tfm->crt_ablkcipher.reqsize = sizeof(struct ablkcipher_request) + | ||
| 456 | crypto_ablkcipher_reqsize(&cryptd_tfm->base); | ||
| 457 | |||
| 458 | return 0; | ||
| 459 | } | ||
| 460 | |||
| 461 | static int ablk_ecb_init(struct crypto_tfm *tfm) | 377 | static int ablk_ecb_init(struct crypto_tfm *tfm) |
| 462 | { | 378 | { |
| 463 | return ablk_init_common(tfm, "__driver-ecb-aes-aesni"); | 379 | return ablk_init_common(tfm, "__driver-ecb-aes-aesni"); |
| @@ -968,7 +884,7 @@ static struct crypto_alg aesni_algs[] = { { | |||
| 968 | .cra_priority = 400, | 884 | .cra_priority = 400, |
| 969 | .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, | 885 | .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, |
| 970 | .cra_blocksize = AES_BLOCK_SIZE, | 886 | .cra_blocksize = AES_BLOCK_SIZE, |
| 971 | .cra_ctxsize = sizeof(struct async_aes_ctx), | 887 | .cra_ctxsize = sizeof(struct async_helper_ctx), |
| 972 | .cra_alignmask = 0, | 888 | .cra_alignmask = 0, |
| 973 | .cra_type = &crypto_ablkcipher_type, | 889 | .cra_type = &crypto_ablkcipher_type, |
| 974 | .cra_module = THIS_MODULE, | 890 | .cra_module = THIS_MODULE, |
| @@ -989,7 +905,7 @@ static struct crypto_alg aesni_algs[] = { { | |||
| 989 | .cra_priority = 400, | 905 | .cra_priority = 400, |
| 990 | .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, | 906 | .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, |
