Skip to content

Commit

Permalink
crypto: vmx - Use skcipher for xts fallback
Browse files Browse the repository at this point in the history
Cc: [email protected] rib#4.10
Signed-off-by: Paulo Flabiano Smorigo <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
pfsmorigo authored and herbertx committed Mar 2, 2017
1 parent c96d0a1 commit 5839f55
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions drivers/crypto/vmx/aes_xts.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
#include <crypto/aes.h>
#include <crypto/scatterwalk.h>
#include <crypto/xts.h>
#include <crypto/skcipher.h>

#include "aesp8-ppc.h"

struct p8_aes_xts_ctx {
struct crypto_blkcipher *fallback;
struct crypto_skcipher *fallback;
struct aes_key enc_key;
struct aes_key dec_key;
struct aes_key tweak_key;
Expand All @@ -41,28 +42,28 @@ struct p8_aes_xts_ctx {
static int p8_aes_xts_init(struct crypto_tfm *tfm)
{
const char *alg;
struct crypto_blkcipher *fallback;
struct crypto_skcipher *fallback;
struct p8_aes_xts_ctx *ctx = crypto_tfm_ctx(tfm);

if (!(alg = crypto_tfm_alg_name(tfm))) {
printk(KERN_ERR "Failed to get algorithm name.\n");
return -ENOENT;
}

fallback =
crypto_alloc_blkcipher(alg, 0, CRYPTO_ALG_NEED_FALLBACK);
fallback = crypto_alloc_skcipher(alg, 0,
CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK);
if (IS_ERR(fallback)) {
printk(KERN_ERR
"Failed to allocate transformation for '%s': %ld\n",
alg, PTR_ERR(fallback));
return PTR_ERR(fallback);
}
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,
crypto_blkcipher_get_flags((struct crypto_blkcipher *)tfm));
crypto_skcipher_get_flags((struct crypto_skcipher *)tfm));
ctx->fallback = fallback;

return 0;
Expand All @@ -73,7 +74,7 @@ static void p8_aes_xts_exit(struct crypto_tfm *tfm)
struct p8_aes_xts_ctx *ctx = crypto_tfm_ctx(tfm);

if (ctx->fallback) {
crypto_free_blkcipher(ctx->fallback);
crypto_free_skcipher(ctx->fallback);
ctx->fallback = NULL;
}
}
Expand All @@ -98,7 +99,7 @@ static int p8_aes_xts_setkey(struct crypto_tfm *tfm, const u8 *key,
pagefault_enable();
preempt_enable();

ret += crypto_blkcipher_setkey(ctx->fallback, key, keylen);
ret += crypto_skcipher_setkey(ctx->fallback, key, keylen);
return ret;
}

Expand All @@ -113,15 +114,14 @@ static int p8_aes_xts_crypt(struct blkcipher_desc *desc,
struct blkcipher_walk walk;
struct p8_aes_xts_ctx *ctx =
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()) {
ret = enc ? crypto_blkcipher_encrypt(&fallback_desc, dst, src, nbytes) :
crypto_blkcipher_decrypt(&fallback_desc, dst, src, nbytes);
SKCIPHER_REQUEST_ON_STACK(req, ctx->fallback);
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 = enc? crypto_skcipher_encrypt(req) : crypto_skcipher_decrypt(req);
skcipher_request_zero(req);
} else {
preempt_disable();
pagefault_disable();
Expand Down

0 comments on commit 5839f55

Please sign in to comment.