diff options
author | Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com> | 2017-03-01 08:58:20 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2017-03-02 05:57:30 -0500 |
commit | c96d0a1c47abd5c4fa544dcedb5fac4d020ac58b (patch) | |
tree | d44198d6b55202e28d05e4ef34aa7f8740b20c9e /drivers | |
parent | 1c68bb0f62bf8de8bb30123ea840d5168f25abea (diff) |
crypto: vmx - Use skcipher for cbc fallback
Cc: stable@vger.kernel.org #4.10
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')
-rw-r--r-- | drivers/crypto/vmx/aes_cbc.c | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/drivers/crypto/vmx/aes_cbc.c b/drivers/crypto/vmx/aes_cbc.c index 94ad5c0adbcb..72a26eb4e954 100644 --- a/drivers/crypto/vmx/aes_cbc.c +++ b/drivers/crypto/vmx/aes_cbc.c | |||
@@ -27,11 +27,12 @@ | |||
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> | ||
30 | 31 | ||
31 | #include "aesp8-ppc.h" | 32 | #include "aesp8-ppc.h" |
32 | 33 | ||
33 | struct p8_aes_cbc_ctx { | 34 | struct p8_aes_cbc_ctx { |
34 | struct crypto_blkcipher *fallback; | 35 | struct crypto_skcipher *fallback; |
35 | struct aes_key enc_key; | 36 | struct aes_key enc_key; |
36 | struct aes_key dec_key; | 37 | struct aes_key dec_key; |
37 | }; | 38 | }; |
@@ -39,7 +40,7 @@ struct p8_aes_cbc_ctx { | |||
39 | static int p8_aes_cbc_init(struct crypto_tfm *tfm) | 40 | static int p8_aes_cbc_init(struct crypto_tfm *tfm) |
40 | { | 41 | { |
41 | const char *alg; | 42 | const char *alg; |
42 | struct crypto_blkcipher *fallback; | 43 | struct crypto_skcipher *fallback; |
43 | struct p8_aes_cbc_ctx *ctx = crypto_tfm_ctx(tfm); | 44 | struct p8_aes_cbc_ctx *ctx = crypto_tfm_ctx(tfm); |
44 | 45 | ||
45 | if (!(alg = crypto_tfm_alg_name(tfm))) { | 46 | if (!(alg = crypto_tfm_alg_name(tfm))) { |
@@ -47,8 +48,9 @@ static int p8_aes_cbc_init(struct crypto_tfm *tfm) | |||
47 | return -ENOENT; | 48 | return -ENOENT; |
48 | } | 49 | } |
49 | 50 | ||
50 | fallback = | 51 | fallback = crypto_alloc_skcipher(alg, 0, |
51 | crypto_alloc_blkcipher(alg, 0, CRYPTO_ALG_NEED_FALLBACK); | 52 | CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK); |
53 | |||
52 | if (IS_ERR(fallback)) { | 54 | if (IS_ERR(fallback)) { |
53 | printk(KERN_ERR | 55 | printk(KERN_ERR |
54 | "Failed to allocate transformation for '%s': %ld\n", | 56 | "Failed to allocate transformation for '%s': %ld\n", |
@@ -56,11 +58,12 @@ static int p8_aes_cbc_init(struct crypto_tfm *tfm) | |||
56 | return PTR_ERR(fallback); | 58 | return PTR_ERR(fallback); |
57 | } | 59 | } |
58 | printk(KERN_INFO "Using '%s' as fallback implementation.\n", | 60 | printk(KERN_INFO "Using '%s' as fallback implementation.\n", |
59 | crypto_tfm_alg_driver_name((struct crypto_tfm *) fallback)); | 61 | crypto_skcipher_driver_name(fallback)); |
62 | |||
60 | 63 | ||
61 | crypto_blkcipher_set_flags( | 64 | crypto_skcipher_set_flags( |
62 | fallback, | 65 | fallback, |
63 | crypto_blkcipher_get_flags((struct crypto_blkcipher *)tfm)); | 66 | crypto_skcipher_get_flags((struct crypto_skcipher *)tfm)); |
64 | ctx->fallback = fallback; | 67 | ctx->fallback = fallback; |
65 | 68 | ||
66 | return 0; | 69 | return 0; |
@@ -71,7 +74,7 @@ static void p8_aes_cbc_exit(struct crypto_tfm *tfm) | |||
71 | struct p8_aes_cbc_ctx *ctx = crypto_tfm_ctx(tfm); | 74 | struct p8_aes_cbc_ctx *ctx = crypto_tfm_ctx(tfm); |
72 | 75 | ||
73 | if (ctx->fallback) { | 76 | if (ctx->fallback) { |
74 | crypto_free_blkcipher(ctx->fallback); | 77 | crypto_free_skcipher(ctx->fallback); |
75 | ctx->fallback = NULL; | 78 | ctx->fallback = NULL; |
76 | } | 79 | } |
77 | } | 80 | } |
@@ -91,7 +94,7 @@ static int p8_aes_cbc_setkey(struct crypto_tfm *tfm, const u8 *key, | |||
91 | pagefault_enable(); | 94 | pagefault_enable(); |
92 | preempt_enable(); | 95 | preempt_enable(); |
93 | 96 | ||
94 | ret += crypto_blkcipher_setkey(ctx->fallback, key, keylen); | 97 | ret += crypto_skcipher_setkey(ctx->fallback, key, keylen); |
95 | return ret; | 98 | return ret; |
96 | } | 99 | } |
97 | 100 | ||
@@ -103,15 +106,14 @@ static int p8_aes_cbc_encrypt(struct blkcipher_desc *desc, | |||
103 | struct blkcipher_walk walk; | 106 | struct blkcipher_walk walk; |
104 | struct p8_aes_cbc_ctx *ctx = | 107 | struct p8_aes_cbc_ctx *ctx = |
105 | crypto_tfm_ctx(crypto_blkcipher_tfm(desc->tfm)); | 108 | crypto_tfm_ctx(crypto_blkcipher_tfm(desc->tfm)); |
106 | struct blkcipher_desc fallback_desc = { | ||
107 | .tfm = ctx->fallback, | ||
108 | .info = desc->info, | ||
109 | .flags = desc->flags | ||
110 | }; | ||
111 | 109 | ||
112 | if (in_interrupt()) { | 110 | if (in_interrupt()) { |
113 | ret = crypto_blkcipher_encrypt(&fallback_desc, dst, src, | 111 | SKCIPHER_REQUEST_ON_STACK(req, ctx->fallback); |
114 | nbytes); | 112 | skcipher_request_set_tfm(req, ctx->fallback); |
113 | skcipher_request_set_callback(req, desc->flags, NULL, NULL); | ||
114 | skcipher_request_set_crypt(req, src, dst, nbytes, desc->info); | ||
115 | ret = crypto_skcipher_encrypt(req); | ||
116 | skcipher_request_zero(req); | ||
115 | } else { | 117 | } else { |
116 | preempt_disable(); | 118 | preempt_disable(); |
117 | pagefault_disable(); | 119 | pagefault_disable(); |
@@ -144,15 +146,14 @@ static int p8_aes_cbc_decrypt(struct blkcipher_desc *desc, | |||
144 | struct blkcipher_walk walk; | 146 | struct blkcipher_walk walk; |
145 | struct p8_aes_cbc_ctx *ctx = | 147 | struct p8_aes_cbc_ctx *ctx = |
146 | crypto_tfm_ctx(crypto_blkcipher_tfm(desc->tfm)); | 148 | crypto_tfm_ctx(crypto_blkcipher_tfm(desc->tfm)); |
147 | struct blkcipher_desc fallback_desc = { | ||
148 | .tfm = ctx->fallback, | ||
149 | .info = desc->info, | ||
150 | .flags = desc->flags | ||
151 | }; | ||
152 | 149 | ||
153 | if (in_interrupt()) { | 150 | if (in_interrupt()) { |
154 | ret = crypto_blkcipher_decrypt(&fallback_desc, dst, src, | 151 | SKCIPHER_REQUEST_ON_STACK(req, ctx->fallback); |
155 | nbytes); | 152 | skcipher_request_set_tfm(req, ctx->fallback); |
153 | skcipher_request_set_callback(req, desc->flags, NULL, NULL); | ||
154 | skcipher_request_set_crypt(req, src, dst, nbytes, desc->info); | ||
155 | ret = crypto_skcipher_decrypt(req); | ||
156 | skcipher_request_zero(req); | ||
156 | } else { | 157 | } else { |
157 | preempt_disable(); | 158 | preempt_disable(); |
158 | pagefault_disable(); | 159 | pagefault_disable(); |