linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] crypto: vmx - Use skcipher for cbc fallback
@ 2017-02-22 18:00 Paulo Flabiano Smorigo
  2017-02-22 19:18 ` Marcelo Cerri
  2017-02-23 11:20 ` Herbert Xu
  0 siblings, 2 replies; 11+ messages in thread
From: Paulo Flabiano Smorigo @ 2017-02-22 18:00 UTC (permalink / raw)
  To: linux-kernel
  Cc: herbert, paulus, linux-crypto, Paulo Flabiano Smorigo,
	linuxppc-dev, davem

Signed-off-by: Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com>
---
 drivers/crypto/vmx/aes_cbc.c | 41 ++++++++++++++++++++---------------------
 1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/drivers/crypto/vmx/aes_cbc.c b/drivers/crypto/vmx/aes_cbc.c
index 94ad5c0..5aa70997 100644
--- a/drivers/crypto/vmx/aes_cbc.c
+++ b/drivers/crypto/vmx/aes_cbc.c
@@ -27,11 +27,12 @@
 #include <asm/switch_to.h>
 #include <crypto/aes.h>
 #include <crypto/scatterwalk.h>
+#include <crypto/internal/skcipher.h>
 
 #include "aesp8-ppc.h"
 
 struct p8_aes_cbc_ctx {
-	struct crypto_blkcipher *fallback;
+	struct crypto_skcipher *fallback;
 	struct aes_key enc_key;
 	struct aes_key dec_key;
 };
