Commit 1fd2ec10 authored by Paulo Flabiano Smorigo's avatar Paulo Flabiano Smorigo Committed by Greg Kroah-Hartman

crypto: vmx - Use skcipher for cbc fallback

commit c96d0a1c upstream.
Signed-off-by: default avatarPaulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent e7fa3bd2
...@@ -27,11 +27,12 @@ ...@@ -27,11 +27,12 @@
#include <asm/switch_to.h> #include <asm/switch_to.h>
#include <crypto/aes.h> #include <crypto/aes.h>
#include <crypto/scatterwalk.h> #include <crypto/scatterwalk.h>
#include <crypto/skcipher.h>
#include "aesp8-ppc.h" #include "aesp8-ppc.h"
struct p8_aes_cbc_ctx { struct p8_aes_cbc_ctx {
struct crypto_blkcipher *fallback; struct crypto_skcipher *fallback;
struct aes_key enc_key; struct aes_key enc_key;
struct aes_key dec_key; struct aes_key dec_key;
}; };
...@@ -39,7 +40,7 @@ struct p8_aes_cbc_ctx { ...@@ -39,7 +40,7 @@ struct p8_aes_cbc_ctx {
static int p8_aes_cbc_init(struct crypto_tfm *tfm) static int p8_aes_cbc_init(struct crypto_tfm *tfm)
{ {
const char *alg; const char *alg;
struct crypto_blkcipher *fallback; struct crypto_skcipher *fallback;
struct p8_aes_cbc_ctx *ctx = crypto_tfm_ctx(tfm); struct p8_aes_cbc_ctx *ctx = crypto_tfm_ctx(tfm);
if (!(alg = crypto_tfm_alg_name(tfm))) { if (!(alg = crypto_tfm_alg_name(tfm))) {
...@@ -47,8 +48,9 @@ static int p8_aes_cbc_init(struct crypto_tfm *tfm) ...@@ -47,8 +48,9 @@ static int p8_aes_cbc_init(struct crypto_tfm *tfm)
return -ENOENT; return -ENOENT;
} }
fallback = fallback = crypto_alloc_skcipher(alg, 0,
crypto_alloc_blkcipher(alg, 0, CRYPTO_ALG_NEED_FALLBACK); CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK);
if (IS_ERR(fallback)) { if (IS_ERR(fallback)) {
printk(KERN_ERR printk(KERN_ERR
"Failed to allocate transformation for '%s': %ld\n", "Failed to allocate transformation for '%s': %ld\n",
...@@ -56,11 +58,12 @@ static int p8_aes_cbc_init(struct crypto_tfm *tfm) ...@@ -56,11 +58,12 @@ static int p8_aes_cbc_init(struct crypto_tfm *tfm)
return PTR_ERR(fallback); return PTR_ERR(fallback);
} }
printk(KERN_INFO "Using '%s' as fallback implementation.\n", printk(KERN_INFO "Using '%s' as fallback implementation.\n",
crypto_tfm_alg_driver_name((struct crypto_tfm *) fallback)); crypto_skcipher_driver_name(fallback));
crypto_blkcipher_set_flags( crypto_skcipher_set_flags(
fallback, fallback,
crypto_blkcipher_get_flags((struct crypto_blkcipher *)tfm)); crypto_skcipher_get_flags((struct crypto_skcipher *)tfm));
ctx->fallback = fallback; ctx->fallback = fallback;
return 0; return 0;
...@@ -71,7 +74,7 @@ static void p8_aes_cbc_exit(struct crypto_tfm *tfm) ...@@ -71,7 +74,7 @@ static void p8_aes_cbc_exit(struct crypto_tfm *tfm)
struct p8_aes_cbc_ctx *ctx = crypto_tfm_ctx(tfm); struct p8_aes_cbc_ctx *ctx = crypto_tfm_ctx(tfm);
if (ctx->fallback) { if (ctx->fallback) {
crypto_free_blkcipher(ctx->fallback); crypto_free_skcipher(ctx->fallback);
ctx->fallback = NULL; ctx->fallback = NULL;
} }
} }
...@@ -91,7 +94,7 @@ static int p8_aes_cbc_setkey(struct crypto_tfm *tfm, const u8 *key, ...@@ -91,7 +94,7 @@ static int p8_aes_cbc_setkey(struct crypto_tfm *tfm, const u8 *key,
pagefault_enable(); pagefault_enable();
preempt_enable(); preempt_enable();
ret += crypto_blkcipher_setkey(ctx->fallback, key, keylen); ret += crypto_skcipher_setkey(ctx->fallback, key, keylen);
return ret; return ret;
} }
...@@ -103,15 +106,14 @@ static int p8_aes_cbc_encrypt(struct blkcipher_desc *desc, ...@@ -103,15 +106,14 @@ static int p8_aes_cbc_encrypt(struct blkcipher_desc *desc,
struct blkcipher_walk walk; struct blkcipher_walk walk;
struct p8_aes_cbc_ctx *ctx = struct p8_aes_cbc_ctx *ctx =
crypto_tfm_ctx(crypto_blkcipher_tfm(desc->tfm)); crypto_tfm_ctx(crypto_blkcipher_tfm(desc->tfm));
struct blkcipher_desc fallback_desc = {
.tfm = ctx->fallback,
.info = desc->info,
.flags = desc->flags
};
if (in_interrupt()) { if (in_interrupt()) {
ret = crypto_blkcipher_encrypt(&fallback_desc, dst, src, SKCIPHER_REQUEST_ON_STACK(req, ctx->fallback);
nbytes); skcipher_request_set_tfm(req, ctx->fallback);
skcipher_request_set_callback(req, desc->flags, NULL, NULL);
skcipher_request_set_crypt(req, src, dst, nbytes, desc->info);
ret = crypto_skcipher_encrypt(req);
skcipher_request_zero(req);
} else { } else {
preempt_disable(); preempt_disable();
pagefault_disable(); pagefault_disable();
...@@ -144,15 +146,14 @@ static int p8_aes_cbc_decrypt(struct blkcipher_desc *desc, ...@@ -144,15 +146,14 @@ static int p8_aes_cbc_decrypt(struct blkcipher_desc *desc,
struct blkcipher_walk walk; struct blkcipher_walk walk;
struct p8_aes_cbc_ctx *ctx = struct p8_aes_cbc_ctx *ctx =
crypto_tfm_ctx(crypto_blkcipher_tfm(desc->tfm)); crypto_tfm_ctx(crypto_blkcipher_tfm(desc->tfm));
struct blkcipher_desc fallback_desc = {
.tfm = ctx->fallback,
.info = desc->info,
.flags = desc->flags
};
if (in_interrupt()) { if (in_interrupt()) {
ret = crypto_blkcipher_decrypt(&fallback_desc, dst, src, SKCIPHER_REQUEST_ON_STACK(req, ctx->fallback);
nbytes); skcipher_request_set_tfm(req, ctx->fallback);
skcipher_request_set_callback(req, desc->flags, NULL, NULL);
skcipher_request_set_crypt(req, src, dst, nbytes, desc->info);
ret = crypto_skcipher_decrypt(req);
skcipher_request_zero(req);
} else { } else {
preempt_disable(); preempt_disable();
pagefault_disable(); pagefault_disable();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment