diff options
author | Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com> | 2017-10-16 18:54:19 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2017-11-03 09:53:32 -0400 |
commit | e666d4e9ceec94c0a88c94b7db31d56474da43b3 (patch) | |
tree | 4daaba9461cfc949b198842523619b51a1050d82 /drivers/crypto | |
parent | e6cd5bf64855cc78054d6f8714f6c9983b7bb8bd (diff) |
crypto: vmx - Use skcipher for ctr fallback
Signed-off-by: Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto')
-rw-r--r-- | drivers/crypto/vmx/aes_ctr.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/drivers/crypto/vmx/aes_ctr.c b/drivers/crypto/vmx/aes_ctr.c index 17d84217dd76..fc60d00a2e84 100644 --- a/drivers/crypto/vmx/aes_ctr.c +++ b/drivers/crypto/vmx/aes_ctr.c | |||
@@ -27,21 +27,23 @@ | |||
27 | #include <asm/switch_to.h> | 27 | #include <asm/switch_to.h> |
28 | #include <crypto/aes.h> | 28 | #include <crypto/aes.h> |
29 | #include <crypto/scatterwalk.h> | 29 | #include <crypto/scatterwalk.h> |
30 | #include <crypto/skcipher.h> | ||
31 | |||
30 | #include "aesp8-ppc.h" | 32 | #include "aesp8-ppc.h" |
31 | 33 | ||
32 | struct p8_aes_ctr_ctx { | 34 | struct p8_aes_ctr_ctx { |
33 | struct crypto_blkcipher *fallback; | 35 | struct crypto_skcipher *fallback; |
34 | struct aes_key enc_key; | 36 | struct aes_key enc_key; |
35 | }; | 37 | }; |
36 | 38 | ||
37 | static int p8_aes_ctr_init(struct crypto_tfm *tfm) | 39 | static int p8_aes_ctr_init(struct crypto_tfm *tfm) |
38 | { | 40 | { |
39 | const char *alg = crypto_tfm_alg_name(tfm); | 41 | const char *alg = crypto_tfm_alg_name(tfm); |
40 | struct crypto_blkcipher *fallback; | 42 | struct crypto_skcipher *fallback; |
41 | struct p8_aes_ctr_ctx *ctx = crypto_tfm_ctx(tfm); | 43 | struct p8_aes_ctr_ctx *ctx = crypto_tfm_ctx(tfm); |
42 | 44 | ||
43 | fallback = | 45 | fallback = crypto_alloc_skcipher(alg, 0, |
44 | crypto_alloc_blkcipher(alg, 0, CRYPTO_ALG_NEED_FALLBACK); | 46 | CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK); |
45 | if (IS_ERR(fallback)) { | 47 | if (IS_ERR(fallback)) { |
46 | printk(KERN_ERR | 48 | printk(KERN_ERR |
47 | "Failed to allocate transformation for '%s': %ld\n", | 49 | "Failed to allocate transformation for '%s': %ld\n", |
@@ -49,11 +51,11 @@ static int p8_aes_ctr_init(struct crypto_tfm *tfm) | |||
49 | return PTR_ERR(fallback); | 51 | return PTR_ERR(fallback); |
50 | } | 52 | } |
51 | printk(KERN_INFO "Using '%s' as fallback implementation.\n", | 53 | printk(KERN_INFO "Using '%s' as fallback implementation.\n", |
52 | crypto_tfm_alg_driver_name((struct crypto_tfm *) fallback)); | 54 | crypto_skcipher_driver_name(fallback)); |
53 | 55 | ||
54 | crypto_blkcipher_set_flags( | 56 | crypto_skcipher_set_flags( |
55 | fallback, | 57 | fallback, |
56 | crypto_blkcipher_get_flags((struct crypto_blkcipher *)tfm)); | 58 | crypto_skcipher_get_flags((struct crypto_skcipher *)tfm)); |
57 | ctx->fallback = fallback; | 59 | ctx->fallback = fallback; |
58 | 60 | ||
59 | return 0; | 61 | return 0; |
@@ -64,7 +66,7 @@ static void p8_aes_ctr_exit(struct crypto_tfm *tfm) | |||
64 | struct p8_aes_ctr_ctx *ctx = crypto_tfm_ctx(tfm); | 66 | struct p8_aes_ctr_ctx *ctx = crypto_tfm_ctx(tfm); |
65 | 67 | ||
66 | if (ctx->fallback) { | 68 | if (ctx->fallback) { |
67 | crypto_free_blkcipher(ctx->fallback); | 69 | crypto_free_skcipher(ctx->fallback); |
68 | ctx->fallback = NULL; | 70 | ctx->fallback = NULL; |
69 | } | 71 | } |
70 | } | 72 | } |
@@ -83,7 +85,7 @@ static int p8_aes_ctr_setkey(struct crypto_tfm *tfm, const u8 *key, | |||
83 | pagefault_enable(); | 85 | pagefault_enable(); |
84 | preempt_enable(); | 86 | preempt_enable(); |
85 | 87 | ||
86 | ret += crypto_blkcipher_setkey(ctx->fallback, key, keylen); | 88 | ret += crypto_skcipher_setkey(ctx->fallback, key, keylen); |
87 | return ret; | 89 | return ret; |
88 | } | 90 | } |
89 | 91 | ||
@@ -117,15 +119,14 @@ static int p8_aes_ctr_crypt(struct blkcipher_desc *desc, | |||
117 | struct blkcipher_walk walk; | 119 | struct blkcipher_walk walk; |
118 | struct p8_aes_ctr_ctx *ctx = | 120 | struct p8_aes_ctr_ctx *ctx = |
119 | crypto_tfm_ctx(crypto_blkcipher_tfm(desc->tfm)); | 121 | crypto_tfm_ctx(crypto_blkcipher_tfm(desc->tfm)); |
120 | struct blkcipher_desc fallback_desc = { | ||
121 | .tfm = ctx->fallback, | ||
122 | .info = desc->info, | ||
123 | .flags = desc->flags | ||
124 | }; | ||
125 | 122 | ||
126 | if (in_interrupt()) { | 123 | if (in_interrupt()) { |
127 | ret = crypto_blkcipher_encrypt(&fallback_desc, dst, src, | 124 | SKCIPHER_REQUEST_ON_STACK(req, ctx->fallback); |
128 | nbytes); | 125 | skcipher_request_set_tfm(req, ctx->fallback); |
126 | skcipher_request_set_callback(req, desc->flags, NULL, NULL); | ||
127 | skcipher_request_set_crypt(req, src, dst, nbytes, desc->info); | ||
128 | ret = crypto_skcipher_encrypt(req); | ||
129 | skcipher_request_zero(req); | ||
129 | } else { | 130 | } else { |
130 | blkcipher_walk_init(&walk, dst, src, nbytes); | 131 | blkcipher_walk_init(&walk, dst, src, nbytes); |
131 | ret = blkcipher_walk_virt_block(desc, &walk, AES_BLOCK_SIZE); | 132 | ret = blkcipher_walk_virt_block(desc, &walk, AES_BLOCK_SIZE); |