Re: [PATCH 2/3] crypto: engine - find request type with cra_type

2017-08-18 Thread Corentin Labbe
On Fri, Aug 18, 2017 at 04:28:37PM +0800, Herbert Xu wrote:
> On Mon, Aug 14, 2017 at 03:17:24PM +0200, Corentin Labbe wrote:
> > The current method for finding request type is based on crypto_tfm_alg_type.
> > 
> > But in case of skcipher, it is the same than ablkcipher.
> > Using cra_type for this work permits to make the distinction between the 
> > two.
> > 
> > Signed-off-by: Corentin Labbe 
> 
> I think you misunderstood my suggestion.  I'm not saying that
> you should use cra_type to distinguish all crypto types, it should
> only be used to distinguish ablkcipher from skcipher.
> 

Will change that in v4

Thanks


Re: [PATCH 2/3] crypto: engine - find request type with cra_type

2017-08-18 Thread Herbert Xu
On Mon, Aug 14, 2017 at 03:17:24PM +0200, Corentin Labbe wrote:
> The current method for finding request type is based on crypto_tfm_alg_type.
> 
> But in case of skcipher, it is the same than ablkcipher.
> Using cra_type for this work permits to make the distinction between the two.
> 
> Signed-off-by: Corentin Labbe 

I think you misunderstood my suggestion.  I'm not saying that
you should use cra_type to distinguish all crypto types, it should
only be used to distinguish ablkcipher from skcipher.

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


Re: [PATCH 2/3] crypto: engine - find request type with cra_type

2017-08-16 Thread Corentin Labbe
On Tue, Aug 15, 2017 at 07:51:14AM +, Fabien DESSENNE wrote:
> Hi Corentin,
> 
> Since I have just sent a patch to add the support of "aead_request" to crypto 
> engine, I am wondering if your proposed change (checking cra_type instead of 
> crypto_tfm_alg_type) and mine are compatible.
> It looks like they are (assuming we export crypto_aead_type): can you confirm?
> BR
> 
> Fabien.
> 

Hello

My change is incompatible with yours since I remove a 
switch(crypto_tfm_alg_type) that you use.
Anyway you will need my change:) because you use ablkcipher which is obsolete 
and you need to convert to skcipher.

regards
Corentin Labbe


RE: [PATCH 2/3] crypto: engine - find request type with cra_type

2017-08-15 Thread Fabien DESSENNE
Hi Corentin,

Since I have just sent a patch to add the support of "aead_request" to crypto 
engine, I am wondering if your proposed change (checking cra_type instead of 
crypto_tfm_alg_type) and mine are compatible.
It looks like they are (assuming we export crypto_aead_type): can you confirm?
BR

Fabien.