@@ -39,7 +40,7 @@ struct p8_aes_cbc_ctx {
 static int p8_aes_cbc_init(struct crypto_tfm *tfm)
 {
 	const char *alg;
-	struct crypto_blkcipher *fallback;
+	struct crypto_skcipher *fallback;
 	struct p8_aes_cbc_ctx *ctx = crypto_tfm_ctx(tfm);
 
 	if (!(alg = crypto_tfm_alg_name(tfm))) {
@@ -48,7 +49,7 @@ static int p8_aes_cbc_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",
@@ -58,9 +59,9 @@ static int p8_aes_cbc_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;
@@ -71,7 +72,7 @@ static void p8_aes_cbc_exit(struct crypto_tfm *tfm)
 	struct p8_aes_cbc_ctx *ctx = crypto_tfm_ctx(tfm);
 
 	if (ctx->fallback) {
-		crypto_free_blkcipher(ctx->fallback);
+		crypto_free_skcipher(ctx->fallback);
 		ctx->fallback = NULL;
 	}
 }
@@ -91,7 +92,7 @@ static int p8_aes_cbc_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;
 }
 
@@ -103,15 +104,14 @@ static int p8_aes_cbc_encrypt(struct blkcipher_desc *desc,
 	struct blkcipher_walk walk;
 	struct p8_aes_cbc_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 = crypto_blkcipher_encrypt(&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);
+		skcipher_request_zero(req);
 	} else {
 		preempt_disable();
 		pagefault_disable();
@@ -144,15 +144,14 @@ static int p8_aes_cbc_decrypt(struct blkcipher_desc *desc,
 	struct blkcipher_walk walk;
 	struct p8_aes_cbc_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 = 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_decrypt(req);
+		skcipher_request_zero(req);
 	} else {
 		preempt_disable();
 		pagefault_disable();
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/2] crypto: vmx - Use skcipher for cbc fallback
  2017-02-22 18:00 [PATCH 1/2] crypto: vmx - Use skcipher for cbc fallback Paulo Flabiano Smorigo
@ 2017-02-22 19:18 ` Marcelo Cerri
  2017-02-22 22:17   ` Marcelo Cerri
  2017-02-23 11:20 ` Herbert Xu
  1 sibling, 1 reply; 11+ messages in thread
From: Marcelo Cerri @ 2017-02-22 19:18 UTC (permalink / raw)
  To: Paulo Flabiano Smorigo
  Cc: herbert, linux-kernel, paulus, linux-crypto, linuxppc-dev, davem

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

Hi Paulo.

On Wed, Feb 22, 2017 at 03:00:15PM -0300, Paulo Flabiano Smorigo wrote:
> Signed-off-by: Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com>
> ---
>  drivers/crypto/vmx/aes_cbc.c | 41 ++++++++++++++++++++---------------------
>  1 file changed, 20 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/crypto/vmx/aes_cbc.c b/drivers/crypto/vmx/aes_cbc.c
> index 94ad5c0..5aa70997 100644
> --- a/drivers/crypto/vmx/aes_cbc.c
> +++ b/drivers/crypto/vmx/aes_cbc.c
> @@ -27,11 +27,12 @@
>  #include <asm/switch_to.h>
>  #include <crypto/aes.h>
>  #include <crypto/scatterwalk.h>
> +#include <crypto/internal/skcipher.h>

Isn't crypto/skcipher.h enough?

>  
>  #include "aesp8-ppc.h"
>  
>  struct p8_aes_cbc_ctx {
> -	struct crypto_blkcipher *fallback;
> +	struct crypto_skcipher *fallback;
>  	struct aes_key enc_key;
>  	struct aes_key dec_key;
>  };
> @@ -39,7 +40,7 @@ struct p8_aes_cbc_ctx {
>  static int p8_aes_cbc_init(struct crypto_tfm *tfm)
>  {
>  	const char *alg;
> -	struct crypto_blkcipher *fallback;
> +	struct crypto_skcipher *fallback;
>  	struct p8_aes_cbc_ctx *ctx = crypto_tfm_ctx(tfm);
>  
>  	if (!(alg = crypto_tfm_alg_name(tfm))) {
> @@ -48,7 +49,7 @@ static int p8_aes_cbc_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",
> @@ -58,9 +59,9 @@ static int p8_aes_cbc_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;
> @@ -71,7 +72,7 @@ static void p8_aes_cbc_exit(struct crypto_tfm *tfm)
>  	struct p8_aes_cbc_ctx *ctx = crypto_tfm_ctx(tfm);
>  
>  	if (ctx->fallback) {
> -		crypto_free_blkcipher(ctx->fallback);
> +		crypto_free_skcipher(ctx->fallback);
>  		ctx->fallback = NULL;
>  	}
>  }
> @@ -91,7 +92,7 @@ static int p8_aes_cbc_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;
>  }
>  
> @@ -103,15 +104,14 @@ static int p8_aes_cbc_encrypt(struct blkcipher_desc *desc,
>  	struct blkcipher_walk walk;
>  	struct p8_aes_cbc_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 = crypto_blkcipher_encrypt(&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);
> +		skcipher_request_zero(req);

Probably you have to wait for the completion here before proceeding.

Check Documentation/crypto/api-samples.rst


>  	} else {
>  		preempt_disable();
>  		pagefault_disable();
> @@ -144,15 +144,14 @@ static int p8_aes_cbc_decrypt(struct blkcipher_desc *desc,
>  	struct blkcipher_walk walk;
>  	struct p8_aes_cbc_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 = 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_decrypt(req);
> +		skcipher_request_zero(req);

Same here.


>  	} else {
>  		preempt_disable();
>  		pagefault_disable();
> -- 
> 2.9.3
> 

-- 
Regards,
Marcelo


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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/2] crypto: vmx - Use skcipher for cbc fallback
  2017-02-22 19:18 ` Marcelo Cerri
@ 2017-02-22 22:17   ` Marcelo Cerri
  2017-02-23 11:21     ` Herbert Xu
  0 siblings, 1 reply; 11+ messages in thread
From: Marcelo Cerri @ 2017-02-22 22:17 UTC (permalink / raw)
  To: herbert; +Cc: linux-crypto

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

Hi Hebert,

On Wed, Feb 22, 2017 at 04:18:19PM -0300, Marcelo Cerri wrote:
> Hi Paulo.
> 
> On Wed, Feb 22, 2017 at 03:00:15PM -0300, Paulo Flabiano Smorigo wrote:
> >  
> >  	if (in_interrupt()) {
> > -		ret = crypto_blkcipher_encrypt(&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);
> > +		skcipher_request_zero(req);
> 
> Probably you have to wait for the completion here before proceeding.
> 
> Check Documentation/crypto/api-samples.rst
> 

I noticed you used a similar approach in arch/s390/crypto/aes_s390.c
(commit 64e2680).

How do you ensure the skcipher operation will not be asynchronous? 

-- 
Regards,
Marcelo


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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/2] crypto: vmx - Use skcipher for cbc fallback
  2017-02-22 18:00 [PATCH 1/2] crypto: vmx - Use skcipher for cbc fallback Paulo Flabiano Smorigo
  2017-02-22 19:18 ` Marcelo Cerri
@ 2017-02-23 11:20 ` Herbert Xu
  2017-02-24 14:23   ` [PATCH v2 " Paulo Flabiano Smorigo
  1 sibling, 1 reply; 11+ messages in thread
From: Herbert Xu @ 2017-02-23 11:20 UTC (permalink / raw)
  To: Paulo Flabiano Smorigo
  Cc: linux-kernel, benh, paulus, mpe, davem, linux-crypto,
	linuxppc-dev, pfsmorigo

Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com> wrote:
>
>        fallback =
> -           crypto_alloc_blkcipher(alg, 0, CRYPTO_ALG_NEED_FALLBACK);
> +           crypto_alloc_skcipher(alg, 0, CRYPTO_ALG_NEED_FALLBACK);

You need to add CRYPTO_ALG_ASYNC to the mask in order to ensure
that you get a sync algorithm.

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/2] crypto: vmx - Use skcipher for cbc fallback
  2017-02-22 22:17   ` Marcelo Cerri
@ 2017-02-23 11:21     ` Herbert Xu
  2017-02-23 13:42       ` Marcelo Cerri
  0 siblings, 1 reply; 11+ messages in thread
From: Herbert Xu @ 2017-02-23 11:21 UTC (permalink / raw)
  To: Marcelo Cerri; +Cc: linux-crypto

Marcelo Cerri <marcelo.cerri@canonical.com> wrote:
>
> I noticed you used a similar approach in arch/s390/crypto/aes_s390.c
> (commit 64e2680).
> 
> How do you ensure the skcipher operation will not be asynchronous? 

You need to set the bit CRYPTO_ALG_ASYNC in the mask field when
allocating the algorithm to ensure that it's synchronous.

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/2] crypto: vmx - Use skcipher for cbc fallback
  2017-02-23 11:21     ` Herbert Xu
@ 2017-02-23 13:42       ` Marcelo Cerri
  2017-02-25 14:42         ` Herbert Xu
  0 siblings, 1 reply; 11+ messages in thread
From: Marcelo Cerri @ 2017-02-23 13:42 UTC (permalink / raw)
  To: Herbert Xu; +Cc: linux-crypto

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

It makes sense. Thanks for the clarification, Herbert.

One more question: are you planning to convert the ctr template to
skcipher?

-- 
Regards,
Marcelo

On Thu, Feb 23, 2017 at 07:21:56PM +0800, Herbert Xu wrote:
> Marcelo Cerri <marcelo.cerri@canonical.com> wrote:
> >
> > I noticed you used a similar approach in arch/s390/crypto/aes_s390.c
> > (commit 64e2680).
> > 
> > How do you ensure the skcipher operation will not be asynchronous? 
> 
> You need to set the bit CRYPTO_ALG_ASYNC in the mask field when
> allocating the algorithm to ensure that it's synchronous.
> 
> Cheers,
> -- 
> Email: Herbert Xu <herbert@gondor.apana.org.au>
> Home Page: http://gondor.apana.org.au/~herbert/
> PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2 1/2] crypto: vmx - Use skcipher for cbc fallback
  2017-02-23 11:20 ` Herbert Xu
@ 2017-02-24 14:23   ` Paulo Flabiano Smorigo
  2017-02-26 19:21     ` Marcelo Cerri
  0 siblings, 1 reply; 11+ messages in thread
From: Paulo Flabiano Smorigo @ 2017-02-24 14:23 UTC (permalink / raw)
  To: linux-kernel
  Cc: herbert, paulus, linux-crypto, Paulo Flabiano Smorigo,
	linuxppc-dev, davem

Signed-off-by: Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com>
---
 drivers/crypto/vmx/aes_cbc.c | 44 ++++++++++++++++++++++----------------------
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/drivers/crypto/vmx/aes_cbc.c b/drivers/crypto/vmx/aes_cbc.c
index 94ad5c0..2bb5910 100644
--- a/drivers/crypto/vmx/aes_cbc.c
+++ b/drivers/crypto/vmx/aes_cbc.c
@@ -27,11 +27,12 @@
 #include <asm/switch_to.h>
 #include <crypto/aes.h>
 #include <crypto/scatterwalk.h>
+#include <crypto/skcipher.h>
 
 #include "aesp8-ppc.h"
 
 struct p8_aes_cbc_ctx {
-	struct crypto_blkcipher *fallback;
+	struct crypto_skcipher *fallback;
 	struct aes_key enc_key;
 	struct aes_key dec_key;
 };
@@ -39,7 +40,7 @@ struct p8_aes_cbc_ctx {
 static int p8_aes_cbc_init(struct crypto_tfm *tfm)
 {
 	const char *alg;
-	struct crypto_blkcipher *fallback;
+	struct crypto_skcipher *fallback;
 	struct p8_aes_cbc_ctx *ctx = crypto_tfm_ctx(tfm);
 
 	if (!(alg = crypto_tfm_alg_name(tfm))) {
@@ -47,8 +48,9 @@ static int p8_aes_cbc_init(struct crypto_tfm *tfm)
 		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",
@@ -58,9 +60,9 @@ static int p8_aes_cbc_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;
@@ -71,7 +73,7 @@ static void p8_aes_cbc_exit(struct crypto_tfm *tfm)
 	struct p8_aes_cbc_ctx *ctx = crypto_tfm_ctx(tfm);
 
 	if (ctx->fallback) {
-		crypto_free_blkcipher(ctx->fallback);
+		crypto_free_skcipher(ctx->fallback);
 		ctx->fallback = NULL;
 	}
 }
@@ -91,7 +93,7 @@ static int p8_aes_cbc_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;
 }
 
@@ -103,15 +105,14 @@ static int p8_aes_cbc_encrypt(struct blkcipher_desc *desc,
 	struct blkcipher_walk walk;
 	struct p8_aes_cbc_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 = crypto_blkcipher_encrypt(&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);
+		skcipher_request_zero(req);
 	} else {
 		preempt_disable();
 		pagefault_disable();
@@ -144,15 +145,14 @@ static int p8_aes_cbc_decrypt(struct blkcipher_desc *desc,
 	struct blkcipher_walk walk;
 	struct p8_aes_cbc_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 = 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_decrypt(req);
+		skcipher_request_zero(req);
 	} else {
 		preempt_disable();
 		pagefault_disable();
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/2] crypto: vmx - Use skcipher for cbc fallback
  2017-02-23 13:42       ` Marcelo Cerri
@ 2017-02-25 14:42         ` Herbert Xu
  0 siblings, 0 replies; 11+ messages in thread
From: Herbert Xu @ 2017-02-25 14:42 UTC (permalink / raw)
  To: Marcelo Cerri; +Cc: linux-crypto

On Thu, Feb 23, 2017 at 10:42:04AM -0300, Marcelo Cerri wrote:
> It makes sense. Thanks for the clarification, Herbert.
> 
> One more question: are you planning to convert the ctr template to
> skcipher?

Yes everything will be converted.

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 1/2] crypto: vmx - Use skcipher for cbc fallback
  2017-02-24 14:23   ` [PATCH v2 " Paulo Flabiano Smorigo
@ 2017-02-26 19:21     ` Marcelo Cerri
  2017-03-01 13:58       ` [PATCH v3 " Paulo Flabiano Smorigo
  0 siblings, 1 reply; 11+ messages in thread
From: Marcelo Cerri @ 2017-02-26 19:21 UTC (permalink / raw)
  To: Paulo Flabiano Smorigo
  Cc: linux-kernel, benh, paulus, mpe, herbert, davem, linux-crypto,
	linuxppc-dev

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

On Fri, Feb 24, 2017 at 11:23:54AM -0300, Paulo Flabiano Smorigo wrote:
> Signed-off-by: Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com>
> ---
>  drivers/crypto/vmx/aes_cbc.c | 44 ++++++++++++++++++++++----------------------
>  1 file changed, 22 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/crypto/vmx/aes_cbc.c b/drivers/crypto/vmx/aes_cbc.c
> index 94ad5c0..2bb5910 100644
> --- a/drivers/crypto/vmx/aes_cbc.c
> +++ b/drivers/crypto/vmx/aes_cbc.c
> @@ -27,11 +27,12 @@
>  #include <asm/switch_to.h>
>  #include <crypto/aes.h>
>  #include <crypto/scatterwalk.h>
> +#include <crypto/skcipher.h>
>  
>  #include "aesp8-ppc.h"
>  
>  struct p8_aes_cbc_ctx {
> -	struct crypto_blkcipher *fallback;
> +	struct crypto_skcipher *fallback;
>  	struct aes_key enc_key;
>  	struct aes_key dec_key;
>  };
> @@ -39,7 +40,7 @@ struct p8_aes_cbc_ctx {
>  static int p8_aes_cbc_init(struct crypto_tfm *tfm)
>  {
>  	const char *alg;
> -	struct crypto_blkcipher *fallback;
> +	struct crypto_skcipher *fallback;
>  	struct p8_aes_cbc_ctx *ctx = crypto_tfm_ctx(tfm);
>  
>  	if (!(alg = crypto_tfm_alg_name(tfm))) {
> @@ -47,8 +48,9 @@ static int p8_aes_cbc_init(struct crypto_tfm *tfm)
>  		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",
> @@ -58,9 +60,9 @@ static int p8_aes_cbc_init(struct crypto_tfm *tfm)
>  	printk(KERN_INFO "Using '%s' as fallback implementation.\n",
>  	       crypto_tfm_alg_driver_name((struct crypto_tfm *) fallback));

You need to update that to use crypto_skcipher_tfm(). The same is valid
for the xts patch.

>  
> -	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;
> @@ -71,7 +73,7 @@ static void p8_aes_cbc_exit(struct crypto_tfm *tfm)
>  	struct p8_aes_cbc_ctx *ctx = crypto_tfm_ctx(tfm);
>  
>  	if (ctx->fallback) {
> -		crypto_free_blkcipher(ctx->fallback);
> +		crypto_free_skcipher(ctx->fallback);
>  		ctx->fallback = NULL;
>  	}
>  }
> @@ -91,7 +93,7 @@ static int p8_aes_cbc_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;
>  }
>  
> @@ -103,15 +105,14 @@ static int p8_aes_cbc_encrypt(struct blkcipher_desc *desc,
>  	struct blkcipher_walk walk;
>  	struct p8_aes_cbc_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 = crypto_blkcipher_encrypt(&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);
> +		skcipher_request_zero(req);
>  	} else {
>  		preempt_disable();
>  		pagefault_disable();
> @@ -144,15 +145,14 @@ static int p8_aes_cbc_decrypt(struct blkcipher_desc *desc,
>  	struct blkcipher_walk walk;
>  	struct p8_aes_cbc_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 = 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_decrypt(req);
> +		skcipher_request_zero(req);
>  	} else {
>  		preempt_disable();
>  		pagefault_disable();
> -- 
> 2.7.4
> 

-- 
Regards,
Marcelo


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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v3 1/2] crypto: vmx - Use skcipher for cbc fallback
  2017-02-26 19:21     ` Marcelo Cerri
@ 2017-03-01 13:58       ` Paulo Flabiano Smorigo
  2017-03-02 11:07         ` Herbert Xu
  0 siblings, 1 reply; 11+ messages in thread
From: Paulo Flabiano Smorigo @ 2017-03-01 13:58 UTC (permalink / raw)
  To: linux-kernel
  Cc: benh, paulus, mpe, herbert, davem, linux-crypto, linuxppc-dev,
	Paulo Flabiano Smorigo

Signed-off-by: Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com>
---
 drivers/crypto/vmx/aes_cbc.c | 47 ++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 23 deletions(-)

diff --git a/drivers/crypto/vmx/aes_cbc.c b/drivers/crypto/vmx/aes_cbc.c
index 94ad5c0..72a26eb 100644
--- a/drivers/crypto/vmx/aes_cbc.c
+++ b/drivers/crypto/vmx/aes_cbc.c
@@ -27,11 +27,12 @@
 #include <asm/switch_to.h>
 #include <crypto/aes.h>
 #include <crypto/scatterwalk.h>
+#include <crypto/skcipher.h>
 
 #include "aesp8-ppc.h"
 
 struct p8_aes_cbc_ctx {
-	struct crypto_blkcipher *fallback;
+	struct crypto_skcipher *fallback;
 	struct aes_key enc_key;
 	struct aes_key dec_key;
 };
@@ -39,7 +40,7 @@ struct p8_aes_cbc_ctx {
 static int p8_aes_cbc_init(struct crypto_tfm *tfm)
 {
 	const char *alg;
-	struct crypto_blkcipher *fallback;
+	struct crypto_skcipher *fallback;
 	struct p8_aes_cbc_ctx *ctx = crypto_tfm_ctx(tfm);
 
 	if (!(alg = crypto_tfm_alg_name(tfm))) {
@@ -47,8 +48,9 @@ static int p8_aes_cbc_init(struct crypto_tfm *tfm)
 		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",
@@ -56,11 +58,12 @@ static int p8_aes_cbc_init(struct crypto_tfm *tfm)
 		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;
@@ -71,7 +74,7 @@ static void p8_aes_cbc_exit(struct crypto_tfm *tfm)
 	struct p8_aes_cbc_ctx *ctx = crypto_tfm_ctx(tfm);
 
 	if (ctx->fallback) {
-		crypto_free_blkcipher(ctx->fallback);
+		crypto_free_skcipher(ctx->fallback);
 		ctx->fallback = NULL;
 	}
 }
@@ -91,7 +94,7 @@ static int p8_aes_cbc_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;
 }
 
@@ -103,15 +106,14 @@ static int p8_aes_cbc_encrypt(struct blkcipher_desc *desc,
 	struct blkcipher_walk walk;
 	struct p8_aes_cbc_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 = crypto_blkcipher_encrypt(&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);
+		skcipher_request_zero(req);
 	} else {
 		preempt_disable();
 		pagefault_disable();
@@ -144,15 +146,14 @@ static int p8_aes_cbc_decrypt(struct blkcipher_desc *desc,
 	struct blkcipher_walk walk;
 	struct p8_aes_cbc_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 = 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_decrypt(req);
+		skcipher_request_zero(req);
 	} else {
 		preempt_disable();
 		pagefault_disable();
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 1/2] crypto: vmx - Use skcipher for cbc fallback
  2017-03-01 13:58       ` [PATCH v3 " Paulo Flabiano Smorigo
@ 2017-03-02 11:07         ` Herbert Xu
  0 siblings, 0 replies; 11+ messages in thread
From: Herbert Xu @ 2017-03-02 11:07 UTC (permalink / raw)
  To: Paulo Flabiano Smorigo
  Cc: linux-kernel, paulus, linux-crypto, linuxppc-dev, davem

On Wed, Mar 01, 2017 at 10:58:20AM -0300, Paulo Flabiano Smorigo wrote:
> Signed-off-by: Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com>
> ---

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-03-02 11:07 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-22 18:00 [PATCH 1/2] crypto: vmx - Use skcipher for cbc fallback Paulo Flabiano Smorigo
2017-02-22 19:18 ` Marcelo Cerri
2017-02-22 22:17   ` Marcelo Cerri
2017-02-23 11:21     ` Herbert Xu
2017-02-23 13:42       ` Marcelo Cerri
2017-02-25 14:42         ` Herbert Xu
2017-02-23 11:20 ` Herbert Xu
2017-02-24 14:23   ` [PATCH v2 " Paulo Flabiano Smorigo
2017-02-26 19:21     ` Marcelo Cerri
2017-03-01 13:58       ` [PATCH v3 " Paulo Flabiano Smorigo
2017-03-02 11:07         ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).