All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Cerri <marcelo.cerri@canonical.com>
To: Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com>
Cc: herbert@gondor.apana.org.au, linux-kernel@vger.kernel.org,
	paulus@samba.org, linux-crypto@vger.kernel.org,
	linuxppc-dev@lists.ozlabs.org, davem@davemloft.net
Subject: Re: [PATCH 2/2] crypto: vmx - Use skcipher for xts fallback
Date: Wed, 22 Feb 2017 16:20:04 -0300	[thread overview]
Message-ID: <20170222192004.GC20626@gallifrey> (raw)
In-Reply-To: <20170222180045.28341-1-pfsmorigo@linux.vnet.ibm.com>

[-- Attachment #1: Type: text/plain, Size: 3788 bytes --]

In addition to cbc comments:

On Wed, Feb 22, 2017 at 03:00:45PM -0300, Paulo Flabiano Smorigo wrote:
> Signed-off-by: Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com>
> ---
>  drivers/crypto/vmx/aes_xts.c | 32 ++++++++++++++++++--------------
>  1 file changed, 18 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/crypto/vmx/aes_xts.c b/drivers/crypto/vmx/aes_xts.c
> index 24353ec3..a8245e1 100644
> --- a/drivers/crypto/vmx/aes_xts.c
> +++ b/drivers/crypto/vmx/aes_xts.c
> @@ -28,11 +28,12 @@
>  #include <crypto/aes.h>
>  #include <crypto/scatterwalk.h>
>  #include <crypto/xts.h>
> +#include <crypto/internal/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;
> @@ -41,7 +42,7 @@ 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))) {
> @@ -50,7 +51,7 @@ static int p8_aes_xts_init(struct crypto_tfm *tfm)
>  	}
>  
>  	fallback =
> -		crypto_alloc_blkcipher(alg, 0, CRYPTO_ALG_NEED_FALLBACK);
> +		crypto_alloc_skcipher(alg, 0, CRYPTO_ALG_NEED_FALLBACK);
>  	if (IS_ERR(fallback)) {
>  		printk(KERN_ERR
>  			"Failed to allocate transformation for '%s': %ld\n",
> @@ -60,9 +61,9 @@ static int p8_aes_xts_init(struct crypto_tfm *tfm)
>  	printk(KERN_INFO "Using '%s' as fallback implementation.\n",
>  		crypto_tfm_alg_driver_name((struct crypto_tfm *) 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;
> @@ -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;
>  	}
>  }
> @@ -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;
>  }
>  
> @@ -113,15 +114,18 @@ 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 = crypto_skcipher_encrypt(req);

You probably don't want this crypto_skcipher_encrypt call.


> +		if (enc)
> +			crypto_skcipher_encrypt(req);
> +		else
> +			crypto_skcipher_decrypt(req);

And you should check the return values here.

> +		skcipher_request_zero(req);
>  	} else {
>  		preempt_disable();
>  		pagefault_disable();
> -- 
> 2.9.3
> 

-- 
Regards,
Marcelo


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: Marcelo Cerri <marcelo.cerri@canonical.com>
To: Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com>
Cc: linux-kernel@vger.kernel.org, benh@kernel.crashing.org,
	paulus@samba.org, mpe@ellerman.id.au,
	herbert@gondor.apana.org.au, davem@davemloft.net,
	linux-crypto@vger.kernel.org, linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH 2/2] crypto: vmx - Use skcipher for xts fallback
Date: Wed, 22 Feb 2017 16:20:04 -0300	[thread overview]
Message-ID: <20170222192004.GC20626@gallifrey> (raw)
In-Reply-To: <20170222180045.28341-1-pfsmorigo@linux.vnet.ibm.com>

[-- Attachment #1: Type: text/plain, Size: 3788 bytes --]

In addition to cbc comments:

On Wed, Feb 22, 2017 at 03:00:45PM -0300, Paulo Flabiano Smorigo wrote:
> Signed-off-by: Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com>
> ---
>  drivers/crypto/vmx/aes_xts.c | 32 ++++++++++++++++++--------------
>  1 file changed, 18 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/crypto/vmx/aes_xts.c b/drivers/crypto/vmx/aes_xts.c
> index 24353ec3..a8245e1 100644
> --- a/drivers/crypto/vmx/aes_xts.c
> +++ b/drivers/crypto/vmx/aes_xts.c
> @@ -28,11 +28,12 @@
>  #include <crypto/aes.h>
>  #include <crypto/scatterwalk.h>
>  #include <crypto/xts.h>
> +#include <crypto/internal/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;
> @@ -41,7 +42,7 @@ 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))) {
> @@ -50,7 +51,7 @@ static int p8_aes_xts_init(struct crypto_tfm *tfm)
>  	}
>  
>  	fallback =
> -		crypto_alloc_blkcipher(alg, 0, CRYPTO_ALG_NEED_FALLBACK);
> +		crypto_alloc_skcipher(alg, 0, CRYPTO_ALG_NEED_FALLBACK);
>  	if (IS_ERR(fallback)) {
>  		printk(KERN_ERR
>  			"Failed to allocate transformation for '%s': %ld\n",
> @@ -60,9 +61,9 @@ static int p8_aes_xts_init(struct crypto_tfm *tfm)
>  	printk(KERN_INFO "Using '%s' as fallback implementation.\n",
>  		crypto_tfm_alg_driver_name((struct crypto_tfm *) 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;
> @@ -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;
>  	}
>  }
> @@ -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;
>  }
>  
> @@ -113,15 +114,18 @@ 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 = crypto_skcipher_encrypt(req);

You probably don't want this crypto_skcipher_encrypt call.


> +		if (enc)
> +			crypto_skcipher_encrypt(req);
> +		else
> +			crypto_skcipher_decrypt(req);

And you should check the return values here.

> +		skcipher_request_zero(req);
>  	} else {
>  		preempt_disable();
>  		pagefault_disable();
> -- 
> 2.9.3
> 

-- 
Regards,
Marcelo


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

  reply	other threads:[~2017-02-22 19:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-22 18:00 [PATCH 2/2] crypto: vmx - Use skcipher for xts fallback Paulo Flabiano Smorigo
2017-02-22 19:20 ` Marcelo Cerri [this message]
2017-02-22 19:20   ` Marcelo Cerri
2017-02-24 14:27   ` [PATCH v2 " Paulo Flabiano Smorigo
2017-03-01 14:00     ` [PATCH v3 " Paulo Flabiano Smorigo
2017-03-01 14:00       ` Paulo Flabiano Smorigo
2017-03-02 11:07       ` Herbert Xu
2017-03-02 11:07         ` Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170222192004.GC20626@gallifrey \
    --to=marcelo.cerri@canonical.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=paulus@samba.org \
    --cc=pfsmorigo@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.