>-Original Message-
>From: linux-crypto-ow...@vger.kernel.org [mailto:linux-crypto-
>ow...@vger.kernel.org] On Behalf Of Corentin Labbe
>Sent: lundi 14 août 2017 15:17
>To: herb...@gondor.apana.org.au; da...@davemloft.net
>Cc: linux-crypto@vger.kernel.org; linux-ker...@vger.kernel.org; Corentin Labbe
><clabbe.montj...@gmail.com>
>Subject: [PATCH 2/3] crypto: engine - find request type with cra_type
>
>The current method for finding request type is based on crypto_tfm_alg_type.
>
>But in case of skcipher, it is the same than ablkcipher.
>Using cra_type for this work permits to make the distinction between the two.
>
>Signed-off-by: Corentin Labbe <clabbe.montj...@gmail.com>
>---
> crypto/crypto_engine.c | 19 ---
> 1 file changed, 8 insertions(+), 11 deletions(-)
>
>diff --git a/crypto/crypto_engine.c b/crypto/crypto_engine.c index
>61e7c4e02fd2..74b840749074 100644
>--- a/crypto/crypto_engine.c
>+++ b/crypto/crypto_engine.c
>@@ -38,7 +38,8 @@ static void crypto_pump_requests(struct crypto_engine
>*engine,
>   struct ablkcipher_request *breq;
>   unsigned long flags;
>   bool was_busy = false;
>-  int ret, rtype;
>+  int ret;
>+  const struct crypto_type *cratype;
>
>   spin_lock_irqsave(>queue_lock, flags);
>
>@@ -94,7 +95,7 @@ static void crypto_pump_requests(struct crypto_engine
>*engine,
>
>   spin_unlock_irqrestore(>queue_lock, flags);
>
>-  rtype = crypto_tfm_alg_type(engine->cur_req->tfm);
>+  cratype = engine->cur_req->tfm->__crt_alg->cra_type;
>   /* Until here we get the request need to be encrypted successfully */
>   if (!was_busy && engine->prepare_crypt_hardware) {
>   ret = engine->prepare_crypt_hardware(engine);
>@@ -104,8 +105,7 @@ static void crypto_pump_requests(struct crypto_engine
>*engine,
>   }
>   }
>
>-  switch (rtype) {
>-  case CRYPTO_ALG_TYPE_AHASH:
>+  if (cratype == _ahash_type) {
>   hreq = ahash_request_cast(engine->cur_req);
>   if (engine->prepare_hash_request) {
>   ret = engine->prepare_hash_request(engine, hreq); @@
>-122,7 +122,7 @@ static void crypto_pump_requests(struct crypto_engine
>*engine,
>   goto req_err;
>   }
>   return;
>-  case CRYPTO_ALG_TYPE_ABLKCIPHER:
>+  } else if (cratype == _ablkcipher_type) {
>   breq = ablkcipher_request_cast(engine->cur_req);
>   if (engine->prepare_cipher_request) {
>   ret = engine->prepare_cipher_request(engine, breq);
>@@ -139,21 +139,18 @@ static void crypto_pump_requests(struct
>crypto_engine *engine,
>   goto req_err;
>   }
>   return;
>-  default:
>+  } else {
>   dev_err(engine->dev, "failed to prepare request of unknown
>type\n");
>   return;
>   }
>
> req_err:
>-  switch (rtype) {
>-  case CRYPTO_ALG_TYPE_AHASH:
>+  if (cratype == _ahash_type) {
>   hreq = ahash_request_cast(engine->cur_req);
>   crypto_finalize_hash_request(engine, hreq, ret);
>-  break;
>-  case CRYPTO_ALG_TYPE_ABLKCIPHER:
>+  } else if (cratype == _ablkcipher_type) {
>   breq = ablkcipher_request_cast(engine->cur_req);
>   crypto_finalize_cipher_request(engine, breq, ret);
>-  break;
>   }
>   return;
>
>--
>2.13.0



[PATCH 2/3] crypto: engine - find request type with cra_type

2017-08-14 Thread Corentin Labbe
The current method for finding request type is based on crypto_tfm_alg_type.

But in case of skcipher, it is the same than ablkcipher.
Using cra_type for this work permits to make the distinction between the two.

Signed-off-by: Corentin Labbe 
---
 crypto/crypto_engine.c | 19 ---
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/crypto/crypto_engine.c b/crypto/crypto_engine.c
index 61e7c4e02fd2..74b840749074 100644
--- a/crypto/crypto_engine.c
+++ b/crypto/crypto_engine.c
@@ -38,7 +38,8 @@ static void crypto_pump_requests(struct crypto_engine *engine,
struct ablkcipher_request *breq;
unsigned long flags;
bool was_busy = false;
-   int ret, rtype;
+   int ret;
+   const struct crypto_type *cratype;
 
spin_lock_irqsave(>queue_lock, flags);
 
@@ -94,7 +95,7 @@ static void crypto_pump_requests(struct crypto_engine *engine,
 
spin_unlock_irqrestore(>queue_lock, flags);
 
-   rtype = crypto_tfm_alg_type(engine->cur_req->tfm);
+   cratype = engine->cur_req->tfm->__crt_alg->cra_type;
/* Until here we get the request need to be encrypted successfully */
if (!was_busy && engine->prepare_crypt_hardware) {
ret = engine->prepare_crypt_hardware(engine);
@@ -104,8 +105,7 @@ static void crypto_pump_requests(struct crypto_engine 
*engine,
}
}
 
-   switch (rtype) {
-   case CRYPTO_ALG_TYPE_AHASH:
+   if (cratype == _ahash_type) {
hreq = ahash_request_cast(engine->cur_req);
if (engine->prepare_hash_request) {
ret = engine->prepare_hash_request(engine, hreq);
@@ -122,7 +122,7 @@ static void crypto_pump_requests(struct crypto_engine 
*engine,
goto req_err;
}
return;
-   case CRYPTO_ALG_TYPE_ABLKCIPHER:
+   } else if (cratype == _ablkcipher_type) {
breq = ablkcipher_request_cast(engine->cur_req);
if (engine->prepare_cipher_request) {
ret = engine->prepare_cipher_request(engine, breq);
@@ -139,21 +139,18 @@ static void crypto_pump_requests(struct crypto_engine 
*engine,
goto req_err;
}
return;
-   default:
+   } else {
dev_err(engine->dev, "failed to prepare request of unknown 
type\n");
return;
}
 
 req_err:
-   switch (rtype) {
-   case CRYPTO_ALG_TYPE_AHASH:
+   if (cratype == _ahash_type) {
hreq = ahash_request_cast(engine->cur_req);
crypto_finalize_hash_request(engine, hreq, ret);
-   break;
-   case CRYPTO_ALG_TYPE_ABLKCIPHER:
+   } else if (cratype == _ablkcipher_type) {
breq = ablkcipher_request_cast(engine->cur_req);
crypto_finalize_cipher_request(engine, breq, ret);
-   break;
}
return;
 
-- 
2.13.0